Browse Source

Remove some old builtin code

optimization/static-shapes
Haled Odat 1 year ago
parent
commit
567a17007e
  1. 1
      boa_builtins/Cargo.toml
  2. 74
      boa_builtins/build.rs
  3. 1
      boa_engine/Cargo.toml
  4. 4
      boa_engine/src/builtins/array/array_iterator.rs
  5. 29
      boa_engine/src/builtins/array/mod.rs
  6. 20
      boa_engine/src/builtins/async_generator/mod.rs
  7. 15
      boa_engine/src/builtins/error/type.rs
  8. 20
      boa_engine/src/builtins/generator/mod.rs
  9. 27
      boa_engine/src/builtins/intl/collator/mod.rs
  10. 7
      boa_engine/src/builtins/intl/date_time_format.rs
  11. 34
      boa_engine/src/builtins/intl/mod.rs
  12. 18
      boa_engine/src/builtins/intl/segmenter/iterator.rs
  13. 17
      boa_engine/src/builtins/intl/segmenter/segments.rs
  14. 27
      boa_engine/src/builtins/iterable/async_from_sync_iterator.rs
  15. 38
      boa_engine/src/builtins/iterable/mod.rs
  16. 13
      boa_engine/src/builtins/json/mod.rs
  17. 32
      boa_engine/src/builtins/map/map_iterator.rs
  18. 95
      boa_engine/src/builtins/math/mod.rs
  19. 150
      boa_engine/src/builtins/mod.rs
  20. 23
      boa_engine/src/builtins/object/for_in_iterator.rs
  21. 35
      boa_engine/src/builtins/reflect/mod.rs
  22. 31
      boa_engine/src/builtins/regexp/regexp_string_iterator.rs
  23. 32
      boa_engine/src/builtins/set/set_iterator.rs
  24. 31
      boa_engine/src/builtins/string/string_iterator.rs
  25. 40
      boa_engine/src/context/intrinsics.rs
  26. 1
      boa_engine/src/value/mod.rs

1
boa_builtins/Cargo.toml

@ -12,6 +12,7 @@ build = "build.rs"
[features] [features]
annex-b = [] annex-b = []
intl = []
[dependencies] [dependencies]
bitflags = "2.1.0" bitflags = "2.1.0"

74
boa_builtins/build.rs

@ -1042,11 +1042,83 @@ fn main() -> io::Result<()> {
.method(WellKnown::Iterator) .method(WellKnown::Iterator)
.build(file)?; .build(file)?;
BuiltInBuilder::new(&context, "ARRAY_ITERATOR_PROTOTYPE") BuiltInBuilder::new(&context, "COMMON_ITERATOR_PROTOTYPE")
.method(utf16!("next")) .method(utf16!("next"))
.property(WellKnown::ToStringTag, Attribute::CONFIGURABLE) .property(WellKnown::ToStringTag, Attribute::CONFIGURABLE)
.build(file)?; .build(file)?;
BuiltInBuilder::new(&context, "FOR_IN_ITERATOR_PROTOTYPE")
.method(utf16!("next"))
.build(file)?;
BuiltInBuilder::new(&context, "ASYNC_ITERATOR_PROTOTYPE")
.method(WellKnown::AsyncIterator)
.build(file)?;
BuiltInBuilder::new(&context, "ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE")
.method(utf16!("next"))
.method(utf16!("return"))
.method(utf16!("throw"))
.build(file)?;
BuiltInBuilder::new(&context, "THROW_TYPE_ERROR_OBJECT")
.property(utf16!("length"), Attribute::empty())
.property(utf16!("name"), Attribute::empty())
.build(file)?;
BuiltInBuilder::new(&context, "GENERATOR_OBJECT")
.method(utf16!("next"))
.method(utf16!("return"))
.method(utf16!("throw"))
.property(WellKnown::ToStringTag, Attribute::CONFIGURABLE)
.property(utf16!("CONSTRUCTOR"), Attribute::CONFIGURABLE)
.build(file)?;
#[cfg(feature = "intl")]
{
BuiltInBuilder::new(&context, "INTL_OBJECT")
.property(
WellKnown::ToStringTag,
Attribute::WRITABLE | Attribute::CONFIGURABLE,
)
.property(
utf16!("Collator"),
Attribute::WRITABLE | Attribute::CONFIGURABLE,
)
.property(
utf16!("ListFormat"),
Attribute::WRITABLE | Attribute::CONFIGURABLE,
)
.property(
utf16!("Locale"),
Attribute::WRITABLE | Attribute::CONFIGURABLE,
)
.property(
utf16!("Segmenter"),
Attribute::WRITABLE | Attribute::CONFIGURABLE,
)
.property(
utf16!("DateTimeFormat"),
Attribute::WRITABLE | Attribute::CONFIGURABLE,
)
.method(utf16!("getCanonicalLocales"))
.build(file)?;
BuiltInBuilderConstructor::new(&context, "DATE_TIME_FORMAT").build(file)?;
BuiltInBuilderConstructor::new(&context, "COLLATOR")
.static_method(utf16!("supportedLocalesOf"))
.property(WellKnown::ToStringTag, Attribute::CONFIGURABLE)
.accessor(utf16!("compare"), Attribute::CONFIGURABLE)
.method(utf16!("resolvedOptions"))
.build(file)?;
BuiltInBuilder::new(&context, "SEGMENTS_PROTOTYPE")
.method(utf16!("containing"))
.method(WellKnown::Iterator)
.build(file)?;
}
context.build(file)?; context.build(file)?;
Ok(()) Ok(())

1
boa_engine/Cargo.toml

@ -16,6 +16,7 @@ profiler = ["boa_profiler/profiler"]
deser = ["boa_interner/serde", "boa_ast/serde"] deser = ["boa_interner/serde", "boa_ast/serde"]
intl = [ intl = [
"boa_icu_provider/full", "boa_icu_provider/full",
"boa_builtins/intl",
"icu_normalizer/serde", "icu_normalizer/serde",
"icu_normalizer/std", "icu_normalizer/std",
"dep:icu_locid_transform", "dep:icu_locid_transform",

4
boa_engine/src/builtins/array/array_iterator.rs

@ -38,9 +38,9 @@ impl IntrinsicObject for ArrayIterator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("ArrayIterator", "init"); let _timer = Profiler::global().start_event("ArrayIterator", "init");
BuiltInBuilder::with_intrinsic_static_shape::<Self>( BuiltInBuilder::with_intrinsic::<Self>(
realm, realm,
&boa_builtins::ARRAY_ITERATOR_PROTOTYPE_STATIC_SHAPE, &boa_builtins::COMMON_ITERATOR_PROTOTYPE_STATIC_SHAPE,
) )
.prototype( .prototype(
realm realm

29
boa_engine/src/builtins/array/mod.rs

@ -36,6 +36,25 @@ pub(crate) use array_iterator::ArrayIterator;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub(crate) struct ArrayPrototypeValues;
impl IntrinsicObject for ArrayPrototypeValues {
fn init(realm: &Realm) {
BuiltInBuilder::callable_intrinsic::<Self>(realm, Array::values)
.length(0)
.name(Self::NAME)
.build();
}
fn get(intrinsics: &Intrinsics) -> JsObject {
intrinsics.objects().array_prototype_values().into()
}
}
impl BuiltInObject for ArrayPrototypeValues {
const NAME: &'static str = "values";
}
/// JavaScript `Array` built-in implementation. /// JavaScript `Array` built-in implementation.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub(crate) struct Array; pub(crate) struct Array;
@ -44,17 +63,13 @@ impl IntrinsicObject for Array {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init"); let _timer = Profiler::global().start_event(Self::NAME, "init");
ArrayPrototypeValues::init(realm);
let get_species = BuiltInBuilder::callable(realm, Self::get_species) let get_species = BuiltInBuilder::callable(realm, Self::get_species)
.name("get [Symbol.species]") .name("get [Symbol.species]")
.build(); .build();
let values_function = BuiltInBuilder::callable_with_object( let values_function = realm.intrinsics().objects().array_prototype_values();
realm,
realm.intrinsics().objects().array_prototype_values().into(),
Self::values,
)
.name("values")
.build();
let unscopables_object = Self::unscopables_object(); let unscopables_object = Self::unscopables_object();

20
boa_engine/src/builtins/async_generator/mod.rs

@ -13,10 +13,8 @@ use crate::{
context::intrinsics::Intrinsics, context::intrinsics::Intrinsics,
error::JsNativeError, error::JsNativeError,
native_function::NativeFunction, native_function::NativeFunction,
object::{FunctionObjectBuilder, JsObject, CONSTRUCTOR}, object::{FunctionObjectBuilder, JsObject},
property::Attribute,
realm::Realm, realm::Realm,
symbol::JsSymbol,
value::JsValue, value::JsValue,
vm::GeneratorResumeKind, vm::GeneratorResumeKind,
Context, JsArgs, JsError, JsResult, Context, JsArgs, JsError, JsResult,
@ -70,7 +68,7 @@ impl IntrinsicObject for AsyncGenerator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init"); let _timer = Profiler::global().start_event(Self::NAME, "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(realm, &boa_builtins::GENERATOR_OBJECT_STATIC_SHAPE)
.prototype( .prototype(
realm realm
.intrinsics() .intrinsics()
@ -78,22 +76,16 @@ impl IntrinsicObject for AsyncGenerator {
.iterator_prototypes() .iterator_prototypes()
.async_iterator(), .async_iterator(),
) )
.static_method(Self::next, "next", 1) .static_method(Self::next, 1)
.static_method(Self::r#return, "return", 1) .static_method(Self::r#return, 1)
.static_method(Self::throw, "throw", 1) .static_method(Self::throw, 1)
.static_property(Self::NAME)
.static_property( .static_property(
JsSymbol::to_string_tag(),
Self::NAME,
Attribute::CONFIGURABLE,
)
.static_property(
CONSTRUCTOR,
realm realm
.intrinsics() .intrinsics()
.constructors() .constructors()
.async_generator_function() .async_generator_function()
.prototype(), .prototype(),
Attribute::CONFIGURABLE,
) )
.build(); .build();
} }

15
boa_engine/src/builtins/error/type.rs

@ -23,7 +23,6 @@ use crate::{
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors}, context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
error::JsNativeError, error::JsNativeError,
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData, ObjectKind}, object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData, ObjectKind},
property::Attribute,
realm::Realm, realm::Realm,
string::utf16, string::utf16,
Context, JsArgs, JsResult, JsString, JsValue, NativeFunction, Context, JsArgs, JsResult, JsString, JsValue, NativeFunction,
@ -131,12 +130,16 @@ impl IntrinsicObject for ThrowTypeError {
.into()) .into())
} }
let obj = BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(
.prototype(realm.intrinsics().constructors().function().prototype()) realm,
.static_property(utf16!("length"), 0, Attribute::empty()) &boa_builtins::THROW_TYPE_ERROR_OBJECT_STATIC_SHAPE,
.static_property(utf16!("name"), "", Attribute::empty()) )
.build(); .prototype(realm.intrinsics().constructors().function().prototype())
.static_property(0)
.static_property("")
.build();
let obj = Self::get(realm.intrinsics());
let mut obj = obj.borrow_mut(); let mut obj = obj.borrow_mut();
obj.extensible = false; obj.extensible = false;

20
boa_engine/src/builtins/generator/mod.rs

@ -14,10 +14,8 @@ use crate::{
context::intrinsics::Intrinsics, context::intrinsics::Intrinsics,
environments::EnvironmentStack, environments::EnvironmentStack,
error::JsNativeError, error::JsNativeError,
object::{JsObject, CONSTRUCTOR}, object::JsObject,
property::Attribute,
realm::Realm, realm::Realm,
symbol::JsSymbol,
value::JsValue, value::JsValue,
vm::{CallFrame, CompletionRecord, GeneratorResumeKind}, vm::{CallFrame, CompletionRecord, GeneratorResumeKind},
Context, JsArgs, JsError, JsResult, Context, JsArgs, JsError, JsResult,
@ -136,7 +134,7 @@ impl IntrinsicObject for Generator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init"); let _timer = Profiler::global().start_event(Self::NAME, "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(realm, &boa_builtins::GENERATOR_OBJECT_STATIC_SHAPE)
.prototype( .prototype(
realm realm
.intrinsics() .intrinsics()
@ -144,22 +142,16 @@ impl IntrinsicObject for Generator {
.iterator_prototypes() .iterator_prototypes()
.iterator(), .iterator(),
) )
.static_method(Self::next, "next", 1) .static_method(Self::next, 1)
.static_method(Self::r#return, "return", 1) .static_method(Self::r#return, 1)
.static_method(Self::throw, "throw", 1) .static_method(Self::throw, 1)
.static_property(Self::NAME)
.static_property( .static_property(
JsSymbol::to_string_tag(),
Self::NAME,
Attribute::CONFIGURABLE,
)
.static_property(
CONSTRUCTOR,
realm realm
.intrinsics() .intrinsics()
.constructors() .constructors()
.generator_function() .generator_function()
.prototype(), .prototype(),
Attribute::CONFIGURABLE,
) )
.build(); .build();
} }

27
boa_engine/src/builtins/intl/collator/mod.rs

@ -21,10 +21,8 @@ use crate::{
internal_methods::get_prototype_from_constructor, FunctionObjectBuilder, JsFunction, internal_methods::get_prototype_from_constructor, FunctionObjectBuilder, JsFunction,
JsObject, ObjectData, JsObject, ObjectData,
}, },
property::Attribute,
realm::Realm, realm::Realm,
string::utf16, string::utf16,
symbol::JsSymbol,
Context, JsArgs, JsNativeError, JsResult, JsValue, Context, JsArgs, JsNativeError, JsResult, JsValue,
}; };
@ -167,21 +165,16 @@ impl IntrinsicObject for Collator {
.name("get compare") .name("get compare")
.build(); .build();
BuiltInBuilder::from_standard_constructor::<Self>(realm) BuiltInBuilder::from_standard_constructor_static_shape::<Self>(
.static_method(Self::supported_locales_of, "supportedLocalesOf", 1) realm,
.property( &boa_builtins::COLLATOR_CONSTRUCTOR_STATIC_SHAPE,
JsSymbol::to_string_tag(), &boa_builtins::COLLATOR_PROTOTYPE_STATIC_SHAPE,
"Intl.Collator", )
Attribute::CONFIGURABLE, .static_method(Self::supported_locales_of, 1)
) .property("Intl.Collator")
.accessor( .accessor(Some(compare), None)
utf16!("compare"), .method(Self::resolved_options, 0)
Some(compare), .build();
None,
Attribute::CONFIGURABLE,
)
.method(Self::resolved_options, "resolvedOptions", 0)
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

7
boa_engine/src/builtins/intl/date_time_format.rs

@ -66,7 +66,12 @@ impl IntrinsicObject for DateTimeFormat {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init"); let _timer = Profiler::global().start_event(Self::NAME, "init");
BuiltInBuilder::from_standard_constructor::<Self>(realm).build(); BuiltInBuilder::from_standard_constructor_static_shape::<Self>(
realm,
&boa_builtins::DATE_TIME_FORMAT_CONSTRUCTOR_STATIC_SHAPE,
&boa_builtins::DATE_TIME_FORMAT_PROTOTYPE_STATIC_SHAPE,
)
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

34
boa_engine/src/builtins/intl/mod.rs

@ -13,9 +13,7 @@ use crate::{
builtins::{Array, BuiltInBuilder, BuiltInObject, IntrinsicObject}, builtins::{Array, BuiltInBuilder, BuiltInObject, IntrinsicObject},
context::{intrinsics::Intrinsics, BoaProvider}, context::{intrinsics::Intrinsics, BoaProvider},
object::JsObject, object::JsObject,
property::Attribute,
realm::Realm, realm::Realm,
symbol::JsSymbol,
Context, JsArgs, JsResult, JsValue, Context, JsArgs, JsResult, JsValue,
}; };
@ -43,46 +41,26 @@ impl IntrinsicObject for Intl {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init"); let _timer = Profiler::global().start_event(Self::NAME, "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(realm, &boa_builtins::INTL_OBJECT_STATIC_SHAPE)
.static_property(Self::NAME)
.static_property(realm.intrinsics().constructors().collator().constructor())
.static_property( .static_property(
JsSymbol::to_string_tag(),
Self::NAME,
Attribute::CONFIGURABLE,
)
.static_property(
Collator::NAME,
realm.intrinsics().constructors().collator().constructor(),
Collator::ATTRIBUTE,
)
.static_property(
ListFormat::NAME,
realm realm
.intrinsics() .intrinsics()
.constructors() .constructors()
.list_format() .list_format()
.constructor(), .constructor(),
ListFormat::ATTRIBUTE,
)
.static_property(
Locale::NAME,
realm.intrinsics().constructors().locale().constructor(),
Locale::ATTRIBUTE,
)
.static_property(
Segmenter::NAME,
realm.intrinsics().constructors().segmenter().constructor(),
Segmenter::ATTRIBUTE,
) )
.static_property(realm.intrinsics().constructors().locale().constructor())
.static_property(realm.intrinsics().constructors().segmenter().constructor())
.static_property( .static_property(
DateTimeFormat::NAME,
realm realm
.intrinsics() .intrinsics()
.constructors() .constructors()
.date_time_format() .date_time_format()
.constructor(), .constructor(),
DateTimeFormat::ATTRIBUTE,
) )
.static_method(Self::get_canonical_locales, "getCanonicalLocales", 1) .static_method(Self::get_canonical_locales, 1)
.build(); .build();
} }

18
boa_engine/src/builtins/intl/segmenter/iterator.rs

@ -9,9 +9,8 @@ use crate::{
context::intrinsics::Intrinsics, context::intrinsics::Intrinsics,
js_string, js_string,
object::ObjectData, object::ObjectData,
property::Attribute,
realm::Realm, realm::Realm,
Context, JsNativeError, JsObject, JsResult, JsString, JsSymbol, JsValue, Context, JsNativeError, JsObject, JsResult, JsString, JsValue,
}; };
use super::create_segment_data_object; use super::create_segment_data_object;
@ -57,14 +56,13 @@ impl IntrinsicObject for SegmentIterator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("%SegmentIteratorPrototype%", "init"); let _timer = Profiler::global().start_event("%SegmentIteratorPrototype%", "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(
.static_property( realm,
JsSymbol::to_string_tag(), &boa_builtins::COMMON_ITERATOR_PROTOTYPE_STATIC_SHAPE,
js_string!("Segmenter String Iterator"), )
Attribute::CONFIGURABLE, .static_method(Self::next, 0)
) .static_property(js_string!("Segmenter String Iterator"))
.static_method(Self::next, js_string!("next"), 0) .build();
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

17
boa_engine/src/builtins/intl/segmenter/segments.rs

@ -8,7 +8,7 @@ use crate::{
js_string, js_string,
object::ObjectData, object::ObjectData,
realm::Realm, realm::Realm,
Context, JsArgs, JsNativeError, JsObject, JsResult, JsString, JsSymbol, JsValue, Context, JsArgs, JsNativeError, JsObject, JsResult, JsString, JsValue,
}; };
use super::{create_segment_data_object, SegmentIterator}; use super::{create_segment_data_object, SegmentIterator};
@ -23,14 +23,13 @@ impl IntrinsicObject for Segments {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("%SegmentsPrototype%", "init"); let _timer = Profiler::global().start_event("%SegmentsPrototype%", "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(
.static_method(Self::containing, "containing", 1) realm,
.static_method( &boa_builtins::SEGMENTS_PROTOTYPE_STATIC_SHAPE,
Self::iterator, )
(JsSymbol::iterator(), js_string!("[Symbol.iterator]")), .static_method(Self::containing, 1)
0, .static_method_with_name(Self::iterator, js_string!("[Symbol.iterator]"), 0)
) .build();
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

27
boa_engine/src/builtins/iterable/async_from_sync_iterator.rs

@ -30,18 +30,21 @@ impl IntrinsicObject for AsyncFromSyncIterator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("AsyncFromSyncIteratorPrototype", "init"); let _timer = Profiler::global().start_event("AsyncFromSyncIteratorPrototype", "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(
.prototype( realm,
realm &boa_builtins::ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_STATIC_SHAPE,
.intrinsics() )
.objects() .prototype(
.iterator_prototypes() realm
.async_iterator(), .intrinsics()
) .objects()
.static_method(Self::next, "next", 1) .iterator_prototypes()
.static_method(Self::r#return, "return", 1) .async_iterator(),
.static_method(Self::throw, "throw", 1) )
.build(); .static_method(Self::next, 1)
.static_method(Self::r#return, 1)
.static_method(Self::throw, 1)
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

38
boa_engine/src/builtins/iterable/mod.rs

@ -79,15 +79,15 @@ impl Default for IteratorPrototypes {
Self { Self {
array: JsObject::default_with_static_shape(), array: JsObject::default_with_static_shape(),
iterator: JsObject::default_with_static_shape(), iterator: JsObject::default_with_static_shape(),
async_iterator: JsObject::default(), async_iterator: JsObject::default_with_static_shape(),
async_from_sync_iterator: JsObject::default(), async_from_sync_iterator: JsObject::default_with_static_shape(),
set: JsObject::default(), set: JsObject::default_with_static_shape(),
string: JsObject::default(), string: JsObject::default_with_static_shape(),
regexp_string: JsObject::default(), regexp_string: JsObject::default_with_static_shape(),
map: JsObject::default(), map: JsObject::default_with_static_shape(),
for_in: JsObject::default(), for_in: JsObject::default_with_static_shape(),
#[cfg(feature = "intl")] #[cfg(feature = "intl")]
segment: JsObject::default(), segment: JsObject::default_with_static_shape(),
} }
} }
} }
@ -168,7 +168,7 @@ impl IntrinsicObject for Iterator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("Iterator Prototype", "init"); let _timer = Profiler::global().start_event("Iterator Prototype", "init");
BuiltInBuilder::with_intrinsic_static_shape::<Self>( BuiltInBuilder::with_intrinsic::<Self>(
realm, realm,
&boa_builtins::ITERATOR_PROTOTYPE_STATIC_SHAPE, &boa_builtins::ITERATOR_PROTOTYPE_STATIC_SHAPE,
) )
@ -193,16 +193,16 @@ impl IntrinsicObject for AsyncIterator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("AsyncIteratorPrototype", "init"); let _timer = Profiler::global().start_event("AsyncIteratorPrototype", "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(
.static_method( realm,
|v, _, _| Ok(v.clone()), &boa_builtins::ASYNC_ITERATOR_PROTOTYPE_STATIC_SHAPE,
( )
JsSymbol::async_iterator(), .static_method_with_name(
js_string!("[Symbol.asyncIterator]"), |v, _, _| Ok(v.clone()),
), js_string!("[Symbol.asyncIterator]"),
0, 0,
) )
.build(); .build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

13
boa_engine/src/builtins/json/mod.rs

@ -49,14 +49,11 @@ impl IntrinsicObject for Json {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init"); let _timer = Profiler::global().start_event(Self::NAME, "init");
BuiltInBuilder::with_intrinsic_static_shape::<Self>( BuiltInBuilder::with_intrinsic::<Self>(realm, &boa_builtins::JSON_OBJECT_STATIC_SHAPE)
realm, .static_method(Self::parse, 2)
&boa_builtins::JSON_OBJECT_STATIC_SHAPE, .static_method(Self::stringify, 3)
) .static_property(Self::NAME)
.static_method(Self::parse, 2) .build();
.static_method(Self::stringify, 3)
.static_property(Self::NAME)
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

32
boa_engine/src/builtins/map/map_iterator.rs

@ -13,9 +13,8 @@ use crate::{
context::intrinsics::Intrinsics, context::intrinsics::Intrinsics,
error::JsNativeError, error::JsNativeError,
object::{JsObject, ObjectData}, object::{JsObject, ObjectData},
property::{Attribute, PropertyNameKind}, property::PropertyNameKind,
realm::Realm, realm::Realm,
symbol::JsSymbol,
Context, JsResult, Context, JsResult,
}; };
use boa_gc::{Finalize, Trace}; use boa_gc::{Finalize, Trace};
@ -40,21 +39,20 @@ impl IntrinsicObject for MapIterator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("MapIterator", "init"); let _timer = Profiler::global().start_event("MapIterator", "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(
.prototype( realm,
realm &boa_builtins::COMMON_ITERATOR_PROTOTYPE_STATIC_SHAPE,
.intrinsics() )
.objects() .prototype(
.iterator_prototypes() realm
.iterator(), .intrinsics()
) .objects()
.static_method(Self::next, "next", 0) .iterator_prototypes()
.static_property( .iterator(),
JsSymbol::to_string_tag(), )
"Map Iterator", .static_method(Self::next, 0)
Attribute::CONFIGURABLE, .static_property("Map Iterator")
) .build();
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

95
boa_engine/src/builtins/math/mod.rs

@ -30,55 +30,52 @@ impl IntrinsicObject for Math {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init"); let _timer = Profiler::global().start_event(Self::NAME, "init");
BuiltInBuilder::with_intrinsic_static_shape::<Self>( BuiltInBuilder::with_intrinsic::<Self>(realm, &boa_builtins::MATH_OBJECT_STATIC_SHAPE)
realm, .static_property(std::f64::consts::E)
&boa_builtins::MATH_OBJECT_STATIC_SHAPE, .static_property(std::f64::consts::LN_10)
) .static_property(std::f64::consts::LN_2)
.static_property(std::f64::consts::E) .static_property(std::f64::consts::LOG10_E)
.static_property(std::f64::consts::LN_10) .static_property(std::f64::consts::LOG2_E)
.static_property(std::f64::consts::LN_2) .static_property(std::f64::consts::PI)
.static_property(std::f64::consts::LOG10_E) .static_property(std::f64::consts::FRAC_1_SQRT_2)
.static_property(std::f64::consts::LOG2_E) .static_property(std::f64::consts::SQRT_2)
.static_property(std::f64::consts::PI) .static_method(Self::abs, 1)
.static_property(std::f64::consts::FRAC_1_SQRT_2) .static_method(Self::acos, 1)
.static_property(std::f64::consts::SQRT_2) .static_method(Self::acosh, 1)
.static_method(Self::abs, 1) .static_method(Self::asin, 1)
.static_method(Self::acos, 1) .static_method(Self::asinh, 1)
.static_method(Self::acosh, 1) .static_method(Self::atan, 1)
.static_method(Self::asin, 1) .static_method(Self::atanh, 1)
.static_method(Self::asinh, 1) .static_method(Self::atan2, 2)
.static_method(Self::atan, 1) .static_method(Self::cbrt, 1)
.static_method(Self::atanh, 1) .static_method(Self::ceil, 1)
.static_method(Self::atan2, 2) .static_method(Self::clz32, 1)
.static_method(Self::cbrt, 1) .static_method(Self::cos, 1)
.static_method(Self::ceil, 1) .static_method(Self::cosh, 1)
.static_method(Self::clz32, 1) .static_method(Self::exp, 1)
.static_method(Self::cos, 1) .static_method(Self::expm1, 1)
.static_method(Self::cosh, 1) .static_method(Self::floor, 1)
.static_method(Self::exp, 1) .static_method(Self::fround, 1)
.static_method(Self::expm1, 1) .static_method(Self::hypot, 2)
.static_method(Self::floor, 1) .static_method(Self::imul, 2)
.static_method(Self::fround, 1) .static_method(Self::log, 1)
.static_method(Self::hypot, 2) .static_method(Self::log1p, 1)
.static_method(Self::imul, 2) .static_method(Self::log10, 1)
.static_method(Self::log, 1) .static_method(Self::log2, 1)
.static_method(Self::log1p, 1) .static_method(Self::max, 2)
.static_method(Self::log10, 1) .static_method(Self::min, 2)
.static_method(Self::log2, 1) .static_method(Self::pow, 2)
.static_method(Self::max, 2) .static_method(Self::random, 0)
.static_method(Self::min, 2) .static_method(Self::round, 1)
.static_method(Self::pow, 2) .static_method(Self::sign, 1)
.static_method(Self::random, 0) .static_method(Self::sin, 1)
.static_method(Self::round, 1) .static_method(Self::sinh, 1)
.static_method(Self::sign, 1) .static_method(Self::sqrt, 1)
.static_method(Self::sin, 1) .static_method(Self::tan, 1)
.static_method(Self::sinh, 1) .static_method(Self::tanh, 1)
.static_method(Self::sqrt, 1) .static_method(Self::trunc, 1)
.static_method(Self::tan, 1) .static_property(Self::NAME)
.static_method(Self::tanh, 1) .build();
.static_method(Self::trunc, 1)
.static_property(Self::NAME)
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

150
boa_engine/src/builtins/mod.rs

@ -397,19 +397,6 @@ impl BuiltInObjectInitializer {
}; };
} }
/// Sets the prototype of the builtin
fn set_prototype(&mut self, prototype: JsObject) {
match self {
Self::Shared(obj) => {
let mut obj = obj.borrow_mut();
obj.set_prototype(prototype);
}
Self::Unique { object, .. } => {
object.set_prototype(prototype);
}
}
}
/// Sets the `ObjectData` of the builtin. /// Sets the `ObjectData` of the builtin.
/// ///
/// # Panics /// # Panics
@ -450,11 +437,6 @@ impl BuiltInObjectInitializer {
} }
} }
} }
/// Converts the builtin into a shared object.
fn into_shared(mut self) -> JsObject {
self.as_shared()
}
} }
/// Marker for a constructor function. /// Marker for a constructor function.
@ -583,13 +565,7 @@ impl ApplyToObject for OrdinaryObject {
/// The marker `ObjectType` restricts the methods that can be called depending on the /// The marker `ObjectType` restricts the methods that can be called depending on the
/// type of object that is being constructed. /// type of object that is being constructed.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "You need to call the `build` method in order for this to correctly assign the inner data"] struct BuiltInBuilder {}
struct BuiltInBuilder<'ctx, Kind> {
realm: &'ctx Realm,
object: BuiltInObjectInitializer,
kind: Kind,
prototype: JsObject,
}
struct BuiltInBuilderCallableIntrinsic<'ctx> { struct BuiltInBuilderCallableIntrinsic<'ctx> {
realm: &'ctx Realm, realm: &'ctx Realm,
@ -615,7 +591,7 @@ impl BuiltInBuilderCallableIntrinsic<'_> {
let function = function::Function::new( let function = function::Function::new(
function::FunctionKind::Native { function::FunctionKind::Native {
function: NativeFunction::from_fn_ptr(self.function), function: NativeFunction::from_fn_ptr(self.function),
constructor: (true).then_some(function::ConstructorKind::Base), constructor: None,
}, },
self.realm.clone(), self.realm.clone(),
); );
@ -652,7 +628,7 @@ struct BuiltInBuilderConstructorStaticShape<'ctx> {
inherits: Option<JsObject>, inherits: Option<JsObject>,
} }
impl<'ctx> BuiltInBuilder<'ctx, Callable<Constructor>> { impl<'ctx> BuiltInBuilder {
fn from_standard_constructor_static_shape<SC: BuiltInConstructor>( fn from_standard_constructor_static_shape<SC: BuiltInConstructor>(
realm: &'ctx Realm, realm: &'ctx Realm,
constructor_shape: &'static RawStaticShape, constructor_shape: &'static RawStaticShape,
@ -918,20 +894,9 @@ impl BuiltInBuilderStaticShape<'_> {
} }
} }
impl<'ctx> BuiltInBuilder<'ctx, OrdinaryObject> { impl<'ctx> BuiltInBuilder {
fn with_intrinsic<I: IntrinsicObject>( fn with_intrinsic<I: IntrinsicObject>(
realm: &'ctx Realm, realm: &'ctx Realm,
) -> BuiltInBuilder<'ctx, OrdinaryObject> {
BuiltInBuilder {
realm,
object: BuiltInObjectInitializer::Shared(I::get(realm.intrinsics())),
kind: OrdinaryObject,
prototype: realm.intrinsics().constructors().object().prototype(),
}
}
fn with_intrinsic_static_shape<I: IntrinsicObject>(
realm: &'ctx Realm,
shape: &'static boa_builtins::StaticShape, shape: &'static boa_builtins::StaticShape,
) -> BuiltInBuilderStaticShape<'ctx> { ) -> BuiltInBuilderStaticShape<'ctx> {
BuiltInBuilderStaticShape { BuiltInBuilderStaticShape {
@ -1267,7 +1232,7 @@ impl BuiltInCallable<'_> {
} }
} }
impl<'ctx> BuiltInBuilder<'ctx, OrdinaryObject> { impl<'ctx> BuiltInBuilder {
fn callable(realm: &'ctx Realm, function: NativeFunctionPointer) -> BuiltInCallable<'ctx> { fn callable(realm: &'ctx Realm, function: NativeFunctionPointer) -> BuiltInCallable<'ctx> {
BuiltInCallable { BuiltInCallable {
realm, realm,
@ -1289,28 +1254,9 @@ impl<'ctx> BuiltInBuilder<'ctx, OrdinaryObject> {
length: 0, length: 0,
} }
} }
fn callable_with_object(
realm: &'ctx Realm,
object: JsObject,
function: NativeFunctionPointer,
) -> BuiltInBuilder<'ctx, Callable<OrdinaryFunction>> {
BuiltInBuilder {
realm,
object: BuiltInObjectInitializer::Shared(object),
kind: Callable {
function,
name: js_string!(""),
length: 0,
kind: OrdinaryFunction,
realm: realm.clone(),
},
prototype: realm.intrinsics().constructors().function().prototype(),
}
}
} }
impl<'ctx> BuiltInBuilder<'ctx, Callable<Constructor>> { impl<'ctx> BuiltInBuilder {
fn from_standard_constructor<SC: BuiltInConstructor>( fn from_standard_constructor<SC: BuiltInConstructor>(
realm: &'ctx Realm, realm: &'ctx Realm,
) -> BuiltInConstructorWithPrototype<'ctx> { ) -> BuiltInConstructorWithPrototype<'ctx> {
@ -1332,87 +1278,3 @@ impl<'ctx> BuiltInBuilder<'ctx, Callable<Constructor>> {
} }
} }
} }
impl<T> BuiltInBuilder<'_, T> {
/// Adds a new static method to the builtin object.
fn static_method<B>(
mut self,
function: NativeFunctionPointer,
binding: B,
length: usize,
) -> Self
where
B: Into<FunctionBinding>,
{
let binding = binding.into();
let function = BuiltInBuilder::callable(self.realm, function)
.name(binding.name)
.length(length)
.build();
self.object.insert(
binding.binding,
PropertyDescriptor::builder()
.value(function)
.writable(true)
.enumerable(false)
.configurable(true),
);
self
}
/// Adds a new static data property to the builtin object.
fn static_property<K, V>(mut self, key: K, value: V, attribute: Attribute) -> Self
where
K: Into<PropertyKey>,
V: Into<JsValue>,
{
let property = PropertyDescriptor::builder()
.value(value)
.writable(attribute.writable())
.enumerable(attribute.enumerable())
.configurable(attribute.configurable());
self.object.insert(key, property);
self
}
/// Specify the `[[Prototype]]` internal field of the builtin object.
///
/// Default is `Function.prototype` for constructors and `Object.prototype` for statics.
fn prototype(mut self, prototype: JsObject) -> Self {
self.prototype = prototype;
self
}
}
impl<FnTyp> BuiltInBuilder<'_, Callable<FnTyp>> {
/// Specify the name of the constructor function.
///
/// Default is `""`
fn name<N: Into<JsString>>(mut self, name: N) -> Self {
self.kind.name = name.into();
self
}
}
impl BuiltInBuilder<'_, OrdinaryObject> {
/// Build the builtin object.
fn build(mut self) -> JsObject {
self.kind.apply_to(&mut self.object);
self.object.set_prototype(self.prototype);
self.object.into_shared()
}
}
impl<FnTyp: ApplyToObject + IsConstructor> BuiltInBuilder<'_, Callable<FnTyp>> {
/// Build the builtin callable.
fn build(mut self) -> JsFunction {
self.kind.apply_to(&mut self.object);
self.object.set_prototype(self.prototype);
JsFunction::from_object_unchecked(self.object.into_shared())
}
}

23
boa_engine/src/builtins/object/for_in_iterator.rs

@ -41,16 +41,19 @@ impl IntrinsicObject for ForInIterator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("ForInIterator", "init"); let _timer = Profiler::global().start_event("ForInIterator", "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(
.prototype( realm,
realm &boa_builtins::FOR_IN_ITERATOR_PROTOTYPE_STATIC_SHAPE,
.intrinsics() )
.objects() .prototype(
.iterator_prototypes() realm
.iterator(), .intrinsics()
) .objects()
.static_method(Self::next, "next", 0) .iterator_prototypes()
.build(); .iterator(),
)
.static_method(Self::next, 0)
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

35
boa_engine/src/builtins/reflect/mod.rs

@ -32,25 +32,22 @@ impl IntrinsicObject for Reflect {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init"); let _timer = Profiler::global().start_event(Self::NAME, "init");
BuiltInBuilder::with_intrinsic_static_shape::<Self>( BuiltInBuilder::with_intrinsic::<Self>(realm, &boa_builtins::REFLECT_OBJECT_STATIC_SHAPE)
realm, .static_method(Self::apply, 3)
&boa_builtins::REFLECT_OBJECT_STATIC_SHAPE, .static_method(Self::construct, 2)
) .static_method(Self::define_property, 3)
.static_method(Self::apply, 3) .static_method(Self::delete_property, 2)
.static_method(Self::construct, 2) .static_method(Self::get, 2)
.static_method(Self::define_property, 3) .static_method(Self::get_own_property_descriptor, 2)
.static_method(Self::delete_property, 2) .static_method(Self::get_prototype_of, 1)
.static_method(Self::get, 2) .static_method(Self::has, 2)
.static_method(Self::get_own_property_descriptor, 2) .static_method(Self::is_extensible, 1)
.static_method(Self::get_prototype_of, 1) .static_method(Self::own_keys, 1)
.static_method(Self::has, 2) .static_method(Self::prevent_extensions, 1)
.static_method(Self::is_extensible, 1) .static_method(Self::set, 3)
.static_method(Self::own_keys, 1) .static_method(Self::set_prototype_of, 2)
.static_method(Self::prevent_extensions, 1) .static_property(Self::NAME)
.static_method(Self::set, 3) .build();
.static_method(Self::set_prototype_of, 2)
.static_property(Self::NAME)
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

31
boa_engine/src/builtins/regexp/regexp_string_iterator.rs

@ -15,10 +15,8 @@ use crate::{
context::intrinsics::Intrinsics, context::intrinsics::Intrinsics,
error::JsNativeError, error::JsNativeError,
object::{JsObject, ObjectData}, object::{JsObject, ObjectData},
property::Attribute,
realm::Realm, realm::Realm,
string::utf16, string::utf16,
symbol::JsSymbol,
Context, JsResult, JsString, JsValue, Context, JsResult, JsString, JsValue,
}; };
use boa_gc::{Finalize, Trace}; use boa_gc::{Finalize, Trace};
@ -44,21 +42,20 @@ impl IntrinsicObject for RegExpStringIterator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("RegExpStringIterator", "init"); let _timer = Profiler::global().start_event("RegExpStringIterator", "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(
.prototype( realm,
realm &boa_builtins::COMMON_ITERATOR_PROTOTYPE_STATIC_SHAPE,
.intrinsics() )
.objects() .prototype(
.iterator_prototypes() realm
.iterator(), .intrinsics()
) .objects()
.static_method(Self::next, "next", 0) .iterator_prototypes()
.static_property( .iterator(),
JsSymbol::to_string_tag(), )
"RegExp String Iterator", .static_method(Self::next, 0)
Attribute::CONFIGURABLE, .static_property("RegExp String Iterator")
) .build();
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

32
boa_engine/src/builtins/set/set_iterator.rs

@ -13,9 +13,8 @@ use crate::{
context::intrinsics::Intrinsics, context::intrinsics::Intrinsics,
error::JsNativeError, error::JsNativeError,
object::{JsObject, ObjectData}, object::{JsObject, ObjectData},
property::{Attribute, PropertyNameKind}, property::PropertyNameKind,
realm::Realm, realm::Realm,
symbol::JsSymbol,
Context, JsResult, Context, JsResult,
}; };
use boa_gc::{Finalize, Trace}; use boa_gc::{Finalize, Trace};
@ -40,21 +39,20 @@ impl IntrinsicObject for SetIterator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("SetIterator", "init"); let _timer = Profiler::global().start_event("SetIterator", "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(
.prototype( realm,
realm &boa_builtins::COMMON_ITERATOR_PROTOTYPE_STATIC_SHAPE,
.intrinsics() )
.objects() .prototype(
.iterator_prototypes() realm
.iterator(), .intrinsics()
) .objects()
.static_method(Self::next, "next", 0) .iterator_prototypes()
.static_property( .iterator(),
JsSymbol::to_string_tag(), )
"Set Iterator", .static_method(Self::next, 0)
Attribute::CONFIGURABLE, .static_property("Set Iterator")
) .build();
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

31
boa_engine/src/builtins/string/string_iterator.rs

@ -11,9 +11,7 @@ use crate::{
error::JsNativeError, error::JsNativeError,
js_string, js_string,
object::{JsObject, ObjectData}, object::{JsObject, ObjectData},
property::Attribute,
realm::Realm, realm::Realm,
symbol::JsSymbol,
Context, JsResult, JsString, JsValue, Context, JsResult, JsString, JsValue,
}; };
use boa_gc::{Finalize, Trace}; use boa_gc::{Finalize, Trace};
@ -35,21 +33,20 @@ impl IntrinsicObject for StringIterator {
fn init(realm: &Realm) { fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("StringIterator", "init"); let _timer = Profiler::global().start_event("StringIterator", "init");
BuiltInBuilder::with_intrinsic::<Self>(realm) BuiltInBuilder::with_intrinsic::<Self>(
.prototype( realm,
realm &boa_builtins::COMMON_ITERATOR_PROTOTYPE_STATIC_SHAPE,
.intrinsics() )
.objects() .prototype(
.iterator_prototypes() realm
.iterator(), .intrinsics()
) .objects()
.static_method(Self::next, "next", 0) .iterator_prototypes()
.static_property( .iterator(),
JsSymbol::to_string_tag(), )
"String Iterator", .static_method(Self::next, 0)
Attribute::CONFIGURABLE, .static_property("String Iterator")
) .build();
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

40
boa_engine/src/context/intrinsics.rs

@ -145,12 +145,13 @@ pub struct StandardConstructors {
typed_float64_array: StandardConstructor, typed_float64_array: StandardConstructor,
array_buffer: StandardConstructor, array_buffer: StandardConstructor,
data_view: StandardConstructor, data_view: StandardConstructor,
date_time_format: StandardConstructor,
promise: StandardConstructor, promise: StandardConstructor,
weak_ref: StandardConstructor, weak_ref: StandardConstructor,
weak_map: StandardConstructor, weak_map: StandardConstructor,
weak_set: StandardConstructor, weak_set: StandardConstructor,
#[cfg(feature = "intl")] #[cfg(feature = "intl")]
date_time_format: StandardConstructor,
#[cfg(feature = "intl")]
collator: StandardConstructor, collator: StandardConstructor,
#[cfg(feature = "intl")] #[cfg(feature = "intl")]
list_format: StandardConstructor, list_format: StandardConstructor,
@ -214,13 +215,15 @@ impl Default for StandardConstructors {
typed_float64_array: StandardConstructor::default_static_shape(), typed_float64_array: StandardConstructor::default_static_shape(),
array_buffer: StandardConstructor::default_static_shape(), array_buffer: StandardConstructor::default_static_shape(),
data_view: StandardConstructor::default_static_shape(), data_view: StandardConstructor::default_static_shape(),
date_time_format: StandardConstructor::default(),
promise: StandardConstructor::default_static_shape(), promise: StandardConstructor::default_static_shape(),
weak_ref: StandardConstructor::default_static_shape(), weak_ref: StandardConstructor::default_static_shape(),
weak_map: StandardConstructor::default_static_shape(), weak_map: StandardConstructor::default_static_shape(),
weak_set: StandardConstructor::default_static_shape(), weak_set: StandardConstructor::default_static_shape(),
#[cfg(feature = "intl")] #[cfg(feature = "intl")]
collator: StandardConstructor::default(), date_time_format: StandardConstructor::default_static_shape(),
#[cfg(feature = "intl")]
collator: StandardConstructor::default_static_shape(),
#[cfg(feature = "intl")] #[cfg(feature = "intl")]
list_format: StandardConstructor::default(), list_format: StandardConstructor::default(),
#[cfg(feature = "intl")] #[cfg(feature = "intl")]
@ -650,17 +653,6 @@ impl StandardConstructors {
&self.data_view &self.data_view
} }
/// Returns the `Intl.DateTimeFormat` constructor.
///
/// More information:
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-intl-datetimeformat-constructor
#[inline]
pub const fn date_time_format(&self) -> &StandardConstructor {
&self.date_time_format
}
/// Returns the `Promise` constructor. /// Returns the `Promise` constructor.
/// ///
/// More information: /// More information:
@ -705,6 +697,18 @@ impl StandardConstructors {
&self.weak_set &self.weak_set
} }
/// Returns the `Intl.DateTimeFormat` constructor.
///
/// More information:
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-intl-datetimeformat-constructor
#[inline]
#[cfg(feature = "intl")]
pub const fn date_time_format(&self) -> &StandardConstructor {
&self.date_time_format
}
/// Returns the `Intl.Collator` constructor. /// Returns the `Intl.Collator` constructor.
/// ///
/// More information: /// More information:
@ -825,8 +829,8 @@ impl Default for IntrinsicObjects {
throw_type_error: JsFunction::empty_intrinsic_function(false), throw_type_error: JsFunction::empty_intrinsic_function(false),
array_prototype_values: JsFunction::empty_intrinsic_function_static_shape(false), array_prototype_values: JsFunction::empty_intrinsic_function_static_shape(false),
iterator_prototypes: IteratorPrototypes::default(), iterator_prototypes: IteratorPrototypes::default(),
generator: JsObject::default(), generator: JsObject::default_with_static_shape(),
async_generator: JsObject::default(), async_generator: JsObject::default_with_static_shape(),
eval: JsFunction::empty_intrinsic_function_static_shape(false), eval: JsFunction::empty_intrinsic_function_static_shape(false),
uri_functions: UriFunctions::default(), uri_functions: UriFunctions::default(),
is_finite: JsFunction::empty_intrinsic_function_static_shape(false), is_finite: JsFunction::empty_intrinsic_function_static_shape(false),
@ -838,9 +842,9 @@ impl Default for IntrinsicObjects {
#[cfg(feature = "annex-b")] #[cfg(feature = "annex-b")]
unescape: JsFunction::empty_intrinsic_function_static_shape(false), unescape: JsFunction::empty_intrinsic_function_static_shape(false),
#[cfg(feature = "intl")] #[cfg(feature = "intl")]
intl: JsObject::default(), intl: JsObject::default_with_static_shape(),
#[cfg(feature = "intl")] #[cfg(feature = "intl")]
segments_prototype: JsObject::default(), segments_prototype: JsObject::default_with_static_shape(),
} }
} }
} }

1
boa_engine/src/value/mod.rs

@ -466,7 +466,6 @@ impl JsValue {
/// ///
/// See: <https://tc39.es/ecma262/#sec-toobject> /// See: <https://tc39.es/ecma262/#sec-toobject>
pub fn to_object(&self, context: &mut Context<'_>) -> JsResult<JsObject> { pub fn to_object(&self, context: &mut Context<'_>) -> JsResult<JsObject> {
// TODO: add fast paths with object template
match self { match self {
Self::Undefined | Self::Null => Err(JsNativeError::typ() Self::Undefined | Self::Null => Err(JsNativeError::typ()
.with_message("cannot convert 'null' or 'undefined' to object") .with_message("cannot convert 'null' or 'undefined' to object")

Loading…
Cancel
Save