Commit dfc08e88 authored by gsathya's avatar gsathya Committed by Commit bot

[promises] Remove IsPromise

Use %is_promise instead

BUG=v8:5343

Review-Url: https://codereview.chromium.org/2521723003
Cr-Commit-Position: refs/heads/master@{#41440}
parent 2b991784
...@@ -219,7 +219,6 @@ void Builtins::Generate_PromiseInternalConstructor( ...@@ -219,7 +219,6 @@ void Builtins::Generate_PromiseInternalConstructor(
a.Return(instance); a.Return(instance);
} }
// TODO(gsathya): Refactor promise.js::IsPromise to use this.
void Builtins::Generate_IsPromise(compiler::CodeAssemblerState* state) { void Builtins::Generate_IsPromise(compiler::CodeAssemblerState* state) {
CodeStubAssembler a(state); CodeStubAssembler a(state);
typedef compiler::Node Node; typedef compiler::Node Node;
......
...@@ -106,12 +106,6 @@ function ClearMirrorCache(value) { ...@@ -106,12 +106,6 @@ function ClearMirrorCache(value) {
} }
function ObjectIsPromise(value) {
return IS_RECEIVER(value) &&
!IS_UNDEFINED(%DebugGetProperty(value, promiseStateSymbol));
}
/** /**
* Returns the mirror for a specified value or object. * Returns the mirror for a specified value or object.
* *
...@@ -168,7 +162,7 @@ function MakeMirror(value, opt_transient) { ...@@ -168,7 +162,7 @@ function MakeMirror(value, opt_transient) {
mirror = new SetMirror(value); mirror = new SetMirror(value);
} else if (IS_MAP_ITERATOR(value) || IS_SET_ITERATOR(value)) { } else if (IS_MAP_ITERATOR(value) || IS_SET_ITERATOR(value)) {
mirror = new IteratorMirror(value); mirror = new IteratorMirror(value);
} else if (ObjectIsPromise(value)) { } else if (%is_promise(value)) {
mirror = new PromiseMirror(value); mirror = new PromiseMirror(value);
} else if (IS_GENERATOR(value)) { } else if (IS_GENERATOR(value)) {
mirror = new GeneratorMirror(value); mirror = new GeneratorMirror(value);
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
var AsyncFunctionNext; var AsyncFunctionNext;
var AsyncFunctionThrow; var AsyncFunctionThrow;
var IsPromise;
var CreateInternalPromiseCapability; var CreateInternalPromiseCapability;
var PerformPromiseThen; var PerformPromiseThen;
var PromiseCreate; var PromiseCreate;
...@@ -24,7 +23,6 @@ var ResolvePromise; ...@@ -24,7 +23,6 @@ var ResolvePromise;
utils.Import(function(from) { utils.Import(function(from) {
AsyncFunctionNext = from.AsyncFunctionNext; AsyncFunctionNext = from.AsyncFunctionNext;
AsyncFunctionThrow = from.AsyncFunctionThrow; AsyncFunctionThrow = from.AsyncFunctionThrow;
IsPromise = from.IsPromise;
CreateInternalPromiseCapability = from.CreateInternalPromiseCapability; CreateInternalPromiseCapability = from.CreateInternalPromiseCapability;
PerformPromiseThen = from.PerformPromiseThen; PerformPromiseThen = from.PerformPromiseThen;
PromiseCreate = from.PromiseCreate; PromiseCreate = from.PromiseCreate;
...@@ -46,7 +44,7 @@ var promiseHasHandlerSymbol = ...@@ -46,7 +44,7 @@ var promiseHasHandlerSymbol =
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function PromiseCastResolved(value) { function PromiseCastResolved(value) {
if (IsPromise(value)) { if (%is_promise(value)) {
return value; return value;
} else { } else {
var promise = PromiseCreate(); var promise = PromiseCreate();
...@@ -96,7 +94,7 @@ function AsyncFunctionAwait(generator, awaited, outerPromise) { ...@@ -96,7 +94,7 @@ function AsyncFunctionAwait(generator, awaited, outerPromise) {
SET_PRIVATE(throwawayCapability.promise, promiseHasHandlerSymbol, true); SET_PRIVATE(throwawayCapability.promise, promiseHasHandlerSymbol, true);
if (DEBUG_IS_ACTIVE) { if (DEBUG_IS_ACTIVE) {
if (IsPromise(awaited)) { if (%is_promise(awaited)) {
// Mark the reject handler callback to be a forwarding edge, rather // Mark the reject handler callback to be a forwarding edge, rather
// than a meaningful catch handler // than a meaningful catch handler
SET_PRIVATE(onRejected, promiseForwardingHandlerSymbol, true); SET_PRIVATE(onRejected, promiseForwardingHandlerSymbol, true);
...@@ -120,7 +118,7 @@ function AsyncFunctionAwaitUncaught(generator, awaited, outerPromise) { ...@@ -120,7 +118,7 @@ function AsyncFunctionAwaitUncaught(generator, awaited, outerPromise) {
// Called by the parser from the desugaring of 'await' when catch // Called by the parser from the desugaring of 'await' when catch
// prediction indicates that there is a locally surrounding catch block // prediction indicates that there is a locally surrounding catch block
function AsyncFunctionAwaitCaught(generator, awaited, outerPromise) { function AsyncFunctionAwaitCaught(generator, awaited, outerPromise) {
if (DEBUG_IS_ACTIVE && IsPromise(awaited)) { if (DEBUG_IS_ACTIVE && %is_promise(awaited)) {
SET_PRIVATE(awaited, promiseHandledHintSymbol, true); SET_PRIVATE(awaited, promiseHandledHintSymbol, true);
} }
AsyncFunctionAwait(generator, awaited, outerPromise); AsyncFunctionAwait(generator, awaited, outerPromise);
......
...@@ -180,12 +180,6 @@ SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true); ...@@ -180,12 +180,6 @@ SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true);
// For bootstrapper. // For bootstrapper.
// Only used by utils
// ES#sec-ispromise IsPromise ( x )
function IsPromise(x) {
return IS_RECEIVER(x) && HAS_DEFINED_PRIVATE(x, promiseStateSymbol);
}
function PromiseCreate() { function PromiseCreate() {
return PromiseInit(%promise_internal_constructor()); return PromiseInit(%promise_internal_constructor());
} }
...@@ -212,7 +206,7 @@ function ResolvePromise(promise, resolution) { ...@@ -212,7 +206,7 @@ function ResolvePromise(promise, resolution) {
// Resolution is a native promise and if it's already resolved or // Resolution is a native promise and if it's already resolved or
// rejected, shortcircuit the resolution procedure by directly // rejected, shortcircuit the resolution procedure by directly
// reusing the value from the promise. // reusing the value from the promise.
if (IsPromise(resolution) && then === PromiseThen) { if (%is_promise(resolution) && then === PromiseThen) {
var thenableState = GET_PRIVATE(resolution, promiseStateSymbol); var thenableState = GET_PRIVATE(resolution, promiseStateSymbol);
if (thenableState === kFulfilled) { if (thenableState === kFulfilled) {
// This goes inside the if-else to save one symbol lookup in // This goes inside the if-else to save one symbol lookup in
...@@ -239,7 +233,7 @@ function ResolvePromise(promise, resolution) { ...@@ -239,7 +233,7 @@ function ResolvePromise(promise, resolution) {
} }
if (IS_CALLABLE(then)) { if (IS_CALLABLE(then)) {
if (DEBUG_IS_ACTIVE && IsPromise(resolution)) { if (DEBUG_IS_ACTIVE && %is_promise(resolution)) {
// Mark the dependency of the new promise on the resolution // Mark the dependency of the new promise on the resolution
SET_PRIVATE(resolution, promiseHandledBySymbol, promise); SET_PRIVATE(resolution, promiseHandledBySymbol, promise);
} }
...@@ -358,7 +352,7 @@ function PerformPromiseThen(promise, onResolve, onReject, resultCapability) { ...@@ -358,7 +352,7 @@ function PerformPromiseThen(promise, onResolve, onReject, resultCapability) {
// Promise.prototype.then ( onFulfilled, onRejected ) // Promise.prototype.then ( onFulfilled, onRejected )
// Multi-unwrapped chaining with thenable coercion. // Multi-unwrapped chaining with thenable coercion.
function PromiseThen(onResolve, onReject) { function PromiseThen(onResolve, onReject) {
if (!IsPromise(this)) { if (!%is_promise(this)) {
throw %make_type_error(kNotAPromise, this); throw %make_type_error(kNotAPromise, this);
} }
...@@ -388,7 +382,7 @@ function PromiseResolve(x) { ...@@ -388,7 +382,7 @@ function PromiseResolve(x) {
if (!IS_RECEIVER(this)) { if (!IS_RECEIVER(this)) {
throw %make_type_error(kCalledOnNonObject, PromiseResolve); throw %make_type_error(kCalledOnNonObject, PromiseResolve);
} }
if (IsPromise(x) && x.constructor === this) return x; if (%is_promise(x) && x.constructor === this) return x;
// Avoid creating resolving functions. // Avoid creating resolving functions.
if (this === GlobalPromise) { if (this === GlobalPromise) {
...@@ -448,7 +442,7 @@ function PromiseAll(iterable) { ...@@ -448,7 +442,7 @@ function PromiseAll(iterable) {
deferred.reject); deferred.reject);
// For catch prediction, mark that rejections here are semantically // For catch prediction, mark that rejections here are semantically
// handled by the combined Promise. // handled by the combined Promise.
if (instrumenting && IsPromise(throwawayPromise)) { if (instrumenting && %is_promise(throwawayPromise)) {
SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise); SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise);
} }
++i; ++i;
...@@ -491,7 +485,7 @@ function PromiseRace(iterable) { ...@@ -491,7 +485,7 @@ function PromiseRace(iterable) {
deferred.reject); deferred.reject);
// For catch prediction, mark that rejections here are semantically // For catch prediction, mark that rejections here are semantically
// handled by the combined Promise. // handled by the combined Promise.
if (instrumenting && IsPromise(throwawayPromise)) { if (instrumenting && %is_promise(throwawayPromise)) {
SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise); SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise);
} }
} }
...@@ -611,7 +605,6 @@ utils.InstallFunctions(extrasUtils, 0, [ ...@@ -611,7 +605,6 @@ utils.InstallFunctions(extrasUtils, 0, [
]); ]);
utils.Export(function(to) { utils.Export(function(to) {
to.IsPromise = IsPromise;
to.PromiseCreate = PromiseCreate; to.PromiseCreate = PromiseCreate;
to.PromiseThen = PromiseThen; to.PromiseThen = PromiseThen;
......
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