Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
RELNOTES[INC]: RecordFunction now runs in strict mode.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 333781698
  • Loading branch information
12wrigja authored and shicks committed Sep 26, 2020
1 parent 6dba573 commit ccd76bd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion closure/goog/async/run_next_tick_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ testSuite({
// and get the correct scope.
const last1 = futureCallback1.popLastCall();
assertEquals(0, last1.getArguments().length);
assertEquals(goog.global, last1.getThis());
assertEquals(undefined, last1.getThis());

const last2 = futureCallback2.popLastCall();
assertEquals(0, last2.getArguments().length);
Expand Down
2 changes: 1 addition & 1 deletion closure/goog/async/run_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ testSuite({
// and get the correct scope.
const last1 = futureCallback1.popLastCall();
assertEquals(0, last1.getArguments().length);
assertEquals(goog.global, last1.getThis());
assertEquals(undefined, last1.getThis());

const last2 = futureCallback2.popLastCall();
assertEquals(0, last2.getArguments().length);
Expand Down
12 changes: 6 additions & 6 deletions closure/goog/promise/promise_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ testSuite({
assertEquals(1, rejectionCall.getArguments().length);
const err = rejectionCall.getArguments()[0];
assertEquals('thenAlways throw', err.message);
assertEquals(goog.global, rejectionCall.getThis());
assertEquals(null, rejectionCall.getThis());
});

return p.thenAlways(() => {
Expand Down Expand Up @@ -2041,7 +2041,7 @@ testSuite({
assertEquals(1, unhandledRejections.getCallCount());
const rejectionCall = unhandledRejections.popLastCall();
assertArrayEquals([sentinel], rejectionCall.getArguments());
assertEquals(goog.global, rejectionCall.getThis());
assertEquals(null, rejectionCall.getThis());
},

testUnhandledRejection2() {
Expand All @@ -2052,7 +2052,7 @@ testSuite({
assertEquals(1, unhandledRejections.getCallCount());
const rejectionCall = unhandledRejections.popLastCall();
assertArrayEquals([sentinel], rejectionCall.getArguments());
assertEquals(goog.global, rejectionCall.getThis());
assertEquals(null, rejectionCall.getThis());
},

testThenVoidUnhandledRejection() {
Expand All @@ -2063,7 +2063,7 @@ testSuite({
assertEquals(1, unhandledRejections.getCallCount());
const rejectionCall = unhandledRejections.popLastCall();
assertArrayEquals([sentinel], rejectionCall.getArguments());
assertEquals(goog.global, rejectionCall.getThis());
assertEquals(null, rejectionCall.getThis());
},

testUnhandledRejection() {
Expand Down Expand Up @@ -2116,7 +2116,7 @@ testSuite({
assertEquals(1, unhandledRejections.getCallCount());
const rejectionCall = unhandledRejections.popLastCall();
assertArrayEquals([sentinel], rejectionCall.getArguments());
assertEquals(goog.global, rejectionCall.getThis());
assertEquals(null, rejectionCall.getThis());
},

testUnhandledRejectionAfterThenAlways() {
Expand All @@ -2129,7 +2129,7 @@ testSuite({
assertEquals(1, unhandledRejections.getCallCount());
const rejectionCall = unhandledRejections.popLastCall();
assertArrayEquals([sentinel], rejectionCall.getArguments());
assertEquals(goog.global, rejectionCall.getThis());
assertEquals(null, rejectionCall.getThis());
},

testHandledBlockingRejection() {
Expand Down
28 changes: 25 additions & 3 deletions closure/goog/testing/recordfunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ goog.testing.recordedFunction_.reset = function() {};
* @return {!goog.testing.recordFunction.Type} The wrapped function.
*/
goog.testing.recordFunction = function(opt_f) {
'use strict';
var f = opt_f || goog.nullFunction;
var calls = [];
/** @type {?goog.promise.Resolver} */
Expand Down Expand Up @@ -141,7 +142,10 @@ goog.testing.recordFunction = function(opt_f) {
/**
* @return {number} Total number of calls.
*/
recordedFunction.getCallCount = function() { return calls.length; };
recordedFunction.getCallCount = function() {
'use strict';
return calls.length;
};

/**
* Asserts that the function was called a certain number of times.
Expand All @@ -150,6 +154,7 @@ goog.testing.recordFunction = function(opt_f) {
* @param {number=} opt_b The expected number of calls (2 args only).
*/
recordedFunction.assertCallCount = function(a, opt_b) {
'use strict';
var actual = calls.length;
var expected = arguments.length == 1 ? a : opt_b;
var message = arguments.length == 1 ? '' : ' ' + a;
Expand All @@ -162,14 +167,18 @@ goog.testing.recordFunction = function(opt_f) {
* @return {!Array<!goog.testing.FunctionCall>} All calls of the recorded
* function.
*/
recordedFunction.getCalls = function() { return calls; };
recordedFunction.getCalls = function() {
'use strict';
return calls;
};


/**
* @return {goog.testing.FunctionCall} Last call of the recorded function or
* null if it hasn't been called.
*/
recordedFunction.getLastCall = function() {
'use strict';
return calls[calls.length - 1] || null;
};

Expand All @@ -178,7 +187,10 @@ goog.testing.recordFunction = function(opt_f) {
* @return {goog.testing.FunctionCall} Last call of the recorded function or
* null if it hasn't been called.
*/
recordedFunction.popLastCall = function() { return calls.pop() || null; };
recordedFunction.popLastCall = function() {
'use strict';
return calls.pop() || null;
};

/**
* Returns a goog.Promise that resolves when the recorded function has equal
Expand All @@ -187,6 +199,7 @@ goog.testing.recordFunction = function(opt_f) {
* @return {!goog.Promise<undefined>}
*/
recordedFunction.waitForCalls = function(num) {
'use strict';
waitForCallsCount = num;
waitForCallsResolver = goog.Promise.withResolver();
var promise = waitForCallsResolver.promise;
Expand All @@ -198,6 +211,7 @@ goog.testing.recordFunction = function(opt_f) {
* Resets the recorded function and removes all calls.
*/
recordedFunction.reset = function() {
'use strict';
calls.length = 0;
waitForCallsResolver = null;
waitForCallsCount = 0;
Expand All @@ -219,6 +233,7 @@ goog.testing.recordFunction.Type;
* @return {!Function} The wrapped function.
*/
goog.testing.recordConstructor = function(ctor) {
'use strict';
var recordedConstructor = goog.testing.recordFunction(ctor);
recordedConstructor.prototype = ctor.prototype;

Expand All @@ -241,6 +256,7 @@ goog.testing.recordConstructor = function(ctor) {
* @constructor
*/
goog.testing.FunctionCall = function(func, thisContext, args, ret, error) {
'use strict';
this.function_ = func;
this.thisContext_ = thisContext;
this.arguments_ = Array.prototype.slice.call(args);
Expand All @@ -253,6 +269,7 @@ goog.testing.FunctionCall = function(func, thisContext, args, ret, error) {
* @return {!Function} The called function.
*/
goog.testing.FunctionCall.prototype.getFunction = function() {
'use strict';
return this.function_;
};

Expand All @@ -262,6 +279,7 @@ goog.testing.FunctionCall.prototype.getFunction = function() {
* the created object if the function is a constructor.
*/
goog.testing.FunctionCall.prototype.getThis = function() {
'use strict';
return this.thisContext_;
};

Expand All @@ -270,6 +288,7 @@ goog.testing.FunctionCall.prototype.getThis = function() {
* @return {!Array<?>} Arguments of the called function.
*/
goog.testing.FunctionCall.prototype.getArguments = function() {
'use strict';
return this.arguments_;
};

Expand All @@ -280,6 +299,7 @@ goog.testing.FunctionCall.prototype.getArguments = function() {
* @return {*} The argument value or undefined if there is no such argument.
*/
goog.testing.FunctionCall.prototype.getArgument = function(index) {
'use strict';
return this.arguments_[index];
};

Expand All @@ -288,6 +308,7 @@ goog.testing.FunctionCall.prototype.getArgument = function(index) {
* @return {*} Return value of the function or undefined in case of error.
*/
goog.testing.FunctionCall.prototype.getReturnValue = function() {
'use strict';
return this.returnValue_;
};

Expand All @@ -296,5 +317,6 @@ goog.testing.FunctionCall.prototype.getReturnValue = function() {
* @return {*} The error thrown by the function or null if none.
*/
goog.testing.FunctionCall.prototype.getError = function() {
'use strict';
return this.error_;
};
6 changes: 3 additions & 3 deletions closure/goog/testing/recordfunction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ testSuite({
const lastCall = f.getLastCall();
assertEquals(
'original function', goog.nullFunction, lastCall.getFunction());
assertEquals('this context', window, lastCall.getThis());
assertEquals('this context', undefined, lastCall.getThis());
assertArrayEquals('arguments', [1], lastCall.getArguments());
assertEquals('arguments[0]', 1, lastCall.getArgument(0));
assertUndefined('arguments[1]', lastCall.getArgument(1));
Expand All @@ -54,7 +54,7 @@ testSuite({
assertEquals('last call', calls[1], lastCall);
assertEquals(
'original function', functions.identity, lastCall.getFunction());
assertEquals('this context of first call', window, firstCall.getThis());
assertEquals('this context of first call', undefined, firstCall.getThis());
assertEquals('this context of last call', dummyThis, lastCall.getThis());
assertArrayEquals(
'arguments of the first call', [1], firstCall.getArguments());
Expand All @@ -76,7 +76,7 @@ testSuite({
assertEquals('error message', 'error', error.message);
assertEquals('call count', 1, f.getCallCount());
const lastCall = f.getLastCall();
assertEquals('this context', window, lastCall.getThis());
assertEquals('this context', undefined, lastCall.getThis());
assertArrayEquals('arguments', [1], lastCall.getArguments());
assertUndefined('return value', lastCall.getReturnValue());
assertEquals(
Expand Down

0 comments on commit ccd76bd

Please sign in to comment.