Browse Source

IteratorPrototype static shape

optimization/static-shapes
Haled Odat 2 years ago
parent
commit
4634b18ff0
  1. 4
      boa_builtins/build.rs
  2. 11
      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)
.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)

11
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,12 +168,11 @@ impl IntrinsicObject for Iterator {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event("Iterator Prototype", "init");
BuiltInBuilder::with_intrinsic::<Self>(realm)
.static_method(
|v, _, _| Ok(v.clone()),
(JsSymbol::iterator(), js_string!("[Symbol.iterator]")),
0,
BuiltInBuilder::with_intrinsic_static_shape::<Self>(
realm,
&boa_builtins::ITERATOR_PROTOTYPE_STATIC_SHAPE,
)
.static_method_with_name(|v, _, _| Ok(v.clone()), js_string!("[Symbol.iterator]"), 0)
.build();
}

17
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<V>(mut self, value: V) -> Self
where

Loading…
Cancel
Save