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

Side by Side Diff: src/bootstrapper.cc

Issue 2405253006: [builtins] implement Array.prototype[@@iterator] in TFJ builtins (Closed)
Patch Set: rebase and get tests passing 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 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 ArrayConstructorStub array_constructor_stub(isolate); 1303 ArrayConstructorStub array_constructor_stub(isolate);
1304 Handle<Code> code = array_constructor_stub.GetCode(); 1304 Handle<Code> code = array_constructor_stub.GetCode();
1305 array_function->shared()->SetConstructStub(*code); 1305 array_function->shared()->SetConstructStub(*code);
1306 1306
1307 Handle<JSFunction> is_arraylike = SimpleInstallFunction( 1307 Handle<JSFunction> is_arraylike = SimpleInstallFunction(
1308 array_function, isolate->factory()->InternalizeUtf8String("isArray"), 1308 array_function, isolate->factory()->InternalizeUtf8String("isArray"),
1309 Builtins::kArrayIsArray, 1, true); 1309 Builtins::kArrayIsArray, 1, true);
1310 native_context()->set_is_arraylike(*is_arraylike); 1310 native_context()->set_is_arraylike(*is_arraylike);
1311 } 1311 }
1312 1312
1313 { // --- A r r a y I t e r a t o r ---
1314 Handle<JSObject> iterator_prototype(
1315 native_context()->initial_iterator_prototype());
1316
1317 Handle<JSObject> array_iterator_prototype =
1318 factory->NewJSObject(isolate->object_function(), TENURED);
1319 JSObject::ForceSetPrototype(array_iterator_prototype, iterator_prototype);
1320
1321 JSObject::AddProperty(
1322 array_iterator_prototype, factory->to_string_tag_symbol(),
1323 factory->ArrayIterator_string(),
1324 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
1325
1326 Handle<JSFunction> next = InstallFunction(
1327 array_iterator_prototype, "next", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1328 MaybeHandle<JSObject>(), Builtins::kArrayIteratorPrototypeNext);
1329
1330 // Set the expected parameters for %ArrayIteratorPrototype%.next to 0 (not
1331 // including the receiver), as required by the builtin.
1332 next->shared()->set_internal_formal_parameter_count(0);
1333
1334 // Set the length for the function to satisfy ECMA-262.
1335 next->shared()->set_length(0);
1336
1337 Handle<JSFunction> array_iterator_function = CreateFunction(
1338 isolate, factory->ArrayIterator_string(),
1339 JS_FAST_ARRAY_VALUE_ITERATOR_TYPE, JSArrayIterator::kSize,
1340 array_iterator_prototype, Builtins::kIllegal);
1341 array_iterator_function->shared()->set_instance_class_name(
1342 isolate->heap()->ArrayIterator_string());
1343
1344 Handle<Map> initial_map(array_iterator_function->initial_map(), isolate);
1345
1346 #define ARRAY_ITERATOR_LIST(V, TypedArray, Array) \
1347 V(TypedArray, TYPED_ARRAY, KEY, typed_array, key) \
1348 V(Array, GENERIC_ARRAY, KEY, array, key) \
1349 V(TypedArray, UINT8_ARRAY, KEY_VALUE, uint8_array, key_value) \
1350 V(TypedArray, INT8_ARRAY, KEY_VALUE, int8_array, key_value) \
1351 V(TypedArray, UINT16_ARRAY, KEY_VALUE, uint16_array, key_value) \
1352 V(TypedArray, INT16_ARRAY, KEY_VALUE, int16_array, key_value) \
1353 V(TypedArray, UINT32_ARRAY, KEY_VALUE, uint32_array, key_value) \
1354 V(TypedArray, INT32_ARRAY, KEY_VALUE, int32_array, key_value) \
1355 V(TypedArray, FLOAT32_ARRAY, KEY_VALUE, float32_array, key_value) \
1356 V(TypedArray, FLOAT64_ARRAY, KEY_VALUE, float64_array, key_value) \
1357 V(TypedArray, UINT8_CLAMPED_ARRAY, KEY_VALUE, uint8_clamped_array, \
1358 key_value) \
1359 V(Array, FAST_SMI_ARRAY, KEY_VALUE, fast_smi_array, key_value) \
1360 V(Array, FAST_HOLEY_SMI_ARRAY, KEY_VALUE, fast_holey_smi_array, key_value) \
1361 V(Array, FAST_ARRAY, KEY_VALUE, fast_array, key_value) \
1362 V(Array, FAST_HOLEY_ARRAY, KEY_VALUE, fast_holey_array, key_value) \
1363 V(Array, FAST_DOUBLE_ARRAY, KEY_VALUE, fast_double_array, key_value) \
1364 V(Array, FAST_HOLEY_DOUBLE_ARRAY, KEY_VALUE, fast_holey_double_array, \
1365 key_value) \
1366 V(Array, GENERIC_ARRAY, KEY_VALUE, array, key_value) \
1367 V(TypedArray, UINT8_ARRAY, VALUE, uint8_array, value) \
1368 V(TypedArray, INT8_ARRAY, VALUE, int8_array, value) \
1369 V(TypedArray, UINT16_ARRAY, VALUE, uint16_array, value) \
1370 V(TypedArray, INT16_ARRAY, VALUE, int16_array, value) \
1371 V(TypedArray, UINT32_ARRAY, VALUE, uint32_array, value) \
1372 V(TypedArray, INT32_ARRAY, VALUE, int32_array, value) \
1373 V(TypedArray, FLOAT32_ARRAY, VALUE, float32_array, value) \
1374 V(TypedArray, FLOAT64_ARRAY, VALUE, float64_array, value) \
1375 V(TypedArray, UINT8_CLAMPED_ARRAY, VALUE, uint8_clamped_array, value) \
1376 V(Array, FAST_SMI_ARRAY, VALUE, fast_smi_array, value) \
1377 V(Array, FAST_HOLEY_SMI_ARRAY, VALUE, fast_holey_smi_array, value) \
1378 V(Array, FAST_ARRAY, VALUE, fast_array, value) \
1379 V(Array, FAST_HOLEY_ARRAY, VALUE, fast_holey_array, value) \
1380 V(Array, FAST_DOUBLE_ARRAY, VALUE, fast_double_array, value) \
1381 V(Array, FAST_HOLEY_DOUBLE_ARRAY, VALUE, fast_holey_double_array, value) \
1382 V(Array, GENERIC_ARRAY, VALUE, array, value)
1383
1384 #define CREATE_ARRAY_ITERATOR_MAP(Class, PREFIX, SUFFIX, prefix, suffix) \
1385 do { \
1386 const InstanceType type = JS_##PREFIX##_##SUFFIX##_ITERATOR_TYPE; \
1387 Handle<Map> map = \
1388 Map::Copy(initial_map, "JS_" #PREFIX "_" #SUFFIX "_ITERATOR_TYPE"); \
1389 map->set_instance_size(Class::kSize); \
1390 map->set_instance_type(type); \
1391 native_context()->set_##prefix##_##suffix##_iterator_map(*map); \
1392 } while (0);
1393
1394 ARRAY_ITERATOR_LIST(CREATE_ARRAY_ITERATOR_MAP, JSTypedArrayIterator,
1395 JSArrayIterator)
1396
1397 #undef CREATE_ARRAY_ITERATOR_MAP
1398 #undef ARRAY_ITERATOR_LIST
1399 }
1400
1313 { // --- N u m b e r --- 1401 { // --- N u m b e r ---
1314 Handle<JSFunction> number_fun = InstallFunction( 1402 Handle<JSFunction> number_fun = InstallFunction(
1315 global, "Number", JS_VALUE_TYPE, JSValue::kSize, 1403 global, "Number", JS_VALUE_TYPE, JSValue::kSize,
1316 isolate->initial_object_prototype(), Builtins::kNumberConstructor); 1404 isolate->initial_object_prototype(), Builtins::kNumberConstructor);
1317 number_fun->shared()->DontAdaptArguments(); 1405 number_fun->shared()->DontAdaptArguments();
1318 number_fun->shared()->SetConstructStub( 1406 number_fun->shared()->SetConstructStub(
1319 *isolate->builtins()->NumberConstructor_ConstructStub()); 1407 *isolate->builtins()->NumberConstructor_ConstructStub());
1320 number_fun->shared()->set_length(1); 1408 number_fun->shared()->set_length(1);
1321 InstallWithIntrinsicDefaultProto(isolate, number_fun, 1409 InstallWithIntrinsicDefaultProto(isolate, number_fun,
1322 Context::NUMBER_FUNCTION_INDEX); 1410 Context::NUMBER_FUNCTION_INDEX);
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 Builtins::kTypedArrayPrototypeBuffer, false); 2173 Builtins::kTypedArrayPrototypeBuffer, false);
2086 SimpleInstallGetter(prototype, factory->byte_length_string(), 2174 SimpleInstallGetter(prototype, factory->byte_length_string(),
2087 Builtins::kTypedArrayPrototypeByteLength, true, 2175 Builtins::kTypedArrayPrototypeByteLength, true,
2088 kTypedArrayByteLength); 2176 kTypedArrayByteLength);
2089 SimpleInstallGetter(prototype, factory->byte_offset_string(), 2177 SimpleInstallGetter(prototype, factory->byte_offset_string(),
2090 Builtins::kTypedArrayPrototypeByteOffset, true, 2178 Builtins::kTypedArrayPrototypeByteOffset, true,
2091 kTypedArrayByteOffset); 2179 kTypedArrayByteOffset);
2092 SimpleInstallGetter(prototype, factory->length_string(), 2180 SimpleInstallGetter(prototype, factory->length_string(),
2093 Builtins::kTypedArrayPrototypeLength, true, 2181 Builtins::kTypedArrayPrototypeLength, true,
2094 kTypedArrayLength); 2182 kTypedArrayLength);
2183
2184 // Install "keys", "values" and "entries" methods on the {prototype}.
2185 SimpleInstallFunction(prototype, factory->entries_string(),
2186 Builtins::kTypedArrayPrototypeEntries, 0, true);
2187 SimpleInstallFunction(prototype, factory->keys_string(),
2188 Builtins::kTypedArrayPrototypeKeys, 0, true);
2189 Handle<JSFunction> iterator =
2190 SimpleInstallFunction(prototype, factory->values_string(),
2191 Builtins::kTypedArrayPrototypeValues, 0, true);
2192 JSObject::AddProperty(prototype, factory->iterator_symbol(), iterator,
2193 DONT_ENUM);
2095 } 2194 }
2096 2195
2097 { // -- T y p e d A r r a y s 2196 { // -- T y p e d A r r a y s
2098 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ 2197 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
2099 { \ 2198 { \
2100 Handle<JSFunction> fun; \ 2199 Handle<JSFunction> fun; \
2101 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ 2200 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \
2102 InstallWithIntrinsicDefaultProto(isolate, fun, \ 2201 InstallWithIntrinsicDefaultProto(isolate, fun, \
2103 Context::TYPE##_ARRAY_FUN_INDEX); \ 2202 Context::TYPE##_ARRAY_FUN_INDEX); \
2104 } 2203 }
(...skipping 2363 matching lines...) Expand 10 before | Expand all | Expand 10 after
4468 } 4567 }
4469 4568
4470 4569
4471 // Called when the top-level V8 mutex is destroyed. 4570 // Called when the top-level V8 mutex is destroyed.
4472 void Bootstrapper::FreeThreadResources() { 4571 void Bootstrapper::FreeThreadResources() {
4473 DCHECK(!IsActive()); 4572 DCHECK(!IsActive());
4474 } 4573 }
4475 4574
4476 } // namespace internal 4575 } // namespace internal
4477 } // namespace v8 4576 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698