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 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1788 to_primitive->shared()->set_length(1); | 1788 to_primitive->shared()->set_length(1); |
1789 } | 1789 } |
1790 | 1790 |
1791 { // -- P r o m i s e | 1791 { // -- P r o m i s e |
1792 // Set catch prediction | 1792 // Set catch prediction |
1793 Handle<Code> promise_code = isolate->builtins()->PromiseConstructor(); | 1793 Handle<Code> promise_code = isolate->builtins()->PromiseConstructor(); |
1794 promise_code->set_is_promise_rejection(true); | 1794 promise_code->set_is_promise_rejection(true); |
1795 | 1795 |
1796 Handle<JSObject> prototype = | 1796 Handle<JSObject> prototype = |
1797 factory->NewJSObject(isolate->object_function(), TENURED); | 1797 factory->NewJSObject(isolate->object_function(), TENURED); |
1798 Handle<JSFunction> promise_fun = | 1798 Handle<JSFunction> promise_fun = InstallFunction( |
1799 InstallFunction(global, "Promise", JS_PROMISE_TYPE, JSPromise::kSize, | 1799 global, "Promise", JS_PROMISE_TYPE, JSObject::kHeaderSize, prototype, |
1800 prototype, Builtins::kPromiseConstructor); | 1800 Builtins::kPromiseConstructor); |
1801 InstallWithIntrinsicDefaultProto(isolate, promise_fun, | 1801 InstallWithIntrinsicDefaultProto(isolate, promise_fun, |
1802 Context::PROMISE_FUNCTION_INDEX); | 1802 Context::PROMISE_FUNCTION_INDEX); |
1803 | 1803 |
1804 Handle<SharedFunctionInfo> shared(promise_fun->shared(), isolate); | 1804 Handle<SharedFunctionInfo> shared(promise_fun->shared(), isolate); |
1805 shared->SetConstructStub(*isolate->builtins()->JSBuiltinsConstructStub()); | 1805 shared->SetConstructStub(*isolate->builtins()->JSBuiltinsConstructStub()); |
1806 shared->set_instance_class_name(isolate->heap()->Object_string()); | 1806 shared->set_instance_class_name(isolate->heap()->Object_string()); |
1807 shared->set_internal_formal_parameter_count(1); | 1807 shared->set_internal_formal_parameter_count(1); |
1808 shared->set_length(1); | 1808 shared->set_length(1); |
1809 | 1809 |
1810 // Install the "constructor" property on the {prototype}. | 1810 // Install the "constructor" property on the {prototype}. |
1811 JSObject::AddProperty(prototype, factory->constructor_string(), promise_fun, | 1811 JSObject::AddProperty(prototype, factory->constructor_string(), promise_fun, |
1812 DONT_ENUM); | 1812 DONT_ENUM); |
1813 | 1813 |
1814 // Install the @@toStringTag property on the {prototype}. | 1814 // Install the @@toStringTag property on the {prototype}. |
1815 JSObject::AddProperty( | 1815 JSObject::AddProperty( |
1816 prototype, factory->to_string_tag_symbol(), factory->Promise_string(), | 1816 prototype, factory->to_string_tag_symbol(), factory->Promise_string(), |
1817 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | 1817 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
1818 | 1818 |
1819 SimpleInstallFunction(prototype, "then", Builtins::kPromiseThen, 2, true, | |
1820 DONT_ENUM); | |
1821 | |
1822 { // Internal: PromiseInternalConstructor | 1819 { // Internal: PromiseInternalConstructor |
1823 Handle<JSFunction> function = | 1820 Handle<JSFunction> function = |
1824 SimpleCreateFunction(isolate, factory->empty_string(), | 1821 SimpleCreateFunction(isolate, factory->empty_string(), |
1825 Builtins::kPromiseInternalConstructor, 0, false); | 1822 Builtins::kPromiseInternalConstructor, 0, false); |
1826 InstallWithIntrinsicDefaultProto( | 1823 InstallWithIntrinsicDefaultProto( |
1827 isolate, function, Context::PROMISE_INTERNAL_CONSTRUCTOR_INDEX); | 1824 isolate, function, Context::PROMISE_INTERNAL_CONSTRUCTOR_INDEX); |
1828 } | 1825 } |
1829 | 1826 |
1830 { // Internal: PromiseCreateAndSet | |
1831 Handle<JSFunction> function = | |
1832 SimpleCreateFunction(isolate, factory->empty_string(), | |
1833 Builtins::kPromiseCreateAndSet, 2, false); | |
1834 InstallWithIntrinsicDefaultProto(isolate, function, | |
1835 Context::PROMISE_CREATE_AND_SET_INDEX); | |
1836 } | |
1837 | |
1838 { // Internal: IsPromise | 1827 { // Internal: IsPromise |
1839 Handle<JSFunction> function = SimpleCreateFunction( | 1828 Handle<JSFunction> function = SimpleCreateFunction( |
1840 isolate, factory->empty_string(), Builtins::kIsPromise, 1, false); | 1829 isolate, factory->empty_string(), Builtins::kIsPromise, 1, false); |
1841 InstallWithIntrinsicDefaultProto(isolate, function, | 1830 InstallWithIntrinsicDefaultProto(isolate, function, |
1842 Context::IS_PROMISE_INDEX); | 1831 Context::IS_PROMISE_INDEX); |
1843 } | 1832 } |
1844 | 1833 |
1845 { // Internal: PerformPromiseThen | |
1846 Handle<JSFunction> function = | |
1847 SimpleCreateFunction(isolate, factory->empty_string(), | |
1848 Builtins::kPerformPromiseThen, 4, false); | |
1849 InstallWithIntrinsicDefaultProto(isolate, function, | |
1850 Context::PERFORM_PROMISE_THEN_INDEX); | |
1851 } | |
1852 | |
1853 { | 1834 { |
1854 Handle<Code> code = | 1835 Handle<Code> code = |
1855 handle(isolate->builtins()->builtin(Builtins::kPromiseResolveClosure), | 1836 handle(isolate->builtins()->builtin(Builtins::kPromiseResolveClosure), |
1856 isolate); | 1837 isolate); |
1857 Handle<SharedFunctionInfo> info = | 1838 Handle<SharedFunctionInfo> info = |
1858 factory->NewSharedFunctionInfo(factory->empty_string(), code, false); | 1839 factory->NewSharedFunctionInfo(factory->empty_string(), code, false); |
1859 info->set_internal_formal_parameter_count(1); | 1840 info->set_internal_formal_parameter_count(1); |
1860 info->set_length(1); | 1841 info->set_length(1); |
1861 native_context()->set_promise_resolve_shared_fun(*info); | 1842 native_context()->set_promise_resolve_shared_fun(*info); |
1862 | 1843 |
(...skipping 2735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4598 } | 4579 } |
4599 | 4580 |
4600 | 4581 |
4601 // Called when the top-level V8 mutex is destroyed. | 4582 // Called when the top-level V8 mutex is destroyed. |
4602 void Bootstrapper::FreeThreadResources() { | 4583 void Bootstrapper::FreeThreadResources() { |
4603 DCHECK(!IsActive()); | 4584 DCHECK(!IsActive()); |
4604 } | 4585 } |
4605 | 4586 |
4606 } // namespace internal | 4587 } // namespace internal |
4607 } // namespace v8 | 4588 } // namespace v8 |
OLD | NEW |