Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Implement unscopables for Array.prototype #1963

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions boa_engine/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ impl BuiltIn for Array {
let _timer = Profiler::global().start_event(Self::NAME, "init");

let symbol_iterator = WellKnownSymbols::iterator();
let symbol_unscopables = WellKnownSymbols::unscopables();

let get_species = FunctionBuilder::native(context, Self::get_species)
.name("get [Symbol.species]")
.constructor(false)
.build();

let values_function = Self::values_intrinsic(context);
let unscopables_object = Self::unscopables_intrinsic(context);

ConstructorBuilder::with_standard_constructor(
context,
Expand Down Expand Up @@ -81,6 +83,11 @@ impl BuiltIn for Array {
values_function,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.property(
symbol_unscopables,
unscopables_object,
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.method(Self::at, "at", 1)
.method(Self::concat, "concat", 1)
.method(Self::push, "push", 1)
Expand Down Expand Up @@ -2855,4 +2862,44 @@ impl Array {
.constructor(false)
.build()
}

pub(crate) fn unscopables_intrinsic(context: &mut Context) -> JsObject {
let object_prototype = context.construct_object();
let result_obj = JsObject::from_proto_and_data(object_prototype, ObjectData::ordinary());
NorbertGarfield marked this conversation as resolved.
Show resolved Hide resolved
result_obj
.create_data_property_or_throw("at", true, context)
.expect("CreateDataPropertyOrThrow for 'at' must not fail");
result_obj
.create_data_property_or_throw("copyWithin", true, context)
.expect("CreateDataPropertyOrThrow for 'copyWithin' must not fail");
result_obj
.create_data_property_or_throw("entries", true, context)
.expect("CreateDataPropertyOrThrow for 'entries' must not fail");
result_obj
.create_data_property_or_throw("fill", true, context)
.expect("CreateDataPropertyOrThrow for 'fill' must not fail");
result_obj
.create_data_property_or_throw("find", true, context)
.expect("CreateDataPropertyOrThrow for 'find' must not fail");
result_obj
.create_data_property_or_throw("findIndex", true, context)
.expect("CreateDataPropertyOrThrow for 'findIndex' must not fail");
result_obj
.create_data_property_or_throw("flat", true, context)
.expect("CreateDataPropertyOrThrow for 'flat' must not fail");
result_obj
.create_data_property_or_throw("flatMap", true, context)
.expect("CreateDataPropertyOrThrow for 'flatMap' must not fail");
result_obj
.create_data_property_or_throw("includes", true, context)
.expect("CreateDataPropertyOrThrow for 'includes' must not fail");
result_obj
.create_data_property_or_throw("keys", true, context)
.expect("CreateDataPropertyOrThrow for 'keys' must not fail");
result_obj
.create_data_property_or_throw("values", true, context)
.expect("CreateDataPropertyOrThrow for 'values' must not fail");

result_obj
}
}