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,
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
Handle<JSFunction> promise_then =
SimpleCreateFunction(isolate, isolate->factory()->then_string(),
Builtins::kPromiseThen, 2, true);
JSObject::AddProperty(prototype, isolate->factory()->then_string(),
promise_then, DONT_ENUM);
SimpleInstallFunction(prototype, isolate->factory()->then_string(),
Builtins::kPromiseThen, 2, true);
InstallWithIntrinsicDefaultProto(isolate, promise_then,
Context::PROMISE_THEN_INDEX);
// TODO(gsathya): Move to TF
SimpleInstallFunction(prototype, "catch", Builtins::kIllegal, 1, true,
DONT_ENUM);
Handle<JSFunction> promise_catch = SimpleInstallFunction(
prototype, "catch", Builtins::kPromiseCatch, 1, true, DONT_ENUM);
InstallWithIntrinsicDefaultProto(isolate, promise_catch,
Context::PROMISE_CATCH_INDEX);
SimpleInstallGetter(promise_fun, factory->symbol_species_string(),
factory->species_symbol(), Builtins::kReturnReceiver,
......
This diff is collapsed.
......@@ -29,12 +29,14 @@ class PromiseBuiltinsAssembler : public CodeStubAssembler {
void AppendPromiseCallback(int offset, compiler::Node* promise,
compiler::Node* value);
Node* InternalPromiseThen(Node* context, Node* promise, Node* on_resolve,
Node* on_reject);
Node* InternalPerformPromiseThen(Node* context, Node* promise,
Node* on_resolve, Node* on_reject,
Node* deferred);
void InternalResolvePromise(Node* context, Node* promise, Node* result,
Label* out);
void InternalResolvePromise(Node* context, Node* promise, Node* result);
void BranchIfFastPath(Node* context, Node* promise, Label* if_isunmodified,
Label* if_ismodified);
......
......@@ -571,6 +571,7 @@ namespace internal {
TFJ(PromiseResolveClosure, 1) \
CPP(PromiseRejectClosure) \
TFJ(PromiseThen, 2) \
TFJ(PromiseCatch, 1) \
TFJ(PromiseCreateAndSet, 2) \
TFJ(PerformPromiseThen, 4) \
TFJ(ResolvePromise, 2) \
......
......@@ -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.
// ES#sec-promise.resolve
......@@ -345,10 +339,7 @@ utils.InstallFunctions(GlobalPromise, DONT_ENUM, [
"resolve", PromiseResolve
]);
%SetCode(GlobalPromise.prototype.catch, PromiseCatch);
%InstallToContext([
"promise_catch", GlobalPromise.prototype.catch,
"promise_create", PromiseCreate,
"promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
"promise_reject", DoRejectPromise,
......
......@@ -49,7 +49,7 @@ function getStack(error) {
map(line => line.replace(/^\s*at (@?[a-zA-Z0-9_\.\[\]]+)(.*)/, "$1"));
// remove `Promise.then()` invocation by assertEqualsAsync()
if (stack[1] === "assertEqualsAsync") return [];
if (stack[2] === "assertEqualsAsync") return [];
return stack.reverse();
}
......@@ -96,6 +96,6 @@ assertEqualsAsync(
}),
"should call Promise[@@Species] after non-internal Then");
assertEquals([
"@@Species: [@testThenOnReturnedPromise > FakePromise]",
"@@Species: [@testThenOnReturnedPromise > Promise.then > FakePromise]",
"Then: foo"
], 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