mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Restore bizarro tests for Object.create.
This commit is contained in:
@@ -1315,7 +1315,6 @@
|
||||
|
||||
/** Built-in value references. */
|
||||
var Buffer = moduleExports ? context.Buffer : undefined,
|
||||
objectCreate = Object.create,
|
||||
Reflect = context.Reflect,
|
||||
Symbol = context.Symbol,
|
||||
Uint8Array = context.Uint8Array,
|
||||
@@ -1324,6 +1323,7 @@
|
||||
getPrototypeOf = Object.getPrototypeOf,
|
||||
getOwnPropertySymbols = Object.getOwnPropertySymbols,
|
||||
iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
|
||||
objectCreate = Object.create,
|
||||
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
||||
setTimeout = context.setTimeout,
|
||||
splice = arrayProto.splice;
|
||||
|
||||
@@ -82,6 +82,19 @@
|
||||
funcProto._method = noop;
|
||||
|
||||
// Set bad shims.
|
||||
setProperty(Object, '_create', Object.create);
|
||||
setProperty(Object, 'create', (function() {
|
||||
function object() {}
|
||||
return function(prototype) {
|
||||
if (prototype === Object(prototype)) {
|
||||
object.prototype = prototype;
|
||||
var result = new object;
|
||||
object.prototype = undefined;
|
||||
}
|
||||
return result || {};
|
||||
};
|
||||
}()));
|
||||
|
||||
setProperty(Object, '_getOwnPropertySymbols', Object.getOwnPropertySymbols);
|
||||
setProperty(Object, 'getOwnPropertySymbols', undefined);
|
||||
|
||||
@@ -130,6 +143,11 @@
|
||||
|
||||
setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
|
||||
|
||||
if (Object._create) {
|
||||
Object.create = Object._create;
|
||||
} else {
|
||||
delete Object.create;
|
||||
}
|
||||
if (Object._getOwnPropertySymbols) {
|
||||
Object.getOwnPropertySymbols = Object._getOwnPropertySymbols;
|
||||
} else {
|
||||
@@ -165,8 +183,9 @@
|
||||
setProperty(window, 'module', document.getElementById('module'));
|
||||
|
||||
delete funcProto._method;
|
||||
delete objectProto._propertyIsEnumerable;
|
||||
delete Object._create;
|
||||
delete Object._getOwnPropertySymbols;
|
||||
delete objectProto._propertyIsEnumerable;
|
||||
}
|
||||
|
||||
// Load lodash to expose it to the bad extensions/shims.
|
||||
|
||||
14
test/test.js
14
test/test.js
@@ -458,7 +458,7 @@
|
||||
// Allow bypassing native checks.
|
||||
setProperty(funcProto, 'toString', function wrapper() {
|
||||
setProperty(funcProto, 'toString', fnToString);
|
||||
var result = _.has(this, 'toString') ? this.toString() : fnToString.call(this);
|
||||
var result = lodashStable.has(this, 'toString') ? this.toString() : fnToString.call(this);
|
||||
setProperty(funcProto, 'toString', wrapper);
|
||||
return result;
|
||||
});
|
||||
@@ -467,6 +467,17 @@
|
||||
funcProto._method = noop;
|
||||
|
||||
// Set bad shims.
|
||||
setProperty(Object, 'create', (function() {
|
||||
function object() {}
|
||||
return function(prototype) {
|
||||
if (lodashStable.isObject(prototype)) {
|
||||
object.prototype = prototype;
|
||||
var result = new object;
|
||||
object.prototype = undefined;
|
||||
}
|
||||
return result || {};
|
||||
};
|
||||
}()));
|
||||
|
||||
var _getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
||||
setProperty(Object, 'getOwnPropertySymbols', undefined);
|
||||
@@ -519,6 +530,7 @@
|
||||
root._ = oldDash;
|
||||
|
||||
// Restore built-in methods.
|
||||
setProperty(Object, 'create', create);
|
||||
setProperty(objectProto, 'propertyIsEnumerable', _propertyIsEnumerable);
|
||||
setProperty(root, 'Buffer', Buffer);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user