From 3ae95f3a98c1837e7f33d59b69fac0b90393307b Mon Sep 17 00:00:00 2001 From: kangax Date: Wed, 16 Apr 2008 23:38:45 -0400 Subject: [PATCH] test for Object.keys/Object.values --- src/base.js | 3 --- test/unit/base.html | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/base.js b/src/base.js index 3335fe5..8a4d741 100644 --- a/src/base.js +++ b/src/base.js @@ -37,9 +37,6 @@ Class.Methods = { var ancestor = this.superclass && this.superclass.prototype; var properties = Object.keys(source); - if (!Object.keys({ toString: true }).length) - properties.push("toString", "valueOf"); - for (var i = 0, length = properties.length; i < length; i++) { var property = properties[i], value = source[property]; if (ancestor && Object.isFunction(value) && diff --git a/test/unit/base.html b/test/unit/base.html index 8af5c49..819db07 100644 --- a/test/unit/base.html +++ b/test/unit/base.html @@ -244,6 +244,29 @@ Object.extend(object, {bla: null})); }, + testObjectKeysObjectValues: function() { + var object = { + toString: true, + toLocaleString: false, + valueOf: 'foo', + hasOwnProperty: 'bar', + isPrototypeOf: Prototype.K, + propertyIsEnumerable: Prototype.emptyFunction, + constructor: {} + } + + /* for..in enumerates over prototype (!), so Object.keys(object_2).length yields 1 + var I = function(){}; + I.prototype.toString = function(){ return 'blah' }; + var object_2 = new I; + */ + this.assertIdentical(7, Object.keys(object).length); + this.assert(Object.keys(object).include('valueOf')); + + this.assertIdentical(7, Object.values(object).length); + this.assert(Object.values(object).include('bar')); + }, + testObjectToQueryString: function() { this.assertEqual('a=A&b=B&c=C&d=D%23', Object.toQueryString({a: 'A', b: 'B', c: 'C', d: 'D#'})); }, -- 1.5.3.8