Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement property accessors #987

Merged
merged 13 commits into from
Dec 31, 2020
13 changes: 6 additions & 7 deletions boa/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl ArrayIterator {
array: Value,
kind: ArrayIterationKind,
) -> Result<Value> {
let array_iterator = Value::new_object(Some(context.global_object()));
let array_iterator = Value::new_object(context);
array_iterator.set_data(ObjectData::ArrayIterator(Self::new(array, kind)));
array_iterator
.as_object()
Expand All @@ -77,7 +77,7 @@ impl ArrayIterator {
}
let len = array_iterator
.array
.get_field("length")
.get_field("length", context)?
.as_number()
.ok_or_else(|| context.construct_type_error("Not an array"))?
as u32;
Expand All @@ -91,13 +91,13 @@ impl ArrayIterator {
Ok(create_iter_result_object(context, index.into(), false))
}
ArrayIterationKind::Value => {
let element_value = array_iterator.array.get_field(index);
let element_value = array_iterator.array.get_field(index, context)?;
Ok(create_iter_result_object(context, element_value, false))
}
ArrayIterationKind::KeyAndValue => {
let element_value = array_iterator.array.get_field(index);
let element_value = array_iterator.array.get_field(index, context)?;
let result = Array::constructor(
&Value::new_object(Some(context.global_object())),
&Value::new_object(context),
&[index.into(), element_value],
context,
)?;
Expand All @@ -119,11 +119,10 @@ impl ArrayIterator {
///
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object
pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: Value) -> Value {
let global = context.global_object();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

// Create prototype
let array_iterator = Value::new_object(Some(global));
let array_iterator = Value::new_object(context);
make_builtin_fn(Self::next, "next", &array_iterator, 0, context);
array_iterator
.as_object()
Expand Down
Loading