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

Side by Side Diff: src/bootstrapper.cc

Issue 2405253006: [builtins] implement Array.prototype[@@iterator] in TFJ builtins (Closed)
Patch Set: add array_iterator_protector, and check array_protector in holey fast arrays 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) \
1347 V(TYPED_ARRAY, KEY, typed_array, key) \
1348 V(GENERIC_ARRAY, KEY, array, key) \
1349 V(UINT8_ARRAY, KEY_VALUE, uint8_array, key_value) \
1350 V(INT8_ARRAY, KEY_VALUE, int8_array, key_value) \
1351 V(UINT16_ARRAY, KEY_VALUE, uint16_array, key_value) \
1352 V(INT16_ARRAY, KEY_VALUE, int16_array, key_value) \
1353 V(UINT32_ARRAY, KEY_VALUE, uint32_array, key_value) \
1354 V(INT32_ARRAY, KEY_VALUE, int32_array, key_value) \
1355 V(FLOAT32_ARRAY, KEY_VALUE, float32_array, key_value) \
1356 V(FLOAT64_ARRAY, KEY_VALUE, float64_array, key_value) \
1357 V(UINT8_CLAMPED_ARRAY, KEY_VALUE, uint8_clamped_array, key_value) \
1358 V(FAST_SMI_ARRAY, KEY_VALUE, fast_smi_array, key_value) \
1359 V(FAST_HOLEY_SMI_ARRAY, KEY_VALUE, fast_holey_smi_array, key_value) \
1360 V(FAST_ARRAY, KEY_VALUE, fast_array, key_value) \
1361 V(FAST_HOLEY_ARRAY, KEY_VALUE, fast_holey_array, key_value) \
1362 V(FAST_DOUBLE_ARRAY, KEY_VALUE, fast_double_array, key_value) \
1363 V(FAST_HOLEY_DOUBLE_ARRAY, KEY_VALUE, fast_holey_double_array, key_value) \
1364 V(GENERIC_ARRAY, KEY_VALUE, array, key_value) \
1365 V(UINT8_ARRAY, VALUE, uint8_array, value) \
1366 V(INT8_ARRAY, VALUE, int8_array, value) \
1367 V(UINT16_ARRAY, VALUE, uint16_array, value) \
1368 V(INT16_ARRAY, VALUE, int16_array, value) \
1369 V(UINT32_ARRAY, VALUE, uint32_array, value) \
1370 V(INT32_ARRAY, VALUE, int32_array, value) \
1371 V(FLOAT32_ARRAY, VALUE, float32_array, value) \
1372 V(FLOAT64_ARRAY, VALUE, float64_array, value) \
1373 V(UINT8_CLAMPED_ARRAY, VALUE, uint8_clamped_array, value) \
1374 V(FAST_SMI_ARRAY, VALUE, fast_smi_array, value) \
1375 V(FAST_HOLEY_SMI_ARRAY, VALUE, fast_holey_smi_array, value) \
1376 V(FAST_ARRAY, VALUE, fast_array, value) \
1377 V(FAST_HOLEY_ARRAY, VALUE, fast_holey_array, value) \
1378 V(FAST_DOUBLE_ARRAY, VALUE, fast_double_array, value) \
1379 V(FAST_HOLEY_DOUBLE_ARRAY, VALUE, fast_holey_double_array, value) \
1380 V(GENERIC_ARRAY, VALUE, array, value)
1381
1382 #define CREATE_ARRAY_ITERATOR_MAP(PREFIX, SUFFIX, prefix, suffix) \
1383 do { \
1384 const InstanceType type = JS_##PREFIX##_##SUFFIX##_ITERATOR_TYPE; \
1385 Handle<Map> map = \
1386 Map::Copy(initial_map, "JS_" #PREFIX "_" #SUFFIX "_ITERATOR_TYPE"); \
1387 map->set_instance_type(type); \
1388 native_context()->set_##prefix##_##suffix##_iterator_map(*map); \
1389 } while (0);
1390
1391 ARRAY_ITERATOR_LIST(CREATE_ARRAY_ITERATOR_MAP)
1392
1393 #undef CREATE_ARRAY_ITERATOR_MAP
1394 #undef ARRAY_ITERATOR_LIST
1395 }
1396
1313 { // --- N u m b e r --- 1397 { // --- N u m b e r ---
1314 Handle<JSFunction> number_fun = InstallFunction( 1398 Handle<JSFunction> number_fun = InstallFunction(
1315 global, "Number", JS_VALUE_TYPE, JSValue::kSize, 1399 global, "Number", JS_VALUE_TYPE, JSValue::kSize,
1316 isolate->initial_object_prototype(), Builtins::kNumberConstructor); 1400 isolate->initial_object_prototype(), Builtins::kNumberConstructor);
1317 number_fun->shared()->DontAdaptArguments(); 1401 number_fun->shared()->DontAdaptArguments();
1318 number_fun->shared()->SetConstructStub( 1402 number_fun->shared()->SetConstructStub(
1319 *isolate->builtins()->NumberConstructor_ConstructStub()); 1403 *isolate->builtins()->NumberConstructor_ConstructStub());
1320 number_fun->shared()->set_length(1); 1404 number_fun->shared()->set_length(1);
1321 InstallWithIntrinsicDefaultProto(isolate, number_fun, 1405 InstallWithIntrinsicDefaultProto(isolate, number_fun,
1322 Context::NUMBER_FUNCTION_INDEX); 1406 Context::NUMBER_FUNCTION_INDEX);
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 Builtins::kTypedArrayPrototypeBuffer, false); 2169 Builtins::kTypedArrayPrototypeBuffer, false);
2086 SimpleInstallGetter(prototype, factory->byte_length_string(), 2170 SimpleInstallGetter(prototype, factory->byte_length_string(),
2087 Builtins::kTypedArrayPrototypeByteLength, true, 2171 Builtins::kTypedArrayPrototypeByteLength, true,
2088 kTypedArrayByteLength); 2172 kTypedArrayByteLength);
2089 SimpleInstallGetter(prototype, factory->byte_offset_string(), 2173 SimpleInstallGetter(prototype, factory->byte_offset_string(),
2090 Builtins::kTypedArrayPrototypeByteOffset, true, 2174 Builtins::kTypedArrayPrototypeByteOffset, true,
2091 kTypedArrayByteOffset); 2175 kTypedArrayByteOffset);
2092 SimpleInstallGetter(prototype, factory->length_string(), 2176 SimpleInstallGetter(prototype, factory->length_string(),
2093 Builtins::kTypedArrayPrototypeLength, true, 2177 Builtins::kTypedArrayPrototypeLength, true,
2094 kTypedArrayLength); 2178 kTypedArrayLength);
2179
2180 // Install "keys", "values" and "entries" methods on the {prototype}.
2181 SimpleInstallFunction(prototype, factory->entries_string(),
2182 Builtins::kTypedArrayPrototypeEntries, 0, true);
2183 SimpleInstallFunction(prototype, factory->keys_string(),
2184 Builtins::kTypedArrayPrototypeKeys, 0, true);
2185 Handle<JSFunction> iterator =
2186 SimpleInstallFunction(prototype, factory->values_string(),
2187 Builtins::kTypedArrayPrototypeValues, 0, true);
2188 JSObject::AddProperty(prototype, factory->iterator_symbol(), iterator,
2189 DONT_ENUM);
2095 } 2190 }
2096 2191
2097 { // -- T y p e d A r r a y s 2192 { // -- T y p e d A r r a y s
2098 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ 2193 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
2099 { \ 2194 { \
2100 Handle<JSFunction> fun; \ 2195 Handle<JSFunction> fun; \
2101 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ 2196 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \
2102 InstallWithIntrinsicDefaultProto(isolate, fun, \ 2197 InstallWithIntrinsicDefaultProto(isolate, fun, \
2103 Context::TYPE##_ARRAY_FUN_INDEX); \ 2198 Context::TYPE##_ARRAY_FUN_INDEX); \
2104 } 2199 }
(...skipping 2363 matching lines...) Expand 10 before | Expand all | Expand 10 after
4468 } 4563 }
4469 4564
4470 4565
4471 // Called when the top-level V8 mutex is destroyed. 4566 // Called when the top-level V8 mutex is destroyed.
4472 void Bootstrapper::FreeThreadResources() { 4567 void Bootstrapper::FreeThreadResources() {
4473 DCHECK(!IsActive()); 4568 DCHECK(!IsActive());
4474 } 4569 }
4475 4570
4476 } // namespace internal 4571 } // namespace internal
4477 } // namespace v8 4572 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698