From f4d9d56c63ae0fa6fa16767b36c0a97f10830147 Mon Sep 17 00:00:00 2001 From: RageKnify Date: Tue, 2 Feb 2021 21:45:34 +0000 Subject: [PATCH 1/2] Refactor: Define all property methods of constructors 6 = 3 * 2 2 instance and static properties 3 data, accessor and properties discussed in #400 --- boa/examples/classes.rs | 4 +- boa/src/builtins/array/mod.rs | 6 +-- boa/src/builtins/error/eval.rs | 4 +- boa/src/builtins/error/mod.rs | 4 +- boa/src/builtins/error/range.rs | 4 +- boa/src/builtins/error/reference.rs | 4 +- boa/src/builtins/error/syntax.rs | 4 +- boa/src/builtins/error/type.rs | 4 +- boa/src/builtins/error/uri.rs | 4 +- boa/src/builtins/map/mod.rs | 4 +- boa/src/builtins/number/mod.rs | 16 +++--- boa/src/builtins/regexp/mod.rs | 2 +- boa/src/builtins/string/mod.rs | 2 +- boa/src/builtins/symbol/mod.rs | 26 ++++----- boa/src/class.rs | 82 ++++++++++++++++++++++++++--- boa/src/object/mod.rs | 73 +++++++++++++++++++++++-- 16 files changed, 187 insertions(+), 56 deletions(-) diff --git a/boa/examples/classes.rs b/boa/examples/classes.rs index 475ce17b5b9..86debcc3d94 100644 --- a/boa/examples/classes.rs +++ b/boa/examples/classes.rs @@ -104,11 +104,11 @@ impl Class for Person { // Add a inherited property with the value `10`, with default attribute. // (`READONLY, NON_ENUMERABLE, PERMANENT). - class.property("inheritedProperty", 10, Attribute::default()); + class.data_property("inheritedProperty", 10, Attribute::default()); // Add a static property with the value `"Im a static property"`, with default attribute. // (`WRITABLE, ENUMERABLE, PERMANENT`). - class.static_property( + class.static_data_property( "staticProperty", "Im a static property", Attribute::WRITABLE | Attribute::ENUMERABLE | Attribute::PERMANENT, diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index 32b734ff072..e6a567b786b 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -58,17 +58,17 @@ impl BuiltIn for Array { ) .name(Self::NAME) .length(Self::LENGTH) - .property( + .data_property( "length", 0, Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::PERMANENT, ) - .property( + .data_property( "values", values_function.clone(), Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, ) - .property( + .data_property( symbol_iterator, values_function, Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, diff --git a/boa/src/builtins/error/eval.rs b/boa/src/builtins/error/eval.rs index 0e1ccad1a3e..10593587b59 100644 --- a/boa/src/builtins/error/eval.rs +++ b/boa/src/builtins/error/eval.rs @@ -44,8 +44,8 @@ impl BuiltIn for EvalError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .property("name", Self::NAME, attribute) - .property("message", "", attribute) + .data_property("name", Self::NAME, attribute) + .data_property("message", "", attribute) .build(); (Self::NAME, eval_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/error/mod.rs b/boa/src/builtins/error/mod.rs index 60622cfd1b9..e7dfaaf4c9c 100644 --- a/boa/src/builtins/error/mod.rs +++ b/boa/src/builtins/error/mod.rs @@ -57,8 +57,8 @@ impl BuiltIn for Error { ) .name(Self::NAME) .length(Self::LENGTH) - .property("name", Self::NAME, attribute) - .property("message", "", attribute) + .data_property("name", Self::NAME, attribute) + .data_property("message", "", attribute) .method(Self::to_string, "toString", 0) .build(); diff --git a/boa/src/builtins/error/range.rs b/boa/src/builtins/error/range.rs index ed020897650..612ab093402 100644 --- a/boa/src/builtins/error/range.rs +++ b/boa/src/builtins/error/range.rs @@ -41,8 +41,8 @@ impl BuiltIn for RangeError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .property("name", Self::NAME, attribute) - .property("message", "", attribute) + .data_property("name", Self::NAME, attribute) + .data_property("message", "", attribute) .build(); (Self::NAME, range_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/error/reference.rs b/boa/src/builtins/error/reference.rs index a1e7153ffb4..05f284fa3c5 100644 --- a/boa/src/builtins/error/reference.rs +++ b/boa/src/builtins/error/reference.rs @@ -40,8 +40,8 @@ impl BuiltIn for ReferenceError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .property("name", Self::NAME, attribute) - .property("message", "", attribute) + .data_property("name", Self::NAME, attribute) + .data_property("message", "", attribute) .build(); (Self::NAME, reference_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/error/syntax.rs b/boa/src/builtins/error/syntax.rs index b5764d219a6..4b0f954c513 100644 --- a/boa/src/builtins/error/syntax.rs +++ b/boa/src/builtins/error/syntax.rs @@ -43,8 +43,8 @@ impl BuiltIn for SyntaxError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .property("name", Self::NAME, attribute) - .property("message", "", attribute) + .data_property("name", Self::NAME, attribute) + .data_property("message", "", attribute) .build(); (Self::NAME, syntax_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/error/type.rs b/boa/src/builtins/error/type.rs index c348d36aeb0..e232da31ce7 100644 --- a/boa/src/builtins/error/type.rs +++ b/boa/src/builtins/error/type.rs @@ -46,8 +46,8 @@ impl BuiltIn for TypeError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .property("name", Self::NAME, attribute) - .property("message", "", attribute) + .data_property("name", Self::NAME, attribute) + .data_property("message", "", attribute) .build(); (Self::NAME, type_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/error/uri.rs b/boa/src/builtins/error/uri.rs index 928627c9531..73e161898ac 100644 --- a/boa/src/builtins/error/uri.rs +++ b/boa/src/builtins/error/uri.rs @@ -42,8 +42,8 @@ impl BuiltIn for UriError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .property("name", Self::NAME, attribute) - .property("message", "", attribute) + .data_property("name", Self::NAME, attribute) + .data_property("message", "", attribute) .build(); (Self::NAME, uri_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/map/mod.rs b/boa/src/builtins/map/mod.rs index 3b9c293743a..5b9ccbf334e 100644 --- a/boa/src/builtins/map/mod.rs +++ b/boa/src/builtins/map/mod.rs @@ -40,12 +40,12 @@ impl BuiltIn for Map { let map_object = ConstructorBuilder::new(context, Self::constructor) .name(Self::NAME) .length(Self::LENGTH) - .property( + .data_property( "entries", entries_function.clone(), Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, ) - .property( + .data_property( iterator_symbol, entries_function, Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, diff --git a/boa/src/builtins/number/mod.rs b/boa/src/builtins/number/mod.rs index e1753997bcd..b7d08ddbd7b 100644 --- a/boa/src/builtins/number/mod.rs +++ b/boa/src/builtins/number/mod.rs @@ -61,14 +61,14 @@ impl BuiltIn for Number { ) .name(Self::NAME) .length(Self::LENGTH) - .static_property("EPSILON", f64::EPSILON, attribute) - .static_property("MAX_SAFE_INTEGER", Self::MAX_SAFE_INTEGER, attribute) - .static_property("MIN_SAFE_INTEGER", Self::MIN_SAFE_INTEGER, attribute) - .static_property("MAX_VALUE", Self::MAX_VALUE, attribute) - .static_property("MIN_VALUE", Self::MIN_VALUE, attribute) - .static_property("NEGATIVE_INFINITY", f64::NEG_INFINITY, attribute) - .static_property("POSITIVE_INFINITY", f64::INFINITY, attribute) - .static_property("NaN", f64::NAN, attribute) + .static_data_property("EPSILON", f64::EPSILON, attribute) + .static_data_property("MAX_SAFE_INTEGER", Self::MAX_SAFE_INTEGER, attribute) + .static_data_property("MIN_SAFE_INTEGER", Self::MIN_SAFE_INTEGER, attribute) + .static_data_property("MAX_VALUE", Self::MAX_VALUE, attribute) + .static_data_property("MIN_VALUE", Self::MIN_VALUE, attribute) + .static_data_property("NEGATIVE_INFINITY", f64::NEG_INFINITY, attribute) + .static_data_property("POSITIVE_INFINITY", f64::INFINITY, attribute) + .static_data_property("NaN", f64::NAN, attribute) .method(Self::to_exponential, "toExponential", 1) .method(Self::to_fixed, "toFixed", 1) .method(Self::to_locale_string, "toLocaleString", 0) diff --git a/boa/src/builtins/regexp/mod.rs b/boa/src/builtins/regexp/mod.rs index 0b40e238e26..f1300b9ffab 100644 --- a/boa/src/builtins/regexp/mod.rs +++ b/boa/src/builtins/regexp/mod.rs @@ -78,7 +78,7 @@ impl BuiltIn for RegExp { ) .name(Self::NAME) .length(Self::LENGTH) - .property("lastIndex", 0, Attribute::all()) + .data_property("lastIndex", 0, Attribute::all()) .method(Self::test, "test", 1) .method(Self::exec, "exec", 1) .method(Self::to_string, "toString", 0) diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index b7ee8b07b4e..f7266b5f2c7 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -105,7 +105,7 @@ impl BuiltIn for String { ) .name(Self::NAME) .length(Self::LENGTH) - .property("length", 0, attribute) + .data_property("length", 0, attribute) .method(Self::char_at, "charAt", 1) .method(Self::char_code_at, "charCodeAt", 1) .method(Self::code_point_at, "codePointAt", 1) diff --git a/boa/src/builtins/symbol/mod.rs b/boa/src/builtins/symbol/mod.rs index 05d1c60be88..b3c3edab152 100644 --- a/boa/src/builtins/symbol/mod.rs +++ b/boa/src/builtins/symbol/mod.rs @@ -268,19 +268,19 @@ impl BuiltIn for Symbol { ) .name(Self::NAME) .length(Self::LENGTH) - .static_property("asyncIterator", symbol_async_iterator, attribute) - .static_property("hasInstance", symbol_has_instance, attribute) - .static_property("isConcatSpreadable", symbol_is_concat_spreadable, attribute) - .static_property("iterator", symbol_iterator, attribute) - .static_property("match", symbol_match, attribute) - .static_property("matchAll", symbol_match_all, attribute) - .static_property("replace", symbol_replace, attribute) - .static_property("search", symbol_search, attribute) - .static_property("species", symbol_species, attribute) - .static_property("split", symbol_split, attribute) - .static_property("toPrimitive", symbol_to_primitive, attribute) - .static_property("toStringTag", symbol_to_string_tag, attribute) - .static_property("unscopables", symbol_unscopables, attribute) + .static_data_property("asyncIterator", symbol_async_iterator, attribute) + .static_data_property("hasInstance", symbol_has_instance, attribute) + .static_data_property("isConcatSpreadable", symbol_is_concat_spreadable, attribute) + .static_data_property("iterator", symbol_iterator, attribute) + .static_data_property("match", symbol_match, attribute) + .static_data_property("matchAll", symbol_match_all, attribute) + .static_data_property("replace", symbol_replace, attribute) + .static_data_property("search", symbol_search, attribute) + .static_data_property("species", symbol_species, attribute) + .static_data_property("split", symbol_split, attribute) + .static_data_property("toPrimitive", symbol_to_primitive, attribute) + .static_data_property("toStringTag", symbol_to_string_tag, attribute) + .static_data_property("unscopables", symbol_unscopables, attribute) .method(Self::to_string, "toString", 0) .callable(true) .constructable(false) diff --git a/boa/src/class.rs b/boa/src/class.rs index 6f33c154f38..bc3f4279a9b 100644 --- a/boa/src/class.rs +++ b/boa/src/class.rs @@ -63,7 +63,7 @@ use crate::{ builtins::function::NativeFunction, object::{ConstructorBuilder, GcObject, NativeObject, ObjectData}, - property::{Attribute, PropertyKey}, + property::{Attribute, PropertyDescriptor, PropertyKey}, Context, Result, Value, }; @@ -156,29 +156,97 @@ impl<'context> ClassBuilder<'context> { self } - /// Add a property to the class, with the specified attribute. + /// Add a data property to the class, with the specified attribute. /// /// It is added to `prototype`. #[inline] - pub fn property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self + pub fn data_property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self where K: Into, V: Into, { - self.builder.property(key, value, attribute); + self.builder.data_property(key, value, attribute); self } - /// Add a static property to the class, with the specified attribute. + /// Add a static data property to the class, with the specified attribute. /// /// It is added to class object itself. #[inline] - pub fn static_property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self + pub fn static_data_property( + &mut self, + key: K, + value: V, + attribute: Attribute, + ) -> &mut Self where K: Into, V: Into, { - self.builder.static_property(key, value, attribute); + self.builder.static_data_property(key, value, attribute); + self + } + + /// Add an accessor property to the class, with the specified attribute. + /// + /// It is added to `prototype`. + #[inline] + pub fn accessor_property( + &mut self, + key: K, + get: Option, + set: Option, + attribute: Attribute, + ) -> &mut Self + where + K: Into, + { + self.builder.accessor_property(key, get, set, attribute); + self + } + + /// Add a static accessor property to the class, with the specified attribute. + /// + /// It is added to class object itself. + #[inline] + pub fn static_accessor_property( + &mut self, + key: K, + get: Option, + set: Option, + attribute: Attribute, + ) -> &mut Self + where + K: Into, + { + self.builder + .static_accessor_property(key, get, set, attribute); + self + } + + /// Add a property descriptor to the class, with the specified attribute. + /// + /// It is added to `prototype`. + #[inline] + pub fn property_descriptor(&mut self, key: K, property: P) -> &mut Self + where + K: Into, + P: Into, + { + self.builder.property_descriptor(key, property); + self + } + + /// Add a static property descriptor to the class, with the specified attribute. + /// + /// It is added to class object itself. + #[inline] + pub fn static_property_descriptor(&mut self, key: K, property: P) -> &mut Self + where + K: Into, + P: Into, + { + self.builder.static_property_descriptor(key, property); self } diff --git a/boa/src/object/mod.rs b/boa/src/object/mod.rs index 93874f107a8..9fbdddf5be7 100644 --- a/boa/src/object/mod.rs +++ b/boa/src/object/mod.rs @@ -11,7 +11,7 @@ use crate::{ }, context::StandardConstructor, gc::{Finalize, Trace}, - property::{Attribute, DataDescriptor, PropertyDescriptor, PropertyKey}, + property::{AccessorDescriptor, Attribute, DataDescriptor, PropertyDescriptor, PropertyKey}, value::{same_value, RcBigInt, RcString, RcSymbol, Value}, BoaProfiler, Context, }; @@ -937,9 +937,9 @@ impl<'context> ConstructorBuilder<'context> { self } - /// Add new property to the constructors prototype. + /// Add new data property to the constructor's prototype. #[inline] - pub fn property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self + pub fn data_property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self where K: Into, V: Into, @@ -949,9 +949,14 @@ impl<'context> ConstructorBuilder<'context> { self } - /// Add new static property to the constructors object itself. + /// Add new static data property to the constructor's object itself. #[inline] - pub fn static_property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self + pub fn static_data_property( + &mut self, + key: K, + value: V, + attribute: Attribute, + ) -> &mut Self where K: Into, V: Into, @@ -961,6 +966,64 @@ impl<'context> ConstructorBuilder<'context> { self } + /// Add new accessor property to the constructor's prototype. + #[inline] + pub fn accessor_property( + &mut self, + key: K, + get: Option, + set: Option, + attribute: Attribute, + ) -> &mut Self + where + K: Into, + { + let property = AccessorDescriptor::new(get, set, attribute); + self.prototype.borrow_mut().insert(key, property); + self + } + + /// Add new static accessor property to the constructor's object itself. + #[inline] + pub fn static_accessor_property( + &mut self, + key: K, + get: Option, + set: Option, + attribute: Attribute, + ) -> &mut Self + where + K: Into, + { + let property = AccessorDescriptor::new(get, set, attribute); + self.constructor_object.borrow_mut().insert(key, property); + self + } + + /// Add new property to the constructor's prototype. + #[inline] + pub fn property_descriptor(&mut self, key: K, property: P) -> &mut Self + where + K: Into, + P: Into, + { + let property = property.into(); + self.prototype.borrow_mut().insert(key, property); + self + } + + /// Add new static property to the constructor's object itself. + #[inline] + pub fn static_property_descriptor(&mut self, key: K, property: P) -> &mut Self + where + K: Into, + P: Into, + { + let property = property.into(); + self.constructor_object.borrow_mut().insert(key, property); + self + } + /// Specify how many arguments the constructor function takes. /// /// Default is `0`. From 7315bf2be5edf4609c89864031d2b1aea0c11d2c Mon Sep 17 00:00:00 2001 From: RageKnify Date: Fri, 5 Feb 2021 17:10:40 +0000 Subject: [PATCH 2/2] Refactor: Simplify naming of ConstructorBuilder methods As per review in #1109 by @HalidOdat Co-authored-by: Halid Odat --- boa/examples/classes.rs | 4 ++-- boa/src/builtins/array/mod.rs | 6 +++--- boa/src/builtins/error/eval.rs | 4 ++-- boa/src/builtins/error/mod.rs | 4 ++-- boa/src/builtins/error/range.rs | 4 ++-- boa/src/builtins/error/reference.rs | 4 ++-- boa/src/builtins/error/syntax.rs | 4 ++-- boa/src/builtins/error/type.rs | 4 ++-- boa/src/builtins/error/uri.rs | 4 ++-- boa/src/builtins/map/mod.rs | 4 ++-- boa/src/builtins/number/mod.rs | 16 ++++++++-------- boa/src/builtins/regexp/mod.rs | 2 +- boa/src/builtins/string/mod.rs | 2 +- boa/src/builtins/symbol/mod.rs | 26 +++++++++++++------------- boa/src/class.rs | 22 ++++++++-------------- boa/src/object/mod.rs | 19 +++++++------------ 16 files changed, 59 insertions(+), 70 deletions(-) diff --git a/boa/examples/classes.rs b/boa/examples/classes.rs index 86debcc3d94..475ce17b5b9 100644 --- a/boa/examples/classes.rs +++ b/boa/examples/classes.rs @@ -104,11 +104,11 @@ impl Class for Person { // Add a inherited property with the value `10`, with default attribute. // (`READONLY, NON_ENUMERABLE, PERMANENT). - class.data_property("inheritedProperty", 10, Attribute::default()); + class.property("inheritedProperty", 10, Attribute::default()); // Add a static property with the value `"Im a static property"`, with default attribute. // (`WRITABLE, ENUMERABLE, PERMANENT`). - class.static_data_property( + class.static_property( "staticProperty", "Im a static property", Attribute::WRITABLE | Attribute::ENUMERABLE | Attribute::PERMANENT, diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index e6a567b786b..32b734ff072 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -58,17 +58,17 @@ impl BuiltIn for Array { ) .name(Self::NAME) .length(Self::LENGTH) - .data_property( + .property( "length", 0, Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::PERMANENT, ) - .data_property( + .property( "values", values_function.clone(), Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, ) - .data_property( + .property( symbol_iterator, values_function, Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, diff --git a/boa/src/builtins/error/eval.rs b/boa/src/builtins/error/eval.rs index 10593587b59..0e1ccad1a3e 100644 --- a/boa/src/builtins/error/eval.rs +++ b/boa/src/builtins/error/eval.rs @@ -44,8 +44,8 @@ impl BuiltIn for EvalError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .data_property("name", Self::NAME, attribute) - .data_property("message", "", attribute) + .property("name", Self::NAME, attribute) + .property("message", "", attribute) .build(); (Self::NAME, eval_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/error/mod.rs b/boa/src/builtins/error/mod.rs index e7dfaaf4c9c..60622cfd1b9 100644 --- a/boa/src/builtins/error/mod.rs +++ b/boa/src/builtins/error/mod.rs @@ -57,8 +57,8 @@ impl BuiltIn for Error { ) .name(Self::NAME) .length(Self::LENGTH) - .data_property("name", Self::NAME, attribute) - .data_property("message", "", attribute) + .property("name", Self::NAME, attribute) + .property("message", "", attribute) .method(Self::to_string, "toString", 0) .build(); diff --git a/boa/src/builtins/error/range.rs b/boa/src/builtins/error/range.rs index 612ab093402..ed020897650 100644 --- a/boa/src/builtins/error/range.rs +++ b/boa/src/builtins/error/range.rs @@ -41,8 +41,8 @@ impl BuiltIn for RangeError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .data_property("name", Self::NAME, attribute) - .data_property("message", "", attribute) + .property("name", Self::NAME, attribute) + .property("message", "", attribute) .build(); (Self::NAME, range_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/error/reference.rs b/boa/src/builtins/error/reference.rs index 05f284fa3c5..a1e7153ffb4 100644 --- a/boa/src/builtins/error/reference.rs +++ b/boa/src/builtins/error/reference.rs @@ -40,8 +40,8 @@ impl BuiltIn for ReferenceError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .data_property("name", Self::NAME, attribute) - .data_property("message", "", attribute) + .property("name", Self::NAME, attribute) + .property("message", "", attribute) .build(); (Self::NAME, reference_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/error/syntax.rs b/boa/src/builtins/error/syntax.rs index 4b0f954c513..b5764d219a6 100644 --- a/boa/src/builtins/error/syntax.rs +++ b/boa/src/builtins/error/syntax.rs @@ -43,8 +43,8 @@ impl BuiltIn for SyntaxError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .data_property("name", Self::NAME, attribute) - .data_property("message", "", attribute) + .property("name", Self::NAME, attribute) + .property("message", "", attribute) .build(); (Self::NAME, syntax_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/error/type.rs b/boa/src/builtins/error/type.rs index e232da31ce7..c348d36aeb0 100644 --- a/boa/src/builtins/error/type.rs +++ b/boa/src/builtins/error/type.rs @@ -46,8 +46,8 @@ impl BuiltIn for TypeError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .data_property("name", Self::NAME, attribute) - .data_property("message", "", attribute) + .property("name", Self::NAME, attribute) + .property("message", "", attribute) .build(); (Self::NAME, type_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/error/uri.rs b/boa/src/builtins/error/uri.rs index 73e161898ac..928627c9531 100644 --- a/boa/src/builtins/error/uri.rs +++ b/boa/src/builtins/error/uri.rs @@ -42,8 +42,8 @@ impl BuiltIn for UriError { .name(Self::NAME) .length(Self::LENGTH) .inherit(error_prototype.into()) - .data_property("name", Self::NAME, attribute) - .data_property("message", "", attribute) + .property("name", Self::NAME, attribute) + .property("message", "", attribute) .build(); (Self::NAME, uri_error_object.into(), Self::attribute()) diff --git a/boa/src/builtins/map/mod.rs b/boa/src/builtins/map/mod.rs index 5b9ccbf334e..3b9c293743a 100644 --- a/boa/src/builtins/map/mod.rs +++ b/boa/src/builtins/map/mod.rs @@ -40,12 +40,12 @@ impl BuiltIn for Map { let map_object = ConstructorBuilder::new(context, Self::constructor) .name(Self::NAME) .length(Self::LENGTH) - .data_property( + .property( "entries", entries_function.clone(), Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, ) - .data_property( + .property( iterator_symbol, entries_function, Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, diff --git a/boa/src/builtins/number/mod.rs b/boa/src/builtins/number/mod.rs index b7d08ddbd7b..e1753997bcd 100644 --- a/boa/src/builtins/number/mod.rs +++ b/boa/src/builtins/number/mod.rs @@ -61,14 +61,14 @@ impl BuiltIn for Number { ) .name(Self::NAME) .length(Self::LENGTH) - .static_data_property("EPSILON", f64::EPSILON, attribute) - .static_data_property("MAX_SAFE_INTEGER", Self::MAX_SAFE_INTEGER, attribute) - .static_data_property("MIN_SAFE_INTEGER", Self::MIN_SAFE_INTEGER, attribute) - .static_data_property("MAX_VALUE", Self::MAX_VALUE, attribute) - .static_data_property("MIN_VALUE", Self::MIN_VALUE, attribute) - .static_data_property("NEGATIVE_INFINITY", f64::NEG_INFINITY, attribute) - .static_data_property("POSITIVE_INFINITY", f64::INFINITY, attribute) - .static_data_property("NaN", f64::NAN, attribute) + .static_property("EPSILON", f64::EPSILON, attribute) + .static_property("MAX_SAFE_INTEGER", Self::MAX_SAFE_INTEGER, attribute) + .static_property("MIN_SAFE_INTEGER", Self::MIN_SAFE_INTEGER, attribute) + .static_property("MAX_VALUE", Self::MAX_VALUE, attribute) + .static_property("MIN_VALUE", Self::MIN_VALUE, attribute) + .static_property("NEGATIVE_INFINITY", f64::NEG_INFINITY, attribute) + .static_property("POSITIVE_INFINITY", f64::INFINITY, attribute) + .static_property("NaN", f64::NAN, attribute) .method(Self::to_exponential, "toExponential", 1) .method(Self::to_fixed, "toFixed", 1) .method(Self::to_locale_string, "toLocaleString", 0) diff --git a/boa/src/builtins/regexp/mod.rs b/boa/src/builtins/regexp/mod.rs index f1300b9ffab..0b40e238e26 100644 --- a/boa/src/builtins/regexp/mod.rs +++ b/boa/src/builtins/regexp/mod.rs @@ -78,7 +78,7 @@ impl BuiltIn for RegExp { ) .name(Self::NAME) .length(Self::LENGTH) - .data_property("lastIndex", 0, Attribute::all()) + .property("lastIndex", 0, Attribute::all()) .method(Self::test, "test", 1) .method(Self::exec, "exec", 1) .method(Self::to_string, "toString", 0) diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index f7266b5f2c7..b7ee8b07b4e 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -105,7 +105,7 @@ impl BuiltIn for String { ) .name(Self::NAME) .length(Self::LENGTH) - .data_property("length", 0, attribute) + .property("length", 0, attribute) .method(Self::char_at, "charAt", 1) .method(Self::char_code_at, "charCodeAt", 1) .method(Self::code_point_at, "codePointAt", 1) diff --git a/boa/src/builtins/symbol/mod.rs b/boa/src/builtins/symbol/mod.rs index b3c3edab152..05d1c60be88 100644 --- a/boa/src/builtins/symbol/mod.rs +++ b/boa/src/builtins/symbol/mod.rs @@ -268,19 +268,19 @@ impl BuiltIn for Symbol { ) .name(Self::NAME) .length(Self::LENGTH) - .static_data_property("asyncIterator", symbol_async_iterator, attribute) - .static_data_property("hasInstance", symbol_has_instance, attribute) - .static_data_property("isConcatSpreadable", symbol_is_concat_spreadable, attribute) - .static_data_property("iterator", symbol_iterator, attribute) - .static_data_property("match", symbol_match, attribute) - .static_data_property("matchAll", symbol_match_all, attribute) - .static_data_property("replace", symbol_replace, attribute) - .static_data_property("search", symbol_search, attribute) - .static_data_property("species", symbol_species, attribute) - .static_data_property("split", symbol_split, attribute) - .static_data_property("toPrimitive", symbol_to_primitive, attribute) - .static_data_property("toStringTag", symbol_to_string_tag, attribute) - .static_data_property("unscopables", symbol_unscopables, attribute) + .static_property("asyncIterator", symbol_async_iterator, attribute) + .static_property("hasInstance", symbol_has_instance, attribute) + .static_property("isConcatSpreadable", symbol_is_concat_spreadable, attribute) + .static_property("iterator", symbol_iterator, attribute) + .static_property("match", symbol_match, attribute) + .static_property("matchAll", symbol_match_all, attribute) + .static_property("replace", symbol_replace, attribute) + .static_property("search", symbol_search, attribute) + .static_property("species", symbol_species, attribute) + .static_property("split", symbol_split, attribute) + .static_property("toPrimitive", symbol_to_primitive, attribute) + .static_property("toStringTag", symbol_to_string_tag, attribute) + .static_property("unscopables", symbol_unscopables, attribute) .method(Self::to_string, "toString", 0) .callable(true) .constructable(false) diff --git a/boa/src/class.rs b/boa/src/class.rs index bc3f4279a9b..a28b1324400 100644 --- a/boa/src/class.rs +++ b/boa/src/class.rs @@ -160,12 +160,12 @@ impl<'context> ClassBuilder<'context> { /// /// It is added to `prototype`. #[inline] - pub fn data_property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self + pub fn property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self where K: Into, V: Into, { - self.builder.data_property(key, value, attribute); + self.builder.property(key, value, attribute); self } @@ -173,17 +173,12 @@ impl<'context> ClassBuilder<'context> { /// /// It is added to class object itself. #[inline] - pub fn static_data_property( - &mut self, - key: K, - value: V, - attribute: Attribute, - ) -> &mut Self + pub fn static_property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self where K: Into, V: Into, { - self.builder.static_data_property(key, value, attribute); + self.builder.static_property(key, value, attribute); self } @@ -191,7 +186,7 @@ impl<'context> ClassBuilder<'context> { /// /// It is added to `prototype`. #[inline] - pub fn accessor_property( + pub fn accessor( &mut self, key: K, get: Option, @@ -201,7 +196,7 @@ impl<'context> ClassBuilder<'context> { where K: Into, { - self.builder.accessor_property(key, get, set, attribute); + self.builder.accessor(key, get, set, attribute); self } @@ -209,7 +204,7 @@ impl<'context> ClassBuilder<'context> { /// /// It is added to class object itself. #[inline] - pub fn static_accessor_property( + pub fn static_accessor( &mut self, key: K, get: Option, @@ -219,8 +214,7 @@ impl<'context> ClassBuilder<'context> { where K: Into, { - self.builder - .static_accessor_property(key, get, set, attribute); + self.builder.static_accessor(key, get, set, attribute); self } diff --git a/boa/src/object/mod.rs b/boa/src/object/mod.rs index 9fbdddf5be7..da2f80a4ee0 100644 --- a/boa/src/object/mod.rs +++ b/boa/src/object/mod.rs @@ -939,7 +939,7 @@ impl<'context> ConstructorBuilder<'context> { /// Add new data property to the constructor's prototype. #[inline] - pub fn data_property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self + pub fn property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self where K: Into, V: Into, @@ -949,14 +949,9 @@ impl<'context> ConstructorBuilder<'context> { self } - /// Add new static data property to the constructor's object itself. + /// Add new static data property to the constructor object itself. #[inline] - pub fn static_data_property( - &mut self, - key: K, - value: V, - attribute: Attribute, - ) -> &mut Self + pub fn static_property(&mut self, key: K, value: V, attribute: Attribute) -> &mut Self where K: Into, V: Into, @@ -968,7 +963,7 @@ impl<'context> ConstructorBuilder<'context> { /// Add new accessor property to the constructor's prototype. #[inline] - pub fn accessor_property( + pub fn accessor( &mut self, key: K, get: Option, @@ -983,9 +978,9 @@ impl<'context> ConstructorBuilder<'context> { self } - /// Add new static accessor property to the constructor's object itself. + /// Add new static accessor property to the constructor object itself. #[inline] - pub fn static_accessor_property( + pub fn static_accessor( &mut self, key: K, get: Option, @@ -1012,7 +1007,7 @@ impl<'context> ConstructorBuilder<'context> { self } - /// Add new static property to the constructor's object itself. + /// Add new static property to the constructor object itself. #[inline] pub fn static_property_descriptor(&mut self, key: K, property: P) -> &mut Self where