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

Side by Side Diff: src/bootstrapper.cc

Issue 2405253006: [builtins] implement Array.prototype[@@iterator] in TFJ builtins (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/bootstrapper.h" 5 #include "src/bootstrapper.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/base/ieee754.h" 9 #include "src/base/ieee754.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 ArrayConstructorStub array_constructor_stub(isolate); 1297 ArrayConstructorStub array_constructor_stub(isolate);
1298 Handle<Code> code = array_constructor_stub.GetCode(); 1298 Handle<Code> code = array_constructor_stub.GetCode();
1299 array_function->shared()->SetConstructStub(*code); 1299 array_function->shared()->SetConstructStub(*code);
1300 1300
1301 Handle<JSFunction> is_arraylike = SimpleInstallFunction( 1301 Handle<JSFunction> is_arraylike = SimpleInstallFunction(
1302 array_function, isolate->factory()->InternalizeUtf8String("isArray"), 1302 array_function, isolate->factory()->InternalizeUtf8String("isArray"),
1303 Builtins::kArrayIsArray, 1, true); 1303 Builtins::kArrayIsArray, 1, true);
1304 native_context()->set_is_arraylike(*is_arraylike); 1304 native_context()->set_is_arraylike(*is_arraylike);
1305 } 1305 }
1306 1306
1307 { // --- A r r a y I t e r a t o r ---
1308 Handle<JSObject> iterator_prototype(
1309 native_context()->initial_iterator_prototype());
1310
1311 Handle<JSObject> array_iterator_prototype =
1312 factory->NewJSObject(isolate->object_function(), TENURED);
1313 JSObject::ForceSetPrototype(array_iterator_prototype, iterator_prototype);
1314
1315 JSObject::AddProperty(
1316 array_iterator_prototype, factory->to_string_tag_symbol(),
1317 factory->NewStringFromAsciiChecked("Array Iterator"),
1318 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
1319
1320 Handle<JSFunction> next = InstallFunction(
1321 array_iterator_prototype, "next", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1322 MaybeHandle<JSObject>(), Builtins::kArrayIteratorPrototypeNext);
1323
1324 // Set the expected parameters for %ArrayIteratorPrototype%.next to 0 (not
1325 // including the receiver), as required by the builtin.
1326 next->shared()->set_internal_formal_parameter_count(0);
1327
1328 // Set the length for the function to satisfy ECMA-262.
1329 next->shared()->set_length(0);
1330
1331 #define ARRAY_ITERATOR_LIST(V, TypedArray, Array) \
1332 V(TypedArray, TYPED_ARRAY, KEY, typed_array, key) \
1333 V(Array, GENERIC_ARRAY, KEY, array, key) \
1334 V(TypedArray, UINT8_ARRAY, KEY_VALUE, uint8_array, key_value) \
1335 V(TypedArray, INT8_ARRAY, KEY_VALUE, int8_array, key_value) \
1336 V(TypedArray, UINT16_ARRAY, KEY_VALUE, uint16_array, key_value) \
1337 V(TypedArray, INT16_ARRAY, KEY_VALUE, int16_array, key_value) \
1338 V(TypedArray, UINT32_ARRAY, KEY_VALUE, uint32_array, key_value) \
1339 V(TypedArray, INT32_ARRAY, KEY_VALUE, int32_array, key_value) \
1340 V(TypedArray, FLOAT32_ARRAY, KEY_VALUE, float32_array, key_value) \
1341 V(TypedArray, FLOAT64_ARRAY, KEY_VALUE, float64_array, key_value) \
1342 V(TypedArray, UINT8_CLAMPED_ARRAY, KEY_VALUE, uint8_clamped_array, \
1343 key_value) \
1344 V(Array, FAST_SMI_ARRAY, KEY_VALUE, fast_smi_array, key_value) \
1345 V(Array, FAST_HOLEY_SMI_ARRAY, KEY_VALUE, fast_holey_smi_array, key_value) \
1346 V(Array, FAST_ARRAY, KEY_VALUE, fast_array, key_value) \
1347 V(Array, FAST_HOLEY_ARRAY, KEY_VALUE, fast_holey_array, key_value) \
1348 V(Array, FAST_DOUBLE_ARRAY, KEY_VALUE, fast_double_array, key_value) \
1349 V(Array, FAST_HOLEY_DOUBLE_ARRAY, KEY_VALUE, fast_holey_double_array, \
1350 key_value) \
1351 V(Array, GENERIC_ARRAY, KEY_VALUE, array, key_value) \
1352 V(TypedArray, UINT8_ARRAY, VALUE, uint8_array, value) \
1353 V(TypedArray, INT8_ARRAY, VALUE, int8_array, value) \
1354 V(TypedArray, UINT16_ARRAY, VALUE, uint16_array, value) \
1355 V(TypedArray, INT16_ARRAY, VALUE, int16_array, value) \
1356 V(TypedArray, UINT32_ARRAY, VALUE, uint32_array, value) \
1357 V(TypedArray, INT32_ARRAY, VALUE, int32_array, value) \
1358 V(TypedArray, FLOAT32_ARRAY, VALUE, float32_array, value) \
1359 V(TypedArray, FLOAT64_ARRAY, VALUE, float64_array, value) \
1360 V(TypedArray, UINT8_CLAMPED_ARRAY, VALUE, uint8_clamped_array, value) \
1361 V(Array, FAST_SMI_ARRAY, VALUE, fast_smi_array, value) \
1362 V(Array, FAST_HOLEY_SMI_ARRAY, VALUE, fast_holey_smi_array, value) \
1363 V(Array, FAST_ARRAY, VALUE, fast_array, value) \
1364 V(Array, FAST_HOLEY_ARRAY, VALUE, fast_holey_array, value) \
1365 V(Array, FAST_DOUBLE_ARRAY, VALUE, fast_double_array, value) \
1366 V(Array, FAST_HOLEY_DOUBLE_ARRAY, VALUE, fast_holey_double_array, value) \
1367 V(Array, GENERIC_ARRAY, VALUE, array, value)
1368
1369 #define CREATE_ARRAY_ITERATOR_MAP(Class, PREFIX, SUFFIX, prefix, suffix) \
1370 do { \
1371 const InstanceType type = JS_##PREFIX##_##SUFFIX##_ITERATOR_TYPE; \
1372 Handle<Map> map = factory->NewMap(type, Class::kSize); \
1373 Map::SetPrototype(map, array_iterator_prototype); \
1374 native_context()->set_##prefix##_##suffix##_iterator_map(*map); \
1375 } while (0);
1376
1377 ARRAY_ITERATOR_LIST(CREATE_ARRAY_ITERATOR_MAP, JSTypedArrayIterator,
1378 JSArrayIterator)
1379
1380 #undef CREATE_ARRAY_ITERATOR_MAP
1381 #undef ARRAY_ITERATOR_LIST
1382 }
1383
1307 { // --- N u m b e r --- 1384 { // --- N u m b e r ---
1308 Handle<JSFunction> number_fun = InstallFunction( 1385 Handle<JSFunction> number_fun = InstallFunction(
1309 global, "Number", JS_VALUE_TYPE, JSValue::kSize, 1386 global, "Number", JS_VALUE_TYPE, JSValue::kSize,
1310 isolate->initial_object_prototype(), Builtins::kNumberConstructor); 1387 isolate->initial_object_prototype(), Builtins::kNumberConstructor);
1311 number_fun->shared()->DontAdaptArguments(); 1388 number_fun->shared()->DontAdaptArguments();
1312 number_fun->shared()->SetConstructStub( 1389 number_fun->shared()->SetConstructStub(
1313 *isolate->builtins()->NumberConstructor_ConstructStub()); 1390 *isolate->builtins()->NumberConstructor_ConstructStub());
1314 number_fun->shared()->set_length(1); 1391 number_fun->shared()->set_length(1);
1315 InstallWithIntrinsicDefaultProto(isolate, number_fun, 1392 InstallWithIntrinsicDefaultProto(isolate, number_fun,
1316 Context::NUMBER_FUNCTION_INDEX); 1393 Context::NUMBER_FUNCTION_INDEX);
(...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after
2765 generator_function_prototype, factory->constructor_string(), 2842 generator_function_prototype, factory->constructor_string(),
2766 generator_function_function, 2843 generator_function_function,
2767 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); 2844 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
2768 2845
2769 native_context->sloppy_generator_function_map()->SetConstructor( 2846 native_context->sloppy_generator_function_map()->SetConstructor(
2770 *generator_function_function); 2847 *generator_function_function);
2771 native_context->strict_generator_function_map()->SetConstructor( 2848 native_context->strict_generator_function_map()->SetConstructor(
2772 *generator_function_function); 2849 *generator_function_function);
2773 } 2850 }
2774 2851
2852 { // -- A r r a y I t e r a t o r
2853 Handle<Object> array_values(native_context->array_values_iterator(),
2854 isolate);
2855 JSObject::AddProperty(container,
2856 factory->NewStringFromAsciiChecked("ArrayValues"),
2857 array_values, DONT_ENUM);
2858 }
2859
2775 { // -- S e t I t e r a t o r 2860 { // -- S e t I t e r a t o r
2776 Handle<JSObject> set_iterator_prototype = 2861 Handle<JSObject> set_iterator_prototype =
2777 isolate->factory()->NewJSObject(isolate->object_function(), TENURED); 2862 isolate->factory()->NewJSObject(isolate->object_function(), TENURED);
2778 JSObject::ForceSetPrototype(set_iterator_prototype, iterator_prototype); 2863 JSObject::ForceSetPrototype(set_iterator_prototype, iterator_prototype);
2779 Handle<JSFunction> set_iterator_function = InstallFunction( 2864 Handle<JSFunction> set_iterator_function = InstallFunction(
2780 container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, 2865 container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize,
2781 set_iterator_prototype, Builtins::kIllegal); 2866 set_iterator_prototype, Builtins::kIllegal);
2782 native_context->set_set_iterator_map(set_iterator_function->initial_map()); 2867 native_context->set_set_iterator_map(set_iterator_function->initial_map());
2783 } 2868 }
2784 2869
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after
4395 } 4480 }
4396 4481
4397 4482
4398 // Called when the top-level V8 mutex is destroyed. 4483 // Called when the top-level V8 mutex is destroyed.
4399 void Bootstrapper::FreeThreadResources() { 4484 void Bootstrapper::FreeThreadResources() {
4400 DCHECK(!IsActive()); 4485 DCHECK(!IsActive());
4401 } 4486 }
4402 4487
4403 } // namespace internal 4488 } // namespace internal
4404 } // namespace v8 4489 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698