Chromium Code Reviews| 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_exception_hint(1); | |
| 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()); | |
|
jgruber
2016/11/22 08:55:55
Shouldn't the instance class name be 'Promise'? If
gsathya
2016/11/23 14:31:17
Nope there's a test for this :
https://cs.chromium
| |
| 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 { // Internal: PromiseInternalConstructor | |
| 1827 Handle<JSFunction> function = factory->NewFunction( | |
| 1828 factory->empty_string(), | |
| 1829 isolate->builtins()->PromiseInternalConstructor(), | |
| 1830 prototype, // can this be shared? | |
|
jgruber
2016/11/22 08:55:55
Does the PromiseInternalConstructor need a prototy
gsathya
2016/11/23 14:31:17
Done.
| |
| 1831 JS_OBJECT_TYPE, JSObject::kHeaderSize); | |
| 1832 function->shared()->set_internal_formal_parameter_count(0); | |
| 1833 function->shared()->set_length(0); | |
| 1834 function->shared()->set_native(true); | |
| 1835 native_context()->set(Context::PROMISE_INTERNAL_CONSTRUCTOR, *function); | |
| 1836 } | |
| 1837 | |
| 1838 { // Internal: IsPromise | |
| 1839 Handle<JSFunction> function = factory->NewFunction( | |
| 1840 factory->empty_string(), isolate->builtins()->IsPromise(), | |
| 1841 JS_OBJECT_TYPE, JSObject::kHeaderSize); | |
|
jgruber
2016/11/22 08:55:55
Same here.
gsathya
2016/11/23 14:31:17
Done.
| |
| 1842 function->shared()->set_internal_formal_parameter_count(1); | |
| 1843 function->shared()->set_length(1); | |
| 1844 function->shared()->set_native(true); | |
| 1845 native_context()->set(Context::IS_PROMISE, *function); | |
| 1846 } | |
| 1847 | |
| 1848 { | |
| 1849 Handle<Code> code = | |
| 1850 handle(isolate->builtins()->builtin(Builtins::kPromiseResolveClosure), | |
| 1851 isolate); | |
| 1852 Handle<SharedFunctionInfo> info = | |
| 1853 factory->NewSharedFunctionInfo(factory->empty_string(), code, false); | |
| 1854 info->set_internal_formal_parameter_count(1); | |
| 1855 info->set_length(1); | |
| 1856 native_context()->set_promise_resolve_shared_fun(*info); | |
| 1857 | |
| 1858 code = | |
| 1859 handle(isolate->builtins()->builtin(Builtins::kPromiseRejectClosure), | |
| 1860 isolate); | |
| 1861 info = | |
| 1862 factory->NewSharedFunctionInfo(factory->empty_string(), code, false); | |
| 1863 info->set_internal_formal_parameter_count(2); | |
| 1864 info->set_length(1); | |
| 1865 native_context()->set_promise_reject_shared_fun(*info); | |
| 1866 } | |
| 1867 | |
| 1868 Handle<JSFunction> create_resolving_functions = | |
| 1869 SimpleCreateFunction(isolate, factory->empty_string(), | |
| 1870 Builtins::kCreateResolvingFunctions, 2, false); | |
| 1871 native_context()->set_create_resolving_functions( | |
| 1872 *create_resolving_functions); | |
| 1873 } | |
| 1874 | |
| 1803 { // -- R e g E x p | 1875 { // -- R e g E x p |
| 1804 // Builtin functions for RegExp.prototype. | 1876 // Builtin functions for RegExp.prototype. |
| 1805 Handle<JSObject> prototype = | 1877 Handle<JSObject> prototype = |
| 1806 factory->NewJSObject(isolate->object_function(), TENURED); | 1878 factory->NewJSObject(isolate->object_function(), TENURED); |
| 1807 Handle<JSFunction> regexp_fun = | 1879 Handle<JSFunction> regexp_fun = |
| 1808 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, | 1880 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, |
| 1809 prototype, Builtins::kRegExpConstructor); | 1881 prototype, Builtins::kRegExpConstructor); |
| 1810 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, | 1882 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, |
| 1811 Context::REGEXP_FUNCTION_INDEX); | 1883 Context::REGEXP_FUNCTION_INDEX); |
| 1812 | 1884 |
| (...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3570 | 3642 |
| 3571 // Make sure that InternalArray.prototype.concat appears to be compiled. | 3643 // Make sure that InternalArray.prototype.concat appears to be compiled. |
| 3572 // The code will never be called, but inline caching for call will | 3644 // The code will never be called, but inline caching for call will |
| 3573 // only work if it appears to be compiled. | 3645 // only work if it appears to be compiled. |
| 3574 concat->shared()->DontAdaptArguments(); | 3646 concat->shared()->DontAdaptArguments(); |
| 3575 DCHECK(concat->is_compiled()); | 3647 DCHECK(concat->is_compiled()); |
| 3576 // Set the lengths for the functions to satisfy ECMA-262. | 3648 // Set the lengths for the functions to satisfy ECMA-262. |
| 3577 concat->shared()->set_length(1); | 3649 concat->shared()->set_length(1); |
| 3578 } | 3650 } |
| 3579 | 3651 |
| 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(); | 3652 InstallBuiltinFunctionIds(); |
| 3621 | 3653 |
| 3622 // Create a map for accessor property descriptors (a variant of JSObject | 3654 // Create a map for accessor property descriptors (a variant of JSObject |
| 3623 // that predefines four properties get, set, configurable and enumerable). | 3655 // that predefines four properties get, set, configurable and enumerable). |
| 3624 { | 3656 { |
| 3625 // AccessorPropertyDescriptor initial map. | 3657 // AccessorPropertyDescriptor initial map. |
| 3626 Handle<Map> map = | 3658 Handle<Map> map = |
| 3627 factory()->NewMap(JS_OBJECT_TYPE, JSAccessorPropertyDescriptor::kSize); | 3659 factory()->NewMap(JS_OBJECT_TYPE, JSAccessorPropertyDescriptor::kSize); |
| 3628 // Create the descriptor array for the property descriptor object. | 3660 // Create the descriptor array for the property descriptor object. |
| 3629 Map::EnsureDescriptorSlack(map, 4); | 3661 Map::EnsureDescriptorSlack(map, 4); |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4558 } | 4590 } |
| 4559 | 4591 |
| 4560 | 4592 |
| 4561 // Called when the top-level V8 mutex is destroyed. | 4593 // Called when the top-level V8 mutex is destroyed. |
| 4562 void Bootstrapper::FreeThreadResources() { | 4594 void Bootstrapper::FreeThreadResources() { |
| 4563 DCHECK(!IsActive()); | 4595 DCHECK(!IsActive()); |
| 4564 } | 4596 } |
| 4565 | 4597 |
| 4566 } // namespace internal | 4598 } // namespace internal |
| 4567 } // namespace v8 | 4599 } // namespace v8 |
| OLD | NEW |