mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Add test for incorrectly shimmed Object.create.
This commit is contained in:
@@ -24,6 +24,9 @@
|
|||||||
Function.prototype._bind = Function.prototype.bind;
|
Function.prototype._bind = Function.prototype.bind;
|
||||||
Function.prototype.bind = function() { return function() {}; };
|
Function.prototype.bind = function() { return function() {}; };
|
||||||
|
|
||||||
|
Object._create = Object.create;
|
||||||
|
Object.create = function() {};
|
||||||
|
|
||||||
Object._defineProperty = Object.defineProperty;
|
Object._defineProperty = Object.defineProperty;
|
||||||
Object.defineProperty = function() {};
|
Object.defineProperty = function() {};
|
||||||
|
|
||||||
@@ -48,6 +51,11 @@
|
|||||||
} else {
|
} else {
|
||||||
delete Function.prototype.bind;
|
delete Function.prototype.bind;
|
||||||
}
|
}
|
||||||
|
if (Object._create) {
|
||||||
|
Object.create = Object._create;
|
||||||
|
} else {
|
||||||
|
delete Object.create;
|
||||||
|
}
|
||||||
if (Object._defineProperty) {
|
if (Object._defineProperty) {
|
||||||
Object.defineProperty = Object._defineProperty;
|
Object.defineProperty = Object._defineProperty;
|
||||||
} else {
|
} else {
|
||||||
@@ -60,6 +68,7 @@
|
|||||||
}
|
}
|
||||||
delete Array._isArray;
|
delete Array._isArray;
|
||||||
delete Function.prototype._bind;
|
delete Function.prototype._bind;
|
||||||
|
delete Object._create;
|
||||||
delete Object._defineProperty;
|
delete Object._defineProperty;
|
||||||
delete Object._keys;
|
delete Object._keys;
|
||||||
|
|
||||||
|
|||||||
29
test/test.js
29
test/test.js
@@ -261,7 +261,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('avoids overwritten native methods', 3, function() {
|
test('avoids overwritten native methods', 4, function() {
|
||||||
function message(methodName) {
|
function message(methodName) {
|
||||||
return '`_.' + methodName + '` should avoid overwritten native methods';
|
return '`_.' + methodName + '` should avoid overwritten native methods';
|
||||||
}
|
}
|
||||||
@@ -271,21 +271,40 @@
|
|||||||
if (document) {
|
if (document) {
|
||||||
try {
|
try {
|
||||||
var actual = lodashBadShim.bind(function() { return this.a; }, object)();
|
var actual = lodashBadShim.bind(function() { return this.a; }, object)();
|
||||||
} catch(e) { }
|
} catch(e) {
|
||||||
|
actual = null;
|
||||||
|
}
|
||||||
ok(actual, message('bind'));
|
ok(actual, message('bind'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
actual = lodashBadShim.isArray([]);
|
actual = lodashBadShim.isArray([]);
|
||||||
} catch(e) { }
|
} catch(e) {
|
||||||
|
actual = null;
|
||||||
|
}
|
||||||
ok(actual, message('isArray'));
|
ok(actual, message('isArray'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
actual = lodashBadShim.keys(object);
|
actual = lodashBadShim.keys(object);
|
||||||
} catch(e) { }
|
} catch(e) {
|
||||||
|
actual = null;
|
||||||
|
}
|
||||||
deepEqual(actual, ['a'], message('keys'));
|
deepEqual(actual, ['a'], message('keys'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
var Foo = function() {
|
||||||
|
this.a = 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
var actual = _.transform(new Foo, function(result, value, key) {
|
||||||
|
result[key] = value * value;
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
actual = null;
|
||||||
|
}
|
||||||
|
ok(actual instanceof Foo, message('transform'));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(3);
|
skipTest(4);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user