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

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