| 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 | |
| 392 Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, | 382 Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, |
| 393 InstanceType type, int instance_size, | 383 InstanceType type, int instance_size, |
| 394 MaybeHandle<JSObject> maybe_prototype, | 384 MaybeHandle<JSObject> maybe_prototype, |
| 395 Builtins::Name call, | 385 Builtins::Name call, |
| 396 bool strict_function_map = false) { | 386 bool strict_function_map = false) { |
| 397 Factory* factory = isolate->factory(); | 387 Factory* factory = isolate->factory(); |
| 398 Handle<Code> call_code(isolate->builtins()->builtin(call)); | 388 Handle<Code> call_code(isolate->builtins()->builtin(call)); |
| 399 Handle<JSObject> prototype; | 389 Handle<JSObject> prototype; |
| 400 static const bool kReadOnlyPrototype = false; | 390 static const bool kReadOnlyPrototype = false; |
| 401 static const bool kInstallConstructor = false; | 391 static const bool kInstallConstructor = false; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 } | 449 } |
| 460 | 450 |
| 461 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, | 451 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, |
| 462 const char* name, Builtins::Name call, | 452 const char* name, Builtins::Name call, |
| 463 int len, bool adapt) { | 453 int len, bool adapt) { |
| 464 Factory* const factory = base->GetIsolate()->factory(); | 454 Factory* const factory = base->GetIsolate()->factory(); |
| 465 return SimpleInstallFunction(base, factory->InternalizeUtf8String(name), call, | 455 return SimpleInstallFunction(base, factory->InternalizeUtf8String(name), call, |
| 466 len, adapt); | 456 len, adapt); |
| 467 } | 457 } |
| 468 | 458 |
| 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 | |
| 490 } // namespace | 459 } // namespace |
| 491 | 460 |
| 492 void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map, | 461 void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map, |
| 493 FunctionMode function_mode) { | 462 FunctionMode function_mode) { |
| 494 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; | 463 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; |
| 495 Map::EnsureDescriptorSlack(map, size); | 464 Map::EnsureDescriptorSlack(map, size); |
| 496 | 465 |
| 497 PropertyAttributes ro_attribs = | 466 PropertyAttributes ro_attribs = |
| 498 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 467 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 499 PropertyAttributes roc_attribs = | 468 PropertyAttributes roc_attribs = |
| (...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1678 SimpleInstallFunction(math, "trunc", Builtins::kMathTrunc, 1, true); | 1647 SimpleInstallFunction(math, "trunc", Builtins::kMathTrunc, 1, true); |
| 1679 } | 1648 } |
| 1680 | 1649 |
| 1681 { // -- A r r a y B u f f e r | 1650 { // -- A r r a y B u f f e r |
| 1682 Handle<JSFunction> array_buffer_fun = | 1651 Handle<JSFunction> array_buffer_fun = |
| 1683 InstallArrayBuffer(global, "ArrayBuffer"); | 1652 InstallArrayBuffer(global, "ArrayBuffer"); |
| 1684 InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun, | 1653 InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun, |
| 1685 Context::ARRAY_BUFFER_FUN_INDEX); | 1654 Context::ARRAY_BUFFER_FUN_INDEX); |
| 1686 } | 1655 } |
| 1687 | 1656 |
| 1688 { // -- T y p e d A r r a y | |
| 1689 Handle<JSObject> prototype = | |
| 1690 factory->NewJSObject(isolate->object_function(), TENURED); | |
| 1691 Handle<JSFunction> typed_array_fun = | |
| 1692 InstallFunction(global, "TypedArray", JS_TYPED_ARRAY_TYPE, | |
| 1693 JSTypedArray::kSize, prototype, Builtins::kIllegal); | |
| 1694 | |
| 1695 // Install the "constructor" property on the {prototype}. | |
| 1696 JSObject::AddProperty(prototype, factory->constructor_string(), | |
| 1697 typed_array_fun, DONT_ENUM); | |
| 1698 | |
| 1699 // Install the "buffer", "byteOffset", "byteLength" and "length" | |
| 1700 // getters on the {prototype}. | |
| 1701 SimpleInstallGetter(prototype, factory->buffer_string(), | |
| 1702 Builtins::kTypedArrayPrototypeBuffer, false); | |
| 1703 SimpleInstallGetter(prototype, factory->byte_length_string(), | |
| 1704 Builtins::kTypedArrayPrototypeByteLength, true, | |
| 1705 kTypedArrayByteLength); | |
| 1706 SimpleInstallGetter(prototype, factory->byte_offset_string(), | |
| 1707 Builtins::kTypedArrayPrototypeByteOffset, true, | |
| 1708 kTypedArrayByteOffset); | |
| 1709 SimpleInstallGetter(prototype, factory->length_string(), | |
| 1710 Builtins::kTypedArrayPrototypeLength, true, | |
| 1711 kTypedArrayLength); | |
| 1712 } | |
| 1713 | |
| 1714 { // -- T y p e d A r r a y s | 1657 { // -- T y p e d A r r a y s |
| 1715 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ | 1658 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ |
| 1716 { \ | 1659 { \ |
| 1717 Handle<JSFunction> fun; \ | 1660 Handle<JSFunction> fun; \ |
| 1718 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ | 1661 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ |
| 1719 InstallWithIntrinsicDefaultProto(isolate, fun, \ | 1662 InstallWithIntrinsicDefaultProto(isolate, fun, \ |
| 1720 Context::TYPE##_ARRAY_FUN_INDEX); \ | 1663 Context::TYPE##_ARRAY_FUN_INDEX); \ |
| 1721 } | 1664 } |
| 1722 TYPED_ARRAYS(INSTALL_TYPED_ARRAY) | 1665 TYPED_ARRAYS(INSTALL_TYPED_ARRAY) |
| 1723 #undef INSTALL_TYPED_ARRAY | 1666 #undef INSTALL_TYPED_ARRAY |
| 1724 } | |
| 1725 | 1667 |
| 1726 { // -- D a t a V i e w | 1668 Handle<JSFunction> data_view_fun = InstallFunction( |
| 1727 Handle<JSObject> prototype = | 1669 global, "DataView", JS_DATA_VIEW_TYPE, |
| 1728 factory->NewJSObject(isolate->object_function(), TENURED); | 1670 JSDataView::kSizeWithInternalFields, |
| 1729 Handle<JSFunction> data_view_fun = | 1671 isolate->initial_object_prototype(), Builtins::kDataViewConstructor); |
| 1730 InstallFunction(global, "DataView", JS_DATA_VIEW_TYPE, | |
| 1731 JSDataView::kSizeWithInternalFields, prototype, | |
| 1732 Builtins::kDataViewConstructor); | |
| 1733 InstallWithIntrinsicDefaultProto(isolate, data_view_fun, | 1672 InstallWithIntrinsicDefaultProto(isolate, data_view_fun, |
| 1734 Context::DATA_VIEW_FUN_INDEX); | 1673 Context::DATA_VIEW_FUN_INDEX); |
| 1735 data_view_fun->shared()->set_construct_stub( | 1674 data_view_fun->shared()->set_construct_stub( |
| 1736 *isolate->builtins()->DataViewConstructor_ConstructStub()); | 1675 *isolate->builtins()->DataViewConstructor_ConstructStub()); |
| 1737 data_view_fun->shared()->set_length(3); | 1676 data_view_fun->shared()->set_length(3); |
| 1738 data_view_fun->shared()->DontAdaptArguments(); | 1677 data_view_fun->shared()->DontAdaptArguments(); |
| 1739 | |
| 1740 // Install the @@toStringTag property on the {prototype}. | |
| 1741 JSObject::AddProperty( | |
| 1742 prototype, factory->to_string_tag_symbol(), | |
| 1743 factory->NewStringFromAsciiChecked("DataView"), | |
| 1744 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | |
| 1745 | |
| 1746 // Install the "constructor" property on the {prototype}. | |
| 1747 JSObject::AddProperty(prototype, factory->constructor_string(), | |
| 1748 data_view_fun, DONT_ENUM); | |
| 1749 | |
| 1750 // Install the "buffer", "byteOffset" and "byteLength" getters | |
| 1751 // on the {prototype}. | |
| 1752 SimpleInstallGetter(prototype, factory->buffer_string(), | |
| 1753 Builtins::kDataViewPrototypeGetBuffer, false, | |
| 1754 kDataViewBuffer); | |
| 1755 SimpleInstallGetter(prototype, factory->byte_length_string(), | |
| 1756 Builtins::kDataViewPrototypeGetByteLength, false, | |
| 1757 kDataViewByteLength); | |
| 1758 SimpleInstallGetter(prototype, factory->byte_offset_string(), | |
| 1759 Builtins::kDataViewPrototypeGetByteOffset, false, | |
| 1760 kDataViewByteOffset); | |
| 1761 } | 1678 } |
| 1762 | 1679 |
| 1763 { // -- M a p | 1680 { // -- M a p |
| 1764 Handle<JSFunction> js_map_fun = InstallFunction( | 1681 Handle<JSFunction> js_map_fun = InstallFunction( |
| 1765 global, "Map", JS_MAP_TYPE, JSMap::kSize, | 1682 global, "Map", JS_MAP_TYPE, JSMap::kSize, |
| 1766 isolate->initial_object_prototype(), Builtins::kIllegal); | 1683 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1767 InstallWithIntrinsicDefaultProto(isolate, js_map_fun, | 1684 InstallWithIntrinsicDefaultProto(isolate, js_map_fun, |
| 1768 Context::JS_MAP_FUN_INDEX); | 1685 Context::JS_MAP_FUN_INDEX); |
| 1769 } | 1686 } |
| 1770 | 1687 |
| (...skipping 2129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3900 } | 3817 } |
| 3901 | 3818 |
| 3902 | 3819 |
| 3903 // Called when the top-level V8 mutex is destroyed. | 3820 // Called when the top-level V8 mutex is destroyed. |
| 3904 void Bootstrapper::FreeThreadResources() { | 3821 void Bootstrapper::FreeThreadResources() { |
| 3905 DCHECK(!IsActive()); | 3822 DCHECK(!IsActive()); |
| 3906 } | 3823 } |
| 3907 | 3824 |
| 3908 } // namespace internal | 3825 } // namespace internal |
| 3909 } // namespace v8 | 3826 } // namespace v8 |
| OLD | NEW |