Commit 2041c504 authored by gsathya's avatar gsathya Committed by Commit bot

[promises] Move Promise.prototype.catch to TF

This patch also refactors most of PromiseThen into InternalPromiseThen to
be reused with PromiseCatch and also changes InternalResolvePromise to
return and not branch.

BUG=v8:5343

Review-Url: https://codereview.chromium.org/2596553002
Cr-Commit-Position: refs/heads/master@{#41902}
parent 91a7a916
...@@ -1872,16 +1872,15 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1872,16 +1872,15 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
Handle<JSFunction> promise_then = Handle<JSFunction> promise_then =
SimpleCreateFunction(isolate, isolate->factory()->then_string(), SimpleInstallFunction(prototype, isolate->factory()->then_string(),
Builtins::kPromiseThen, 2, true); Builtins::kPromiseThen, 2, true);
JSObject::AddProperty(prototype, isolate->factory()->then_string(),
promise_then, DONT_ENUM);
InstallWithIntrinsicDefaultProto(isolate, promise_then, InstallWithIntrinsicDefaultProto(isolate, promise_then,
Context::PROMISE_THEN_INDEX); Context::PROMISE_THEN_INDEX);
// TODO(gsathya): Move to TF Handle<JSFunction> promise_catch = SimpleInstallFunction(
SimpleInstallFunction(prototype, "catch", Builtins::kIllegal, 1, true, prototype, "catch", Builtins::kPromiseCatch, 1, true, DONT_ENUM);
DONT_ENUM); InstallWithIntrinsicDefaultProto(isolate, promise_catch,
Context::PROMISE_CATCH_INDEX);
SimpleInstallGetter(promise_fun, factory->symbol_species_string(), SimpleInstallGetter(promise_fun, factory->symbol_species_string(),
factory->species_symbol(), Builtins::kReturnReceiver, factory->species_symbol(), Builtins::kReturnReceiver,
......
This diff is collapsed.
...@@ -29,12 +29,14 @@ class PromiseBuiltinsAssembler : public CodeStubAssembler { ...@@ -29,12 +29,14 @@ class PromiseBuiltinsAssembler : public CodeStubAssembler {
void AppendPromiseCallback(int offset, compiler::Node* promise, void AppendPromiseCallback(int offset, compiler::Node* promise,
compiler::Node* value); compiler::Node* value);
Node* InternalPromiseThen(Node* context, Node* promise, Node* on_resolve,
Node* on_reject);
Node* InternalPerformPromiseThen(Node* context, Node* promise, Node* InternalPerformPromiseThen(Node* context, Node* promise,
Node* on_resolve, Node* on_reject, Node* on_resolve, Node* on_reject,
Node* deferred); Node* deferred);
void InternalResolvePromise(Node* context, Node* promise, Node* result, void InternalResolvePromise(Node* context, Node* promise, Node* result);
Label* out);
void BranchIfFastPath(Node* context, Node* promise, Label* if_isunmodified, void BranchIfFastPath(Node* context, Node* promise, Label* if_isunmodified,
Label* if_ismodified); Label* if_ismodified);
......
...@@ -571,6 +571,7 @@ namespace internal { ...@@ -571,6 +571,7 @@ namespace internal {
TFJ(PromiseResolveClosure, 1) \ TFJ(PromiseResolveClosure, 1) \
CPP(PromiseRejectClosure) \ CPP(PromiseRejectClosure) \
TFJ(PromiseThen, 2) \ TFJ(PromiseThen, 2) \
TFJ(PromiseCatch, 1) \
TFJ(PromiseCreateAndSet, 2) \ TFJ(PromiseCreateAndSet, 2) \
TFJ(PerformPromiseThen, 4) \ TFJ(PerformPromiseThen, 4) \
TFJ(ResolvePromise, 2) \ TFJ(ResolvePromise, 2) \
......
...@@ -142,12 +142,6 @@ function PromiseReject(r) { ...@@ -142,12 +142,6 @@ function PromiseReject(r) {
} }
} }
// ES#sec-promise.prototype.catch
// Promise.prototype.catch ( onRejected )
function PromiseCatch(onReject) {
return this.then(UNDEFINED, onReject);
}
// Combinators. // Combinators.
// ES#sec-promise.resolve // ES#sec-promise.resolve
...@@ -345,10 +339,7 @@ utils.InstallFunctions(GlobalPromise, DONT_ENUM, [ ...@@ -345,10 +339,7 @@ utils.InstallFunctions(GlobalPromise, DONT_ENUM, [
"resolve", PromiseResolve "resolve", PromiseResolve
]); ]);
%SetCode(GlobalPromise.prototype.catch, PromiseCatch);
%InstallToContext([ %InstallToContext([
"promise_catch", GlobalPromise.prototype.catch,
"promise_create", PromiseCreate, "promise_create", PromiseCreate,
"promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
"promise_reject", DoRejectPromise, "promise_reject", DoRejectPromise,
......
...@@ -49,7 +49,7 @@ function getStack(error) { ...@@ -49,7 +49,7 @@ function getStack(error) {
map(line => line.replace(/^\s*at (@?[a-zA-Z0-9_\.\[\]]+)(.*)/, "$1")); map(line => line.replace(/^\s*at (@?[a-zA-Z0-9_\.\[\]]+)(.*)/, "$1"));
// remove `Promise.then()` invocation by assertEqualsAsync() // remove `Promise.then()` invocation by assertEqualsAsync()
if (stack[1] === "assertEqualsAsync") return []; if (stack[2] === "assertEqualsAsync") return [];
return stack.reverse(); return stack.reverse();
} }
...@@ -96,6 +96,6 @@ assertEqualsAsync( ...@@ -96,6 +96,6 @@ assertEqualsAsync(
}), }),
"should call Promise[@@Species] after non-internal Then"); "should call Promise[@@Species] after non-internal Then");
assertEquals([ assertEquals([
"@@Species: [@testThenOnReturnedPromise > FakePromise]", "@@Species: [@testThenOnReturnedPromise > Promise.then > FakePromise]",
"Then: foo" "Then: foo"
], log); ], log);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment