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

Unified Diff: src/js/promise.js

Issue 1536013002: [promise] make Promise.resolve match spec (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Update test expectations Created 5 years 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 | test/mjsunit/es6/promises.js » ('j') | test/mjsunit/es6/promises.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/promise.js
diff --git a/src/js/promise.js b/src/js/promise.js
index de9597942c010f52d6dd996fc5faac2000b628ec..041b598764f7b7733284a9a4fc512b6efff2ac2b 100644
--- a/src/js/promise.js
+++ b/src/js/promise.js
@@ -354,11 +354,15 @@ function PromiseThen(onResolve, onReject) {
// Combinators.
function PromiseCast(x) {
- if (IsPromise(x) && x.constructor === this) {
- return x;
- } else {
- return new this(function(resolve) { resolve(x) });
+ if (!IS_RECEIVER(this)) {
+ throw MakeTypeError(kCalledOnNonObject, "Promise.resolve");
}
+
+ if (IsPromise(x) && x.constructor === this) return x;
+
+ var promiseCapability = NewPromiseCapability(this);
caitp (gmail) 2016/01/04 14:52:11 Technically, the assertions added in NewPromiseCap
Dan Ehrenberg 2016/01/04 18:04:20 Yep, I agree. Still looks good to me. The trybot j
+ var resolveResult = promiseCapability.resolve(x);
+ return promiseCapability.promise;
}
function PromiseAll(iterable) {
« no previous file with comments | « no previous file | test/mjsunit/es6/promises.js » ('j') | test/mjsunit/es6/promises.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698