Removed protections against user code redefining undefined

Jasmine hasn't even run on platforms that allowed redefining undefined
since 2.x.
This commit is contained in:
Steve Gravrock
2025-06-22 11:59:16 -07:00
parent 6891789ed2
commit 2d07b3e6d7
11 changed files with 32 additions and 65 deletions

View File

@@ -253,9 +253,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};
j$.isObject_ = function(value) {
return (
!j$.util.isUndefined(value) && value !== null && j$.isA_('Object', value)
);
return value !== undefined && value !== null && j$.isA_('Object', value);
};
j$.isString_ = function(value) {
@@ -676,10 +674,6 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
getJasmineRequireObj().util = function(j$) {
const util = {};
util.isUndefined = function(obj) {
return obj === void 0;
};
util.clone = function(obj) {
if (Object.prototype.toString.apply(obj) === '[object Array]') {
return obj.slice();
@@ -2315,7 +2309,7 @@ getJasmineRequireObj().Anything = function(j$) {
function Anything() {}
Anything.prototype.asymmetricMatch = function(other) {
return !j$.util.isUndefined(other) && other !== null;
return other !== undefined && other !== null;
};
Anything.prototype.jasmineToString = function() {
@@ -2976,7 +2970,7 @@ getJasmineRequireObj().clearStack = function(j$) {
function getUnclampedSetTimeout(global) {
const { setTimeout } = global;
if (j$.util.isUndefined(global.MessageChannel)) {
if (!global.MessageChannel) {
return setTimeout;
}
@@ -3036,10 +3030,7 @@ getJasmineRequireObj().clearStack = function(j$) {
// Unlike browsers, Node doesn't require us to do a periodic setTimeout
// so we avoid the overhead.
return nodeQueueMicrotaskImpl(global);
} else if (
SAFARI_OR_WIN_WEBKIT ||
j$.util.isUndefined(global.MessageChannel) /* tests */
) {
} else if (SAFARI_OR_WIN_WEBKIT || !global.MessageChannel /* tests */) {
// queueMicrotask is dramatically faster than MessageChannel in Safari
// and other WebKit-based browsers, such as the one distributed by Playwright
// to test Safari-like behavior on Windows.
@@ -4877,10 +4868,8 @@ getJasmineRequireObj().DiffBuilder = function(j$) {
const actualCustom = this.prettyPrinter_.customFormat_(actual);
const expectedCustom = this.prettyPrinter_.customFormat_(expected);
const useCustom = !(
j$.util.isUndefined(actualCustom) &&
j$.util.isUndefined(expectedCustom)
);
const useCustom =
actualCustom !== undefined || expectedCustom !== undefined;
if (useCustom) {
const prettyActual = actualCustom || this.prettyPrinter_(actual);
@@ -5139,13 +5128,13 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
bStack,
diffBuilder
);
if (!j$.util.isUndefined(asymmetricResult)) {
if (asymmetricResult !== undefined) {
return asymmetricResult;
}
for (const tester of this.customTesters_) {
const customTesterResult = tester(a, b);
if (!j$.util.isUndefined(customTesterResult)) {
if (customTesterResult !== undefined) {
if (!customTesterResult) {
diffBuilder.recordMismatch();
}
@@ -7527,7 +7516,7 @@ getJasmineRequireObj().MockDate = function(j$) {
if (mockDate instanceof GlobalDate) {
currentTime = mockDate.getTime();
} else {
if (!j$.util.isUndefined(mockDate)) {
if (mockDate !== undefined) {
throw new Error(
'The argument to jasmine.clock().mockDate(), if specified, ' +
'should be a Date instance.'
@@ -7744,7 +7733,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
if (customFormatResult) {
this.emitScalar(customFormatResult);
} else if (j$.util.isUndefined(value)) {
} else if (value === undefined) {
this.emitScalar('undefined');
} else if (value === null) {
this.emitScalar('null');
@@ -9843,7 +9832,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
this.spyOn = function(obj, methodName) {
const getErrorMsg = spyOnMsg;
if (j$.util.isUndefined(obj) || obj === null) {
if (obj === undefined || obj === null) {
throw new Error(
getErrorMsg(
'could not find an object to spy upon for ' + methodName + '()'
@@ -9851,11 +9840,11 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
);
}
if (j$.util.isUndefined(methodName) || methodName === null) {
if (methodName === undefined || methodName === null) {
throw new Error(getErrorMsg('No method name supplied'));
}
if (j$.util.isUndefined(obj[methodName])) {
if (obj[methodName] === undefined) {
throw new Error(getErrorMsg(methodName + '() method does not exist'));
}
@@ -9920,7 +9909,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
accessType = accessType || 'get';
if (j$.util.isUndefined(obj)) {
if (!obj) {
throw new Error(
getErrorMsg(
'spyOn could not find an object to spy upon for ' +
@@ -9930,7 +9919,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
);
}
if (j$.util.isUndefined(propertyName)) {
if (propertyName === undefined) {
throw new Error(getErrorMsg('No property name supplied'));
}
@@ -9995,7 +9984,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
};
this.spyOnAllFunctions = function(obj, includeNonEnumerable) {
if (j$.util.isUndefined(obj)) {
if (!obj) {
throw new Error(
'spyOnAllFunctions could not find an object to spy upon'
);

View File

@@ -128,17 +128,6 @@ describe('util', function() {
});
});
describe('isUndefined', function() {
it('reports if a variable is defined', function() {
let a;
expect(jasmineUnderTest.util.isUndefined(a)).toBe(true);
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(true);
const defined = 'diz be undefined yo';
expect(jasmineUnderTest.util.isUndefined(defined)).toBe(false);
});
});
describe('cloneArgs', function() {
it('clones primitives as-is', function() {
expect(jasmineUnderTest.util.cloneArgs([true, false])).toEqual([

View File

@@ -44,7 +44,7 @@ getJasmineRequireObj().clearStack = function(j$) {
function getUnclampedSetTimeout(global) {
const { setTimeout } = global;
if (j$.util.isUndefined(global.MessageChannel)) {
if (!global.MessageChannel) {
return setTimeout;
}
@@ -104,10 +104,7 @@ getJasmineRequireObj().clearStack = function(j$) {
// Unlike browsers, Node doesn't require us to do a periodic setTimeout
// so we avoid the overhead.
return nodeQueueMicrotaskImpl(global);
} else if (
SAFARI_OR_WIN_WEBKIT ||
j$.util.isUndefined(global.MessageChannel) /* tests */
) {
} else if (SAFARI_OR_WIN_WEBKIT || !global.MessageChannel /* tests */) {
// queueMicrotask is dramatically faster than MessageChannel in Safari
// and other WebKit-based browsers, such as the one distributed by Playwright
// to test Safari-like behavior on Windows.

View File

@@ -15,7 +15,7 @@ getJasmineRequireObj().MockDate = function(j$) {
if (mockDate instanceof GlobalDate) {
currentTime = mockDate.getTime();
} else {
if (!j$.util.isUndefined(mockDate)) {
if (mockDate !== undefined) {
throw new Error(
'The argument to jasmine.clock().mockDate(), if specified, ' +
'should be a Date instance.'

View File

@@ -16,7 +16,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
if (customFormatResult) {
this.emitScalar(customFormatResult);
} else if (j$.util.isUndefined(value)) {
} else if (value === undefined) {
this.emitScalar('undefined');
} else if (value === null) {
this.emitScalar('null');

View File

@@ -25,7 +25,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
this.spyOn = function(obj, methodName) {
const getErrorMsg = spyOnMsg;
if (j$.util.isUndefined(obj) || obj === null) {
if (obj === undefined || obj === null) {
throw new Error(
getErrorMsg(
'could not find an object to spy upon for ' + methodName + '()'
@@ -33,11 +33,11 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
);
}
if (j$.util.isUndefined(methodName) || methodName === null) {
if (methodName === undefined || methodName === null) {
throw new Error(getErrorMsg('No method name supplied'));
}
if (j$.util.isUndefined(obj[methodName])) {
if (obj[methodName] === undefined) {
throw new Error(getErrorMsg(methodName + '() method does not exist'));
}
@@ -102,7 +102,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
accessType = accessType || 'get';
if (j$.util.isUndefined(obj)) {
if (!obj) {
throw new Error(
getErrorMsg(
'spyOn could not find an object to spy upon for ' +
@@ -112,7 +112,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
);
}
if (j$.util.isUndefined(propertyName)) {
if (propertyName === undefined) {
throw new Error(getErrorMsg('No property name supplied'));
}
@@ -177,7 +177,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
};
this.spyOnAllFunctions = function(obj, includeNonEnumerable) {
if (j$.util.isUndefined(obj)) {
if (!obj) {
throw new Error(
'spyOnAllFunctions could not find an object to spy upon'
);

View File

@@ -2,7 +2,7 @@ getJasmineRequireObj().Anything = function(j$) {
function Anything() {}
Anything.prototype.asymmetricMatch = function(other) {
return !j$.util.isUndefined(other) && other !== null;
return other !== undefined && other !== null;
};
Anything.prototype.jasmineToString = function() {

View File

@@ -73,9 +73,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};
j$.isObject_ = function(value) {
return (
!j$.util.isUndefined(value) && value !== null && j$.isA_('Object', value)
);
return value !== undefined && value !== null && j$.isA_('Object', value);
};
j$.isString_ = function(value) {

View File

@@ -31,10 +31,8 @@ getJasmineRequireObj().DiffBuilder = function(j$) {
const actualCustom = this.prettyPrinter_.customFormat_(actual);
const expectedCustom = this.prettyPrinter_.customFormat_(expected);
const useCustom = !(
j$.util.isUndefined(actualCustom) &&
j$.util.isUndefined(expectedCustom)
);
const useCustom =
actualCustom !== undefined || expectedCustom !== undefined;
if (useCustom) {
const prettyActual = actualCustom || this.prettyPrinter_(actual);

View File

@@ -177,13 +177,13 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
bStack,
diffBuilder
);
if (!j$.util.isUndefined(asymmetricResult)) {
if (asymmetricResult !== undefined) {
return asymmetricResult;
}
for (const tester of this.customTesters_) {
const customTesterResult = tester(a, b);
if (!j$.util.isUndefined(customTesterResult)) {
if (customTesterResult !== undefined) {
if (!customTesterResult) {
diffBuilder.recordMismatch();
}

View File

@@ -1,10 +1,6 @@
getJasmineRequireObj().util = function(j$) {
const util = {};
util.isUndefined = function(obj) {
return obj === void 0;
};
util.clone = function(obj) {
if (Object.prototype.toString.apply(obj) === '[object Array]') {
return obj.slice();