On Nov 28, 2012, at 6:40 PM, Andrea Giammarchi wrote:

> This was not true at some point, but now it seems to be the case in every 
> browser.
> 
> Just 
> Object.prototype.get = function(){};
> 
> and any further attempt to use Object.defineProperty(obj, key, {value:123}) 
> will fail because defineProperty checks inherited get property, or set, and 
> these cannot be used together with value ... 
> 
> Is this a bug or kinda a joke ?

It's what the ES5/5.1 spec says. this is the first time I've seen this raised 
as an issue and as far as I know it was always been that way.

It conceivably could be changed to only check own properties but I wonder if 
that might not break more code than that which actually has this problem.  
There are at least semi-plausable reasons why you might want to intentionally 
use inherited properties in a property descriptor:

var defaultDataProperty = {enumerable: true, configurable: true, writable: 
true};

Object.defineProperty(obj,key, Object.create(defaultDataProperty, {value: 123});

Who knows whether anybody does things like this.

You can protect yourself against exposure to such Object.prototype attacks  by 
using patterns like:

Object.defineProperty(obj,key,Object.create(null, {value:       123};

Allen





> 
> Scary stuff, IMHO, thanks for clarifications.
> 
> br
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to