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/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/extensions/externalize-string-extension.h" | 10 #include "src/extensions/externalize-string-extension.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 function->shared()->set_native(true); | 372 function->shared()->set_native(true); |
373 } | 373 } |
374 | 374 |
375 void InstallFunction(Handle<JSObject> target, Handle<JSFunction> function, | 375 void InstallFunction(Handle<JSObject> target, Handle<JSFunction> function, |
376 Handle<Name> name, | 376 Handle<Name> name, |
377 PropertyAttributes attributes = DONT_ENUM) { | 377 PropertyAttributes attributes = DONT_ENUM) { |
378 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); | 378 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); |
379 InstallFunction(target, name, function, name_string, attributes); | 379 InstallFunction(target, name, function, name_string, attributes); |
380 } | 380 } |
381 | 381 |
| 382 Handle<JSFunction> InstallGetter(Handle<JSObject> target, |
| 383 Handle<Name> property_name, |
| 384 Handle<JSFunction> getter, |
| 385 PropertyAttributes attributes = DONT_ENUM) { |
| 386 Handle<Object> setter = target->GetIsolate()->factory()->undefined_value(); |
| 387 JSObject::DefineAccessor(target, property_name, getter, setter, attributes) |
| 388 .Check(); |
| 389 return getter; |
| 390 } |
| 391 |
382 Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, | 392 Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, |
383 InstanceType type, int instance_size, | 393 InstanceType type, int instance_size, |
384 MaybeHandle<JSObject> maybe_prototype, | 394 MaybeHandle<JSObject> maybe_prototype, |
385 Builtins::Name call, | 395 Builtins::Name call, |
386 bool strict_function_map = false) { | 396 bool strict_function_map = false) { |
387 Factory* factory = isolate->factory(); | 397 Factory* factory = isolate->factory(); |
388 Handle<Code> call_code(isolate->builtins()->builtin(call)); | 398 Handle<Code> call_code(isolate->builtins()->builtin(call)); |
389 Handle<JSObject> prototype; | 399 Handle<JSObject> prototype; |
390 static const bool kReadOnlyPrototype = false; | 400 static const bool kReadOnlyPrototype = false; |
391 static const bool kInstallConstructor = false; | 401 static const bool kInstallConstructor = false; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 459 } |
450 | 460 |
451 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, | 461 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, |
452 const char* name, Builtins::Name call, | 462 const char* name, Builtins::Name call, |
453 int len, bool adapt) { | 463 int len, bool adapt) { |
454 Factory* const factory = base->GetIsolate()->factory(); | 464 Factory* const factory = base->GetIsolate()->factory(); |
455 return SimpleInstallFunction(base, factory->InternalizeUtf8String(name), call, | 465 return SimpleInstallFunction(base, factory->InternalizeUtf8String(name), call, |
456 len, adapt); | 466 len, adapt); |
457 } | 467 } |
458 | 468 |
| 469 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, |
| 470 Handle<String> name, Builtins::Name call, |
| 471 bool adapt) { |
| 472 Isolate* const isolate = base->GetIsolate(); |
| 473 Handle<String> fun_name = |
| 474 Name::ToFunctionName(name, isolate->factory()->get_string()) |
| 475 .ToHandleChecked(); |
| 476 Handle<JSFunction> fun = |
| 477 SimpleCreateFunction(isolate, fun_name, call, 0, adapt); |
| 478 InstallGetter(base, name, fun); |
| 479 return fun; |
| 480 } |
| 481 |
| 482 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, |
| 483 Handle<String> name, Builtins::Name call, |
| 484 bool adapt, BuiltinFunctionId id) { |
| 485 Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt); |
| 486 fun->shared()->set_builtin_function_id(id); |
| 487 return fun; |
| 488 } |
| 489 |
459 } // namespace | 490 } // namespace |
460 | 491 |
461 void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map, | 492 void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map, |
462 FunctionMode function_mode) { | 493 FunctionMode function_mode) { |
463 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; | 494 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; |
464 Map::EnsureDescriptorSlack(map, size); | 495 Map::EnsureDescriptorSlack(map, size); |
465 | 496 |
466 PropertyAttributes ro_attribs = | 497 PropertyAttributes ro_attribs = |
467 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 498 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
468 PropertyAttributes roc_attribs = | 499 PropertyAttributes roc_attribs = |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 SimpleInstallFunction(math, "trunc", Builtins::kMathTrunc, 1, true); | 1678 SimpleInstallFunction(math, "trunc", Builtins::kMathTrunc, 1, true); |
1648 } | 1679 } |
1649 | 1680 |
1650 { // -- A r r a y B u f f e r | 1681 { // -- A r r a y B u f f e r |
1651 Handle<JSFunction> array_buffer_fun = | 1682 Handle<JSFunction> array_buffer_fun = |
1652 InstallArrayBuffer(global, "ArrayBuffer"); | 1683 InstallArrayBuffer(global, "ArrayBuffer"); |
1653 InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun, | 1684 InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun, |
1654 Context::ARRAY_BUFFER_FUN_INDEX); | 1685 Context::ARRAY_BUFFER_FUN_INDEX); |
1655 } | 1686 } |
1656 | 1687 |
| 1688 { // -- T y p e d A r r a y |
| 1689 Handle<JSObject> prototype = |
| 1690 factory->NewJSObject(isolate->object_function(), TENURED); |
| 1691 native_context()->set_typed_array_prototype(*prototype); |
| 1692 |
| 1693 Handle<JSFunction> typed_array_fun = |
| 1694 CreateFunction(isolate, factory->InternalizeUtf8String("TypedArray"), |
| 1695 JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, prototype, |
| 1696 Builtins::kIllegal); |
| 1697 |
| 1698 // Install the "constructor" property on the {prototype}. |
| 1699 JSObject::AddProperty(prototype, factory->constructor_string(), |
| 1700 typed_array_fun, DONT_ENUM); |
| 1701 native_context()->set_typed_array_function(*typed_array_fun); |
| 1702 |
| 1703 // Install the "buffer", "byteOffset", "byteLength" and "length" |
| 1704 // getters on the {prototype}. |
| 1705 SimpleInstallGetter(prototype, factory->buffer_string(), |
| 1706 Builtins::kTypedArrayPrototypeBuffer, false); |
| 1707 SimpleInstallGetter(prototype, factory->byte_length_string(), |
| 1708 Builtins::kTypedArrayPrototypeByteLength, true, |
| 1709 kTypedArrayByteLength); |
| 1710 SimpleInstallGetter(prototype, factory->byte_offset_string(), |
| 1711 Builtins::kTypedArrayPrototypeByteOffset, true, |
| 1712 kTypedArrayByteOffset); |
| 1713 SimpleInstallGetter(prototype, factory->length_string(), |
| 1714 Builtins::kTypedArrayPrototypeLength, true, |
| 1715 kTypedArrayLength); |
| 1716 } |
| 1717 |
1657 { // -- T y p e d A r r a y s | 1718 { // -- T y p e d A r r a y s |
1658 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ | 1719 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ |
1659 { \ | 1720 { \ |
1660 Handle<JSFunction> fun; \ | 1721 Handle<JSFunction> fun; \ |
1661 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ | 1722 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ |
1662 InstallWithIntrinsicDefaultProto(isolate, fun, \ | 1723 InstallWithIntrinsicDefaultProto(isolate, fun, \ |
1663 Context::TYPE##_ARRAY_FUN_INDEX); \ | 1724 Context::TYPE##_ARRAY_FUN_INDEX); \ |
1664 } | 1725 } |
1665 TYPED_ARRAYS(INSTALL_TYPED_ARRAY) | 1726 TYPED_ARRAYS(INSTALL_TYPED_ARRAY) |
1666 #undef INSTALL_TYPED_ARRAY | 1727 #undef INSTALL_TYPED_ARRAY |
| 1728 } |
1667 | 1729 |
1668 Handle<JSFunction> data_view_fun = InstallFunction( | 1730 { // -- D a t a V i e w |
1669 global, "DataView", JS_DATA_VIEW_TYPE, | 1731 Handle<JSObject> prototype = |
1670 JSDataView::kSizeWithInternalFields, | 1732 factory->NewJSObject(isolate->object_function(), TENURED); |
1671 isolate->initial_object_prototype(), Builtins::kDataViewConstructor); | 1733 Handle<JSFunction> data_view_fun = |
| 1734 InstallFunction(global, "DataView", JS_DATA_VIEW_TYPE, |
| 1735 JSDataView::kSizeWithInternalFields, prototype, |
| 1736 Builtins::kDataViewConstructor); |
1672 InstallWithIntrinsicDefaultProto(isolate, data_view_fun, | 1737 InstallWithIntrinsicDefaultProto(isolate, data_view_fun, |
1673 Context::DATA_VIEW_FUN_INDEX); | 1738 Context::DATA_VIEW_FUN_INDEX); |
1674 data_view_fun->shared()->set_construct_stub( | 1739 data_view_fun->shared()->set_construct_stub( |
1675 *isolate->builtins()->DataViewConstructor_ConstructStub()); | 1740 *isolate->builtins()->DataViewConstructor_ConstructStub()); |
1676 data_view_fun->shared()->set_length(3); | 1741 data_view_fun->shared()->set_length(3); |
1677 data_view_fun->shared()->DontAdaptArguments(); | 1742 data_view_fun->shared()->DontAdaptArguments(); |
| 1743 |
| 1744 // Install the @@toStringTag property on the {prototype}. |
| 1745 JSObject::AddProperty( |
| 1746 prototype, factory->to_string_tag_symbol(), |
| 1747 factory->NewStringFromAsciiChecked("DataView"), |
| 1748 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 1749 |
| 1750 // Install the "constructor" property on the {prototype}. |
| 1751 JSObject::AddProperty(prototype, factory->constructor_string(), |
| 1752 data_view_fun, DONT_ENUM); |
| 1753 |
| 1754 // Install the "buffer", "byteOffset" and "byteLength" getters |
| 1755 // on the {prototype}. |
| 1756 SimpleInstallGetter(prototype, factory->buffer_string(), |
| 1757 Builtins::kDataViewPrototypeGetBuffer, false, |
| 1758 kDataViewBuffer); |
| 1759 SimpleInstallGetter(prototype, factory->byte_length_string(), |
| 1760 Builtins::kDataViewPrototypeGetByteLength, false, |
| 1761 kDataViewByteLength); |
| 1762 SimpleInstallGetter(prototype, factory->byte_offset_string(), |
| 1763 Builtins::kDataViewPrototypeGetByteOffset, false, |
| 1764 kDataViewByteOffset); |
1678 } | 1765 } |
1679 | 1766 |
1680 { // -- M a p | 1767 { // -- M a p |
1681 Handle<JSFunction> js_map_fun = InstallFunction( | 1768 Handle<JSFunction> js_map_fun = InstallFunction( |
1682 global, "Map", JS_MAP_TYPE, JSMap::kSize, | 1769 global, "Map", JS_MAP_TYPE, JSMap::kSize, |
1683 isolate->initial_object_prototype(), Builtins::kIllegal); | 1770 isolate->initial_object_prototype(), Builtins::kIllegal); |
1684 InstallWithIntrinsicDefaultProto(isolate, js_map_fun, | 1771 InstallWithIntrinsicDefaultProto(isolate, js_map_fun, |
1685 Context::JS_MAP_FUN_INDEX); | 1772 Context::JS_MAP_FUN_INDEX); |
1686 } | 1773 } |
1687 | 1774 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1966 { | 2053 { |
1967 // Set up the call-as-constructor delegate. | 2054 // Set up the call-as-constructor delegate. |
1968 Handle<Code> code = isolate->builtins()->HandleApiCallAsConstructor(); | 2055 Handle<Code> code = isolate->builtins()->HandleApiCallAsConstructor(); |
1969 Handle<JSFunction> delegate = factory->NewFunction( | 2056 Handle<JSFunction> delegate = factory->NewFunction( |
1970 factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); | 2057 factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); |
1971 native_context()->set_call_as_constructor_delegate(*delegate); | 2058 native_context()->set_call_as_constructor_delegate(*delegate); |
1972 delegate->shared()->DontAdaptArguments(); | 2059 delegate->shared()->DontAdaptArguments(); |
1973 } | 2060 } |
1974 } // NOLINT(readability/fn_size) | 2061 } // NOLINT(readability/fn_size) |
1975 | 2062 |
1976 | |
1977 void Genesis::InstallTypedArray(const char* name, ElementsKind elements_kind, | 2063 void Genesis::InstallTypedArray(const char* name, ElementsKind elements_kind, |
1978 Handle<JSFunction>* fun) { | 2064 Handle<JSFunction>* fun) { |
1979 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); | 2065 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); |
1980 Handle<JSFunction> result = InstallFunction( | 2066 |
1981 global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, | 2067 Handle<JSObject> typed_array_prototype = |
1982 isolate()->initial_object_prototype(), Builtins::kIllegal); | 2068 Handle<JSObject>(isolate()->typed_array_prototype()); |
| 2069 Handle<JSFunction> typed_array_function = |
| 2070 Handle<JSFunction>(isolate()->typed_array_function()); |
| 2071 |
| 2072 Handle<JSObject> prototype = |
| 2073 factory()->NewJSObject(isolate()->object_function(), TENURED); |
| 2074 Handle<JSFunction> result = |
| 2075 InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, |
| 2076 prototype, Builtins::kIllegal); |
1983 | 2077 |
1984 Handle<Map> initial_map = isolate()->factory()->NewMap( | 2078 Handle<Map> initial_map = isolate()->factory()->NewMap( |
1985 JS_TYPED_ARRAY_TYPE, | 2079 JS_TYPED_ARRAY_TYPE, |
1986 JSTypedArray::kSizeWithInternalFields, | 2080 JSTypedArray::kSizeWithInternalFields, |
1987 elements_kind); | 2081 elements_kind); |
1988 JSFunction::SetInitialMap(result, initial_map, | 2082 JSFunction::SetInitialMap(result, initial_map, |
1989 handle(initial_map->prototype(), isolate())); | 2083 handle(initial_map->prototype(), isolate())); |
| 2084 |
| 2085 CHECK(JSObject::SetPrototype(result, typed_array_function, false, |
| 2086 Object::DONT_THROW) |
| 2087 .FromJust()); |
| 2088 |
| 2089 CHECK(JSObject::SetPrototype(prototype, typed_array_prototype, false, |
| 2090 Object::DONT_THROW) |
| 2091 .FromJust()); |
1990 *fun = result; | 2092 *fun = result; |
1991 } | 2093 } |
1992 | 2094 |
1993 | 2095 |
1994 void Genesis::InitializeExperimentalGlobal() { | 2096 void Genesis::InitializeExperimentalGlobal() { |
1995 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id(); | 2097 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id(); |
1996 | 2098 |
1997 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL) | 2099 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL) |
1998 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) | 2100 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) |
1999 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) | 2101 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) |
(...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3817 } | 3919 } |
3818 | 3920 |
3819 | 3921 |
3820 // Called when the top-level V8 mutex is destroyed. | 3922 // Called when the top-level V8 mutex is destroyed. |
3821 void Bootstrapper::FreeThreadResources() { | 3923 void Bootstrapper::FreeThreadResources() { |
3822 DCHECK(!IsActive()); | 3924 DCHECK(!IsActive()); |
3823 } | 3925 } |
3824 | 3926 |
3825 } // namespace internal | 3927 } // namespace internal |
3826 } // namespace v8 | 3928 } // namespace v8 |
OLD | NEW |