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

Side by Side Diff: src/promise.js

Issue 393283007: Introduce more debug events for promises. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix calling promise parent event Created 6 years, 5 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 | Annotate | Revision Log
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 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Object = global.Object 9 // var $Object = global.Object
10 // var $WeakMap = global.WeakMap 10 // var $WeakMap = global.WeakMap
(...skipping 20 matching lines...) Expand all
31 var promiseRaw = GLOBAL_PRIVATE("Promise#raw"); 31 var promiseRaw = GLOBAL_PRIVATE("Promise#raw");
32 var lastMicrotaskId = 0; 32 var lastMicrotaskId = 0;
33 33
34 (function() { 34 (function() {
35 35
36 var $Promise = function Promise(resolver) { 36 var $Promise = function Promise(resolver) {
37 if (resolver === promiseRaw) return; 37 if (resolver === promiseRaw) return;
38 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); 38 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]);
39 if (!IS_SPEC_FUNCTION(resolver)) 39 if (!IS_SPEC_FUNCTION(resolver))
40 throw MakeTypeError('resolver_not_a_function', [resolver]); 40 throw MakeTypeError('resolver_not_a_function', [resolver]);
41 var promise = PromiseInit(this); 41 var promise = PromiseInit(this);
aandrey 2014/07/18 12:10:44 this will fire "update" event before "new". please
Alexandra Mikhaylova 2014/07/22 10:45:36 Changed the instrumentation: moved the "update" ev
42 if (DEBUG_IS_ACTIVE) { 42 if (DEBUG_IS_ACTIVE) {
43 %DebugPromiseEvent({ type : "new Promise", 43 %DebugPromiseEvent({ type : "new Promise",
aandrey 2014/07/18 12:10:44 "new"
Alexandra Mikhaylova 2014/07/22 10:45:36 Done.
44 promise: this, 44 promise: this,
45 resolver: resolver }); 45 resolver: resolver });
46 } 46 }
47 try { 47 try {
48 %DebugPromiseHandlePrologue(function() { return promise }); 48 %DebugPromiseHandlePrologue(function() { return promise });
49 resolver(function(x) { PromiseResolve(promise, x) }, 49 resolver(function(x) { PromiseResolve(promise, x) },
50 function(r) { PromiseReject(promise, r) }); 50 function(r) { PromiseReject(promise, r) });
51 } catch (e) { 51 } catch (e) {
52 PromiseReject(promise, e); 52 PromiseReject(promise, e);
53 } finally { 53 } finally {
54 %DebugPromiseHandleEpilogue(); 54 %DebugPromiseHandleEpilogue();
55 } 55 }
56 } 56 }
57 57
58 // Core functionality. 58 // Core functionality.
59 59
60 function PromiseSet(promise, status, value, onResolve, onReject) { 60 function PromiseSet(promise, status, value, onResolve, onReject) {
61 SET_PRIVATE(promise, promiseStatus, status); 61 SET_PRIVATE(promise, promiseStatus, status);
62 SET_PRIVATE(promise, promiseValue, value); 62 SET_PRIVATE(promise, promiseValue, value);
63 SET_PRIVATE(promise, promiseOnResolve, onResolve); 63 SET_PRIVATE(promise, promiseOnResolve, onResolve);
64 SET_PRIVATE(promise, promiseOnReject, onReject); 64 SET_PRIVATE(promise, promiseOnReject, onReject);
65 if (DEBUG_IS_ACTIVE) {
66 %DebugPromiseEvent({ type: "update Promise status",
aandrey 2014/07/18 12:10:44 "update"
Alexandra Mikhaylova 2014/07/22 10:45:36 Done.
67 promise: promise,
68 status: status,
69 value: value });
70 }
65 return promise; 71 return promise;
66 } 72 }
67 73
68 function PromiseInit(promise) { 74 function PromiseInit(promise) {
69 return PromiseSet( 75 return PromiseSet(
70 promise, 0, UNDEFINED, new InternalArray, new InternalArray) 76 promise, 0, UNDEFINED, new InternalArray, new InternalArray)
71 } 77 }
72 78
73 function PromiseDone(promise, status, value, promiseQueue) { 79 function PromiseDone(promise, status, value, promiseQueue) {
74 if (GET_PRIVATE(promise, promiseStatus) === 0) { 80 if (GET_PRIVATE(promise, promiseStatus) === 0) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 PromiseEnqueue(GET_PRIVATE(this, promiseValue), 233 PromiseEnqueue(GET_PRIVATE(this, promiseValue),
228 [onResolve, deferred], 234 [onResolve, deferred],
229 +1); 235 +1);
230 break; 236 break;
231 case -1: // Rejected 237 case -1: // Rejected
232 PromiseEnqueue(GET_PRIVATE(this, promiseValue), 238 PromiseEnqueue(GET_PRIVATE(this, promiseValue),
233 [onReject, deferred], 239 [onReject, deferred],
234 -1); 240 -1);
235 break; 241 break;
236 } 242 }
243 if (DEBUG_IS_ACTIVE) {
244 %DebugPromiseEvent({ type: "update Promise parent",
aandrey 2014/07/18 12:10:44 "chain"
Alexandra Mikhaylova 2014/07/22 10:45:36 Done.
245 promise: deferred.promise,
246 parentPromise: this });
247 }
237 return deferred.promise; 248 return deferred.promise;
238 } 249 }
239 250
240 PromiseCatch = function PromiseCatch(onReject) { 251 PromiseCatch = function PromiseCatch(onReject) {
241 return this.then(UNDEFINED, onReject); 252 return this.then(UNDEFINED, onReject);
242 } 253 }
243 254
244 // Multi-unwrapped chaining with thenable coercion. 255 // Multi-unwrapped chaining with thenable coercion.
245 256
246 PromiseThen = function PromiseThen(onResolve, onReject) { 257 PromiseThen = function PromiseThen(onResolve, onReject) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 "race", PromiseOne, 345 "race", PromiseOne,
335 "resolve", PromiseCast 346 "resolve", PromiseCast
336 ]); 347 ]);
337 InstallFunctions($Promise.prototype, DONT_ENUM, [ 348 InstallFunctions($Promise.prototype, DONT_ENUM, [
338 "chain", PromiseChain, 349 "chain", PromiseChain,
339 "then", PromiseThen, 350 "then", PromiseThen,
340 "catch", PromiseCatch 351 "catch", PromiseCatch
341 ]); 352 ]);
342 353
343 })(); 354 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698