From 5cbc44610cbaf7a2a8e10280c909977315ae4642 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 30 Jul 2014 00:00:22 -0700 Subject: [PATCH] Simplify support property detection. --- lodash.js | 6 ++---- test/index.html | 23 ++++++++++------------- test/test.js | 6 +++--- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/lodash.js b/lodash.js index 81a603b6d..77a73250b 100644 --- a/lodash.js +++ b/lodash.js @@ -852,8 +852,6 @@ Ctor.prototype = { 'valueOf': 1, 'y': 1 }; for (var key in new Ctor) { props.push(key); } - for (var argsKey in arguments) {} - for (var strKey in 'x') {} /** * Detect if the `[[Class]]` of `arguments` objects is resolvable @@ -912,7 +910,7 @@ * @memberOf _.support * @type boolean */ - support.nonEnumStrings = strKey != '0'; + support.nonEnumStrings = !propertyIsEnumerable.call('x', 0); /** * Detect if properties shadowing those on `Object.prototype` are @@ -1001,7 +999,7 @@ * @type boolean */ try { - support.nonEnumArgs = !(hasOwnProperty.call(arguments, 1) && propertyIsEnumerable.call(arguments, 1)); + support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1); } catch(e) { support.nonEnumArgs = true; } diff --git a/test/index.html b/test/index.html index 598d3a9c0..67e85f4e4 100644 --- a/test/index.html +++ b/test/index.html @@ -100,19 +100,16 @@ setProperty(Object, '_keys', Object.keys); setProperty(Object, 'keys', noop); - setProperty(objectProto, 'hasOwnProperty', (function() { - function wrapper(key) { - if (key == '1' && this && typeof this == 'object' && this.length === 2 && - hasOwnProperty.call(this, 'callee') && - !propertyIsEnumerable.call(this, 'callee') && - this[0] === 0 && this[1] === 0) { - throw new Error; - } - return hasOwnProperty.call(this, key); + setProperty(objectProto, '_propertyIsEnumerable', propertyIsEnumerable); + setProperty(objectProto, 'propertyIsEnumerable', function(key) { + if (key == '1' && this && typeof this == 'object' && this.length === 2 && + hasOwnProperty.call(this, 'callee') && + !propertyIsEnumerable.call(this, 'callee') && + this[0] === 0 && this[1] === 0) { + throw new Error; } - setProperty(objectProto, '_hasOwnProperty', hasOwnProperty); - return wrapper; - }())); + return propertyIsEnumerable.call(this, key); + }); setProperty(Number, '_isFinite', Number.isFinite); setProperty(Number, 'isFinite', noop); @@ -228,7 +225,7 @@ } else { delete stringProto.contains; } - setProperty(objectProto, 'hasOwnProperty', objectProto._hasOwnProperty); + setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable); document.createDocumentFragment = document._createDocumentFragment; setProperty(document, '_createDocumentFragment', undefined); diff --git a/test/test.js b/test/test.js index e77cb4c0c..918bb88ec 100644 --- a/test/test.js +++ b/test/test.js @@ -375,8 +375,8 @@ var _keys = Object.keys; setProperty(Object, 'keys', _.noop); - var _hasOwnProperty = objectProto.hasOwnProperty; - setProperty(objectProto, 'hasOwnProperty', function(key) { + var _propertyIsEnumerable = objectProto.propertyIsEnumerable; + setProperty(objectProto, 'propertyIsEnumerable', function(key) { if (key == '1' && _.isArguments(this) && _.isEqual(_.values(this), [0, 0])) { throw new Error; } @@ -463,7 +463,7 @@ setProperty(Object, 'getPrototypeOf', _getPrototypeOf); setProperty(Object, 'keys', _keys); - setProperty(objectProto, 'hasOwnProperty', _hasOwnProperty); + setProperty(objectProto, 'propertyIsEnumerable', _propertyIsEnumerable); setProperty(root, 'parseInt', _parseInt); if (_isFinite) {