Skip to content

Commit efe88f5

Browse files
committed
Simplify logic for inserting new frames into the control flow.
1 parent c77869b commit efe88f5

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

javascript/webdriver/promise.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ promise.Promise.prototype.scheduleNotifications_ = function() {
519519
}
520520

521521
if (this.callbacks_ && this.callbacks_.length) {
522-
activeFrame = this.flow_.getActiveFrame_();
522+
activeFrame = this.flow_.getSchedulingFrame_();
523523
var self = this;
524524
goog.array.forEach(this.callbacks_, function(callback) {
525525
if (!callback.frame_.getParent()) {
@@ -653,7 +653,7 @@ promise.Promise.prototype.addCallback_ = function(callback, errback, name, fn) {
653653
if (this.state_ !== promise.Promise.State_.PENDING &&
654654
this.state_ !== promise.Promise.State_.BLOCKED) {
655655
cb.frame_.pendingCallback = true;
656-
this.flow_.getActiveFrame_().addChild(cb.frame_);
656+
this.flow_.getSchedulingFrame_().addChild(cb.frame_);
657657
this.scheduleNotifications_();
658658
}
659659
return cb.promise;
@@ -1463,6 +1463,15 @@ promise.ControlFlow.prototype.getActiveFrame_ = function() {
14631463
};
14641464

14651465

1466+
/**
1467+
* @return {!promise.Frame_} The frame that new items should be added to.
1468+
* @private
1469+
*/
1470+
promise.ControlFlow.prototype.getSchedulingFrame_ = function() {
1471+
return this.schedulingFrame_ || this.getActiveFrame_();
1472+
};
1473+
1474+
14661475
/**
14671476
* Schedules a task for execution. If there is nothing currently in the
14681477
* queue, the task will be executed in the next turn of the event loop. If
@@ -1493,9 +1502,7 @@ promise.ControlFlow.prototype.execute = function(fn, opt_description) {
14931502
task.promise.stack_ = promise.captureStackTrace('Task', description,
14941503
promise.ControlFlow.prototype.execute);
14951504

1496-
var scheduleIn = this.schedulingFrame_ || this.getActiveFrame_();
1497-
scheduleIn.addChild(task);
1498-
1505+
this.getSchedulingFrame_().addChild(task);
14991506
this.emit(promise.ControlFlow.EventType.SCHEDULE_TASK, opt_description);
15001507
this.scheduleEventLoopStart_();
15011508
return task.promise;
@@ -2246,14 +2253,6 @@ promise.Frame_.prototype.addChild = function(node) {
22462253
return; // Child will never run, no point keeping a reference.
22472254
}
22482255

2249-
if (this.lastInsertedChild_ &&
2250-
this.lastInsertedChild_ instanceof promise.Frame_ &&
2251-
!this.lastInsertedChild_.pendingCallback &&
2252-
!this.lastInsertedChild_.isLocked_) {
2253-
this.lastInsertedChild_.addChild(node);
2254-
return;
2255-
}
2256-
22572256
node.setParent(this);
22582257
if (this.isLocked_ && node instanceof promise.Frame_) {
22592258
var index = 0;

0 commit comments

Comments
 (0)