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 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 |
1657 { // -- T y p e d A r r a y s | 1714 { // -- T y p e d A r r a y s |
1658 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ | 1715 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ |
1659 { \ | 1716 { \ |
1660 Handle<JSFunction> fun; \ | 1717 Handle<JSFunction> fun; \ |
1661 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ | 1718 InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ |
1662 InstallWithIntrinsicDefaultProto(isolate, fun, \ | 1719 InstallWithIntrinsicDefaultProto(isolate, fun, \ |
1663 Context::TYPE##_ARRAY_FUN_INDEX); \ | 1720 Context::TYPE##_ARRAY_FUN_INDEX); \ |
1664 } | 1721 } |
1665 TYPED_ARRAYS(INSTALL_TYPED_ARRAY) | 1722 TYPED_ARRAYS(INSTALL_TYPED_ARRAY) |
1666 #undef INSTALL_TYPED_ARRAY | 1723 #undef INSTALL_TYPED_ARRAY |
| 1724 } |
1667 | 1725 |
1668 Handle<JSFunction> data_view_fun = InstallFunction( | 1726 { // -- D a t a V i e w |
1669 global, "DataView", JS_DATA_VIEW_TYPE, | 1727 Handle<JSObject> prototype = |
1670 JSDataView::kSizeWithInternalFields, | 1728 factory->NewJSObject(isolate->object_function(), TENURED); |
1671 isolate->initial_object_prototype(), Builtins::kDataViewConstructor); | 1729 Handle<JSFunction> data_view_fun = |
| 1730 InstallFunction(global, "DataView", JS_DATA_VIEW_TYPE, |
| 1731 JSDataView::kSizeWithInternalFields, prototype, |
| 1732 Builtins::kDataViewConstructor); |
1672 InstallWithIntrinsicDefaultProto(isolate, data_view_fun, | 1733 InstallWithIntrinsicDefaultProto(isolate, data_view_fun, |
1673 Context::DATA_VIEW_FUN_INDEX); | 1734 Context::DATA_VIEW_FUN_INDEX); |
1674 data_view_fun->shared()->set_construct_stub( | 1735 data_view_fun->shared()->set_construct_stub( |
1675 *isolate->builtins()->DataViewConstructor_ConstructStub()); | 1736 *isolate->builtins()->DataViewConstructor_ConstructStub()); |
1676 data_view_fun->shared()->set_length(3); | 1737 data_view_fun->shared()->set_length(3); |
1677 data_view_fun->shared()->DontAdaptArguments(); | 1738 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); |
1678 } | 1761 } |
1679 | 1762 |
1680 { // -- M a p | 1763 { // -- M a p |
1681 Handle<JSFunction> js_map_fun = InstallFunction( | 1764 Handle<JSFunction> js_map_fun = InstallFunction( |
1682 global, "Map", JS_MAP_TYPE, JSMap::kSize, | 1765 global, "Map", JS_MAP_TYPE, JSMap::kSize, |
1683 isolate->initial_object_prototype(), Builtins::kIllegal); | 1766 isolate->initial_object_prototype(), Builtins::kIllegal); |
1684 InstallWithIntrinsicDefaultProto(isolate, js_map_fun, | 1767 InstallWithIntrinsicDefaultProto(isolate, js_map_fun, |
1685 Context::JS_MAP_FUN_INDEX); | 1768 Context::JS_MAP_FUN_INDEX); |
1686 } | 1769 } |
1687 | 1770 |
(...skipping 2129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3817 } | 3900 } |
3818 | 3901 |
3819 | 3902 |
3820 // Called when the top-level V8 mutex is destroyed. | 3903 // Called when the top-level V8 mutex is destroyed. |
3821 void Bootstrapper::FreeThreadResources() { | 3904 void Bootstrapper::FreeThreadResources() { |
3822 DCHECK(!IsActive()); | 3905 DCHECK(!IsActive()); |
3823 } | 3906 } |
3824 | 3907 |
3825 } // namespace internal | 3908 } // namespace internal |
3826 } // namespace v8 | 3909 } // namespace v8 |
OLD | NEW |