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

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: Re-add mjsunit/es6/promises.js fixups Created 4 years, 11 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') | no next file with comments »
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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 310 }
311 311
312 function PromiseCatch(onReject) { 312 function PromiseCatch(onReject) {
313 return this.then(UNDEFINED, onReject); 313 return this.then(UNDEFINED, onReject);
314 } 314 }
315 315
316 // Combinators. 316 // Combinators.
317 317
318 function PromiseCast(x) { 318 function PromiseCast(x) {
319 if (!IS_RECEIVER(this)) { 319 if (!IS_RECEIVER(this)) {
320 throw MakeTypeError(kCalledOnNonObject, PromiseCast); 320 throw MakeTypeError(kCalledOnNonObject, "Promise.resolve");
321 } 321 }
322 if (IsPromise(x) && x.constructor === this) { 322 if (IsPromise(x) && x.constructor === this) return x;
323 return x; 323
324 } else { 324 var promiseCapability = NewPromiseCapability(this);
325 return new this(function(resolve, reject) { resolve(x) }); 325 var resolveResult = %_Call(promiseCapability.resolve, UNDEFINED, x);
326 } 326 return promiseCapability.promise;
327 } 327 }
328 328
329 function PromiseAll(iterable) { 329 function PromiseAll(iterable) {
330 var deferred = NewPromiseCapability(this); 330 var deferred = NewPromiseCapability(this);
331 var resolutions = []; 331 var resolutions = [];
332 try { 332 try {
333 var count = 0; 333 var count = 0;
334 var i = 0; 334 var i = 0;
335 for (var value of iterable) { 335 for (var value of iterable) {
336 var reject = function(r) { deferred.reject(r) }; 336 var reject = function(r) { deferred.reject(r) };
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( 443 [PromiseChain, PromiseDeferred, PromiseResolved].forEach(
444 fn => %FunctionRemovePrototype(fn)); 444 fn => %FunctionRemovePrototype(fn));
445 445
446 utils.Export(function(to) { 446 utils.Export(function(to) {
447 to.PromiseChain = PromiseChain; 447 to.PromiseChain = PromiseChain;
448 to.PromiseDeferred = PromiseDeferred; 448 to.PromiseDeferred = PromiseDeferred;
449 to.PromiseResolved = PromiseResolved; 449 to.PromiseResolved = PromiseResolved;
450 }); 450 });
451 451
452 }) 452 })
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/promises.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698