Bug 32721
| Summary: | Allow Reserved Words in Object Literals | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Joseph Pecoraro <joepeck> |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED DUPLICATE | ||
| Severity: | Normal | CC: | erights, inimino, jwalden+bwo, pmuellr, skyul |
| Priority: | P2 | Keywords: | ES5 |
| Version: | 528+ (Nightly build) | ||
| Hardware: | PC | ||
| OS: | OS X 10.5 | ||
Joseph Pecoraro
Currently JavaScriptCore does not allow reserved words as property names in Object Literals:
jsc> var x = { import: 1 };
Exception: SyntaxError: Parse error
Other browsers seem to allow this right now. The above works in Chrome 4, FF 3.5, and Opera 10.
The Grammar rules are different. Notice that the last step is different (IdentifierName instead of Identifier).
ES3:
ObjectLiteral
→ PropertyNameAndValueList
→ PropertyName
→ Identifier
ES5:
ObjectLiteral
→ PropertyNameAndValueList
→ PropertyAssignment
→ PropertyName
→ IdentifierName
Workaround: (this is what JSON ended up doing)
jsc> var x = { 'import': 1 };
jsc> x['import']; // 1
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Patrick Mueller
See also Bug 32721, as that bug and this one can possibly be addressed with the similar patch to the grammar.
Jeff Walden (remove +bwo to email)
*** This bug has been marked as a duplicate of bug 42471 ***