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

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: Try new strategy (Option C) 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // which is usually simply noise. Do not trigger that debug event. 261 // which is usually simply noise. Do not trigger that debug event.
262 %PromiseRejectEvent(promise, r, false); 262 %PromiseRejectEvent(promise, r, false);
263 return promise; 263 return promise;
264 } else { 264 } else {
265 var promiseCapability = NewPromiseCapability(this); 265 var promiseCapability = NewPromiseCapability(this);
266 %_Call(promiseCapability.reject, UNDEFINED, r); 266 %_Call(promiseCapability.reject, UNDEFINED, r);
267 return promiseCapability.promise; 267 return promiseCapability.promise;
268 } 268 }
269 } 269 }
270 270
271 // Shortcut Promise.reject and Promise.resolve() implementations, used by
272 // Async Functions implementation.
273 function PromiseCreateRejected(r) {
274 var promise = PromiseCreateAndSet(-1, r);
275 %PromiseRejectEvent(promise, r, false);
276 return promise;
277 }
278
279 function PromiseCreateResolved(x) {
280 if (IsPromise(x) && x.constructor === GlobalPromise) return x;
281 return PromiseCreateAndSet(+1, x);
282 }
283
271 // Multi-unwrapped chaining with thenable coercion. 284 // Multi-unwrapped chaining with thenable coercion.
272 285
273 function PromiseThen(onResolve, onReject) { 286 function PromiseThen(onResolve, onReject) {
274 var status = GET_PRIVATE(this, promiseStatusSymbol); 287 var status = GET_PRIVATE(this, promiseStatusSymbol);
275 if (IS_UNDEFINED(status)) { 288 if (IS_UNDEFINED(status)) {
276 throw MakeTypeError(kNotAPromise, this); 289 throw MakeTypeError(kNotAPromise, this);
277 } 290 }
278 291
279 var constructor = SpeciesConstructor(this, GlobalPromise); 292 var constructor = SpeciesConstructor(this, GlobalPromise);
280 onResolve = IS_CALLABLE(onResolve) ? onResolve : PromiseIdResolveHandler; 293 onResolve = IS_CALLABLE(onResolve) ? onResolve : PromiseIdResolveHandler;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 ]); 457 ]);
445 458
446 %InstallToContext([ 459 %InstallToContext([
447 "promise_catch", PromiseCatch, 460 "promise_catch", PromiseCatch,
448 "promise_chain", PromiseChain, 461 "promise_chain", PromiseChain,
449 "promise_create", PromiseCreate, 462 "promise_create", PromiseCreate,
450 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, 463 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
451 "promise_reject", PromiseReject, 464 "promise_reject", PromiseReject,
452 "promise_resolve", PromiseResolve, 465 "promise_resolve", PromiseResolve,
453 "promise_then", PromiseThen, 466 "promise_then", PromiseThen,
467 "promise_create_rejected", PromiseCreateRejected,
468 "promise_create_resolved", PromiseCreateResolved
454 ]); 469 ]);
455 470
456 // This allows extras to create promises quickly without building extra 471 // This allows extras to create promises quickly without building extra
457 // resolve/reject closures, and allows them to later resolve and reject any 472 // resolve/reject closures, and allows them to later resolve and reject any
458 // promise without having to hold on to those closures forever. 473 // promise without having to hold on to those closures forever.
459 utils.InstallFunctions(extrasUtils, 0, [ 474 utils.InstallFunctions(extrasUtils, 0, [
460 "createPromise", PromiseCreate, 475 "createPromise", PromiseCreate,
461 "resolvePromise", PromiseResolve, 476 "resolvePromise", PromiseResolve,
462 "rejectPromise", PromiseReject 477 "rejectPromise", PromiseReject
463 ]); 478 ]);
464 479
465 // TODO(v8:4567): Allow experimental natives to remove function prototype 480 // TODO(v8:4567): Allow experimental natives to remove function prototype
466 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( 481 [PromiseChain, PromiseDeferred, PromiseResolved].forEach(
467 fn => %FunctionRemovePrototype(fn)); 482 fn => %FunctionRemovePrototype(fn));
468 483
469 utils.Export(function(to) { 484 utils.Export(function(to) {
470 to.PromiseChain = PromiseChain; 485 to.PromiseChain = PromiseChain;
471 to.PromiseDeferred = PromiseDeferred; 486 to.PromiseDeferred = PromiseDeferred;
472 to.PromiseResolved = PromiseResolved; 487 to.PromiseResolved = PromiseResolved;
488
489 to.PromiseCreateRejected = PromiseCreateRejected;
490 to.PromiseCreateResolved = PromiseCreateResolved;
491 to.PromiseThen = PromiseThen;
473 }); 492 });
474 493
475 }) 494 })
OLDNEW
« src/isolate.cc ('K') | « src/js/prologue.js ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698