Skip to content

Commit

Permalink
Apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed May 17, 2023
1 parent a835cde commit 69d0171
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ use crate::{

use super::{InternalObjectMethods, ORDINARY_INTERNAL_METHODS};

/// Definitions of the internal object methods for [**Module Namespace Exotic Objects**][spec].
/// Definitions of the internal object methods for [**Immutable Prototype Exotic Objects**][spec].
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects
/// [spec]: https://tc39.es/ecma262/#sec-immutable-prototype-exotic-objects
pub(crate) static IMMUTABLE_PROTOTYPE_EXOTIC_INTERNAL_METHODS: InternalObjectMethods =
InternalObjectMethods {
__set_prototype_of__: set_prototype_of,
__set_prototype_of__: immutable_prototype_exotic_set_prototype_of,
..ORDINARY_INTERNAL_METHODS
};

/// [`[[SetPrototypeOf]] ( V )`][spec].
///
/// [spec]: https://tc39.es/ecma262/#sec-immutable-prototype-exotic-objects-setprototypeof-v
#[allow(clippy::needless_pass_by_value)]
pub(crate) fn set_prototype_of(
pub(crate) fn immutable_prototype_exotic_set_prototype_of(
obj: &JsObject,
val: JsPrototype,
context: &mut Context<'_>,
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/object/internal_methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub(super) mod arguments;
pub(super) mod array;
pub(super) mod bound_function;
pub(super) mod function;
pub(super) mod immutable;
pub(super) mod immutable_prototype;
pub(super) mod integer_indexed;
pub(super) mod namespace;
pub(super) mod module_namespace;
pub(super) mod proxy;
pub(super) mod string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};

use super::{
immutable, ordinary_define_own_property, ordinary_delete, ordinary_get,
immutable_prototype, ordinary_define_own_property, ordinary_delete, ordinary_get,
ordinary_get_own_property, ordinary_has_property, ordinary_own_property_keys,
InternalObjectMethods, ORDINARY_INTERNAL_METHODS,
};
Expand All @@ -18,25 +18,28 @@ use super::{
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects
pub(crate) static MODULE_NAMESPACE_EXOTIC_INTERNAL_METHODS: InternalObjectMethods =
InternalObjectMethods {
__get_prototype_of__: get_prototype_of,
__set_prototype_of__: set_prototype_of,
__is_extensible__: is_extensible,
__prevent_extensions__: prevent_extensions,
__get_own_property__: get_own_property,
__define_own_property__: define_own_property,
__has_property__: has_property,
__get__: get,
__set__: set,
__delete__: delete,
__own_property_keys__: own_property_keys,
__get_prototype_of__: module_namespace_exotic_get_prototype_of,
__set_prototype_of__: module_namespace_exotic_set_prototype_of,
__is_extensible__: module_namespace_exotic_is_extensible,
__prevent_extensions__: module_namespace_exotic_prevent_extensions,
__get_own_property__: module_namespace_exotic_get_own_property,
__define_own_property__: module_namespace_exotic_define_own_property,
__has_property__: module_namespace_exotic_has_property,
__get__: module_namespace_exotic_get,
__set__: module_namespace_exotic_set,
__delete__: module_namespace_exotic_delete,
__own_property_keys__: module_namespace_exotic_own_property_keys,
..ORDINARY_INTERNAL_METHODS
};

/// [`[[GetPrototypeOf]] ( )`][spec].
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-getprototypeof
#[allow(clippy::unnecessary_wraps)]
fn get_prototype_of(_: &JsObject, _: &mut Context<'_>) -> JsResult<JsPrototype> {
fn module_namespace_exotic_get_prototype_of(
_: &JsObject,
_: &mut Context<'_>,
) -> JsResult<JsPrototype> {
// 1. Return null.
Ok(None)
}
Expand All @@ -45,16 +48,23 @@ fn get_prototype_of(_: &JsObject, _: &mut Context<'_>) -> JsResult<JsPrototype>
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-setprototypeof-v
#[allow(clippy::unnecessary_wraps)]
fn set_prototype_of(obj: &JsObject, val: JsPrototype, context: &mut Context<'_>) -> JsResult<bool> {
fn module_namespace_exotic_set_prototype_of(
obj: &JsObject,
val: JsPrototype,
context: &mut Context<'_>,
) -> JsResult<bool> {
// 1. Return ! SetImmutablePrototype(O, V).
Ok(immutable::set_prototype_of(obj, val, context).expect("this must not fail per the spec"))
Ok(
immutable_prototype::immutable_prototype_exotic_set_prototype_of(obj, val, context)
.expect("this must not fail per the spec"),
)
}

/// [`[[IsExtensible]] ( )`][spec].
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-isextensible
#[allow(clippy::unnecessary_wraps)]
fn is_extensible(_: &JsObject, _: &mut Context<'_>) -> JsResult<bool> {
fn module_namespace_exotic_is_extensible(_: &JsObject, _: &mut Context<'_>) -> JsResult<bool> {
// 1. Return false.
Ok(false)
}
Expand All @@ -63,14 +73,14 @@ fn is_extensible(_: &JsObject, _: &mut Context<'_>) -> JsResult<bool> {
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-preventextensions
#[allow(clippy::unnecessary_wraps)]
fn prevent_extensions(_: &JsObject, _: &mut Context<'_>) -> JsResult<bool> {
fn module_namespace_exotic_prevent_extensions(_: &JsObject, _: &mut Context<'_>) -> JsResult<bool> {
Ok(true)
}

/// [`[[GetOwnProperty]] ( P )`][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-getownproperty-p
fn get_own_property(
fn module_namespace_exotic_get_own_property(
obj: &JsObject,
key: &PropertyKey,
context: &mut Context<'_>,
Expand Down Expand Up @@ -113,7 +123,7 @@ fn get_own_property(
/// [`[[DefineOwnProperty]] ( P, Desc )`][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-defineownproperty-p-desc
fn define_own_property(
fn module_namespace_exotic_define_own_property(
obj: &JsObject,
key: &PropertyKey,
desc: PropertyDescriptor,
Expand Down Expand Up @@ -150,7 +160,11 @@ fn define_own_property(
/// [`[[HasProperty]] ( P )`][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-hasproperty-p
fn has_property(obj: &JsObject, key: &PropertyKey, context: &mut Context<'_>) -> JsResult<bool> {
fn module_namespace_exotic_has_property(
obj: &JsObject,
key: &PropertyKey,
context: &mut Context<'_>,
) -> JsResult<bool> {
// 1. If P is a Symbol, return ! OrdinaryHasProperty(O, P).
let key = match key {
PropertyKey::Symbol(_) => return ordinary_has_property(obj, key, context),
Expand All @@ -174,7 +188,7 @@ fn has_property(obj: &JsObject, key: &PropertyKey, context: &mut Context<'_>) ->
/// [`[[Get]] ( P, Receiver )`][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-get-p-receiver
fn get(
fn module_namespace_exotic_get(
obj: &JsObject,
key: &PropertyKey,
receiver: JsValue,
Expand Down Expand Up @@ -248,7 +262,7 @@ fn get(
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-set-p-v-receiver
#[allow(clippy::needless_pass_by_value, clippy::unnecessary_wraps)]
fn set(
fn module_namespace_exotic_set(
_obj: &JsObject,
_key: PropertyKey,
_value: JsValue,
Expand All @@ -262,7 +276,11 @@ fn set(
/// [`[[Delete]] ( P )`][spec].
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-delete-p
fn delete(obj: &JsObject, key: &PropertyKey, context: &mut Context<'_>) -> JsResult<bool> {
fn module_namespace_exotic_delete(
obj: &JsObject,
key: &PropertyKey,
context: &mut Context<'_>,
) -> JsResult<bool> {
// 1. If P is a Symbol, then
// a. Return ! OrdinaryDelete(O, P).
let key = match key {
Expand All @@ -287,7 +305,10 @@ fn delete(obj: &JsObject, key: &PropertyKey, context: &mut Context<'_>) -> JsRes
/// [`[[OwnPropertyKeys]] ( )`][spec].
///
/// [spec]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-ownpropertykeys
fn own_property_keys(obj: &JsObject, context: &mut Context<'_>) -> JsResult<Vec<PropertyKey>> {
fn module_namespace_exotic_own_property_keys(
obj: &JsObject,
context: &mut Context<'_>,
) -> JsResult<Vec<PropertyKey>> {
// 2. Let symbolKeys be OrdinaryOwnPropertyKeys(O).
let symbol_keys = ordinary_own_property_keys(obj, context)?;

Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use self::{
BOUND_CONSTRUCTOR_EXOTIC_INTERNAL_METHODS, BOUND_FUNCTION_EXOTIC_INTERNAL_METHODS,
},
function::{CONSTRUCTOR_INTERNAL_METHODS, FUNCTION_INTERNAL_METHODS},
immutable::IMMUTABLE_PROTOTYPE_EXOTIC_INTERNAL_METHODS,
immutable_prototype::IMMUTABLE_PROTOTYPE_EXOTIC_INTERNAL_METHODS,
integer_indexed::INTEGER_INDEXED_EXOTIC_INTERNAL_METHODS,
namespace::MODULE_NAMESPACE_EXOTIC_INTERNAL_METHODS,
module_namespace::MODULE_NAMESPACE_EXOTIC_INTERNAL_METHODS,
proxy::{
PROXY_EXOTIC_INTERNAL_METHODS_ALL, PROXY_EXOTIC_INTERNAL_METHODS_BASIC,
PROXY_EXOTIC_INTERNAL_METHODS_WITH_CALL,
Expand Down
2 changes: 2 additions & 0 deletions boa_interner/src/sym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct Sym {
value: NonZeroUsize,
}

// SAFETY: `NonZeroUsize` is a constrained `usize`, and all primitive types don't need to be traced
// by the garbage collector.
unsafe impl Trace for Sym {
empty_trace!();
}
Expand Down

0 comments on commit 69d0171

Please sign in to comment.