Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: src/bootstrapper.cc

Issue 2405253006: [builtins] implement Array.prototype[@@iterator] in TFJ builtins (Closed)
Patch Set: latest round Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast/prettyprinter.cc ('k') | src/builtins/builtins.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 6f799e2599aef030cf449847593b53787c8a8f02..02b2a240881a5a04a75a106eadb4ac44271fb29e 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1310,6 +1310,91 @@ 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->ArrayIterator_string(),
+ 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);
+
+ Handle<JSFunction> array_iterator_function = CreateFunction(
+ isolate, factory->ArrayIterator_string(),
+ JS_FAST_ARRAY_VALUE_ITERATOR_TYPE, JSArrayIterator::kSize,
+ array_iterator_prototype, Builtins::kIllegal);
+ array_iterator_function->shared()->set_instance_class_name(
+ isolate->heap()->ArrayIterator_string());
+
+ Handle<Map> initial_map(array_iterator_function->initial_map(), isolate);
+
+#define ARRAY_ITERATOR_LIST(V) \
+ V(TYPED_ARRAY, KEY, typed_array, key) \
+ V(FAST_ARRAY, KEY, fast_array, key) \
+ V(GENERIC_ARRAY, KEY, array, key) \
+ V(UINT8_ARRAY, KEY_VALUE, uint8_array, key_value) \
+ V(INT8_ARRAY, KEY_VALUE, int8_array, key_value) \
+ V(UINT16_ARRAY, KEY_VALUE, uint16_array, key_value) \
+ V(INT16_ARRAY, KEY_VALUE, int16_array, key_value) \
+ V(UINT32_ARRAY, KEY_VALUE, uint32_array, key_value) \
+ V(INT32_ARRAY, KEY_VALUE, int32_array, key_value) \
+ V(FLOAT32_ARRAY, KEY_VALUE, float32_array, key_value) \
+ V(FLOAT64_ARRAY, KEY_VALUE, float64_array, key_value) \
+ V(UINT8_CLAMPED_ARRAY, KEY_VALUE, uint8_clamped_array, key_value) \
+ V(FAST_SMI_ARRAY, KEY_VALUE, fast_smi_array, key_value) \
+ V(FAST_HOLEY_SMI_ARRAY, KEY_VALUE, fast_holey_smi_array, key_value) \
+ V(FAST_ARRAY, KEY_VALUE, fast_array, key_value) \
+ V(FAST_HOLEY_ARRAY, KEY_VALUE, fast_holey_array, key_value) \
+ V(FAST_DOUBLE_ARRAY, KEY_VALUE, fast_double_array, key_value) \
+ V(FAST_HOLEY_DOUBLE_ARRAY, KEY_VALUE, fast_holey_double_array, key_value) \
+ V(GENERIC_ARRAY, KEY_VALUE, array, key_value) \
+ V(UINT8_ARRAY, VALUE, uint8_array, value) \
+ V(INT8_ARRAY, VALUE, int8_array, value) \
+ V(UINT16_ARRAY, VALUE, uint16_array, value) \
+ V(INT16_ARRAY, VALUE, int16_array, value) \
+ V(UINT32_ARRAY, VALUE, uint32_array, value) \
+ V(INT32_ARRAY, VALUE, int32_array, value) \
+ V(FLOAT32_ARRAY, VALUE, float32_array, value) \
+ V(FLOAT64_ARRAY, VALUE, float64_array, value) \
+ V(UINT8_CLAMPED_ARRAY, VALUE, uint8_clamped_array, value) \
+ V(FAST_SMI_ARRAY, VALUE, fast_smi_array, value) \
+ V(FAST_HOLEY_SMI_ARRAY, VALUE, fast_holey_smi_array, value) \
+ V(FAST_ARRAY, VALUE, fast_array, value) \
+ V(FAST_HOLEY_ARRAY, VALUE, fast_holey_array, value) \
+ V(FAST_DOUBLE_ARRAY, VALUE, fast_double_array, value) \
+ V(FAST_HOLEY_DOUBLE_ARRAY, VALUE, fast_holey_double_array, value) \
+ V(GENERIC_ARRAY, VALUE, array, value)
+
+#define CREATE_ARRAY_ITERATOR_MAP(PREFIX, SUFFIX, prefix, suffix) \
+ do { \
+ const InstanceType type = JS_##PREFIX##_##SUFFIX##_ITERATOR_TYPE; \
+ Handle<Map> map = \
+ Map::Copy(initial_map, "JS_" #PREFIX "_" #SUFFIX "_ITERATOR_TYPE"); \
+ map->set_instance_type(type); \
+ native_context()->set_##prefix##_##suffix##_iterator_map(*map); \
+ } while (0);
+
+ ARRAY_ITERATOR_LIST(CREATE_ARRAY_ITERATOR_MAP)
+
+#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,
@@ -2092,6 +2177,17 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallGetter(prototype, factory->length_string(),
Builtins::kTypedArrayPrototypeLength, true,
kTypedArrayLength);
+
+ // Install "keys", "values" and "entries" methods on the {prototype}.
+ SimpleInstallFunction(prototype, factory->entries_string(),
+ Builtins::kTypedArrayPrototypeEntries, 0, true);
+ SimpleInstallFunction(prototype, factory->keys_string(),
+ Builtins::kTypedArrayPrototypeKeys, 0, true);
+ Handle<JSFunction> iterator =
+ SimpleInstallFunction(prototype, factory->values_string(),
+ Builtins::kTypedArrayPrototypeValues, 0, true);
+ JSObject::AddProperty(prototype, factory->iterator_symbol(), iterator,
+ DONT_ENUM);
}
{ // -- T y p e d A r r a y s
« no previous file with comments | « src/ast/prettyprinter.cc ('k') | src/builtins/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698