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

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

Issue 2606093002: [promises] Refactor debug code (Closed)
Patch Set: fix stuff Created 3 years, 11 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/macros.py ('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
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var InternalArray = utils.InternalArray; 14 var InternalArray = utils.InternalArray;
15 var promiseAsyncStackIDSymbol =
16 utils.ImportNow("promise_async_stack_id_symbol");
17 var promiseHandledBySymbol = 15 var promiseHandledBySymbol =
18 utils.ImportNow("promise_handled_by_symbol"); 16 utils.ImportNow("promise_handled_by_symbol");
19 var promiseForwardingHandlerSymbol = 17 var promiseForwardingHandlerSymbol =
20 utils.ImportNow("promise_forwarding_handler_symbol"); 18 utils.ImportNow("promise_forwarding_handler_symbol");
21 var ObjectHasOwnProperty; // Used by HAS_PRIVATE.
22 var GlobalPromise = global.Promise; 19 var GlobalPromise = global.Promise;
23 20
24 utils.Import(function(from) {
25 ObjectHasOwnProperty = from.ObjectHasOwnProperty;
26 });
27
28 // ------------------------------------------------------------------- 21 // -------------------------------------------------------------------
29 22
30 // Core functionality. 23 // Core functionality.
31 24
32 function PromiseDebugGetInfo(deferred_promise, status) {
33 var id, name, instrumenting = DEBUG_IS_ACTIVE;
34
35 if (instrumenting) {
36 // In an async function, reuse the existing stack related to the outer
37 // Promise. Otherwise, e.g. in a direct call to then, save a new stack.
38 // Promises with multiple reactions with one or more of them being async
39 // functions will not get a good stack trace, as async functions require
40 // different stacks from direct Promise use, but we save and restore a
41 // stack once for all reactions. TODO(littledan): Improve this case.
42 if (!IS_UNDEFINED(deferred_promise) &&
43 HAS_PRIVATE(deferred_promise, promiseHandledBySymbol) &&
44 HAS_PRIVATE(GET_PRIVATE(deferred_promise, promiseHandledBySymbol),
45 promiseAsyncStackIDSymbol)) {
46 id = GET_PRIVATE(GET_PRIVATE(deferred_promise, promiseHandledBySymbol),
47 promiseAsyncStackIDSymbol);
48 name = "async function";
49 } else {
50 id = %DebugNextMicrotaskId();
51 name = status === kFulfilled ? "Promise.resolve" : "Promise.reject";
52 %DebugAsyncTaskEvent("enqueue", id, name);
53 }
54 }
55 return [id, name];
56 }
57
58 function PromiseIdResolveHandler(x) { return x; } 25 function PromiseIdResolveHandler(x) { return x; }
59 function PromiseIdRejectHandler(r) { %_ReThrow(r); } 26 function PromiseIdRejectHandler(r) { %_ReThrow(r); }
60 SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true); 27 SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true);
61 28
62 // ------------------------------------------------------------------- 29 // -------------------------------------------------------------------
63 // Define exported functions. 30 // Define exported functions.
64 31
65 // For bootstrapper. 32 // For bootstrapper.
66 33
67 // This is used by utils and v8-extras. 34 // This is used by utils and v8-extras.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 "all", PromiseAll, 199 "all", PromiseAll,
233 "race", PromiseRace, 200 "race", PromiseRace,
234 "resolve", PromiseResolve 201 "resolve", PromiseResolve
235 ]); 202 ]);
236 203
237 %InstallToContext([ 204 %InstallToContext([
238 "promise_create", PromiseCreate, 205 "promise_create", PromiseCreate,
239 "promise_reject", DoRejectPromise, 206 "promise_reject", DoRejectPromise,
240 // TODO(gsathya): Remove this once we update the promise builtin. 207 // TODO(gsathya): Remove this once we update the promise builtin.
241 "promise_internal_reject", RejectPromise, 208 "promise_internal_reject", RejectPromise,
242 "promise_debug_get_info", PromiseDebugGetInfo,
243 "promise_id_resolve_handler", PromiseIdResolveHandler, 209 "promise_id_resolve_handler", PromiseIdResolveHandler,
244 "promise_id_reject_handler", PromiseIdRejectHandler 210 "promise_id_reject_handler", PromiseIdRejectHandler
245 ]); 211 ]);
246 212
247 // This allows extras to create promises quickly without building extra 213 // This allows extras to create promises quickly without building extra
248 // resolve/reject closures, and allows them to later resolve and reject any 214 // resolve/reject closures, and allows them to later resolve and reject any
249 // promise without having to hold on to those closures forever. 215 // promise without having to hold on to those closures forever.
250 utils.InstallFunctions(extrasUtils, 0, [ 216 utils.InstallFunctions(extrasUtils, 0, [
251 "createPromise", PromiseCreate, 217 "createPromise", PromiseCreate,
252 "rejectPromise", DoRejectPromise, 218 "rejectPromise", DoRejectPromise,
253 "markPromiseAsHandled", MarkPromiseAsHandled 219 "markPromiseAsHandled", MarkPromiseAsHandled
254 ]); 220 ]);
255 221
256 utils.Export(function(to) { 222 utils.Export(function(to) {
257 to.PromiseCreate = PromiseCreate; 223 to.PromiseCreate = PromiseCreate;
258 to.RejectPromise = RejectPromise; 224 to.RejectPromise = RejectPromise;
259 }); 225 });
260 226
261 }) 227 })
OLDNEW
« no previous file with comments | « src/js/macros.py ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698