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] - Fast path for static property keys #2604

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
62 changes: 31 additions & 31 deletions boa_engine/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ impl IntrinsicObject for Array {
Attribute::CONFIGURABLE,
)
.property(
"length",
utf16!("length"),
0,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::PERMANENT,
)
.property(
"values",
utf16!("values"),
values_function.clone(),
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
Expand Down Expand Up @@ -191,7 +191,7 @@ impl BuiltInConstructor for Array {
};
// e. Perform ! Set(array, "length", intLen, true).
array
.set("length", int_len, true, context)
.set(utf16!("length"), int_len, true, context)
.expect("this Set call must not fail");
// f. Return array.
Ok(array.into())
Expand Down Expand Up @@ -250,7 +250,7 @@ impl Array {
// 6. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
crate::object::internal_methods::ordinary_define_own_property(
&array,
"length".into(),
&utf16!("length").into(),
PropertyDescriptor::builder()
.value(length)
.writable(true)
Expand Down Expand Up @@ -291,7 +291,7 @@ impl Array {
.properties_mut()
.override_indexed_properties(elements);
array
.set("length", length, true, context)
.set(utf16!("length"), length, true, context)
.expect("Should not fail");

// 5. Return array.
Expand Down Expand Up @@ -475,7 +475,7 @@ impl Array {
}

// 13. Perform ? Set(A, "length", 𝔽(len), true).
a.set("length", len, true, context)?;
a.set(utf16!("length"), len, true, context)?;

// 14. Return A.
return Ok(a.into());
Expand Down Expand Up @@ -508,7 +508,7 @@ impl Array {
// iv. If next is false, then
let Some(next) = next else {
// 1. Perform ? Set(A, "length", 𝔽(k), true).
a.set("length", k, true, context)?;
a.set(utf16!("length"), k, true, context)?;

// 2. Return A.
return Ok(a.into());
Expand Down Expand Up @@ -609,7 +609,7 @@ impl Array {
}

// 8. Perform ? Set(A, "length", lenNumber, true).
a.set("length", len, true, context)?;
a.set(utf16!("length"), len, true, context)?;

// 9. Return A.
Ok(a.into())
Expand Down Expand Up @@ -733,7 +733,7 @@ impl Array {
}
}
// 6. Perform ? Set(A, "length", 𝔽(n), true).
arr.set("length", n, true, context)?;
arr.set(utf16!("length"), n, true, context)?;

// 7. Return A.
Ok(JsValue::new(arr))
Expand Down Expand Up @@ -778,7 +778,7 @@ impl Array {
len += 1;
}
// 6. Perform ? Set(O, "length", 𝔽(len), true).
o.set("length", len, true, context)?;
o.set(utf16!("length"), len, true, context)?;
// 7. Return 𝔽(len).
Ok(len.into())
}
Expand All @@ -805,7 +805,7 @@ impl Array {
// 3. If len = 0, then
if len == 0 {
// a. Perform ? Set(O, "length", +0𝔽, true).
o.set("length", 0, true, context)?;
o.set(utf16!("length"), 0, true, context)?;
// b. Return undefined.
Ok(JsValue::undefined())
// 4. Else,
Expand All @@ -820,7 +820,7 @@ impl Array {
// e. Perform ? DeletePropertyOrThrow(O, index).
o.delete_property_or_throw(index, context)?;
// f. Perform ? Set(O, "length", newLen, true).
o.set("length", new_len, true, context)?;
o.set(utf16!("length"), new_len, true, context)?;
// g. Return element.
Ok(element)
}
Expand Down Expand Up @@ -946,7 +946,7 @@ impl Array {
// 1. Let array be ? ToObject(this value).
let array = this.to_object(context)?;
// 2. Let func be ? Get(array, "join").
let func = array.get("join", context)?;
let func = array.get(utf16!("join"), context)?;
// 3. If IsCallable(func) is false, set func to the intrinsic function %Object.prototype.toString%.
// 4. Return ? Call(func, array).
if let Some(func) = func.as_callable() {
Expand Down Expand Up @@ -1061,7 +1061,7 @@ impl Array {
// 3. If len = 0, then
if len == 0 {
// a. Perform ? Set(O, "length", +0𝔽, true).
o.set("length", 0, true, context)?;
o.set(utf16!("length"), 0, true, context)?;
// b. Return undefined.
return Ok(JsValue::undefined());
}
Expand Down Expand Up @@ -1093,7 +1093,7 @@ impl Array {
// 7. Perform ? DeletePropertyOrThrow(O, ! ToString(𝔽(len - 1))).
o.delete_property_or_throw(len - 1, context)?;
// 8. Perform ? Set(O, "length", 𝔽(len - 1), true).
o.set("length", len - 1, true, context)?;
o.set(utf16!("length"), len - 1, true, context)?;
// 9. Return first.
Ok(first)
}
Expand Down Expand Up @@ -1163,7 +1163,7 @@ impl Array {
}
}
// 5. Perform ? Set(O, "length", 𝔽(len + argCount), true).
o.set("length", len + arg_count, true, context)?;
o.set(utf16!("length"), len + arg_count, true, context)?;
// 6. Return 𝔽(len + argCount).
Ok((len + arg_count).into())
}
Expand Down Expand Up @@ -2042,7 +2042,7 @@ impl Array {
}

// 15. Perform ? Set(A, "length", 𝔽(n), true).
a.set("length", n, true, context)?;
a.set(utf16!("length"), n, true, context)?;

// 16. Return A.
Ok(a.into())
Expand Down Expand Up @@ -2102,7 +2102,7 @@ impl Array {
if !next.is_null_or_undefined() {
// i. Let S be ? ToString(? Invoke(nextElement, "toLocaleString", « locales, options »)).
let s = next
.invoke("toLocaleString", args, context)?
.invoke(utf16!("toLocaleString"), args, context)?
.to_string(context)?;

// ii. Set R to the string-concatenation of R and S.
Expand Down Expand Up @@ -2197,7 +2197,7 @@ impl Array {
}

// 14. Perform ? Set(A, "length", 𝔽(actualDeleteCount), true).
arr.set("length", actual_delete_count, true, context)?;
arr.set(utf16!("length"), actual_delete_count, true, context)?;

// 15. Let itemCount be the number of elements in items.
let item_count = items.len() as u64;
Expand Down Expand Up @@ -2283,7 +2283,7 @@ impl Array {

// 20. Perform ? Set(O, "length", 𝔽(len - actualDeleteCount + itemCount), true).
o.set(
"length",
utf16!("length"),
len - actual_delete_count + item_count,
true,
context,
Expand Down Expand Up @@ -2980,27 +2980,27 @@ impl Array {
{
let mut obj = unscopable_list.borrow_mut();
// 2. Perform ! CreateDataPropertyOrThrow(unscopableList, "at", true).
obj.insert("at", true_prop.clone());
obj.insert(utf16!("at"), true_prop.clone());
// 3. Perform ! CreateDataPropertyOrThrow(unscopableList, "copyWithin", true).
obj.insert("copyWithin", true_prop.clone());
obj.insert(utf16!("copyWithin"), true_prop.clone());
// 4. Perform ! CreateDataPropertyOrThrow(unscopableList, "entries", true).
obj.insert("entries", true_prop.clone());
obj.insert(utf16!("entries"), true_prop.clone());
// 5. Perform ! CreateDataPropertyOrThrow(unscopableList, "fill", true).
obj.insert("fill", true_prop.clone());
obj.insert(utf16!("fill"), true_prop.clone());
// 6. Perform ! CreateDataPropertyOrThrow(unscopableList, "find", true).
obj.insert("find", true_prop.clone());
obj.insert(utf16!("find"), true_prop.clone());
// 7. Perform ! CreateDataPropertyOrThrow(unscopableList, "findIndex", true).
obj.insert("findIndex", true_prop.clone());
obj.insert(utf16!("findIndex"), true_prop.clone());
// 8. Perform ! CreateDataPropertyOrThrow(unscopableList, "flat", true).
obj.insert("flat", true_prop.clone());
obj.insert(utf16!("flat"), true_prop.clone());
// 9. Perform ! CreateDataPropertyOrThrow(unscopableList, "flatMap", true).
obj.insert("flatMap", true_prop.clone());
obj.insert(utf16!("flatMap"), true_prop.clone());
// 10. Perform ! CreateDataPropertyOrThrow(unscopableList, "includes", true).
obj.insert("includes", true_prop.clone());
obj.insert(utf16!("includes"), true_prop.clone());
// 11. Perform ! CreateDataPropertyOrThrow(unscopableList, "keys", true).
obj.insert("keys", true_prop.clone());
obj.insert(utf16!("keys"), true_prop.clone());
// 12. Perform ! CreateDataPropertyOrThrow(unscopableList, "values", true).
obj.insert("values", true_prop);
obj.insert(utf16!("values"), true_prop);
}

// 13. Return unscopableList.
Expand Down
8 changes: 7 additions & 1 deletion boa_engine/src/builtins/array_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
error::JsNativeError,
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::Attribute,
string::utf16,
symbol::JsSymbol,
value::{IntegerOrInfinity, Numeric},
Context, JsArgs, JsResult, JsValue,
Expand Down Expand Up @@ -62,7 +63,12 @@ impl IntrinsicObject for ArrayBuffer {
.build();

BuiltInBuilder::from_standard_constructor::<Self>(intrinsics)
.accessor("byteLength", Some(get_byte_length), None, flag_attributes)
.accessor(
utf16!("byteLength"),
Some(get_byte_length),
None,
flag_attributes,
)
.static_accessor(
JsSymbol::species(),
Some(get_species),
Expand Down
17 changes: 14 additions & 3 deletions boa_engine/src/builtins/dataview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
error::JsNativeError,
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::Attribute,
string::utf16,
symbol::JsSymbol,
value::JsValue,
Context, JsArgs, JsResult,
Expand Down Expand Up @@ -49,9 +50,19 @@ impl IntrinsicObject for DataView {
.build();

BuiltInBuilder::from_standard_constructor::<Self>(intrinsics)
.accessor("buffer", Some(get_buffer), None, flag_attributes)
.accessor("byteLength", Some(get_byte_length), None, flag_attributes)
.accessor("byteOffset", Some(get_byte_offset), None, flag_attributes)
.accessor(utf16!("buffer"), Some(get_buffer), None, flag_attributes)
.accessor(
utf16!("byteLength"),
Some(get_byte_length),
None,
flag_attributes,
)
.accessor(
utf16!("byteOffset"),
Some(get_byte_offset),
None,
flag_attributes,
)
.method(Self::get_big_int64, "getBigInt64", 1)
.method(Self::get_big_uint64, "getBigUint64", 1)
.method(Self::get_float32, "getFloat32", 1)
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ impl Date {
}

// 4. Return ? Invoke(O, "toISOString").
let func = o.get("toISOString", context)?;
let func = o.get(utf16!("toISOString"), context)?;
func.call(this, &[], context)
}

Expand Down
9 changes: 5 additions & 4 deletions boa_engine/src/builtins/error/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::{Attribute, PropertyDescriptorBuilder},
string::utf16,
Context, JsArgs, JsResult, JsValue,
};
use boa_profiler::Profiler;
Expand All @@ -32,8 +33,8 @@ impl IntrinsicObject for AggregateError {
BuiltInBuilder::from_standard_constructor::<Self>(intrinsics)
.prototype(intrinsics.constructors().error().constructor())
.inherits(Some(intrinsics.constructors().error().prototype()))
.property("name", Self::NAME, attribute)
.property("message", "", attribute)
.property(utf16!("name"), Self::NAME, attribute)
.property(utf16!("message"), "", attribute)
.build();
}

Expand Down Expand Up @@ -74,7 +75,7 @@ impl BuiltInConstructor for AggregateError {
let msg = message.to_string(context)?;

// b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg).
o.create_non_enumerable_data_property_or_throw("message", msg, context);
o.create_non_enumerable_data_property_or_throw(utf16!("message"), msg, context);
}

// 4. Perform ? InstallErrorCause(O, options).
Expand All @@ -91,7 +92,7 @@ impl BuiltInConstructor for AggregateError {
// [[Value]]: CreateArrayFromList(errorsList)
// }).
o.define_property_or_throw(
"errors",
utf16!("errors"),
PropertyDescriptorBuilder::new()
.configurable(true)
.enumerable(false)
Expand Down
7 changes: 4 additions & 3 deletions boa_engine/src/builtins/error/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::Attribute,
string::utf16,
Context, JsArgs, JsResult, JsValue,
};
use boa_profiler::Profiler;
Expand All @@ -34,8 +35,8 @@ impl IntrinsicObject for EvalError {
BuiltInBuilder::from_standard_constructor::<Self>(intrinsics)
.prototype(intrinsics.constructors().error().constructor())
.inherits(Some(intrinsics.constructors().error().prototype()))
.property("name", Self::NAME, attribute)
.property("message", "", attribute)
.property(utf16!("name"), Self::NAME, attribute)
.property(utf16!("message"), "", attribute)
.build();
}

Expand Down Expand Up @@ -73,7 +74,7 @@ impl BuiltInConstructor for EvalError {
let msg = message.to_string(context)?;

// b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg).
o.create_non_enumerable_data_property_or_throw("message", msg, context);
o.create_non_enumerable_data_property_or_throw(utf16!("message"), msg, context);
}

// 4. Perform ? InstallErrorCause(O, options).
Expand Down
12 changes: 6 additions & 6 deletions boa_engine/src/builtins/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ impl IntrinsicObject for Error {

let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
BuiltInBuilder::from_standard_constructor::<Self>(intrinsics)
.property("name", Self::NAME, attribute)
.property("message", "", attribute)
.property(utf16!("name"), Self::NAME, attribute)
.property(utf16!("message"), "", attribute)
.method(Self::to_string, "toString", 0)
.build();
}
Expand Down Expand Up @@ -175,7 +175,7 @@ impl BuiltInConstructor for Error {
let msg = message.to_string(context)?;

// b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg).
o.create_non_enumerable_data_property_or_throw("message", msg, context);
o.create_non_enumerable_data_property_or_throw(utf16!("message"), msg, context);
}

// 4. Perform ? InstallErrorCause(O, options).
Expand All @@ -194,12 +194,12 @@ impl Error {
) -> JsResult<()> {
// 1. If Type(options) is Object and ? HasProperty(options, "cause") is true, then
if let Some(options) = options.as_object() {
if options.has_property("cause", context)? {
if options.has_property(utf16!("cause"), context)? {
// a. Let cause be ? Get(options, "cause").
let cause = options.get("cause", context)?;
let cause = options.get(utf16!("cause"), context)?;

// b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "cause", cause).
o.create_non_enumerable_data_property_or_throw("cause", cause, context);
o.create_non_enumerable_data_property_or_throw(utf16!("cause"), cause, context);
}
}

Expand Down
Loading