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

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

Issue 2314903004: [promises] Move PromiseResolveThenableJob to c++ (Closed)
Patch Set: rebase Created 4 years, 3 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/isolate.cc ('k') | src/objects.h » ('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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 %PromiseRevokeReject(resolution); 277 %PromiseRevokeReject(resolution);
278 } 278 }
279 // Don't cause a debug event as this case is forwarding a rejection 279 // Don't cause a debug event as this case is forwarding a rejection
280 RejectPromise(promise, thenableValue, false); 280 RejectPromise(promise, thenableValue, false);
281 SET_PRIVATE(resolution, promiseHasHandlerSymbol, true); 281 SET_PRIVATE(resolution, promiseHasHandlerSymbol, true);
282 return; 282 return;
283 } 283 }
284 } 284 }
285 285
286 if (IS_CALLABLE(then)) { 286 if (IS_CALLABLE(then)) {
287 // PromiseResolveThenableJob 287 var callbacks = CreateResolvingFunctions(promise, false);
288 var id; 288 var id, before_debug_event, after_debug_event;
289 var name = "PromiseResolveThenableJob";
290 var instrumenting = DEBUG_IS_ACTIVE; 289 var instrumenting = DEBUG_IS_ACTIVE;
291 if (instrumenting && IsPromise(resolution)) { 290 if (instrumenting) {
292 // Mark the dependency of the new promise on the resolution 291 if (IsPromise(resolution)) {
293 SET_PRIVATE(resolution, promiseHandledBySymbol, promise); 292 // Mark the dependency of the new promise on the resolution
293 SET_PRIVATE(resolution, promiseHandledBySymbol, promise);
294 }
295 id = ++lastMicrotaskId;
296 before_debug_event = {
297 type: "willHandle",
298 id: id,
299 name: "PromiseResolveThenableJob"
300 };
301 after_debug_event = {
302 type: "didHandle",
303 id: id,
304 name: "PromiseResolveThenableJob"
305 };
306 %DebugAsyncTaskEvent({
307 type: "enqueue",
308 id: id,
309 name: "PromiseResolveThenableJob"
310 });
294 } 311 }
295 %EnqueueMicrotask(function() { 312 %EnqueuePromiseResolveThenableJob(
296 if (instrumenting) { 313 resolution, then, callbacks.resolve, callbacks.reject,
297 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); 314 before_debug_event, after_debug_event);
298 }
299 // These resolving functions simply forward the exception, so
300 // don't create a new debugEvent.
301 var callbacks = CreateResolvingFunctions(promise, false);
302 try {
303 %_Call(then, resolution, callbacks.resolve, callbacks.reject);
304 } catch (e) {
305 %_Call(callbacks.reject, UNDEFINED, e);
306 }
307 if (instrumenting) {
308 %DebugAsyncTaskEvent({ type: "didHandle", id: id, name: name });
309 }
310 });
311 if (instrumenting) {
312 id = ++lastMicrotaskId;
313 %DebugAsyncTaskEvent({ type: "enqueue", id: id, name: name });
314 }
315 return; 315 return;
316 } 316 }
317 } 317 }
318 FulfillPromise(promise, kFulfilled, resolution, 318 FulfillPromise(promise, kFulfilled, resolution,
319 promiseFulfillReactionsSymbol); 319 promiseFulfillReactionsSymbol);
320 } 320 }
321 321
322 // ES#sec-rejectpromise 322 // ES#sec-rejectpromise
323 // RejectPromise ( promise, reason ) 323 // RejectPromise ( promise, reason )
324 function RejectPromise(promise, reason, debugEvent) { 324 function RejectPromise(promise, reason, debugEvent) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 "then", PromiseThen, 648 "then", PromiseThen,
649 "catch", PromiseCatch 649 "catch", PromiseCatch
650 ]); 650 ]);
651 651
652 %InstallToContext([ 652 %InstallToContext([
653 "promise_catch", PromiseCatch, 653 "promise_catch", PromiseCatch,
654 "promise_create", PromiseCreate, 654 "promise_create", PromiseCreate,
655 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, 655 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
656 "promise_reject", DoRejectPromise, 656 "promise_reject", DoRejectPromise,
657 "promise_resolve", ResolvePromise, 657 "promise_resolve", ResolvePromise,
658 "promise_then", PromiseThen, 658 "promise_then", PromiseThen
659 ]); 659 ]);
660 660
661 // This allows extras to create promises quickly without building extra 661 // This allows extras to create promises quickly without building extra
662 // resolve/reject closures, and allows them to later resolve and reject any 662 // resolve/reject closures, and allows them to later resolve and reject any
663 // promise without having to hold on to those closures forever. 663 // promise without having to hold on to those closures forever.
664 utils.InstallFunctions(extrasUtils, 0, [ 664 utils.InstallFunctions(extrasUtils, 0, [
665 "createPromise", PromiseCreate, 665 "createPromise", PromiseCreate,
666 "resolvePromise", ResolvePromise, 666 "resolvePromise", ResolvePromise,
667 "rejectPromise", DoRejectPromise 667 "rejectPromise", DoRejectPromise
668 ]); 668 ]);
669 669
670 utils.Export(function(to) { 670 utils.Export(function(to) {
671 to.IsPromise = IsPromise; 671 to.IsPromise = IsPromise;
672 to.PromiseCreate = PromiseCreate; 672 to.PromiseCreate = PromiseCreate;
673 to.PromiseThen = PromiseThen; 673 to.PromiseThen = PromiseThen;
674 674
675 to.GlobalPromise = GlobalPromise; 675 to.GlobalPromise = GlobalPromise;
676 to.NewPromiseCapability = NewPromiseCapability; 676 to.NewPromiseCapability = NewPromiseCapability;
677 to.PerformPromiseThen = PerformPromiseThen; 677 to.PerformPromiseThen = PerformPromiseThen;
678 to.ResolvePromise = ResolvePromise; 678 to.ResolvePromise = ResolvePromise;
679 to.RejectPromise = RejectPromise; 679 to.RejectPromise = RejectPromise;
680 }); 680 });
681 681
682 }) 682 })
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698