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