diff --git a/boa_engine/src/builtins/array/mod.rs b/boa_engine/src/builtins/array/mod.rs index 1f8aafb47c..bfea05fe98 100644 --- a/boa_engine/src/builtins/array/mod.rs +++ b/boa_engine/src/builtins/array/mod.rs @@ -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, ) @@ -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()) @@ -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) @@ -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. @@ -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()); @@ -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()); @@ -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()) @@ -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)) @@ -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()) } @@ -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, @@ -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) } @@ -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() { @@ -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()); } @@ -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) } @@ -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()) } @@ -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()) @@ -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. @@ -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; @@ -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, @@ -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. diff --git a/boa_engine/src/builtins/array_buffer/mod.rs b/boa_engine/src/builtins/array_buffer/mod.rs index 09e5f334b9..be5b99fedf 100644 --- a/boa_engine/src/builtins/array_buffer/mod.rs +++ b/boa_engine/src/builtins/array_buffer/mod.rs @@ -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, @@ -62,7 +63,12 @@ impl IntrinsicObject for ArrayBuffer { .build(); BuiltInBuilder::from_standard_constructor::(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), diff --git a/boa_engine/src/builtins/dataview/mod.rs b/boa_engine/src/builtins/dataview/mod.rs index 4c1658e9c4..0999c5a1c9 100644 --- a/boa_engine/src/builtins/dataview/mod.rs +++ b/boa_engine/src/builtins/dataview/mod.rs @@ -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, @@ -49,9 +50,19 @@ impl IntrinsicObject for DataView { .build(); BuiltInBuilder::from_standard_constructor::(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) diff --git a/boa_engine/src/builtins/date/mod.rs b/boa_engine/src/builtins/date/mod.rs index 2aecb5bad3..aed1cbce60 100644 --- a/boa_engine/src/builtins/date/mod.rs +++ b/boa_engine/src/builtins/date/mod.rs @@ -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) } diff --git a/boa_engine/src/builtins/error/aggregate.rs b/boa_engine/src/builtins/error/aggregate.rs index 386dc55657..becc22f015 100644 --- a/boa_engine/src/builtins/error/aggregate.rs +++ b/boa_engine/src/builtins/error/aggregate.rs @@ -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; @@ -32,8 +33,8 @@ impl IntrinsicObject for AggregateError { BuiltInBuilder::from_standard_constructor::(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(); } @@ -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). @@ -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) diff --git a/boa_engine/src/builtins/error/eval.rs b/boa_engine/src/builtins/error/eval.rs index 46d0e66a2b..cd1581609d 100644 --- a/boa_engine/src/builtins/error/eval.rs +++ b/boa_engine/src/builtins/error/eval.rs @@ -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; @@ -34,8 +35,8 @@ impl IntrinsicObject for EvalError { BuiltInBuilder::from_standard_constructor::(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(); } @@ -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). diff --git a/boa_engine/src/builtins/error/mod.rs b/boa_engine/src/builtins/error/mod.rs index 1a610a3e56..6c11588e38 100644 --- a/boa_engine/src/builtins/error/mod.rs +++ b/boa_engine/src/builtins/error/mod.rs @@ -132,8 +132,8 @@ impl IntrinsicObject for Error { let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE; BuiltInBuilder::from_standard_constructor::(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(); } @@ -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). @@ -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); } } diff --git a/boa_engine/src/builtins/error/range.rs b/boa_engine/src/builtins/error/range.rs index 09976d92d6..e6618cf37b 100644 --- a/boa_engine/src/builtins/error/range.rs +++ b/boa_engine/src/builtins/error/range.rs @@ -14,6 +14,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; @@ -32,8 +33,8 @@ impl IntrinsicObject for RangeError { BuiltInBuilder::from_standard_constructor::(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(); } @@ -71,7 +72,7 @@ impl BuiltInConstructor for RangeError { 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). diff --git a/boa_engine/src/builtins/error/reference.rs b/boa_engine/src/builtins/error/reference.rs index 59828f673c..710983db04 100644 --- a/boa_engine/src/builtins/error/reference.rs +++ b/boa_engine/src/builtins/error/reference.rs @@ -14,6 +14,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; @@ -31,8 +32,8 @@ impl IntrinsicObject for ReferenceError { BuiltInBuilder::from_standard_constructor::(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(); } @@ -73,7 +74,7 @@ impl BuiltInConstructor for ReferenceError { 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). diff --git a/boa_engine/src/builtins/error/syntax.rs b/boa_engine/src/builtins/error/syntax.rs index f1270fb6ed..70811c4fca 100644 --- a/boa_engine/src/builtins/error/syntax.rs +++ b/boa_engine/src/builtins/error/syntax.rs @@ -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; @@ -34,8 +35,8 @@ impl IntrinsicObject for SyntaxError { BuiltInBuilder::from_standard_constructor::(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(); } @@ -76,7 +77,7 @@ impl BuiltInConstructor for SyntaxError { 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). diff --git a/boa_engine/src/builtins/error/type.rs b/boa_engine/src/builtins/error/type.rs index 336ef945e6..6a82717bf2 100644 --- a/boa_engine/src/builtins/error/type.rs +++ b/boa_engine/src/builtins/error/type.rs @@ -24,6 +24,7 @@ use crate::{ native_function::NativeFunction, object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData}, property::Attribute, + string::utf16, Context, JsArgs, JsResult, JsValue, }; use boa_profiler::Profiler; @@ -42,8 +43,8 @@ impl IntrinsicObject for TypeError { BuiltInBuilder::from_standard_constructor::(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(); } @@ -81,7 +82,7 @@ impl BuiltInConstructor for TypeError { 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). @@ -108,8 +109,8 @@ impl IntrinsicObject for ThrowTypeError { let obj = BuiltInBuilder::with_intrinsic::(intrinsics) .prototype(intrinsics.constructors().function().prototype()) - .static_property("name", "ThrowTypeError", Attribute::empty()) - .static_property("length", 0, Attribute::empty()) + .static_property(utf16!("name"), "ThrowTypeError", Attribute::empty()) + .static_property(utf16!("length"), 0, Attribute::empty()) .build(); let mut obj = obj.borrow_mut(); diff --git a/boa_engine/src/builtins/error/uri.rs b/boa_engine/src/builtins/error/uri.rs index 2f849dfb6c..180a368d35 100644 --- a/boa_engine/src/builtins/error/uri.rs +++ b/boa_engine/src/builtins/error/uri.rs @@ -15,6 +15,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; @@ -33,8 +34,8 @@ impl IntrinsicObject for UriError { BuiltInBuilder::from_standard_constructor::(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(); } @@ -72,7 +73,7 @@ impl BuiltInConstructor for UriError { 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). diff --git a/boa_engine/src/builtins/function/arguments.rs b/boa_engine/src/builtins/function/arguments.rs index dae9b0d23f..40b4c97acd 100644 --- a/boa_engine/src/builtins/function/arguments.rs +++ b/boa_engine/src/builtins/function/arguments.rs @@ -2,6 +2,7 @@ use crate::{ environments::DeclarativeEnvironment, object::{JsObject, ObjectData}, property::PropertyDescriptor, + string::utf16, symbol::{self, JsSymbol}, Context, JsValue, }; @@ -87,7 +88,7 @@ impl Arguments { // 4. Perform DefinePropertyOrThrow(obj, "length", PropertyDescriptor { [[Value]]: 𝔽(len), // [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }). obj.define_property_or_throw( - "length", + utf16!("length"), PropertyDescriptor::builder() .value(len) .writable(true) @@ -129,7 +130,7 @@ impl Arguments { // [[Get]]: %ThrowTypeError%, [[Set]]: %ThrowTypeError%, [[Enumerable]]: false, // [[Configurable]]: false }). obj.define_property_or_throw( - "callee", + utf16!("callee"), PropertyDescriptor::builder() .get(throw_type_error.clone()) .set(throw_type_error) @@ -249,7 +250,7 @@ impl Arguments { // 16. Perform ! DefinePropertyOrThrow(obj, "length", PropertyDescriptor { [[Value]]: 𝔽(len), // [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }). obj.define_property_or_throw( - "length", + utf16!("length"), PropertyDescriptor::builder() .value(len) .writable(true) @@ -277,7 +278,7 @@ impl Arguments { // 21. Perform ! DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { // [[Value]]: func, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }). obj.define_property_or_throw( - "callee", + utf16!("callee"), PropertyDescriptor::builder() .value(func.clone()) .writable(true) diff --git a/boa_engine/src/builtins/function/mod.rs b/boa_engine/src/builtins/function/mod.rs index 2676d8585b..45a0152878 100644 --- a/boa_engine/src/builtins/function/mod.rs +++ b/boa_engine/src/builtins/function/mod.rs @@ -419,13 +419,13 @@ impl IntrinsicObject for BuiltInFunctionObject { .method(Self::to_string, "toString", 0) .property(JsSymbol::has_instance(), has_instance, Attribute::default()) .accessor( - "caller", + utf16!("caller"), Some(throw_type_error.clone()), Some(throw_type_error.clone()), Attribute::CONFIGURABLE, ) .accessor( - "arguments", + utf16!("arguments"), Some(throw_type_error.clone()), Some(throw_type_error), Attribute::CONFIGURABLE, @@ -734,9 +734,9 @@ impl BuiltInFunctionObject { // 5. Let targetHasLength be ? HasOwnProperty(Target, "length"). // 6. If targetHasLength is true, then - if target.has_own_property("length", context)? { + if target.has_own_property(utf16!("length"), context)? { // a. Let targetLen be ? Get(Target, "length"). - let target_len = target.get("length", context)?; + let target_len = target.get(utf16!("length"), context)?; // b. If Type(targetLen) is Number, then if target_len.is_number() { // 1. Let targetLenAsInt be ! ToIntegerOrInfinity(targetLen). @@ -761,7 +761,7 @@ impl BuiltInFunctionObject { // 7. Perform ! SetFunctionLength(F, L). f.define_property_or_throw( - "length", + utf16!("length"), PropertyDescriptor::builder() .value(l) .writable(false) @@ -772,7 +772,7 @@ impl BuiltInFunctionObject { .expect("defining the `length` property for a new object should not fail"); // 8. Let targetName be ? Get(Target, "name"). - let target_name = target.get("name", context)?; + let target_name = target.get(utf16!("name"), context)?; // 9. If Type(targetName) is not String, set targetName to the empty String. let target_name = target_name @@ -825,7 +825,7 @@ impl BuiltInFunctionObject { let value = this .as_object() .expect("checked that `this` was an object above") - .get("name", &mut *context)?; + .get(utf16!("name"), &mut *context)?; if value.is_null_or_undefined() { None } else { @@ -923,7 +923,7 @@ pub(crate) fn set_function_name( // [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }). function .define_property_or_throw( - "name", + utf16!("name"), PropertyDescriptor::builder() .value(name) .writable(false) diff --git a/boa_engine/src/builtins/intl/collator/mod.rs b/boa_engine/src/builtins/intl/collator/mod.rs index 5eef808e90..5af7149d1b 100644 --- a/boa_engine/src/builtins/intl/collator/mod.rs +++ b/boa_engine/src/builtins/intl/collator/mod.rs @@ -22,6 +22,7 @@ use crate::{ JsObject, ObjectData, }, property::Attribute, + string::utf16, symbol::JsSymbol, Context, JsArgs, JsNativeError, JsResult, JsValue, }; @@ -173,7 +174,12 @@ impl IntrinsicObject for Collator { "Intl.Collator", Attribute::CONFIGURABLE, ) - .accessor("compare", Some(compare), None, Attribute::CONFIGURABLE) + .accessor( + utf16!("compare"), + Some(compare), + None, + Attribute::CONFIGURABLE, + ) .method(Self::resolved_options, "resolvedOptions", 0) .build(); } @@ -234,29 +240,31 @@ impl BuiltInConstructor for Collator { // a. Let localeData be %Collator%.[[SortLocaleData]]. // 6. Else, // a. Let localeData be %Collator%.[[SearchLocaleData]]. - let usage = get_option::(&options, "usage", false, context)?.unwrap_or_default(); + let usage = + get_option::(&options, utf16!("usage"), false, context)?.unwrap_or_default(); // 7. Let opt be a new Record. // 8. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit"). // 9. Set opt.[[localeMatcher]] to matcher. - let matcher = get_option::(&options, "localeMatcher", false, context)? - .unwrap_or_default(); + let matcher = + get_option::(&options, utf16!("localeMatcher"), false, context)? + .unwrap_or_default(); // 10. Let collation be ? GetOption(options, "collation", string, empty, undefined). // 11. If collation is not undefined, then // a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. // 12. Set opt.[[co]] to collation. - let collation = get_option::(&options, "collation", false, context)?; + let collation = get_option::(&options, utf16!("collation"), false, context)?; // 13. Let numeric be ? GetOption(options, "numeric", boolean, empty, undefined). // 14. If numeric is not undefined, then // a. Let numeric be ! ToString(numeric). // 15. Set opt.[[kn]] to numeric. - let numeric = get_option::(&options, "numeric", false, context)?; + let numeric = get_option::(&options, utf16!("numeric"), false, context)?; // 16. Let caseFirst be ? GetOption(options, "caseFirst", string, « "upper", "lower", "false" », undefined). // 17. Set opt.[[kf]] to caseFirst. - let case_first = get_option::(&options, "caseFirst", false, context)?; + let case_first = get_option::(&options, utf16!("caseFirst"), false, context)?; let mut intl_options = IntlOptions { matcher, @@ -305,20 +313,22 @@ impl BuiltInConstructor for Collator { // 26. Let sensitivity be ? GetOption(options, "sensitivity", string, « "base", "accent", "case", "variant" », undefined). // 28. Set collator.[[Sensitivity]] to sensitivity. - let sensitivity = get_option::(&options, "sensitivity", false, context)? - // 27. If sensitivity is undefined, then - // a. If usage is "sort", then - // i. Let sensitivity be "variant". - // b. Else, - // i. Let dataLocale be r.[[dataLocale]]. - // ii. Let dataLocaleData be localeData.[[]]. - // iii. Let sensitivity be dataLocaleData.[[sensitivity]]. - .or_else(|| (usage == Usage::Sort).then_some(Sensitivity::Variant)); + let sensitivity = + get_option::(&options, utf16!("sensitivity"), false, context)? + // 27. If sensitivity is undefined, then + // a. If usage is "sort", then + // i. Let sensitivity be "variant". + // b. Else, + // i. Let dataLocale be r.[[dataLocale]]. + // ii. Let dataLocaleData be localeData.[[]]. + // iii. Let sensitivity be dataLocaleData.[[sensitivity]]. + .or_else(|| (usage == Usage::Sort).then_some(Sensitivity::Variant)); // 29. Let ignorePunctuation be ? GetOption(options, "ignorePunctuation", boolean, empty, false). // 30. Set collator.[[IgnorePunctuation]] to ignorePunctuation. let ignore_punctuation = - get_option::(&options, "ignorePunctuation", false, context)?.unwrap_or_default(); + get_option::(&options, utf16!("ignorePunctuation"), false, context)? + .unwrap_or_default(); let (strength, case_level) = sensitivity.map(Sensitivity::to_collator_options).unzip(); @@ -504,11 +514,11 @@ impl Collator { // i. Perform ! CreateDataPropertyOrThrow(options, p, v). // 5. Return options. options - .create_data_property_or_throw("locale", collator.locale.to_string(), context) + .create_data_property_or_throw(utf16!("locale"), collator.locale.to_string(), context) .expect("operation must not fail per the spec"); options .create_data_property_or_throw( - "usage", + utf16!("usage"), match collator.usage { Usage::Search => "search", Usage::Sort => "sort", @@ -518,7 +528,7 @@ impl Collator { .expect("operation must not fail per the spec"); options .create_data_property_or_throw( - "sensitivity", + utf16!("sensitivity"), match collator.sensitivity { Sensitivity::Base => "base", Sensitivity::Accent => "accent", @@ -530,21 +540,25 @@ impl Collator { .expect("operation must not fail per the spec"); options .create_data_property_or_throw( - "ignorePunctuation", + utf16!("ignorePunctuation"), collator.ignore_punctuation, context, ) .expect("operation must not fail per the spec"); options - .create_data_property_or_throw("collation", collator.collation.to_string(), context) + .create_data_property_or_throw( + utf16!("collation"), + collator.collation.to_string(), + context, + ) .expect("operation must not fail per the spec"); options - .create_data_property_or_throw("numeric", collator.numeric, context) + .create_data_property_or_throw(utf16!("numeric"), collator.numeric, context) .expect("operation must not fail per the spec"); if let Some(kf) = collator.case_first { options .create_data_property_or_throw( - "caseFirst", + utf16!("caseFirst"), match kf { CaseFirst::Off => "false", CaseFirst::LowerFirst => "lower", diff --git a/boa_engine/src/builtins/intl/date_time_format.rs b/boa_engine/src/builtins/intl/date_time_format.rs index 72293c1ccf..ca38623e9a 100644 --- a/boa_engine/src/builtins/intl/date_time_format.rs +++ b/boa_engine/src/builtins/intl/date_time_format.rs @@ -13,6 +13,7 @@ use crate::{ error::JsNativeError, js_string, object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData}, + string::utf16, Context, JsResult, JsString, JsValue, }; @@ -182,7 +183,12 @@ pub(crate) fn to_date_time_options( // 4. If required is "date" or "any", then if [DateTimeReqs::Date, DateTimeReqs::AnyAll].contains(required) { // a. For each property name prop of « "weekday", "year", "month", "day" », do - for property in ["weekday", "year", "month", "day"] { + for property in [ + utf16!("weekday"), + utf16!("year"), + utf16!("month"), + utf16!("day"), + ] { // i. Let value be ? Get(options, prop). let value = options.get(property, context)?; @@ -198,11 +204,11 @@ pub(crate) fn to_date_time_options( // a. For each property name prop of « "dayPeriod", "hour", "minute", "second", // "fractionalSecondDigits" », do for property in [ - "dayPeriod", - "hour", - "minute", - "second", - "fractionalSecondDigits", + utf16!("dayPeriod"), + utf16!("hour"), + utf16!("minute"), + utf16!("second"), + utf16!("fractionalSecondDigits"), ] { // i. Let value be ? Get(options, prop). let value = options.get(property, context)?; @@ -215,10 +221,10 @@ pub(crate) fn to_date_time_options( } // 6. Let dateStyle be ? Get(options, "dateStyle"). - let date_style = options.get("dateStyle", context)?; + let date_style = options.get(utf16!("dateStyle"), context)?; // 7. Let timeStyle be ? Get(options, "timeStyle"). - let time_style = options.get("timeStyle", context)?; + let time_style = options.get(utf16!("timeStyle"), context)?; // 8. If dateStyle is not undefined or timeStyle is not undefined, let needDefaults be false. if !date_style.is_undefined() || !time_style.is_undefined() { @@ -244,7 +250,7 @@ pub(crate) fn to_date_time_options( // 11. If needDefaults is true and defaults is either "date" or "all", then if need_defaults && [DateTimeReqs::Date, DateTimeReqs::AnyAll].contains(defaults) { // a. For each property name prop of « "year", "month", "day" », do - for property in ["year", "month", "day"] { + for property in [utf16!("year"), utf16!("month"), utf16!("day")] { // i. Perform ? CreateDataPropertyOrThrow(options, prop, "numeric"). options.create_data_property_or_throw(property, "numeric", context)?; } @@ -253,7 +259,7 @@ pub(crate) fn to_date_time_options( // 12. If needDefaults is true and defaults is either "time" or "all", then if need_defaults && [DateTimeReqs::Time, DateTimeReqs::AnyAll].contains(defaults) { // a. For each property name prop of « "hour", "minute", "second" », do - for property in ["hour", "minute", "second"] { + for property in [utf16!("hour"), utf16!("minute"), utf16!("second")] { // i. Perform ? CreateDataPropertyOrThrow(options, prop, "numeric"). options.create_data_property_or_throw(property, "numeric", context)?; } diff --git a/boa_engine/src/builtins/intl/list_format/mod.rs b/boa_engine/src/builtins/intl/list_format/mod.rs index d381962f02..af3575c49e 100644 --- a/boa_engine/src/builtins/intl/list_format/mod.rs +++ b/boa_engine/src/builtins/intl/list_format/mod.rs @@ -10,6 +10,7 @@ use crate::{ context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors}, object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData}, property::Attribute, + string::utf16, symbol::JsSymbol, Context, JsArgs, JsNativeError, JsResult, JsString, JsValue, }; @@ -110,8 +111,9 @@ impl BuiltInConstructor for ListFormat { // 5. Let opt be a new Record. // 6. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit"). - let matcher = get_option::(&options, "localeMatcher", false, context)? - .unwrap_or_default(); + let matcher = + get_option::(&options, utf16!("localeMatcher"), false, context)? + .unwrap_or_default(); // 7. Set opt.[[localeMatcher]] to matcher. // 8. Let localeData be %ListFormat%.[[LocaleData]]. @@ -128,12 +130,12 @@ impl BuiltInConstructor for ListFormat { // 11. Let type be ? GetOption(options, "type", string, « "conjunction", "disjunction", "unit" », "conjunction"). // 12. Set listFormat.[[Type]] to type. - let typ = - get_option::(&options, "type", false, context)?.unwrap_or_default(); + let typ = get_option::(&options, utf16!("type"), false, context)? + .unwrap_or_default(); // 13. Let style be ? GetOption(options, "style", string, « "long", "short", "narrow" », "long"). // 14. Set listFormat.[[Style]] to style. - let style = get_option::(&options, "style", false, context)? + let style = get_option::(&options, utf16!("style"), false, context)? .unwrap_or(ListLength::Wide); // 15. Let dataLocale be r.[[dataLocale]]. @@ -361,11 +363,11 @@ impl ListFormat { ); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). - o.create_data_property_or_throw("type", part.typ(), context) + o.create_data_property_or_throw(utf16!("type"), part.typ(), context) .expect("operation must not fail per the spec"); // c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]). - o.create_data_property_or_throw("value", part.value(), context) + o.create_data_property_or_throw(utf16!("value"), part.value(), context) .expect("operation must not fail per the spec"); // d. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O). @@ -418,11 +420,11 @@ impl ListFormat { // c. Assert: v is not undefined. // d. Perform ! CreateDataPropertyOrThrow(options, p, v). options - .create_data_property_or_throw("locale", lf.locale.to_string(), context) + .create_data_property_or_throw(utf16!("locale"), lf.locale.to_string(), context) .expect("operation must not fail per the spec"); options .create_data_property_or_throw( - "type", + utf16!("type"), match lf.typ { ListFormatType::Conjunction => "conjunction", ListFormatType::Disjunction => "disjunction", @@ -433,7 +435,7 @@ impl ListFormat { .expect("operation must not fail per the spec"); options .create_data_property_or_throw( - "style", + utf16!("style"), match lf.style { ListLength::Wide => "long", ListLength::Short => "short", diff --git a/boa_engine/src/builtins/intl/locale/mod.rs b/boa_engine/src/builtins/intl/locale/mod.rs index 2267b1b4b8..264335c0ac 100644 --- a/boa_engine/src/builtins/intl/locale/mod.rs +++ b/boa_engine/src/builtins/intl/locale/mod.rs @@ -1,3 +1,4 @@ +use crate::string::utf16; use boa_profiler::Profiler; use icu_collator::CaseFirst; use icu_datetime::options::preferences::HourCycle; @@ -93,21 +94,66 @@ impl IntrinsicObject for Locale { .method(Self::maximize, "maximize", 0) .method(Self::minimize, "minimize", 0) .method(Self::to_string, "toString", 0) - .accessor("baseName", Some(base_name), None, Attribute::CONFIGURABLE) - .accessor("calendar", Some(calendar), None, Attribute::CONFIGURABLE) - .accessor("caseFirst", Some(case_first), None, Attribute::CONFIGURABLE) - .accessor("collation", Some(collation), None, Attribute::CONFIGURABLE) - .accessor("hourCycle", Some(hour_cycle), None, Attribute::CONFIGURABLE) - .accessor("numeric", Some(numeric), None, Attribute::CONFIGURABLE) .accessor( - "numberingSystem", + utf16!("baseName"), + Some(base_name), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("calendar"), + Some(calendar), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("caseFirst"), + Some(case_first), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("collation"), + Some(collation), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("hourCycle"), + Some(hour_cycle), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("numeric"), + Some(numeric), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("numberingSystem"), Some(numbering_system), None, Attribute::CONFIGURABLE, ) - .accessor("language", Some(language), None, Attribute::CONFIGURABLE) - .accessor("script", Some(script), None, Attribute::CONFIGURABLE) - .accessor("region", Some(region), None, Attribute::CONFIGURABLE) + .accessor( + utf16!("language"), + Some(language), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("script"), + Some(script), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("region"), + Some(region), + None, + Attribute::CONFIGURABLE, + ) .build(); } @@ -197,7 +243,7 @@ impl BuiltInConstructor for Locale { // 3. If ! IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception. // 4. Let language be ? GetOption(options, "language", string, empty, undefined). // 5. If language is not undefined, then - let language = get_option::(options, "language", false, context)? + let language = get_option::(options, utf16!("language"), false, context)? // a. If language does not match the unicode_language_subtag production, throw a RangeError exception. .map(|s| s.to_std_string_escaped().parse::()) .transpose() @@ -205,7 +251,7 @@ impl BuiltInConstructor for Locale { // 6. Let script be ? GetOption(options, "script", string, empty, undefined). // 7. If script is not undefined, then - let script = get_option::(options, "script", false, context)? + let script = get_option::(options, utf16!("script"), false, context)? .map(|s| s.to_std_string_escaped().parse::