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

Side by Side Diff: src/bootstrapper.cc

Issue 2405253006: [builtins] implement Array.prototype[@@iterator] in TFJ builtins (Closed)
Patch Set: remove apparently redundant var bindings and fix other bugs 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 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 ArrayConstructorStub array_constructor_stub(isolate); 1296 ArrayConstructorStub array_constructor_stub(isolate);
1297 Handle<Code> code = array_constructor_stub.GetCode(); 1297 Handle<Code> code = array_constructor_stub.GetCode();
1298 array_function->shared()->SetConstructStub(*code); 1298 array_function->shared()->SetConstructStub(*code);
1299 1299
1300 Handle<JSFunction> is_arraylike = SimpleInstallFunction( 1300 Handle<JSFunction> is_arraylike = SimpleInstallFunction(
1301 array_function, isolate->factory()->InternalizeUtf8String("isArray"), 1301 array_function, isolate->factory()->InternalizeUtf8String("isArray"),
1302 Builtins::kArrayIsArray, 1, true); 1302 Builtins::kArrayIsArray, 1, true);
1303 native_context()->set_is_arraylike(*is_arraylike); 1303 native_context()->set_is_arraylike(*is_arraylike);
1304 } 1304 }
1305 1305
1306 { // --- A r r a y I t e r a t o r ---
1307 Handle<JSObject> iterator_prototype(
1308 native_context()->initial_iterator_prototype());
1309
1310 Handle<JSObject> array_iterator_prototype =
1311 factory->NewJSObject(isolate->object_function(), TENURED);
1312 JSObject::ForceSetPrototype(array_iterator_prototype, iterator_prototype);
1313
1314 JSObject::AddProperty(
1315 array_iterator_prototype, factory->to_string_tag_symbol(),
1316 factory->ArrayIterator_string(),
1317 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
1318
1319 Handle<JSFunction> next = InstallFunction(
1320 array_iterator_prototype, "next", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1321 MaybeHandle<JSObject>(), Builtins::kArrayIteratorPrototypeNext);
1322
1323 // Set the expected parameters for %ArrayIteratorPrototype%.next to 0 (not
1324 // including the receiver), as required by the builtin.
1325 next->shared()->set_internal_formal_parameter_count(0);
1326
1327 // Set the length for the function to satisfy ECMA-262.
1328 next->shared()->set_length(0);
1329
1330 Handle<JSFunction> array_iterator_function = CreateFunction(
1331 isolate, factory->ArrayIterator_string(),
1332 JS_FAST_ARRAY_VALUE_ITERATOR_TYPE, JSArrayIterator::kSize,
1333 array_iterator_prototype, Builtins::kIllegal);
1334 array_iterator_function->shared()->set_instance_class_name(
1335 isolate->heap()->ArrayIterator_string());
1336
1337 Handle<Map> initial_map(array_iterator_function->initial_map(), isolate);
1338
1339 #define ARRAY_ITERATOR_LIST(V, TypedArray, Array) \
1340 V(TypedArray, TYPED_ARRAY, KEY, typed_array, key) \
1341 V(Array, GENERIC_ARRAY, KEY, array, key) \
1342 V(TypedArray, UINT8_ARRAY, KEY_VALUE, uint8_array, key_value) \
1343 V(TypedArray, INT8_ARRAY, KEY_VALUE, int8_array, key_value) \
1344 V(TypedArray, UINT16_ARRAY, KEY_VALUE, uint16_array, key_value) \
1345 V(TypedArray, INT16_ARRAY, KEY_VALUE, int16_array, key_value) \
1346 V(TypedArray, UINT32_ARRAY, KEY_VALUE, uint32_array, key_value) \
1347 V(TypedArray, INT32_ARRAY, KEY_VALUE, int32_array, key_value) \
1348 V(TypedArray, FLOAT32_ARRAY, KEY_VALUE, float32_array, key_value) \
1349 V(TypedArray, FLOAT64_ARRAY, KEY_VALUE, float64_array, key_value) \
1350 V(TypedArray, UINT8_CLAMPED_ARRAY, KEY_VALUE, uint8_clamped_array, \
1351 key_value) \
1352 V(Array, FAST_SMI_ARRAY, KEY_VALUE, fast_smi_array, key_value) \
1353 V(Array, FAST_HOLEY_SMI_ARRAY, KEY_VALUE, fast_holey_smi_array, key_value) \
1354 V(Array, FAST_ARRAY, KEY_VALUE, fast_array, key_value) \
1355 V(Array, FAST_HOLEY_ARRAY, KEY_VALUE, fast_holey_array, key_value) \
1356 V(Array, FAST_DOUBLE_ARRAY, KEY_VALUE, fast_double_array, key_value) \
1357 V(Array, FAST_HOLEY_DOUBLE_ARRAY, KEY_VALUE, fast_holey_double_array, \
1358 key_value) \
1359 V(Array, GENERIC_ARRAY, KEY_VALUE, array, key_value) \
1360 V(TypedArray, UINT8_ARRAY, VALUE, uint8_array, value) \
1361 V(TypedArray, INT8_ARRAY, VALUE, int8_array, value) \
1362 V(TypedArray, UINT16_ARRAY, VALUE, uint16_array, value) \
1363 V(TypedArray, INT16_ARRAY, VALUE, int16_array, value) \
1364 V(TypedArray, UINT32_ARRAY, VALUE, uint32_array, value) \
1365 V(TypedArray, INT32_ARRAY, VALUE, int32_array, value) \
1366 V(TypedArray, FLOAT32_ARRAY, VALUE, float32_array, value) \
1367 V(TypedArray, FLOAT64_ARRAY, VALUE, float64_array, value) \
1368 V(TypedArray, UINT8_CLAMPED_ARRAY, VALUE, uint8_clamped_array, value) \
1369 V(Array, FAST_SMI_ARRAY, VALUE, fast_smi_array, value) \
1370 V(Array, FAST_HOLEY_SMI_ARRAY, VALUE, fast_holey_smi_array, value) \
1371 V(Array, FAST_ARRAY, VALUE, fast_array, value) \
1372 V(Array, FAST_HOLEY_ARRAY, VALUE, fast_holey_array, value) \
1373 V(Array, FAST_DOUBLE_ARRAY, VALUE, fast_double_array, value) \
1374 V(Array, FAST_HOLEY_DOUBLE_ARRAY, VALUE, fast_holey_double_array, value) \
1375 V(Array, GENERIC_ARRAY, VALUE, array, value)
1376
1377 #define CREATE_ARRAY_ITERATOR_MAP(Class, PREFIX, SUFFIX, prefix, suffix) \
1378 do { \
1379 const InstanceType type = JS_##PREFIX##_##SUFFIX##_ITERATOR_TYPE; \
1380 Handle<Map> map = \
1381 Map::Copy(initial_map, "JS_" #PREFIX "_" #SUFFIX "_ITERATOR_TYPE"); \
1382 map->set_instance_size(Class::kSize); \
1383 map->set_instance_type(type); \
1384 native_context()->set_##prefix##_##suffix##_iterator_map(*map); \
1385 } while (0);
1386
1387 ARRAY_ITERATOR_LIST(CREATE_ARRAY_ITERATOR_MAP, JSTypedArrayIterator,
1388 JSArrayIterator)
1389
1390 #undef CREATE_ARRAY_ITERATOR_MAP
1391 #undef ARRAY_ITERATOR_LIST
1392 }
1393
1306 { // --- N u m b e r --- 1394 { // --- N u m b e r ---
1307 Handle<JSFunction> number_fun = InstallFunction( 1395 Handle<JSFunction> number_fun = InstallFunction(
1308 global, "Number", JS_VALUE_TYPE, JSValue::kSize, 1396 global, "Number", JS_VALUE_TYPE, JSValue::kSize,
1309 isolate->initial_object_prototype(), Builtins::kNumberConstructor); 1397 isolate->initial_object_prototype(), Builtins::kNumberConstructor);
1310 number_fun->shared()->DontAdaptArguments(); 1398 number_fun->shared()->DontAdaptArguments();
1311 number_fun->shared()->SetConstructStub( 1399 number_fun->shared()->SetConstructStub(
1312 *isolate->builtins()->NumberConstructor_ConstructStub()); 1400 *isolate->builtins()->NumberConstructor_ConstructStub());
1313 number_fun->shared()->set_length(1); 1401 number_fun->shared()->set_length(1);
1314 InstallWithIntrinsicDefaultProto(isolate, number_fun, 1402 InstallWithIntrinsicDefaultProto(isolate, number_fun,
1315 Context::NUMBER_FUNCTION_INDEX); 1403 Context::NUMBER_FUNCTION_INDEX);
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 Builtins::kTypedArrayPrototypeBuffer, false); 2158 Builtins::kTypedArrayPrototypeBuffer, false);
2071 SimpleInstallGetter(prototype, factory->byte_length_string(), 2159 SimpleInstallGetter(prototype, factory->byte_length_string(),
2072 Builtins::kTypedArrayPrototypeByteLength, true, 2160 Builtins::kTypedArrayPrototypeByteLength, true,
2073 kTypedArrayByteLength); 2161 kTypedArrayByteLength);
2074 SimpleInstallGetter(prototype, factory->byte_offset_string(), 2162 SimpleInstallGetter(prototype, factory->byte_offset_string(),
2075 Builtins::kTypedArrayPrototypeByteOffset, true, 2163 Builtins::kTypedArrayPrototypeByteOffset, true,
2076 kTypedArrayByteOffset); 2164 kTypedArrayByteOffset);
2077 SimpleInstallGetter(prototype, factory->length_string(), 2165 SimpleInstallGetter(prototype, factory->length_string(),
2078 Builtins::kTypedArrayPrototypeLength, true, 2166 Builtins::kTypedArrayPrototypeLength, true,
2079 kTypedArrayLength); 2167 kTypedArrayLength);
2168
2169 // Install "keys", "values" and "entries" methods on the {prototype}.
2170 SimpleInstallFunction(prototype, factory->entries_string(),
2171 Builtins::kTypedArrayPrototypeEntries, 0, true);
2172 SimpleInstallFunction(prototype, factory->keys_string(),
2173 Builtins::kTypedArrayPrototypeKeys, 0, true);
2174 Handle<JSFunction> iterator =
2175 SimpleInstallFunction(prototype, factory->values_string(),
2176 Builtins::kTypedArrayPrototypeValues, 0, true);
2177 JSObject::AddProperty(prototype, factory->iterator_symbol(), iterator,
2178 DONT_ENUM);
2179 native_context()->set_array_values_iterator(*iterator);
2080 } 2180 }
2081 2181
2082 { // -- T y p e d A r r a y s 2182 { // -- T y p e d A r r a y s
2083 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ 2183 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
2084 { \ 2184 { \
2085 Handle<JSFunction> fun; \ 2185 Handle<JSFunction> fun; \
2086 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ 2186 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \
2087 InstallWithIntrinsicDefaultProto(isolate, fun, \ 2187 InstallWithIntrinsicDefaultProto(isolate, fun, \
2088 Context::TYPE##_ARRAY_FUN_INDEX); \ 2188 Context::TYPE##_ARRAY_FUN_INDEX); \
2089 } 2189 }
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
2804 generator_function_prototype, factory->constructor_string(), 2904 generator_function_prototype, factory->constructor_string(),
2805 generator_function_function, 2905 generator_function_function,
2806 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); 2906 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
2807 2907
2808 native_context->sloppy_generator_function_map()->SetConstructor( 2908 native_context->sloppy_generator_function_map()->SetConstructor(
2809 *generator_function_function); 2909 *generator_function_function);
2810 native_context->strict_generator_function_map()->SetConstructor( 2910 native_context->strict_generator_function_map()->SetConstructor(
2811 *generator_function_function); 2911 *generator_function_function);
2812 } 2912 }
2813 2913
2914 { // -- A r r a y I t e r a t o r
2915 Handle<Object> array_values(native_context->array_values_iterator(),
2916 isolate);
2917 JSObject::AddProperty(container,
2918 factory->NewStringFromAsciiChecked("ArrayValues"),
2919 array_values, DONT_ENUM);
2920 }
2921
2814 { // -- F i x e d A r r a y I t e r a t o r 2922 { // -- F i x e d A r r a y I t e r a t o r
2815 int size = JSFixedArrayIterator::kHeaderSize + 2923 int size = JSFixedArrayIterator::kHeaderSize +
2816 JSFixedArrayIterator::kInObjectPropertyCount * kPointerSize; 2924 JSFixedArrayIterator::kInObjectPropertyCount * kPointerSize;
2817 Handle<Map> map = factory->NewMap(JS_FIXED_ARRAY_ITERATOR_TYPE, size); 2925 Handle<Map> map = factory->NewMap(JS_FIXED_ARRAY_ITERATOR_TYPE, size);
2818 Map::SetPrototype(map, iterator_prototype); 2926 Map::SetPrototype(map, iterator_prototype);
2819 Map::EnsureDescriptorSlack(map, 2927 Map::EnsureDescriptorSlack(map,
2820 JSFixedArrayIterator::kInObjectPropertyCount); 2928 JSFixedArrayIterator::kInObjectPropertyCount);
2821 map->SetInObjectProperties(JSFixedArrayIterator::kInObjectPropertyCount); 2929 map->SetInObjectProperties(JSFixedArrayIterator::kInObjectPropertyCount);
2822 map->SetConstructor(native_context->object_function()); 2930 map->SetConstructor(native_context->object_function());
2823 2931
(...skipping 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after
4453 } 4561 }
4454 4562
4455 4563
4456 // Called when the top-level V8 mutex is destroyed. 4564 // Called when the top-level V8 mutex is destroyed.
4457 void Bootstrapper::FreeThreadResources() { 4565 void Bootstrapper::FreeThreadResources() {
4458 DCHECK(!IsActive()); 4566 DCHECK(!IsActive());
4459 } 4567 }
4460 4568
4461 } // namespace internal 4569 } // namespace internal
4462 } // namespace v8 4570 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698