Skip to content

Commit 7c293e2

Browse files
authored
Remove all references to goog.bind (bazelbuild#644)
1 parent 3352921 commit 7c293e2

3 files changed

Lines changed: 25 additions & 28 deletions

File tree

closure/testing/library/jsunit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ goog.exportSymbol('G_testRunner.getTestResultsAsJson', tr.getTestResultsAsJson);
8383
// Export debug as a global function for JSUnit compatibility. This just
8484
// calls log on the current test case.
8585
if (!goog.global['debug']) {
86-
goog.exportSymbol('debug', goog.bind(tr.log, tr));
86+
goog.exportSymbol('debug', tr.log.bind(tr));
8787
}
8888

8989
// If the application has defined a global error filter, set it now. This

closure/testing/library/testcase.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ goog.testing.TestCase.prototype.runNextTest_ = function() {
899899
if (!this.curTest_ || !this.running) {
900900
this.finalize();
901901
return new goog.testing.TestCase.Continuation_(
902-
goog.bind(this.runNextTestCallback_, this, this.result_));
902+
this.runNextTestCallback_.bind(this, this.result_));
903903
}
904904

905905
var shouldRunTest = true;
@@ -908,20 +908,20 @@ goog.testing.TestCase.prototype.runNextTest_ = function() {
908908
} catch (error) {
909909
this.curTest_.name = 'shouldRunTests for ' + this.curTest_.name;
910910
return new goog.testing.TestCase.Continuation_(
911-
goog.bind(this.finishTestInvocation_, this, error));
911+
this.finishTestInvocation_.bind(this, error));
912912
}
913913

914914
if (!shouldRunTest) {
915915
return new goog.testing.TestCase.Continuation_(
916-
goog.bind(this.finishTestInvocation_, this));
916+
this.finishTestInvocation_.bind(this));
917917
}
918918

919919
this.curTest_.started();
920920
this.result_.runCount++;
921921
this.log('Running test: ' + this.curTest_.name);
922922
if (this.maybeFailTestEarly(this.curTest_)) {
923923
return new goog.testing.TestCase.Continuation_(
924-
goog.bind(this.finishTestInvocation_, this));
924+
this.finishTestInvocation_.bind(this));
925925
}
926926
goog.testing.TestCase.currentTestName = this.curTest_.name;
927927
return this.safeSetUp_();
@@ -1007,8 +1007,7 @@ goog.testing.TestCase.prototype.safeSetUpHelper_ = function(setUps) {
10071007
if (!setUps.length) {
10081008
return this.safeRunTest_;
10091009
}
1010-
return goog.bind(
1011-
this.invokeFunction_, this, setUps.shift(), this.safeSetUpHelper_(setUps),
1010+
return this.invokeFunction_.bind(this, setUps.shift(), this.safeSetUpHelper_(setUps),
10121011
this.safeTearDown_, 'setUp');
10131012
};
10141013

@@ -1020,7 +1019,7 @@ goog.testing.TestCase.prototype.safeSetUpHelper_ = function(setUps) {
10201019
goog.testing.TestCase.prototype.safeRunTest_ = function() {
10211020
'use strict';
10221021
return this.invokeFunction_(
1023-
goog.bind(this.curTest_.ref, this.curTest_.scope), this.safeTearDown_,
1022+
this.curTest_.ref.bind(this.curTest_.scope), this.safeTearDown_,
10241023
this.safeTearDown_, this.curTest_.name);
10251024
};
10261025

@@ -1054,8 +1053,7 @@ goog.testing.TestCase.prototype.safeTearDownHelper_ = function(tearDowns) {
10541053
if (!tearDowns.length) {
10551054
return this.finishTestInvocation_;
10561055
}
1057-
return goog.bind(
1058-
this.invokeFunction_, this, tearDowns.shift(),
1056+
return this.invokeFunction_.bind(this, tearDowns.shift(),
10591057
this.safeTearDownHelper_(tearDowns), this.finishTestInvocation_,
10601058
'tearDown');
10611059
};
@@ -1127,17 +1125,16 @@ goog.testing.TestCase.prototype.invokeFunction_ = function(
11271125
} else {
11281126
if (this.thrownAssertionExceptions_.length == 0) {
11291127
return new goog.testing.TestCase.Continuation_(
1130-
goog.bind(onSuccess, this));
1128+
onSuccess.bind(this));
11311129
} else {
1132-
return new goog.testing.TestCase.Continuation_(goog.bind(
1133-
onFailure, this,
1134-
this.reportUnpropagatedAssertionExceptions_(fnName)));
1130+
return new goog.testing.TestCase.Continuation_(
1131+
onFailure.bind(this, this.reportUnpropagatedAssertionExceptions_(fnName)));
11351132
}
11361133
}
11371134
} catch (e) {
11381135
this.reportUnpropagatedAssertionExceptions_(fnName, e);
11391136
return new goog.testing.TestCase.Continuation_(
1140-
goog.bind(onFailure, this, e));
1137+
onFailure.bind(this, e));
11411138
}
11421139
};
11431140

@@ -1234,11 +1231,11 @@ goog.testing.TestCase.prototype.finishTestInvocation_ = function(opt_error) {
12341231
// yield to avoid blocking the browser. Otherwise, proceed to the next test.
12351232
if (this.now() - this.batchTime_ > goog.testing.TestCase.maxRunTime) {
12361233
this.saveMessage('Breaking async');
1237-
this.timeout(goog.bind(this.startNextBatch_, this), 0);
1234+
this.timeout(this.startNextBatch_.bind(this), 0);
12381235
return null;
12391236
} else {
12401237
return new goog.testing.TestCase.Continuation_(
1241-
goog.bind(this.runNextTest_, this));
1238+
this.runNextTest_.bind(this));
12421239
}
12431240
};
12441241

@@ -1454,22 +1451,22 @@ goog.testing.TestCase.prototype.autoDiscoverLifecycle = function() {
14541451
goog.testing.TestCase.prototype.setLifecycleObj = function(obj) {
14551452
'use strict';
14561453
if (obj['setUp']) {
1457-
this.setUp = goog.bind(obj['setUp'], obj);
1454+
this.setUp = obj['setUp'].bind(obj);
14581455
}
14591456
if (obj['tearDown']) {
1460-
this.tearDown = goog.bind(obj['tearDown'], obj);
1457+
this.tearDown = obj['tearDown'].bind(obj);
14611458
}
14621459
if (obj['setUpPage']) {
1463-
this.setUpPage = goog.bind(obj['setUpPage'], obj);
1460+
this.setUpPage = obj['setUpPage'].bind(obj);
14641461
}
14651462
if (obj['tearDownPage']) {
1466-
this.tearDownPage = goog.bind(obj['tearDownPage'], obj);
1463+
this.tearDownPage = obj['tearDownPage'].bind(obj);
14671464
}
14681465
if (obj['runTests']) {
1469-
this.runTests = goog.bind(obj['runTests'], obj);
1466+
this.runTests = obj['runTests'].bind(obj);
14701467
}
14711468
if (obj['shouldRunTests']) {
1472-
this.shouldRunTests = goog.bind(obj['shouldRunTests'], obj);
1469+
this.shouldRunTests = obj['shouldRunTests'].bind(obj);
14731470
}
14741471
};
14751472

@@ -2014,10 +2011,10 @@ goog.testing.TestCase.Test = function(name, ref, scope, objChain) {
20142011
if (objChain) {
20152012
for (var i = 0; i < objChain.length; i++) {
20162013
if (typeof objChain[i].setUp === 'function') {
2017-
this.setUps.push(goog.bind(objChain[i].setUp, objChain[i]));
2014+
this.setUps.push(objChain[i].setUp.bind(objChain[i]));
20182015
}
20192016
if (typeof objChain[i].tearDown === 'function') {
2020-
this.tearDowns.push(goog.bind(objChain[i].tearDown, objChain[i]));
2017+
this.tearDowns.push(objChain[i].tearDown.bind(objChain[i]));
20212018
}
20222019
}
20232020
this.tearDowns.reverse();

closure/testing/library/testrunner.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ goog.testing.TestRunner.prototype.execute = function() {
324324
'setStrict() method, or G_testRunner.setStrict()');
325325
}
326326

327-
this.testCase.addCompletedCallback(goog.bind(this.onComplete_, this));
327+
this.testCase.addCompletedCallback(this.onComplete_.bind(this));
328328
if (goog.testing.TestRunner.shouldUsePromises_(this.testCase)) {
329329
this.testCase.runTestsReturningPromise();
330330
} else {
@@ -379,11 +379,11 @@ goog.testing.TestRunner.prototype.onComplete_ = function() {
379379
runAgainLink.style.fontSize = 'small';
380380
runAgainLink.style.marginBottom = '16px';
381381
runAgainLink.href = '';
382-
runAgainLink.onclick = goog.bind(function() {
382+
runAgainLink.onclick = (function() {
383383
'use strict';
384384
this.execute();
385385
return false;
386-
}, this);
386+
}).bind(this);
387387
runAgainLink.textContent = 'Run again without reloading';
388388
this.logEl_.appendChild(runAgainLink);
389389
};

0 commit comments

Comments
 (0)