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 1782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1793 Builtins::kDatePrototypeToPrimitive, | 1793 Builtins::kDatePrototypeToPrimitive, |
1794 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | 1794 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
1795 | 1795 |
1796 // Set the expected parameters for @@toPrimitive to 1; required by builtin. | 1796 // Set the expected parameters for @@toPrimitive to 1; required by builtin. |
1797 to_primitive->shared()->set_internal_formal_parameter_count(1); | 1797 to_primitive->shared()->set_internal_formal_parameter_count(1); |
1798 | 1798 |
1799 // Set the length for the function to satisfy ECMA-262. | 1799 // Set the length for the function to satisfy ECMA-262. |
1800 to_primitive->shared()->set_length(1); | 1800 to_primitive->shared()->set_length(1); |
1801 } | 1801 } |
1802 | 1802 |
| 1803 { // -- P r o m i s e |
| 1804 // Set catch prediction |
| 1805 Handle<Code> promise_code = isolate->builtins()->PromiseConstructor(); |
| 1806 promise_code->set_is_promise_rejection(true); |
| 1807 |
| 1808 Handle<JSObject> prototype = |
| 1809 factory->NewJSObject(isolate->object_function(), TENURED); |
| 1810 Handle<JSFunction> promise_fun = InstallFunction( |
| 1811 global, "Promise", JS_PROMISE_TYPE, JSObject::kHeaderSize, prototype, |
| 1812 Builtins::kPromiseConstructor); |
| 1813 InstallWithIntrinsicDefaultProto(isolate, promise_fun, |
| 1814 Context::PROMISE_FUNCTION_INDEX); |
| 1815 |
| 1816 Handle<SharedFunctionInfo> shared(promise_fun->shared(), isolate); |
| 1817 shared->SetConstructStub(*isolate->builtins()->JSBuiltinsConstructStub()); |
| 1818 shared->set_instance_class_name(isolate->heap()->Object_string()); |
| 1819 shared->set_internal_formal_parameter_count(1); |
| 1820 shared->set_length(1); |
| 1821 |
| 1822 // Install the "constructor" property on the {prototype}. |
| 1823 JSObject::AddProperty(prototype, factory->constructor_string(), promise_fun, |
| 1824 DONT_ENUM); |
| 1825 |
| 1826 // Install the @@toStringTag property on the {prototype}. |
| 1827 JSObject::AddProperty( |
| 1828 prototype, factory->to_string_tag_symbol(), factory->Promise_string(), |
| 1829 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 1830 |
| 1831 { // Internal: PromiseInternalConstructor |
| 1832 Handle<JSFunction> function = |
| 1833 SimpleCreateFunction(isolate, factory->empty_string(), |
| 1834 Builtins::kPromiseInternalConstructor, 0, false); |
| 1835 InstallWithIntrinsicDefaultProto( |
| 1836 isolate, function, Context::PROMISE_INTERNAL_CONSTRUCTOR_INDEX); |
| 1837 } |
| 1838 |
| 1839 { // Internal: IsPromise |
| 1840 Handle<JSFunction> function = SimpleCreateFunction( |
| 1841 isolate, factory->empty_string(), Builtins::kIsPromise, 1, false); |
| 1842 InstallWithIntrinsicDefaultProto(isolate, function, |
| 1843 Context::IS_PROMISE_INDEX); |
| 1844 } |
| 1845 |
| 1846 { |
| 1847 Handle<Code> code = |
| 1848 handle(isolate->builtins()->builtin(Builtins::kPromiseResolveClosure), |
| 1849 isolate); |
| 1850 Handle<SharedFunctionInfo> info = |
| 1851 factory->NewSharedFunctionInfo(factory->empty_string(), code, false); |
| 1852 info->set_internal_formal_parameter_count(1); |
| 1853 info->set_length(1); |
| 1854 native_context()->set_promise_resolve_shared_fun(*info); |
| 1855 |
| 1856 code = |
| 1857 handle(isolate->builtins()->builtin(Builtins::kPromiseRejectClosure), |
| 1858 isolate); |
| 1859 info = |
| 1860 factory->NewSharedFunctionInfo(factory->empty_string(), code, false); |
| 1861 info->set_internal_formal_parameter_count(2); |
| 1862 info->set_length(1); |
| 1863 native_context()->set_promise_reject_shared_fun(*info); |
| 1864 } |
| 1865 |
| 1866 Handle<JSFunction> create_resolving_functions = |
| 1867 SimpleCreateFunction(isolate, factory->empty_string(), |
| 1868 Builtins::kCreateResolvingFunctions, 2, false); |
| 1869 native_context()->set_create_resolving_functions( |
| 1870 *create_resolving_functions); |
| 1871 } |
| 1872 |
1803 { // -- R e g E x p | 1873 { // -- R e g E x p |
1804 // Builtin functions for RegExp.prototype. | 1874 // Builtin functions for RegExp.prototype. |
1805 Handle<JSObject> prototype = | 1875 Handle<JSObject> prototype = |
1806 factory->NewJSObject(isolate->object_function(), TENURED); | 1876 factory->NewJSObject(isolate->object_function(), TENURED); |
1807 Handle<JSFunction> regexp_fun = | 1877 Handle<JSFunction> regexp_fun = |
1808 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, | 1878 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, |
1809 prototype, Builtins::kRegExpConstructor); | 1879 prototype, Builtins::kRegExpConstructor); |
1810 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, | 1880 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, |
1811 Context::REGEXP_FUNCTION_INDEX); | 1881 Context::REGEXP_FUNCTION_INDEX); |
1812 | 1882 |
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3570 | 3640 |
3571 // Make sure that InternalArray.prototype.concat appears to be compiled. | 3641 // Make sure that InternalArray.prototype.concat appears to be compiled. |
3572 // The code will never be called, but inline caching for call will | 3642 // The code will never be called, but inline caching for call will |
3573 // only work if it appears to be compiled. | 3643 // only work if it appears to be compiled. |
3574 concat->shared()->DontAdaptArguments(); | 3644 concat->shared()->DontAdaptArguments(); |
3575 DCHECK(concat->is_compiled()); | 3645 DCHECK(concat->is_compiled()); |
3576 // Set the lengths for the functions to satisfy ECMA-262. | 3646 // Set the lengths for the functions to satisfy ECMA-262. |
3577 concat->shared()->set_length(1); | 3647 concat->shared()->set_length(1); |
3578 } | 3648 } |
3579 | 3649 |
3580 // Set up the Promise constructor. | |
3581 { | |
3582 Handle<String> key = factory()->Promise_string(); | |
3583 Handle<JSFunction> function = Handle<JSFunction>::cast( | |
3584 JSReceiver::GetProperty(global_object, key).ToHandleChecked()); | |
3585 JSFunction::EnsureHasInitialMap(function); | |
3586 function->initial_map()->set_instance_type(JS_PROMISE_TYPE); | |
3587 function->shared()->SetConstructStub( | |
3588 *isolate()->builtins()->JSBuiltinsConstructStub()); | |
3589 InstallWithIntrinsicDefaultProto(isolate(), function, | |
3590 Context::PROMISE_FUNCTION_INDEX); | |
3591 | |
3592 { | |
3593 Handle<Code> code = handle( | |
3594 isolate()->builtins()->builtin(Builtins::kPromiseResolveClosure), | |
3595 isolate()); | |
3596 Handle<SharedFunctionInfo> info = | |
3597 isolate()->factory()->NewSharedFunctionInfo(factory()->empty_string(), | |
3598 code, false); | |
3599 info->set_internal_formal_parameter_count(1); | |
3600 info->set_length(1); | |
3601 native_context()->set_promise_resolve_shared_fun(*info); | |
3602 | |
3603 code = handle( | |
3604 isolate()->builtins()->builtin(Builtins::kPromiseRejectClosure), | |
3605 isolate()); | |
3606 info = isolate()->factory()->NewSharedFunctionInfo( | |
3607 factory()->empty_string(), code, false); | |
3608 info->set_internal_formal_parameter_count(2); | |
3609 info->set_length(1); | |
3610 native_context()->set_promise_reject_shared_fun(*info); | |
3611 } | |
3612 | |
3613 Handle<JSFunction> create_resolving_functions = | |
3614 SimpleCreateFunction(isolate(), factory()->empty_string(), | |
3615 Builtins::kCreateResolvingFunctions, 2, false); | |
3616 native_context()->set_create_resolving_functions( | |
3617 *create_resolving_functions); | |
3618 } | |
3619 | |
3620 InstallBuiltinFunctionIds(); | 3650 InstallBuiltinFunctionIds(); |
3621 | 3651 |
3622 // Create a map for accessor property descriptors (a variant of JSObject | 3652 // Create a map for accessor property descriptors (a variant of JSObject |
3623 // that predefines four properties get, set, configurable and enumerable). | 3653 // that predefines four properties get, set, configurable and enumerable). |
3624 { | 3654 { |
3625 // AccessorPropertyDescriptor initial map. | 3655 // AccessorPropertyDescriptor initial map. |
3626 Handle<Map> map = | 3656 Handle<Map> map = |
3627 factory()->NewMap(JS_OBJECT_TYPE, JSAccessorPropertyDescriptor::kSize); | 3657 factory()->NewMap(JS_OBJECT_TYPE, JSAccessorPropertyDescriptor::kSize); |
3628 // Create the descriptor array for the property descriptor object. | 3658 // Create the descriptor array for the property descriptor object. |
3629 Map::EnsureDescriptorSlack(map, 4); | 3659 Map::EnsureDescriptorSlack(map, 4); |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4558 } | 4588 } |
4559 | 4589 |
4560 | 4590 |
4561 // Called when the top-level V8 mutex is destroyed. | 4591 // Called when the top-level V8 mutex is destroyed. |
4562 void Bootstrapper::FreeThreadResources() { | 4592 void Bootstrapper::FreeThreadResources() { |
4563 DCHECK(!IsActive()); | 4593 DCHECK(!IsActive()); |
4564 } | 4594 } |
4565 | 4595 |
4566 } // namespace internal | 4596 } // namespace internal |
4567 } // namespace v8 | 4597 } // namespace v8 |
OLD | NEW |