Skip to content

Commit

Permalink
Remove some old builtin code
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed May 24, 2023
1 parent 9c04098 commit 5fdf50e
Show file tree
Hide file tree
Showing 25 changed files with 237 additions and 343 deletions.
1 change: 1 addition & 0 deletions boa_builtins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ build = "build.rs"

[features]
annex-b = []
intl = []

[dependencies]
bitflags = "2.1.0"
Expand Down
58 changes: 58 additions & 0 deletions boa_builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,64 @@ fn main() -> io::Result<()> {
.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)?;

Ok(())
Expand Down
1 change: 1 addition & 0 deletions boa_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ profiler = ["boa_profiler/profiler"]
deser = ["boa_interner/serde", "boa_ast/serde"]
intl = [
"boa_icu_provider/full",
"boa_builtins/intl",
"icu_normalizer/serde",
"icu_normalizer/std",
"dep:icu_locid_transform",
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl IntrinsicObject for ArrayIterator {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("ArrayIterator", "init");

BuiltInBuilder::with_intrinsic_static_shape::<Self>(
BuiltInBuilder::with_intrinsic::<Self>(
realm,
&boa_builtins::COMMON_ITERATOR_PROTOTYPE_STATIC_SHAPE,
)
Expand Down
29 changes: 22 additions & 7 deletions boa_engine/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ pub(crate) use array_iterator::ArrayIterator;
#[cfg(test)]
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.
#[derive(Debug, Clone, Copy)]
pub(crate) struct Array;
Expand All @@ -44,17 +63,13 @@ impl IntrinsicObject for Array {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init");

ArrayPrototypeValues::init(realm);

let get_species = BuiltInBuilder::callable(realm, Self::get_species)
.name("get [Symbol.species]")
.build();

let values_function = BuiltInBuilder::callable_with_object(
realm,
realm.intrinsics().objects().array_prototype_values().into(),
Self::values,
)
.name("values")
.build();
let values_function = realm.intrinsics().objects().array_prototype_values();

let unscopables_object = Self::unscopables_object();

Expand Down
20 changes: 6 additions & 14 deletions boa_engine/src/builtins/async_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ use crate::{
context::intrinsics::Intrinsics,
error::JsNativeError,
native_function::NativeFunction,
object::{FunctionObjectBuilder, JsObject, CONSTRUCTOR},
property::Attribute,
object::{FunctionObjectBuilder, JsObject},
realm::Realm,
symbol::JsSymbol,
value::JsValue,
vm::GeneratorResumeKind,
Context, JsArgs, JsError, JsResult,
Expand Down Expand Up @@ -70,30 +68,24 @@ impl IntrinsicObject for AsyncGenerator {
fn init(realm: &Realm) {
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(
realm
.intrinsics()
.objects()
.iterator_prototypes()
.async_iterator(),
)
.static_method(Self::next, "next", 1)
.static_method(Self::r#return, "return", 1)
.static_method(Self::throw, "throw", 1)
.static_method(Self::next, 1)
.static_method(Self::r#return, 1)
.static_method(Self::throw, 1)
.static_property(Self::NAME)
.static_property(
JsSymbol::to_string_tag(),
Self::NAME,
Attribute::CONFIGURABLE,
)
.static_property(
CONSTRUCTOR,
realm
.intrinsics()
.constructors()
.async_generator_function()
.prototype(),
Attribute::CONFIGURABLE,
)
.build();
}
Expand Down
15 changes: 9 additions & 6 deletions boa_engine/src/builtins/error/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::{
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
error::JsNativeError,
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData, ObjectKind},
property::Attribute,
realm::Realm,
string::utf16,
Context, JsArgs, JsResult, JsString, JsValue, NativeFunction,
Expand Down Expand Up @@ -131,12 +130,16 @@ impl IntrinsicObject for ThrowTypeError {
.into())
}

let obj = BuiltInBuilder::with_intrinsic::<Self>(realm)
.prototype(realm.intrinsics().constructors().function().prototype())
.static_property(utf16!("length"), 0, Attribute::empty())
.static_property(utf16!("name"), "", Attribute::empty())
.build();
BuiltInBuilder::with_intrinsic::<Self>(
realm,
&boa_builtins::THROW_TYPE_ERROR_OBJECT_STATIC_SHAPE,
)
.prototype(realm.intrinsics().constructors().function().prototype())
.static_property(0)
.static_property("")
.build();

let obj = Self::get(realm.intrinsics());
let mut obj = obj.borrow_mut();

obj.extensible = false;
Expand Down
20 changes: 6 additions & 14 deletions boa_engine/src/builtins/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ use crate::{
context::intrinsics::Intrinsics,
environments::EnvironmentStack,
error::JsNativeError,
object::{JsObject, CONSTRUCTOR},
property::Attribute,
object::JsObject,
realm::Realm,
symbol::JsSymbol,
value::JsValue,
vm::{CallFrame, CompletionRecord, GeneratorResumeKind},
Context, JsArgs, JsError, JsResult,
Expand Down Expand Up @@ -136,30 +134,24 @@ impl IntrinsicObject for Generator {
fn init(realm: &Realm) {
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(
realm
.intrinsics()
.objects()
.iterator_prototypes()
.iterator(),
)
.static_method(Self::next, "next", 1)
.static_method(Self::r#return, "return", 1)
.static_method(Self::throw, "throw", 1)
.static_method(Self::next, 1)
.static_method(Self::r#return, 1)
.static_method(Self::throw, 1)
.static_property(Self::NAME)
.static_property(
JsSymbol::to_string_tag(),
Self::NAME,
Attribute::CONFIGURABLE,
)
.static_property(
CONSTRUCTOR,
realm
.intrinsics()
.constructors()
.generator_function()
.prototype(),
Attribute::CONFIGURABLE,
)
.build();
}
Expand Down
27 changes: 10 additions & 17 deletions boa_engine/src/builtins/intl/collator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ use crate::{
internal_methods::get_prototype_from_constructor, FunctionObjectBuilder, JsFunction,
JsObject, ObjectData,
},
property::Attribute,
realm::Realm,
string::utf16,
symbol::JsSymbol,
Context, JsArgs, JsNativeError, JsResult, JsValue,
};

Expand Down Expand Up @@ -167,21 +165,16 @@ impl IntrinsicObject for Collator {
.name("get compare")
.build();

BuiltInBuilder::from_standard_constructor::<Self>(realm)
.static_method(Self::supported_locales_of, "supportedLocalesOf", 1)
.property(
JsSymbol::to_string_tag(),
"Intl.Collator",
Attribute::CONFIGURABLE,
)
.accessor(
utf16!("compare"),
Some(compare),
None,
Attribute::CONFIGURABLE,
)
.method(Self::resolved_options, "resolvedOptions", 0)
.build();
BuiltInBuilder::from_standard_constructor_static_shape::<Self>(
realm,
&boa_builtins::COLLATOR_CONSTRUCTOR_STATIC_SHAPE,
&boa_builtins::COLLATOR_PROTOTYPE_STATIC_SHAPE,
)
.static_method(Self::supported_locales_of, 1)
.property("Intl.Collator")
.accessor(Some(compare), None)
.method(Self::resolved_options, 0)
.build();
}

fn get(intrinsics: &Intrinsics) -> JsObject {
Expand Down
7 changes: 6 additions & 1 deletion boa_engine/src/builtins/intl/date_time_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ impl IntrinsicObject for DateTimeFormat {
fn init(realm: &Realm) {
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 {
Expand Down
34 changes: 6 additions & 28 deletions boa_engine/src/builtins/intl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use crate::{
builtins::{Array, BuiltInBuilder, BuiltInObject, IntrinsicObject},
context::{intrinsics::Intrinsics, BoaProvider},
object::JsObject,
property::Attribute,
realm::Realm,
symbol::JsSymbol,
Context, JsArgs, JsResult, JsValue,
};

Expand Down Expand Up @@ -43,46 +41,26 @@ impl IntrinsicObject for Intl {
fn init(realm: &Realm) {
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(
JsSymbol::to_string_tag(),
Self::NAME,
Attribute::CONFIGURABLE,
)
.static_property(
Collator::NAME,
realm.intrinsics().constructors().collator().constructor(),
Collator::ATTRIBUTE,
)
.static_property(
ListFormat::NAME,
realm
.intrinsics()
.constructors()
.list_format()
.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(
DateTimeFormat::NAME,
realm
.intrinsics()
.constructors()
.date_time_format()
.constructor(),
DateTimeFormat::ATTRIBUTE,
)
.static_method(Self::get_canonical_locales, "getCanonicalLocales", 1)
.static_method(Self::get_canonical_locales, 1)
.build();
}

Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/intl/segmenter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl IntrinsicObject for SegmentIterator {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("%SegmentIteratorPrototype%", "init");

BuiltInBuilder::with_intrinsic_static_shape::<Self>(
BuiltInBuilder::with_intrinsic::<Self>(
realm,
&boa_builtins::COMMON_ITERATOR_PROTOTYPE_STATIC_SHAPE,
)
Expand Down

0 comments on commit 5fdf50e

Please sign in to comment.