Browse Source

IteratorPrototype static shape

optimization/static-shapes
Haled Odat 2 years ago
parent
commit
4634b18ff0
  1. 4
      boa_builtins/build.rs
  2. 15
      boa_engine/src/builtins/iterable/mod.rs
  3. 17
      boa_engine/src/builtins/mod.rs

4
boa_builtins/build.rs

@ -1038,6 +1038,10 @@ fn main() -> io::Result<()> {
.property(WellKnown::ToStringTag, Attribute::CONFIGURABLE) .property(WellKnown::ToStringTag, Attribute::CONFIGURABLE)
.build(file)?; .build(file)?;
BuiltInBuilder::new(&context, "ITERATOR_PROTOTYPE")
.method(WellKnown::Iterator)
.build(file)?;
BuiltInBuilder::new(&context, "ARRAY_ITERATOR_PROTOTYPE") BuiltInBuilder::new(&context, "ARRAY_ITERATOR_PROTOTYPE")
.method(utf16!("next")) .method(utf16!("next"))
.property(WellKnown::ToStringTag, Attribute::CONFIGURABLE) .property(WellKnown::ToStringTag, Attribute::CONFIGURABLE)

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

@ -78,7 +78,7 @@ impl Default for IteratorPrototypes {
fn default() -> Self { fn default() -> Self {
Self { Self {
array: JsObject::default_with_static_shape(), array: JsObject::default_with_static_shape(),
iterator: JsObject::default(), iterator: JsObject::default_with_static_shape(),
async_iterator: JsObject::default(), async_iterator: JsObject::default(),
async_from_sync_iterator: JsObject::default(), async_from_sync_iterator: JsObject::default(),
set: JsObject::default(), set: JsObject::default(),
@ -168,13 +168,12 @@ 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::<Self>(realm) BuiltInBuilder::with_intrinsic_static_shape::<Self>(
.static_method( realm,
|v, _, _| Ok(v.clone()), &boa_builtins::ITERATOR_PROTOTYPE_STATIC_SHAPE,
(JsSymbol::iterator(), js_string!("[Symbol.iterator]")), )
0, .static_method_with_name(|v, _, _| Ok(v.clone()), js_string!("[Symbol.iterator]"), 0)
) .build();
.build();
} }
fn get(intrinsics: &Intrinsics) -> JsObject { fn get(intrinsics: &Intrinsics) -> JsObject {

17
boa_engine/src/builtins/mod.rs

@ -878,6 +878,23 @@ impl BuiltInBuilderStaticShape<'_> {
self self
} }
/// Adds a new static method to the builtin object with name.
fn static_method_with_name(
mut self,
function: NativeFunctionPointer,
name: JsString,
length: usize,
) -> Self {
let function = BuiltInBuilder::callable(self.realm, function)
.name(name)
.length(length)
.build();
self.storage.push(function.into());
self.property_index += 1;
self
}
/// Adds a new static data property to the builtin object. /// Adds a new static data property to the builtin object.
fn static_property<V>(mut self, value: V) -> Self fn static_property<V>(mut self, value: V) -> Self
where where

Loading…
Cancel
Save