-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[[FIX]] Improve support for
__proto__
identifier
Information about identifiers used are stored internally as properties of objects whose key values are the identifier value. Because of non-standard implementations of the `__proto__` property, input source code that uses it as an identifier can have inconsistent side effects across environments. When using an object as a lookup table, the built-in `Object.hasOwnProperty` is generally preferable for detecting property membership. Unfortunately, due to the non-standard implementations described above, this check has environment-specific results. An alternate approach to membership detection is coercing direct property references to a boolean value. This is not appropriate in cases where the entries may themselves be "falsey" values, but in the identifier lookup tables, entries are consistently object literals. This second approach yields the same results across all legacy environments and is also compatable with the standardized specification for the `__proto__` attribute (provided the table is initialized to have no prototype). `var o = {};` | Compliant | Node.js v0.10.40 | IE9 | PhantomJS v1.9 ------------------------------------------ | --------- | ---------------- | ----- | -------------- **Before `__proto__` assignment** | | | | !!o.__proto__ | true | true | false | true '__proto__' in o | true | true | false | true Object.hasOwnProperty.call(o, '__proto__') | false | false | false | true Object.keys(o).length | 0 | 0 | 0 | 0 **After `__proto__` assignment** | | | | !!o.__proto__ | true | true | true | true '__proto__' in o | true | true | true | true Object.hasOwnProperty.call(o, '__proto__') | false | false | true | true Object.keys(o).length | 0 | 0 | 1 | 0 `var o = Object.create(null);` | Compliant | Node.js v0.10.40 | IE9 | PhantomJS v1.9 ------------------------------------------ | --------- | ---------------- | ----- | -------------- **Before `__proto__` assignment** | | | | !!o.__proto__ | false | false | false | false '__proto__' in o | false | true | false | true Object.hasOwnProperty.call(o, '__proto__') | false | false | false | true Object.keys(o).length | 0 | 0 | 0 | 0 **After `__proto__` assignment** | | | | !!o.__proto__ | true | true | true | true '__proto__' in o | true | true | true | true Object.hasOwnProperty.call(o, '__proto__') | true | false | true | true Object.keys(o).length | 1 | 0 | 1 | 0 Compliant enviroments: latest SpiderMonkey (and Firefox), latest V8 (and Chrome), Node.js v0.12.7, Iojs v.2.3.4 Update all lookup tables to be created without a prototype, and update all membership tests to simply coerce direct attribute references.
- Loading branch information
1 parent
56c19a5
commit 925a983
Showing
3 changed files
with
174 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Oops, something went wrong.