Created
November 18, 2011 23:39
-
-
Save aadsm/1378111 to your computer and use it in GitHub Desktop.
Chrome and Safari issue creating new properties that were defined has writable: false in the prototype chain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <!-- | |
| o.foo (o.hasOwnProperty("foo") === true) shouldn't be created because o's prototype "foo" descriptor has writable === false. | |
| According to the 5th version of Ecma-262 (http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf): | |
| 11.13.1 Simple Assignment ( = ) | |
| The production AssignmentExpression : LeftHandSideExpression = AssignmentExpression is evaluated as follows: | |
| [...] | |
| 5. Call PutValue(lref, rval). | |
| [...] | |
| 8.7.2 PutValue (V, W) | |
| [...] | |
| 3. If IsUnresolvableReference(V), then | |
| b. Call the [[Put]] internal method of the global object, passing GetReferencedName( V) for the property name, W for the value, and false for the Throw flag. | |
| [...] | |
| 8.12.5 [[Put]] ( P, V, Throw ) | |
| 1. If the result of calling the [[CanPut]] internal method of O with argument P is false, then | |
| [...] | |
| b. Else return. | |
| [...] | |
| 8.12.4 [[CanPut]] (P) | |
| [...] | |
| 3. Let proto be the [[Prototype]] internal property of O. | |
| [...] | |
| 5. Let inherited be the result of calling the [[GetProperty]] internal method of proto with property name P. | |
| [...] | |
| 8. Else, inherited must be a DataDescriptor | |
| [...] | |
| b. Else return the value of inherited.[[Writable]]. | |
| 8.12.2 [[GetProperty]] (P) | |
| 1. Let prop be the result of calling the [[GetOwnProperty]] internal method of O with property name P. | |
| 2. If prop is not undefined, return prop. | |
| [...] | |
| 8.12.1 [[GetOwnProperty]] (P) | |
| 1. I f O doesn‘t have an own property with name P, return undefined. | |
| 2. Let D be a newly created Property Descriptor with no fields. | |
| 3. Let X be O‘s own property named P. | |
| 4. If X is a data property, then | |
| a. Set D.[[Value]] to the value of X‘s [[Value]] attribute. | |
| b. Set D.[[Writable]] to the value of X‘s [[Writable]] attribute | |
| [...] | |
| 6. Set D.[[Enumerable]] to the value of X‘s [[Enumerable]] attribute. | |
| 7. Set D.[[Configurable]] to the value of X‘s [[Configurable]] attribute. | |
| 8. Return D. | |
| --> | |
| <script> | |
| // http://jsfiddle.net/sSDme/1/ | |
| var Super = Object.create(Object.prototype, { | |
| foo: { | |
| value: null, | |
| writable: false // the default and what makes [[CanPut]] return false at 8.b) | |
| } | |
| }); | |
| var o = Object.create(Super); | |
| Super.foo = false; | |
| o.foo = true; | |
| console.log("Super.foo: " + Super.foo); | |
| console.log("o.foo: " + o.foo); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment