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

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

Issue 1895603002: [esnext] prototype runtime implementation for async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@AsyncFunction
Patch Set: properly rebase Created 4 years, 7 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
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // which is usually simply noise. Do not trigger that debug event. 286 // which is usually simply noise. Do not trigger that debug event.
287 %PromiseRejectEvent(promise, r, false); 287 %PromiseRejectEvent(promise, r, false);
288 return promise; 288 return promise;
289 } else { 289 } else {
290 var promiseCapability = NewPromiseCapability(this); 290 var promiseCapability = NewPromiseCapability(this);
291 %_Call(promiseCapability.reject, UNDEFINED, r); 291 %_Call(promiseCapability.reject, UNDEFINED, r);
292 return promiseCapability.promise; 292 return promiseCapability.promise;
293 } 293 }
294 } 294 }
295 295
296 // Shortcut Promise.reject and Promise.resolve() implementations, used by
297 // Async Functions implementation.
298 function PromiseCreateRejected(r) {
299 var promise = PromiseCreateAndSet(-1, r);
300 %PromiseRejectEvent(promise, r, false);
301 return promise;
302 }
303
304 function PromiseCreateResolved(x) {
305 if (IsPromise(x) && x.constructor === GlobalPromise) return x;
306 return PromiseCreateAndSet(+1, x);
307 }
Dan Ehrenberg 2016/05/04 22:52:36 This seems like a good optimization. Maybe in a se
308
296 // ES#sec-promise.prototype.then 309 // ES#sec-promise.prototype.then
297 // Promise.prototype.then ( onFulfilled, onRejected ) 310 // Promise.prototype.then ( onFulfilled, onRejected )
298 // Multi-unwrapped chaining with thenable coercion. 311 // Multi-unwrapped chaining with thenable coercion.
299 function PromiseThen(onResolve, onReject) { 312 function PromiseThen(onResolve, onReject) {
300 var status = GET_PRIVATE(this, promiseStateSymbol); 313 var status = GET_PRIVATE(this, promiseStateSymbol);
301 if (IS_UNDEFINED(status)) { 314 if (IS_UNDEFINED(status)) {
302 throw MakeTypeError(kNotAPromise, this); 315 throw MakeTypeError(kNotAPromise, this);
303 } 316 }
304 317
305 var constructor = SpeciesConstructor(this, GlobalPromise); 318 var constructor = SpeciesConstructor(this, GlobalPromise);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 ]); 493 ]);
481 494
482 %InstallToContext([ 495 %InstallToContext([
483 "promise_catch", PromiseCatch, 496 "promise_catch", PromiseCatch,
484 "promise_chain", PromiseChain, 497 "promise_chain", PromiseChain,
485 "promise_create", PromiseCreate, 498 "promise_create", PromiseCreate,
486 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, 499 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
487 "promise_reject", RejectPromise, 500 "promise_reject", RejectPromise,
488 "promise_resolve", FulfillPromise, 501 "promise_resolve", FulfillPromise,
489 "promise_then", PromiseThen, 502 "promise_then", PromiseThen,
503 "promise_create_rejected", PromiseCreateRejected,
504 "promise_create_resolved", PromiseCreateResolved
490 ]); 505 ]);
491 506
492 // This allows extras to create promises quickly without building extra 507 // This allows extras to create promises quickly without building extra
493 // resolve/reject closures, and allows them to later resolve and reject any 508 // resolve/reject closures, and allows them to later resolve and reject any
494 // promise without having to hold on to those closures forever. 509 // promise without having to hold on to those closures forever.
495 utils.InstallFunctions(extrasUtils, 0, [ 510 utils.InstallFunctions(extrasUtils, 0, [
496 "createPromise", PromiseCreate, 511 "createPromise", PromiseCreate,
497 "resolvePromise", FulfillPromise, 512 "resolvePromise", FulfillPromise,
498 "rejectPromise", RejectPromise 513 "rejectPromise", RejectPromise
499 ]); 514 ]);
500 515
501 // TODO(v8:4567): Allow experimental natives to remove function prototype 516 // TODO(v8:4567): Allow experimental natives to remove function prototype
502 [PromiseChain, PromiseDefer, PromiseAccept].forEach( 517 [PromiseChain, PromiseDefer, PromiseAccept].forEach(
503 fn => %FunctionRemovePrototype(fn)); 518 fn => %FunctionRemovePrototype(fn));
504 519
505 utils.Export(function(to) { 520 utils.Export(function(to) {
506 to.PromiseChain = PromiseChain; 521 to.PromiseChain = PromiseChain;
507 to.PromiseDefer = PromiseDefer; 522 to.PromiseDefer = PromiseDefer;
508 to.PromiseAccept = PromiseAccept; 523 to.PromiseAccept = PromiseAccept;
524
525 to.PromiseCreateRejected = PromiseCreateRejected;
526 to.PromiseCreateResolved = PromiseCreateResolved;
527 to.PromiseThen = PromiseThen;
509 }); 528 });
510 529
511 }) 530 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698