Index: src/bootstrapper.cc |
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc |
index 0e56f74e0b8dac811be9884a09e0ab668a94e3c2..da4902b8388af44eab366578703987c0058500c1 100644 |
--- a/src/bootstrapper.cc |
+++ b/src/bootstrapper.cc |
@@ -1304,6 +1304,83 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, |
native_context()->set_is_arraylike(*is_arraylike); |
} |
+ { // --- A r r a y I t e r a t o r --- |
+ Handle<JSObject> iterator_prototype( |
+ native_context()->initial_iterator_prototype()); |
+ |
+ Handle<JSObject> array_iterator_prototype = |
+ factory->NewJSObject(isolate->object_function(), TENURED); |
+ JSObject::ForceSetPrototype(array_iterator_prototype, iterator_prototype); |
+ |
+ JSObject::AddProperty( |
+ array_iterator_prototype, factory->to_string_tag_symbol(), |
+ factory->NewStringFromAsciiChecked("Array Iterator"), |
+ static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
+ |
+ Handle<JSFunction> next = InstallFunction( |
+ array_iterator_prototype, "next", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
+ MaybeHandle<JSObject>(), Builtins::kArrayIteratorPrototypeNext); |
+ |
+ // Set the expected parameters for %ArrayIteratorPrototype%.next to 0 (not |
+ // including the receiver), as required by the builtin. |
+ next->shared()->set_internal_formal_parameter_count(0); |
+ |
+ // Set the length for the function to satisfy ECMA-262. |
+ next->shared()->set_length(0); |
+ |
+#define ARRAY_ITERATOR_LIST(V, TypedArray, Array) \ |
+ V(TypedArray, TYPED_ARRAY, KEY, typed_array, key) \ |
+ V(Array, GENERIC_ARRAY, KEY, array, key) \ |
+ V(TypedArray, UINT8_ARRAY, KEY_VALUE, uint8_array, key_value) \ |
+ V(TypedArray, INT8_ARRAY, KEY_VALUE, int8_array, key_value) \ |
+ V(TypedArray, UINT16_ARRAY, KEY_VALUE, uint16_array, key_value) \ |
+ V(TypedArray, INT16_ARRAY, KEY_VALUE, int16_array, key_value) \ |
+ V(TypedArray, UINT32_ARRAY, KEY_VALUE, uint32_array, key_value) \ |
+ V(TypedArray, INT32_ARRAY, KEY_VALUE, int32_array, key_value) \ |
+ V(TypedArray, FLOAT32_ARRAY, KEY_VALUE, float32_array, key_value) \ |
+ V(TypedArray, FLOAT64_ARRAY, KEY_VALUE, float64_array, key_value) \ |
+ V(TypedArray, UINT8_CLAMPED_ARRAY, KEY_VALUE, uint8_clamped_array, \ |
+ key_value) \ |
+ V(Array, FAST_SMI_ARRAY, KEY_VALUE, fast_smi_array, key_value) \ |
+ V(Array, FAST_HOLEY_SMI_ARRAY, KEY_VALUE, fast_holey_smi_array, key_value) \ |
+ V(Array, FAST_ARRAY, KEY_VALUE, fast_array, key_value) \ |
+ V(Array, FAST_HOLEY_ARRAY, KEY_VALUE, fast_holey_array, key_value) \ |
+ V(Array, FAST_DOUBLE_ARRAY, KEY_VALUE, fast_double_array, key_value) \ |
+ V(Array, FAST_HOLEY_DOUBLE_ARRAY, KEY_VALUE, fast_holey_double_array, \ |
+ key_value) \ |
+ V(Array, GENERIC_ARRAY, KEY_VALUE, array, key_value) \ |
+ V(TypedArray, UINT8_ARRAY, VALUE, uint8_array, value) \ |
+ V(TypedArray, INT8_ARRAY, VALUE, int8_array, value) \ |
+ V(TypedArray, UINT16_ARRAY, VALUE, uint16_array, value) \ |
+ V(TypedArray, INT16_ARRAY, VALUE, int16_array, value) \ |
+ V(TypedArray, UINT32_ARRAY, VALUE, uint32_array, value) \ |
+ V(TypedArray, INT32_ARRAY, VALUE, int32_array, value) \ |
+ V(TypedArray, FLOAT32_ARRAY, VALUE, float32_array, value) \ |
+ V(TypedArray, FLOAT64_ARRAY, VALUE, float64_array, value) \ |
+ V(TypedArray, UINT8_CLAMPED_ARRAY, VALUE, uint8_clamped_array, value) \ |
+ V(Array, FAST_SMI_ARRAY, VALUE, fast_smi_array, value) \ |
+ V(Array, FAST_HOLEY_SMI_ARRAY, VALUE, fast_holey_smi_array, value) \ |
+ V(Array, FAST_ARRAY, VALUE, fast_array, value) \ |
+ V(Array, FAST_HOLEY_ARRAY, VALUE, fast_holey_array, value) \ |
+ V(Array, FAST_DOUBLE_ARRAY, VALUE, fast_double_array, value) \ |
+ V(Array, FAST_HOLEY_DOUBLE_ARRAY, VALUE, fast_holey_double_array, value) \ |
+ V(Array, GENERIC_ARRAY, VALUE, array, value) |
+ |
+#define CREATE_ARRAY_ITERATOR_MAP(Class, PREFIX, SUFFIX, prefix, suffix) \ |
+ do { \ |
+ const InstanceType type = JS_##PREFIX##_##SUFFIX##_ITERATOR_TYPE; \ |
+ Handle<Map> map = factory->NewMap(type, Class::kSize); \ |
+ Map::SetPrototype(map, array_iterator_prototype); \ |
+ native_context()->set_##prefix##_##suffix##_iterator_map(*map); \ |
+ } while (0); |
+ |
+ ARRAY_ITERATOR_LIST(CREATE_ARRAY_ITERATOR_MAP, JSTypedArrayIterator, |
+ JSArrayIterator) |
+ |
+#undef CREATE_ARRAY_ITERATOR_MAP |
+#undef ARRAY_ITERATOR_LIST |
+ } |
+ |
{ // --- N u m b e r --- |
Handle<JSFunction> number_fun = InstallFunction( |
global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
@@ -2772,6 +2849,14 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, |
*generator_function_function); |
} |
+ { // -- A r r a y I t e r a t o r |
+ Handle<Object> array_values(native_context->array_values_iterator(), |
+ isolate); |
+ JSObject::AddProperty(container, |
+ factory->NewStringFromAsciiChecked("ArrayValues"), |
+ array_values, DONT_ENUM); |
+ } |
+ |
{ // -- S e t I t e r a t o r |
Handle<JSObject> set_iterator_prototype = |
isolate->factory()->NewJSObject(isolate->object_function(), TENURED); |