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

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

Issue 2590563003: [promises] Remove deferred object (Closed)
Patch Set: Remove comment Created 3 years, 12 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 function PromiseIdResolveHandler(x) { return x; } 68 function PromiseIdResolveHandler(x) { return x; }
69 function PromiseIdRejectHandler(r) { %_ReThrow(r); } 69 function PromiseIdRejectHandler(r) { %_ReThrow(r); }
70 SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true); 70 SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true);
71 71
72 // ------------------------------------------------------------------- 72 // -------------------------------------------------------------------
73 // Define exported functions. 73 // Define exported functions.
74 74
75 // For bootstrapper. 75 // For bootstrapper.
76 76
77 // This is used by utils and v8-extras. 77 // This is used by utils and v8-extras.
78 function PromiseCreate() { 78 function PromiseCreate(parent) {
79 return %promise_internal_constructor(UNDEFINED); 79 return %promise_internal_constructor(parent);
80 } 80 }
81 81
82 // Only used by async-await.js 82 // Only used by async-await.js
83 function RejectPromise(promise, reason, debugEvent) { 83 function RejectPromise(promise, reason, debugEvent) {
84 %PromiseReject(promise, reason, debugEvent); 84 %PromiseReject(promise, reason, debugEvent);
85 } 85 }
86 86
87 // Export to bindings 87 // Export to bindings
88 function DoRejectPromise(promise, reason) { 88 function DoRejectPromise(promise, reason) {
89 %PromiseReject(promise, reason, true); 89 %PromiseReject(promise, reason, true);
90 } 90 }
91 91
92 // The resultCapability.promise is only ever fulfilled internally,
93 // so we don't need the closures to protect against accidentally
94 // calling them multiple times.
95 function CreateInternalPromiseCapability(parent) {
96 return {
97 promise: %promise_internal_constructor(parent),
98 resolve: UNDEFINED,
99 reject: UNDEFINED
100 };
101 }
102
103 // ES#sec-newpromisecapability 92 // ES#sec-newpromisecapability
104 // NewPromiseCapability ( C ) 93 // NewPromiseCapability ( C )
105 function NewPromiseCapability(C, debugEvent) { 94 function NewPromiseCapability(C, debugEvent) {
106 if (C === GlobalPromise) { 95 if (C === GlobalPromise) {
107 // Optimized case, avoid extra closure. 96 // Optimized case, avoid extra closure.
108 var promise = %promise_internal_constructor(UNDEFINED); 97 var promise = %promise_internal_constructor(UNDEFINED);
109 // TODO(gsathya): Remove container for callbacks when this is 98 // TODO(gsathya): Remove container for callbacks when this is
110 // moved to CPP/TF. 99 // moved to CPP/TF.
111 var callbacks = %create_resolving_functions(promise, debugEvent); 100 var callbacks = %create_resolving_functions(promise, debugEvent);
112 return { 101 return {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // Utility for debugger 270 // Utility for debugger
282 271
283 function PromiseHasUserDefinedRejectHandlerCheck(handler, deferred) { 272 function PromiseHasUserDefinedRejectHandlerCheck(handler, deferred) {
284 // Recurse to the forwarding Promise, if any. This may be due to 273 // Recurse to the forwarding Promise, if any. This may be due to
285 // - await reaction forwarding to the throwaway Promise, which has 274 // - await reaction forwarding to the throwaway Promise, which has
286 // a dependency edge to the outer Promise. 275 // a dependency edge to the outer Promise.
287 // - PromiseIdResolveHandler forwarding to the output of .then 276 // - PromiseIdResolveHandler forwarding to the output of .then
288 // - Promise.all/Promise.race forwarding to a throwaway Promise, which 277 // - Promise.all/Promise.race forwarding to a throwaway Promise, which
289 // has a dependency edge to the generated outer Promise. 278 // has a dependency edge to the generated outer Promise.
290 if (GET_PRIVATE(handler, promiseForwardingHandlerSymbol)) { 279 if (GET_PRIVATE(handler, promiseForwardingHandlerSymbol)) {
291 return PromiseHasUserDefinedRejectHandlerRecursive(deferred.promise); 280 return PromiseHasUserDefinedRejectHandlerRecursive(deferred);
292 } 281 }
293 282
294 // Otherwise, this is a real reject handler for the Promise 283 // Otherwise, this is a real reject handler for the Promise
295 return true; 284 return true;
296 } 285 }
297 286
298 function PromiseHasUserDefinedRejectHandlerRecursive(promise) { 287 function PromiseHasUserDefinedRejectHandlerRecursive(promise) {
299 // If this promise was marked as being handled by a catch block 288 // If this promise was marked as being handled by a catch block
300 // in an async function, then it has a user-defined reject handler. 289 // in an async function, then it has a user-defined reject handler.
301 if (GET_PRIVATE(promise, promiseHandledHintSymbol)) return true; 290 if (GET_PRIVATE(promise, promiseHandledHintSymbol)) return true;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 353
365 %InstallToContext([ 354 %InstallToContext([
366 "promise_catch", GlobalPromise.prototype.catch, 355 "promise_catch", GlobalPromise.prototype.catch,
367 "promise_create", PromiseCreate, 356 "promise_create", PromiseCreate,
368 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, 357 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
369 "promise_reject", DoRejectPromise, 358 "promise_reject", DoRejectPromise,
370 // TODO(gsathya): Remove this once we update the promise builtin. 359 // TODO(gsathya): Remove this once we update the promise builtin.
371 "promise_internal_reject", RejectPromise, 360 "promise_internal_reject", RejectPromise,
372 "promise_debug_get_info", PromiseDebugGetInfo, 361 "promise_debug_get_info", PromiseDebugGetInfo,
373 "new_promise_capability", NewPromiseCapability, 362 "new_promise_capability", NewPromiseCapability,
374 "internal_promise_capability", CreateInternalPromiseCapability,
375 "promise_id_resolve_handler", PromiseIdResolveHandler, 363 "promise_id_resolve_handler", PromiseIdResolveHandler,
376 "promise_id_reject_handler", PromiseIdRejectHandler 364 "promise_id_reject_handler", PromiseIdRejectHandler
377 ]); 365 ]);
378 366
379 // This allows extras to create promises quickly without building extra 367 // This allows extras to create promises quickly without building extra
380 // resolve/reject closures, and allows them to later resolve and reject any 368 // resolve/reject closures, and allows them to later resolve and reject any
381 // promise without having to hold on to those closures forever. 369 // promise without having to hold on to those closures forever.
382 utils.InstallFunctions(extrasUtils, 0, [ 370 utils.InstallFunctions(extrasUtils, 0, [
383 "createPromise", PromiseCreate, 371 "createPromise", PromiseCreate,
384 "rejectPromise", DoRejectPromise, 372 "rejectPromise", DoRejectPromise,
385 "markPromiseAsHandled", MarkPromiseAsHandled 373 "markPromiseAsHandled", MarkPromiseAsHandled
386 ]); 374 ]);
387 375
388 utils.Export(function(to) { 376 utils.Export(function(to) {
389 to.PromiseCreate = PromiseCreate; 377 to.PromiseCreate = PromiseCreate;
390 to.PromiseThen = PromiseThen; 378 to.PromiseThen = PromiseThen;
391 379
392 to.CreateInternalPromiseCapability = CreateInternalPromiseCapability;
393 to.RejectPromise = RejectPromise; 380 to.RejectPromise = RejectPromise;
394 }); 381 });
395 382
396 }) 383 })
OLDNEW
« src/builtins/builtins-promise.cc ('K') | « src/js/async-await.js ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698