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

Side by Side Diff: src/js/promise.js

Issue 1561193002: [promise] Test IsPromise() early in Promise.prototype.then() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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/test262/test262.status » ('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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } else { 267 } else {
268 var promiseCapability = NewPromiseCapability(this); 268 var promiseCapability = NewPromiseCapability(this);
269 %_Call(promiseCapability.reject, UNDEFINED, r); 269 %_Call(promiseCapability.reject, UNDEFINED, r);
270 return promiseCapability.promise; 270 return promiseCapability.promise;
271 } 271 }
272 } 272 }
273 273
274 // Multi-unwrapped chaining with thenable coercion. 274 // Multi-unwrapped chaining with thenable coercion.
275 275
276 function PromiseThen(onResolve, onReject) { 276 function PromiseThen(onResolve, onReject) {
277 var status = GET_PRIVATE(this, promiseStatusSymbol);
278 if (IS_UNDEFINED(status)) {
279 throw MakeTypeError(kNotAPromise, this);
280 }
281
277 var constructor = this.constructor; 282 var constructor = this.constructor;
278 onResolve = IS_CALLABLE(onResolve) ? onResolve : PromiseIdResolveHandler; 283 onResolve = IS_CALLABLE(onResolve) ? onResolve : PromiseIdResolveHandler;
279 onReject = IS_CALLABLE(onReject) ? onReject : PromiseIdRejectHandler; 284 onReject = IS_CALLABLE(onReject) ? onReject : PromiseIdRejectHandler;
280 var deferred = NewPromiseCapability(constructor); 285 var deferred = NewPromiseCapability(constructor);
281 switch (GET_PRIVATE(this, promiseStatusSymbol)) { 286 switch (status) {
282 case UNDEFINED:
283 // TODO(littledan): The type check should be called before
284 // constructing NewPromiseCapability; this is observable when
285 // erroneously copying this method to other classes.
286 throw MakeTypeError(kNotAPromise, this);
287 case 0: // Pending 287 case 0: // Pending
288 GET_PRIVATE(this, promiseOnResolveSymbol).push(onResolve, deferred); 288 GET_PRIVATE(this, promiseOnResolveSymbol).push(onResolve, deferred);
289 GET_PRIVATE(this, promiseOnRejectSymbol).push(onReject, deferred); 289 GET_PRIVATE(this, promiseOnRejectSymbol).push(onReject, deferred);
290 break; 290 break;
291 case +1: // Resolved 291 case +1: // Resolved
292 PromiseEnqueue(GET_PRIVATE(this, promiseValueSymbol), 292 PromiseEnqueue(GET_PRIVATE(this, promiseValueSymbol),
293 [onResolve, deferred], 293 [onResolve, deferred],
294 +1); 294 +1);
295 break; 295 break;
296 case -1: // Rejected 296 case -1: // Rejected
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( 455 [PromiseChain, PromiseDeferred, PromiseResolved].forEach(
456 fn => %FunctionRemovePrototype(fn)); 456 fn => %FunctionRemovePrototype(fn));
457 457
458 utils.Export(function(to) { 458 utils.Export(function(to) {
459 to.PromiseChain = PromiseChain; 459 to.PromiseChain = PromiseChain;
460 to.PromiseDeferred = PromiseDeferred; 460 to.PromiseDeferred = PromiseDeferred;
461 to.PromiseResolved = PromiseResolved; 461 to.PromiseResolved = PromiseResolved;
462 }); 462 });
463 463
464 }) 464 })
OLDNEW
« no previous file with comments | « no previous file | test/test262/test262.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698