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

Side by Side 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 4 years, 12 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/es6/promises.js » ('j') | test/mjsunit/es6/promises.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils, extrasUtils) { 5 (function(global, utils, extrasUtils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return onResolve(x); 347 return onResolve(x);
348 } 348 }
349 }, 349 },
350 onReject 350 onReject
351 ); 351 );
352 } 352 }
353 353
354 // Combinators. 354 // Combinators.
355 355
356 function PromiseCast(x) { 356 function PromiseCast(x) {
357 if (IsPromise(x) && x.constructor === this) { 357 if (!IS_RECEIVER(this)) {
358 return x; 358 throw MakeTypeError(kCalledOnNonObject, "Promise.resolve");
359 } else {
360 return new this(function(resolve) { resolve(x) });
361 } 359 }
360
361 if (IsPromise(x) && x.constructor === this) return x;
362
363 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
364 var resolveResult = promiseCapability.resolve(x);
365 return promiseCapability.promise;
362 } 366 }
363 367
364 function PromiseAll(iterable) { 368 function PromiseAll(iterable) {
365 var deferred = NewPromiseCapability(this); 369 var deferred = NewPromiseCapability(this);
366 var resolutions = []; 370 var resolutions = [];
367 try { 371 try {
368 var count = 0; 372 var count = 0;
369 var i = 0; 373 var i = 0;
370 for (var value of iterable) { 374 for (var value of iterable) {
371 var reject = function(r) { deferred.reject(r) }; 375 var reject = function(r) { deferred.reject(r) };
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( 482 [PromiseChain, PromiseDeferred, PromiseResolved].forEach(
479 fn => %FunctionRemovePrototype(fn)); 483 fn => %FunctionRemovePrototype(fn));
480 484
481 utils.Export(function(to) { 485 utils.Export(function(to) {
482 to.PromiseChain = PromiseChain; 486 to.PromiseChain = PromiseChain;
483 to.PromiseDeferred = PromiseDeferred; 487 to.PromiseDeferred = PromiseDeferred;
484 to.PromiseResolved = PromiseResolved; 488 to.PromiseResolved = PromiseResolved;
485 }); 489 });
486 490
487 }) 491 })
OLDNEW
« 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