Ensure Hash does not return keys from the prototype chain (e.g., constructor, valueOf, toString).

This commit is contained in:
Andrew Dupont 2008-05-23 13:31:29 -05:00 committed by Tobie Langel
parent 64002a9083
commit b31f642e64
3 changed files with 8 additions and 1 deletions

View File

@ -1,3 +1,5 @@
* Ensure Hash does not return keys from the prototype chain (e.g., constructor, valueOf, toString). (kangax)
* Fix toString/valueOf sharing same method reference via closure in Class#addMethods. Use plain property assignment, since Object.extend fails to enumerate over toString/valueOf. (kangax)
* Stop Form.Element.disable from stealing focus. (jddalton)

View File

@ -28,7 +28,9 @@ var Hash = Class.create(Enumerable, (function() {
},
get: function(key) {
return this._object[key];
// simulating poorly supported hasOwnProperty
if (this._object[key] !== Object.prototype[key])
return this._object[key];
},
unset: function(key) {

View File

@ -14,6 +14,9 @@ new Test.Unit.Runner({
this.assertEqual('A', h.get('a'));
this.assertUndefined(h.a);
this.assertUndefined($H({}).get('a'));
this.assertUndefined($H({}).get('toString'));
this.assertUndefined($H({}).get('constructor'));
},
testUnset: function() {