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

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

Issue 1985293002: Promises: Make debug calls only when debugging (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use local var 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 | « no previous file | no next file » | 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 if (resolver === promiseRawSymbol) { 76 if (resolver === promiseRawSymbol) {
77 return %_NewObject(GlobalPromise, new.target); 77 return %_NewObject(GlobalPromise, new.target);
78 } 78 }
79 if (IS_UNDEFINED(new.target)) throw MakeTypeError(kNotAPromise, this); 79 if (IS_UNDEFINED(new.target)) throw MakeTypeError(kNotAPromise, this);
80 if (!IS_CALLABLE(resolver)) { 80 if (!IS_CALLABLE(resolver)) {
81 throw MakeTypeError(kResolverNotAFunction, resolver); 81 throw MakeTypeError(kResolverNotAFunction, resolver);
82 } 82 }
83 83
84 var promise = PromiseInit(%_NewObject(GlobalPromise, new.target)); 84 var promise = PromiseInit(%_NewObject(GlobalPromise, new.target));
85 var callbacks = CreateResolvingFunctions(promise); 85 var callbacks = CreateResolvingFunctions(promise);
86 86 var debug_is_active = DEBUG_IS_ACTIVE;
87 try { 87 try {
88 %DebugPushPromise(promise, Promise); 88 if (debug_is_active) %DebugPushPromise(promise, Promise);
89 resolver(callbacks.resolve, callbacks.reject); 89 resolver(callbacks.resolve, callbacks.reject);
90 } catch (e) { 90 } catch (e) {
91 %_Call(callbacks.reject, UNDEFINED, e); 91 %_Call(callbacks.reject, UNDEFINED, e);
92 } finally { 92 } finally {
93 %DebugPopPromise(); 93 if (debug_is_active) %DebugPopPromise();
94 } 94 }
95 95
96 return promise; 96 return promise;
97 } 97 }
98 98
99 // Core functionality. 99 // Core functionality.
100 100
101 function PromiseSet(promise, status, value, onResolve, onReject) { 101 function PromiseSet(promise, status, value, onResolve, onReject) {
102 SET_PRIVATE(promise, promiseStateSymbol, status); 102 SET_PRIVATE(promise, promiseStateSymbol, status);
103 SET_PRIVATE(promise, promiseResultSymbol, value); 103 SET_PRIVATE(promise, promiseResultSymbol, value);
(...skipping 16 matching lines...) Expand all
120 120
121 function PromiseDone(promise, status, value, promiseQueue) { 121 function PromiseDone(promise, status, value, promiseQueue) {
122 if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) { 122 if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) {
123 var tasks = GET_PRIVATE(promise, promiseQueue); 123 var tasks = GET_PRIVATE(promise, promiseQueue);
124 if (tasks.length) PromiseEnqueue(value, tasks, status); 124 if (tasks.length) PromiseEnqueue(value, tasks, status);
125 PromiseSet(promise, status, value); 125 PromiseSet(promise, status, value);
126 } 126 }
127 } 127 }
128 128
129 function PromiseHandle(value, handler, deferred) { 129 function PromiseHandle(value, handler, deferred) {
130 var debug_is_active = DEBUG_IS_ACTIVE;
130 try { 131 try {
131 %DebugPushPromise(deferred.promise, PromiseHandle); 132 if (debug_is_active) %DebugPushPromise(deferred.promise, PromiseHandle);
132 var result = handler(value); 133 var result = handler(value);
133 deferred.resolve(result); 134 deferred.resolve(result);
134 } catch (exception) { 135 } catch (exception) {
135 try { deferred.reject(exception); } catch (e) { } 136 try { deferred.reject(exception); } catch (e) { }
136 } finally { 137 } finally {
137 %DebugPopPromise(); 138 if (debug_is_active) %DebugPopPromise();
138 } 139 }
139 } 140 }
140 141
141 function PromiseEnqueue(value, tasks, status) { 142 function PromiseEnqueue(value, tasks, status) {
142 var id, name, instrumenting = DEBUG_IS_ACTIVE; 143 var id, name, instrumenting = DEBUG_IS_ACTIVE;
143 %EnqueueMicrotask(function() { 144 %EnqueueMicrotask(function() {
144 if (instrumenting) { 145 if (instrumenting) {
145 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); 146 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name });
146 } 147 }
147 for (var i = 0; i < tasks.length; i += 2) { 148 for (var i = 0; i < tasks.length; i += 2) {
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 to.PromiseChain = PromiseChain; 519 to.PromiseChain = PromiseChain;
519 to.PromiseDefer = PromiseDefer; 520 to.PromiseDefer = PromiseDefer;
520 to.PromiseAccept = PromiseAccept; 521 to.PromiseAccept = PromiseAccept;
521 522
522 to.PromiseCreateRejected = PromiseCreateRejected; 523 to.PromiseCreateRejected = PromiseCreateRejected;
523 to.PromiseCreateResolved = PromiseCreateResolved; 524 to.PromiseCreateResolved = PromiseCreateResolved;
524 to.PromiseThen = PromiseThen; 525 to.PromiseThen = PromiseThen;
525 }); 526 });
526 527
527 }) 528 })
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698