diff --git a/lodash.js b/lodash.js index 28681263a..4aa0a00d4 100644 --- a/lodash.js +++ b/lodash.js @@ -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; diff --git a/test/index.html b/test/index.html index b17a37108..965da3333 100644 --- a/test/index.html +++ b/test/index.html @@ -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. diff --git a/test/test.js b/test/test.js index fe161a24b..d98aedb48 100644 --- a/test/test.js +++ b/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);