OLD | NEW |
---|---|
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 Loading... | |
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->ArrayIterator_string(), | |
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 Handle<JSFunction> array_iterator_function = CreateFunction( | |
1332 isolate, factory->ArrayIterator_string(), | |
1333 JS_FAST_ARRAY_VALUE_ITERATOR_TYPE, JSArrayIterator::kSize, | |
1334 array_iterator_prototype, Builtins::kIllegal); | |
1335 array_iterator_function->shared()->set_instance_class_name( | |
caitp
2016/10/13 22:32:44
This doesn't change allows me to not alter some te
| |
1336 isolate->heap()->ArrayIterator_string()); | |
1337 | |
1338 Handle<Map> initial_map(array_iterator_function->initial_map(), isolate); | |
1339 | |
1340 #define ARRAY_ITERATOR_LIST(V, TypedArray, Array) \ | |
1341 V(TypedArray, TYPED_ARRAY, KEY, typed_array, key) \ | |
1342 V(Array, GENERIC_ARRAY, KEY, array, key) \ | |
1343 V(TypedArray, UINT8_ARRAY, KEY_VALUE, uint8_array, key_value) \ | |
1344 V(TypedArray, INT8_ARRAY, KEY_VALUE, int8_array, key_value) \ | |
1345 V(TypedArray, UINT16_ARRAY, KEY_VALUE, uint16_array, key_value) \ | |
1346 V(TypedArray, INT16_ARRAY, KEY_VALUE, int16_array, key_value) \ | |
1347 V(TypedArray, UINT32_ARRAY, KEY_VALUE, uint32_array, key_value) \ | |
1348 V(TypedArray, INT32_ARRAY, KEY_VALUE, int32_array, key_value) \ | |
1349 V(TypedArray, FLOAT32_ARRAY, KEY_VALUE, float32_array, key_value) \ | |
1350 V(TypedArray, FLOAT64_ARRAY, KEY_VALUE, float64_array, key_value) \ | |
1351 V(TypedArray, UINT8_CLAMPED_ARRAY, KEY_VALUE, uint8_clamped_array, \ | |
1352 key_value) \ | |
1353 V(Array, FAST_SMI_ARRAY, KEY_VALUE, fast_smi_array, key_value) \ | |
1354 V(Array, FAST_HOLEY_SMI_ARRAY, KEY_VALUE, fast_holey_smi_array, key_value) \ | |
1355 V(Array, FAST_ARRAY, KEY_VALUE, fast_array, key_value) \ | |
1356 V(Array, FAST_HOLEY_ARRAY, KEY_VALUE, fast_holey_array, key_value) \ | |
1357 V(Array, FAST_DOUBLE_ARRAY, KEY_VALUE, fast_double_array, key_value) \ | |
1358 V(Array, FAST_HOLEY_DOUBLE_ARRAY, KEY_VALUE, fast_holey_double_array, \ | |
1359 key_value) \ | |
1360 V(Array, GENERIC_ARRAY, KEY_VALUE, array, key_value) \ | |
1361 V(TypedArray, UINT8_ARRAY, VALUE, uint8_array, value) \ | |
1362 V(TypedArray, INT8_ARRAY, VALUE, int8_array, value) \ | |
1363 V(TypedArray, UINT16_ARRAY, VALUE, uint16_array, value) \ | |
1364 V(TypedArray, INT16_ARRAY, VALUE, int16_array, value) \ | |
1365 V(TypedArray, UINT32_ARRAY, VALUE, uint32_array, value) \ | |
1366 V(TypedArray, INT32_ARRAY, VALUE, int32_array, value) \ | |
1367 V(TypedArray, FLOAT32_ARRAY, VALUE, float32_array, value) \ | |
1368 V(TypedArray, FLOAT64_ARRAY, VALUE, float64_array, value) \ | |
1369 V(TypedArray, UINT8_CLAMPED_ARRAY, VALUE, uint8_clamped_array, value) \ | |
1370 V(Array, FAST_SMI_ARRAY, VALUE, fast_smi_array, value) \ | |
1371 V(Array, FAST_HOLEY_SMI_ARRAY, VALUE, fast_holey_smi_array, value) \ | |
1372 V(Array, FAST_ARRAY, VALUE, fast_array, value) \ | |
1373 V(Array, FAST_HOLEY_ARRAY, VALUE, fast_holey_array, value) \ | |
1374 V(Array, FAST_DOUBLE_ARRAY, VALUE, fast_double_array, value) \ | |
1375 V(Array, FAST_HOLEY_DOUBLE_ARRAY, VALUE, fast_holey_double_array, value) \ | |
1376 V(Array, GENERIC_ARRAY, VALUE, array, value) | |
1377 | |
1378 #define CREATE_ARRAY_ITERATOR_MAP(Class, PREFIX, SUFFIX, prefix, suffix) \ | |
1379 do { \ | |
1380 const InstanceType type = JS_##PREFIX##_##SUFFIX##_ITERATOR_TYPE; \ | |
1381 Handle<Map> map = \ | |
1382 Map::Copy(initial_map, "JS_" #PREFIX "_" #SUFFIX "_ITERATOR_TYPE"); \ | |
1383 map->set_instance_size(Class::kSize); \ | |
1384 map->set_instance_type(type); \ | |
1385 native_context()->set_##prefix##_##suffix##_iterator_map(*map); \ | |
1386 } while (0); | |
1387 | |
1388 ARRAY_ITERATOR_LIST(CREATE_ARRAY_ITERATOR_MAP, JSTypedArrayIterator, | |
1389 JSArrayIterator) | |
1390 | |
1391 #undef CREATE_ARRAY_ITERATOR_MAP | |
1392 #undef ARRAY_ITERATOR_LIST | |
1393 } | |
1394 | |
1307 { // --- N u m b e r --- | 1395 { // --- N u m b e r --- |
1308 Handle<JSFunction> number_fun = InstallFunction( | 1396 Handle<JSFunction> number_fun = InstallFunction( |
1309 global, "Number", JS_VALUE_TYPE, JSValue::kSize, | 1397 global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
1310 isolate->initial_object_prototype(), Builtins::kNumberConstructor); | 1398 isolate->initial_object_prototype(), Builtins::kNumberConstructor); |
1311 number_fun->shared()->DontAdaptArguments(); | 1399 number_fun->shared()->DontAdaptArguments(); |
1312 number_fun->shared()->SetConstructStub( | 1400 number_fun->shared()->SetConstructStub( |
1313 *isolate->builtins()->NumberConstructor_ConstructStub()); | 1401 *isolate->builtins()->NumberConstructor_ConstructStub()); |
1314 number_fun->shared()->set_length(1); | 1402 number_fun->shared()->set_length(1); |
1315 InstallWithIntrinsicDefaultProto(isolate, number_fun, | 1403 InstallWithIntrinsicDefaultProto(isolate, number_fun, |
1316 Context::NUMBER_FUNCTION_INDEX); | 1404 Context::NUMBER_FUNCTION_INDEX); |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2040 Builtins::kTypedArrayPrototypeBuffer, false); | 2128 Builtins::kTypedArrayPrototypeBuffer, false); |
2041 SimpleInstallGetter(prototype, factory->byte_length_string(), | 2129 SimpleInstallGetter(prototype, factory->byte_length_string(), |
2042 Builtins::kTypedArrayPrototypeByteLength, true, | 2130 Builtins::kTypedArrayPrototypeByteLength, true, |
2043 kTypedArrayByteLength); | 2131 kTypedArrayByteLength); |
2044 SimpleInstallGetter(prototype, factory->byte_offset_string(), | 2132 SimpleInstallGetter(prototype, factory->byte_offset_string(), |
2045 Builtins::kTypedArrayPrototypeByteOffset, true, | 2133 Builtins::kTypedArrayPrototypeByteOffset, true, |
2046 kTypedArrayByteOffset); | 2134 kTypedArrayByteOffset); |
2047 SimpleInstallGetter(prototype, factory->length_string(), | 2135 SimpleInstallGetter(prototype, factory->length_string(), |
2048 Builtins::kTypedArrayPrototypeLength, true, | 2136 Builtins::kTypedArrayPrototypeLength, true, |
2049 kTypedArrayLength); | 2137 kTypedArrayLength); |
2138 | |
2139 // Install "keys", "values" and "entries" methods on the {prototype}. | |
2140 SimpleInstallFunction(prototype, factory->entries_string(), | |
2141 Builtins::kTypedArrayPrototypeEntries, 0, true); | |
2142 SimpleInstallFunction(prototype, factory->keys_string(), | |
2143 Builtins::kTypedArrayPrototypeKeys, 0, true); | |
2144 Handle<JSFunction> iterator = | |
2145 SimpleInstallFunction(prototype, factory->values_string(), | |
2146 Builtins::kTypedArrayPrototypeValues, 0, true); | |
2147 JSObject::AddProperty(prototype, factory->iterator_symbol(), iterator, | |
2148 DONT_ENUM); | |
2050 } | 2149 } |
2051 | 2150 |
2052 { // -- T y p e d A r r a y s | 2151 { // -- T y p e d A r r a y s |
2053 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ | 2152 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ |
2054 { \ | 2153 { \ |
2055 Handle<JSFunction> fun; \ | 2154 Handle<JSFunction> fun; \ |
2056 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ | 2155 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ |
2057 InstallWithIntrinsicDefaultProto(isolate, fun, \ | 2156 InstallWithIntrinsicDefaultProto(isolate, fun, \ |
2058 Context::TYPE##_ARRAY_FUN_INDEX); \ | 2157 Context::TYPE##_ARRAY_FUN_INDEX); \ |
2059 } | 2158 } |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2765 generator_function_prototype, factory->constructor_string(), | 2864 generator_function_prototype, factory->constructor_string(), |
2766 generator_function_function, | 2865 generator_function_function, |
2767 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | 2866 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
2768 | 2867 |
2769 native_context->sloppy_generator_function_map()->SetConstructor( | 2868 native_context->sloppy_generator_function_map()->SetConstructor( |
2770 *generator_function_function); | 2869 *generator_function_function); |
2771 native_context->strict_generator_function_map()->SetConstructor( | 2870 native_context->strict_generator_function_map()->SetConstructor( |
2772 *generator_function_function); | 2871 *generator_function_function); |
2773 } | 2872 } |
2774 | 2873 |
2874 { // -- A r r a y I t e r a t o r | |
2875 Handle<Object> array_values(native_context->array_values_iterator(), | |
2876 isolate); | |
2877 JSObject::AddProperty(container, | |
2878 factory->NewStringFromAsciiChecked("ArrayValues"), | |
2879 array_values, DONT_ENUM); | |
2880 } | |
2881 | |
2775 { // -- S e t I t e r a t o r | 2882 { // -- S e t I t e r a t o r |
2776 Handle<JSObject> set_iterator_prototype = | 2883 Handle<JSObject> set_iterator_prototype = |
2777 isolate->factory()->NewJSObject(isolate->object_function(), TENURED); | 2884 isolate->factory()->NewJSObject(isolate->object_function(), TENURED); |
2778 JSObject::ForceSetPrototype(set_iterator_prototype, iterator_prototype); | 2885 JSObject::ForceSetPrototype(set_iterator_prototype, iterator_prototype); |
2779 Handle<JSFunction> set_iterator_function = InstallFunction( | 2886 Handle<JSFunction> set_iterator_function = InstallFunction( |
2780 container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, | 2887 container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, |
2781 set_iterator_prototype, Builtins::kIllegal); | 2888 set_iterator_prototype, Builtins::kIllegal); |
2782 native_context->set_set_iterator_map(set_iterator_function->initial_map()); | 2889 native_context->set_set_iterator_map(set_iterator_function->initial_map()); |
2783 } | 2890 } |
2784 | 2891 |
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4395 } | 4502 } |
4396 | 4503 |
4397 | 4504 |
4398 // Called when the top-level V8 mutex is destroyed. | 4505 // Called when the top-level V8 mutex is destroyed. |
4399 void Bootstrapper::FreeThreadResources() { | 4506 void Bootstrapper::FreeThreadResources() { |
4400 DCHECK(!IsActive()); | 4507 DCHECK(!IsActive()); |
4401 } | 4508 } |
4402 | 4509 |
4403 } // namespace internal | 4510 } // namespace internal |
4404 } // namespace v8 | 4511 } // namespace v8 |
OLD | NEW |