@@ -1411,37 +1411,54 @@ promise.ControlFlow.prototype.annotateError = function(e) {
1411
1411
*/
1412
1412
promise . ControlFlow . prototype . getSchedule = function ( opt_includeStackTraces ) {
1413
1413
var ret = 'ControlFlow::' + goog . getUid ( this ) ;
1414
- if ( ! this . activeFrame_ ) {
1414
+ var activeFrame = this . activeFrame_ ;
1415
+ if ( ! activeFrame ) {
1415
1416
return ret ;
1416
1417
}
1417
1418
var childIndent = '| ' ;
1418
- return ret + '\n' + toStringHelper ( this . activeFrame_ . getRoot ( ) , childIndent ) ;
1419
+ return ret + '\n' + toStringHelper ( activeFrame . getRoot ( ) , childIndent ) ;
1419
1420
1420
1421
/**
1421
1422
* @param {!(promise.Frame_|promise.Task_) } node .
1422
1423
* @param {string } indent .
1424
+ * @param {boolean= } opt_isPending .
1423
1425
* @return {string } .
1424
1426
*/
1425
- function toStringHelper ( node , indent ) {
1427
+ function toStringHelper ( node , indent , opt_isPending ) {
1426
1428
var ret = node . toString ( ) ;
1429
+ if ( opt_isPending ) {
1430
+ ret = '(pending) ' + ret ;
1431
+ }
1432
+ if ( node === activeFrame ) {
1433
+ ret = '(active) ' + ret ;
1434
+ }
1427
1435
if ( node instanceof promise . Frame_ ) {
1428
1436
if ( node . getPendingTask ( ) ) {
1429
1437
ret += '\n' + toStringHelper (
1430
1438
/** @type {!promise.Task_ } */ ( node . getPendingTask ( ) ) ,
1431
- childIndent ) ;
1439
+ childIndent ,
1440
+ true ) ;
1432
1441
}
1433
1442
if ( node . children_ ) {
1434
1443
goog . array . forEach ( node . children_ , function ( child ) {
1435
- ret += '\n' + toStringHelper ( child , childIndent ) ;
1444
+ if ( ! node . getPendingTask ( ) ||
1445
+ node . getPendingTask ( ) . getFrame ( ) !== child ) {
1446
+ ret += '\n' + toStringHelper ( child , childIndent ) ;
1447
+ }
1436
1448
} ) ;
1437
1449
}
1438
- } else if ( opt_includeStackTraces ) {
1450
+ } else {
1439
1451
var task = /** @type {!promise.Task_ } */ ( node ) ;
1440
- if ( task . promise . stack_ ) {
1452
+ if ( opt_includeStackTraces && task . promise . stack_ ) {
1441
1453
ret += '\n' + childIndent +
1442
1454
( task . promise . stack_ . stack || task . promise . stack_ ) .
1443
1455
replace ( / \n / g, '\n' + childIndent ) ;
1444
1456
}
1457
+ if ( task . getFrame ( ) ) {
1458
+ ret += '\n' + toStringHelper (
1459
+ /** @type {!promise.Frame_ } */ ( task . getFrame ( ) ) ,
1460
+ childIndent ) ;
1461
+ }
1445
1462
}
1446
1463
return indent + ret . replace ( / \n / g, '\n' + indent ) ;
1447
1464
}
@@ -1725,18 +1742,21 @@ promise.ControlFlow.prototype.runEventLoop_ = function() {
1725
1742
1726
1743
var onSuccess = function ( value ) {
1727
1744
activeFrame . setPendingTask ( null ) ;
1745
+ task . setFrame ( null ) ;
1728
1746
task . fulfill ( value ) ;
1729
1747
scheduleEventLoop ( ) ;
1730
1748
} ;
1731
1749
1732
1750
var onFailure = function ( reason ) {
1733
1751
activeFrame . setPendingTask ( null ) ;
1752
+ task . setFrame ( null ) ;
1734
1753
task . reject ( reason ) ;
1735
1754
scheduleEventLoop ( ) ;
1736
1755
} ;
1737
1756
1738
1757
activeFrame . setPendingTask ( task ) ;
1739
1758
var frame = new promise . Frame_ ( this ) ;
1759
+ task . setFrame ( frame ) ;
1740
1760
this . runInFrame_ ( frame , task . execute , function ( result ) {
1741
1761
promise . asap ( result , onSuccess , onFailure ) ;
1742
1762
} , onFailure , true ) ;
@@ -1846,9 +1866,7 @@ promise.ControlFlow.prototype.runInFrame_ = function(
1846
1866
oldFrame = this . activeFrame_ ;
1847
1867
1848
1868
try {
1849
- if ( ! this . activeFrame_ ) {
1850
- this . activeFrame_ = newFrame ;
1851
- } else if ( this . activeFrame_ !== newFrame && ! newFrame . getParent ( ) ) {
1869
+ if ( this . activeFrame_ !== newFrame && ! newFrame . getParent ( ) ) {
1852
1870
this . activeFrame_ . addChild ( newFrame ) ;
1853
1871
}
1854
1872
@@ -2229,6 +2247,14 @@ promise.Frame_ = goog.defineClass(webdriver.EventEmitter, {
2229
2247
this . pendingTask_ = task ;
2230
2248
} ,
2231
2249
2250
+ /**
2251
+ * @return {boolean } Whether this frame is empty (has no scheduled tasks or
2252
+ * pending callback frames).
2253
+ */
2254
+ isEmpty : function ( ) {
2255
+ return ! this . children_ || ! this . children_ . length ;
2256
+ } ,
2257
+
2232
2258
/**
2233
2259
* Adds a new node to this frame.
2234
2260
* @param {!(promise.Frame_|promise.Task_) } node The node to insert.
@@ -2330,6 +2356,25 @@ promise.Task_ = goog.defineClass(promise.Deferred, {
2330
2356
2331
2357
/** @private {promise.Frame_} */
2332
2358
this . parent_ = null ;
2359
+
2360
+ /** @private {promise.Frame_} */
2361
+ this . frame_ = null ;
2362
+ } ,
2363
+
2364
+ /**
2365
+ * @return {promise.Frame_ } frame The frame used to run this task's
2366
+ * {@link #execute} method.
2367
+ */
2368
+ getFrame : function ( ) {
2369
+ return this . frame_ ;
2370
+ } ,
2371
+
2372
+ /**
2373
+ * @param {promise.Frame_ } frame The frame used to run this task's
2374
+ * {@link #execute} method.
2375
+ */
2376
+ setFrame : function ( frame ) {
2377
+ this . frame_ = frame ;
2333
2378
} ,
2334
2379
2335
2380
/**
0 commit comments