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

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: fix some nits 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
« no previous file with comments | « src/js/prologue.js ('k') | src/objects.cc » ('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 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 return %_Call(PromiseReject, GlobalPromise, r);
300 }
301
302 function PromiseCreateResolved(x) {
303 return %_Call(PromiseResolve, GlobalPromise, x);
304 }
305
296 // ES#sec-promise.prototype.then 306 // ES#sec-promise.prototype.then
297 // Promise.prototype.then ( onFulfilled, onRejected ) 307 // Promise.prototype.then ( onFulfilled, onRejected )
298 // Multi-unwrapped chaining with thenable coercion. 308 // Multi-unwrapped chaining with thenable coercion.
299 function PromiseThen(onResolve, onReject) { 309 function PromiseThen(onResolve, onReject) {
300 var status = GET_PRIVATE(this, promiseStateSymbol); 310 var status = GET_PRIVATE(this, promiseStateSymbol);
301 if (IS_UNDEFINED(status)) { 311 if (IS_UNDEFINED(status)) {
302 throw MakeTypeError(kNotAPromise, this); 312 throw MakeTypeError(kNotAPromise, this);
303 } 313 }
304 314
305 var constructor = SpeciesConstructor(this, GlobalPromise); 315 var constructor = SpeciesConstructor(this, GlobalPromise);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 ]); 490 ]);
481 491
482 %InstallToContext([ 492 %InstallToContext([
483 "promise_catch", PromiseCatch, 493 "promise_catch", PromiseCatch,
484 "promise_chain", PromiseChain, 494 "promise_chain", PromiseChain,
485 "promise_create", PromiseCreate, 495 "promise_create", PromiseCreate,
486 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, 496 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
487 "promise_reject", RejectPromise, 497 "promise_reject", RejectPromise,
488 "promise_resolve", FulfillPromise, 498 "promise_resolve", FulfillPromise,
489 "promise_then", PromiseThen, 499 "promise_then", PromiseThen,
500 "promise_create_rejected", PromiseCreateRejected,
501 "promise_create_resolved", PromiseCreateResolved
490 ]); 502 ]);
491 503
492 // This allows extras to create promises quickly without building extra 504 // This allows extras to create promises quickly without building extra
493 // resolve/reject closures, and allows them to later resolve and reject any 505 // resolve/reject closures, and allows them to later resolve and reject any
494 // promise without having to hold on to those closures forever. 506 // promise without having to hold on to those closures forever.
495 utils.InstallFunctions(extrasUtils, 0, [ 507 utils.InstallFunctions(extrasUtils, 0, [
496 "createPromise", PromiseCreate, 508 "createPromise", PromiseCreate,
497 "resolvePromise", FulfillPromise, 509 "resolvePromise", FulfillPromise,
498 "rejectPromise", RejectPromise 510 "rejectPromise", RejectPromise
499 ]); 511 ]);
500 512
501 // TODO(v8:4567): Allow experimental natives to remove function prototype 513 // TODO(v8:4567): Allow experimental natives to remove function prototype
502 [PromiseChain, PromiseDefer, PromiseAccept].forEach( 514 [PromiseChain, PromiseDefer, PromiseAccept].forEach(
503 fn => %FunctionRemovePrototype(fn)); 515 fn => %FunctionRemovePrototype(fn));
504 516
505 utils.Export(function(to) { 517 utils.Export(function(to) {
506 to.PromiseChain = PromiseChain; 518 to.PromiseChain = PromiseChain;
507 to.PromiseDefer = PromiseDefer; 519 to.PromiseDefer = PromiseDefer;
508 to.PromiseAccept = PromiseAccept; 520 to.PromiseAccept = PromiseAccept;
521
522 to.PromiseCreateRejected = PromiseCreateRejected;
523 to.PromiseCreateResolved = PromiseCreateResolved;
524 to.PromiseThen = PromiseThen;
509 }); 525 });
510 526
511 }) 527 })
OLDNEW
« no previous file with comments | « src/js/prologue.js ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698