Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: src/bootstrapper.cc

Issue 2497523002: [promises] Move promise constructor to TFS (Closed)
Patch Set: use jsbuiltinconstruct stub Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/builtins/builtins.h » ('j') | src/builtins/builtins-promise.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index fefa4a7f2c8d535bbc1330332d5236a3288ec50d..2197178be01d86092eec40dd454ef294119ccad2 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1800,6 +1800,78 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
to_primitive->shared()->set_length(1);
}
+ { // -- P r o m i s e
+ // Set catch prediction
+ Handle<Code> promise_code = isolate->builtins()->PromiseConstructor();
+ promise_code->set_exception_hint(1);
+
+ Handle<JSObject> prototype =
+ factory->NewJSObject(isolate->object_function(), TENURED);
+ Handle<JSFunction> promise_fun = InstallFunction(
+ global, "Promise", JS_PROMISE_TYPE, JSObject::kHeaderSize, prototype,
+ Builtins::kPromiseConstructor);
+ InstallWithIntrinsicDefaultProto(isolate, promise_fun,
+ Context::PROMISE_FUNCTION_INDEX);
+
+ Handle<SharedFunctionInfo> shared(promise_fun->shared(), isolate);
+ shared->SetConstructStub(*isolate->builtins()->JSBuiltinsConstructStub());
+ 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
+ shared->set_internal_formal_parameter_count(1);
+ shared->set_length(1);
+
+ // Install the "constructor" property on the {prototype}.
+ JSObject::AddProperty(prototype, factory->constructor_string(), promise_fun,
+ DONT_ENUM);
+
+ { // Internal: PromiseInternalConstructor
+ Handle<JSFunction> function = factory->NewFunction(
+ factory->empty_string(),
+ isolate->builtins()->PromiseInternalConstructor(),
+ 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.
+ JS_OBJECT_TYPE, JSObject::kHeaderSize);
+ function->shared()->set_internal_formal_parameter_count(0);
+ function->shared()->set_length(0);
+ function->shared()->set_native(true);
+ native_context()->set(Context::PROMISE_INTERNAL_CONSTRUCTOR, *function);
+ }
+
+ { // Internal: IsPromise
+ Handle<JSFunction> function = factory->NewFunction(
+ factory->empty_string(), isolate->builtins()->IsPromise(),
+ JS_OBJECT_TYPE, JSObject::kHeaderSize);
jgruber 2016/11/22 08:55:55 Same here.
gsathya 2016/11/23 14:31:17 Done.
+ function->shared()->set_internal_formal_parameter_count(1);
+ function->shared()->set_length(1);
+ function->shared()->set_native(true);
+ native_context()->set(Context::IS_PROMISE, *function);
+ }
+
+ {
+ Handle<Code> code =
+ handle(isolate->builtins()->builtin(Builtins::kPromiseResolveClosure),
+ isolate);
+ Handle<SharedFunctionInfo> info =
+ factory->NewSharedFunctionInfo(factory->empty_string(), code, false);
+ info->set_internal_formal_parameter_count(1);
+ info->set_length(1);
+ native_context()->set_promise_resolve_shared_fun(*info);
+
+ code =
+ handle(isolate->builtins()->builtin(Builtins::kPromiseRejectClosure),
+ isolate);
+ info =
+ factory->NewSharedFunctionInfo(factory->empty_string(), code, false);
+ info->set_internal_formal_parameter_count(2);
+ info->set_length(1);
+ native_context()->set_promise_reject_shared_fun(*info);
+ }
+
+ Handle<JSFunction> create_resolving_functions =
+ SimpleCreateFunction(isolate, factory->empty_string(),
+ Builtins::kCreateResolvingFunctions, 2, false);
+ native_context()->set_create_resolving_functions(
+ *create_resolving_functions);
+ }
+
{ // -- R e g E x p
// Builtin functions for RegExp.prototype.
Handle<JSObject> prototype =
@@ -3577,46 +3649,6 @@ bool Genesis::InstallNatives(GlobalContextType context_type) {
concat->shared()->set_length(1);
}
- // Set up the Promise constructor.
- {
- Handle<String> key = factory()->Promise_string();
- Handle<JSFunction> function = Handle<JSFunction>::cast(
- JSReceiver::GetProperty(global_object, key).ToHandleChecked());
- JSFunction::EnsureHasInitialMap(function);
- function->initial_map()->set_instance_type(JS_PROMISE_TYPE);
- function->shared()->SetConstructStub(
- *isolate()->builtins()->JSBuiltinsConstructStub());
- InstallWithIntrinsicDefaultProto(isolate(), function,
- Context::PROMISE_FUNCTION_INDEX);
-
- {
- Handle<Code> code = handle(
- isolate()->builtins()->builtin(Builtins::kPromiseResolveClosure),
- isolate());
- Handle<SharedFunctionInfo> info =
- isolate()->factory()->NewSharedFunctionInfo(factory()->empty_string(),
- code, false);
- info->set_internal_formal_parameter_count(1);
- info->set_length(1);
- native_context()->set_promise_resolve_shared_fun(*info);
-
- code = handle(
- isolate()->builtins()->builtin(Builtins::kPromiseRejectClosure),
- isolate());
- info = isolate()->factory()->NewSharedFunctionInfo(
- factory()->empty_string(), code, false);
- info->set_internal_formal_parameter_count(2);
- info->set_length(1);
- native_context()->set_promise_reject_shared_fun(*info);
- }
-
- Handle<JSFunction> create_resolving_functions =
- SimpleCreateFunction(isolate(), factory()->empty_string(),
- Builtins::kCreateResolvingFunctions, 2, false);
- native_context()->set_create_resolving_functions(
- *create_resolving_functions);
- }
-
InstallBuiltinFunctionIds();
// Create a map for accessor property descriptors (a variant of JSObject
« no previous file with comments | « no previous file | src/builtins/builtins.h » ('j') | src/builtins/builtins-promise.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698