diff --git a/boa_builtins/build.rs b/boa_builtins/build.rs index 30aa655f60..eff739132e 100644 --- a/boa_builtins/build.rs +++ b/boa_builtins/build.rs @@ -1038,6 +1038,10 @@ fn main() -> io::Result<()> { .property(WellKnown::ToStringTag, Attribute::CONFIGURABLE) .build(file)?; + BuiltInBuilder::new(&context, "ITERATOR_PROTOTYPE") + .method(WellKnown::Iterator) + .build(file)?; + BuiltInBuilder::new(&context, "ARRAY_ITERATOR_PROTOTYPE") .method(utf16!("next")) .property(WellKnown::ToStringTag, Attribute::CONFIGURABLE) diff --git a/boa_engine/src/builtins/iterable/mod.rs b/boa_engine/src/builtins/iterable/mod.rs index 12a86bb6c4..f77475076d 100644 --- a/boa_engine/src/builtins/iterable/mod.rs +++ b/boa_engine/src/builtins/iterable/mod.rs @@ -78,7 +78,7 @@ impl Default for IteratorPrototypes { fn default() -> Self { Self { array: JsObject::default_with_static_shape(), - iterator: JsObject::default(), + iterator: JsObject::default_with_static_shape(), async_iterator: JsObject::default(), async_from_sync_iterator: JsObject::default(), set: JsObject::default(), @@ -168,13 +168,12 @@ impl IntrinsicObject for Iterator { fn init(realm: &Realm) { let _timer = Profiler::global().start_event("Iterator Prototype", "init"); - BuiltInBuilder::with_intrinsic::(realm) - .static_method( - |v, _, _| Ok(v.clone()), - (JsSymbol::iterator(), js_string!("[Symbol.iterator]")), - 0, - ) - .build(); + BuiltInBuilder::with_intrinsic_static_shape::( + realm, + &boa_builtins::ITERATOR_PROTOTYPE_STATIC_SHAPE, + ) + .static_method_with_name(|v, _, _| Ok(v.clone()), js_string!("[Symbol.iterator]"), 0) + .build(); } fn get(intrinsics: &Intrinsics) -> JsObject { diff --git a/boa_engine/src/builtins/mod.rs b/boa_engine/src/builtins/mod.rs index 85ff7f77d6..a061ca37bd 100644 --- a/boa_engine/src/builtins/mod.rs +++ b/boa_engine/src/builtins/mod.rs @@ -878,6 +878,23 @@ impl BuiltInBuilderStaticShape<'_> { 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. fn static_property(mut self, value: V) -> Self where