Bug 32721 - Allow Reserved Words in Object Literals
Summary: Allow Reserved Words in Object Literals
Status: RESOLVED DUPLICATE of bug 42471
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords: ES5
Depends on:
Blocks:
 
Reported: 2009-12-18 10:17 PST by Joseph Pecoraro
Modified: 2011-01-24 07:32 PST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2009-12-18 10:17:07 PST
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
Comment 1 Patrick Mueller 2010-01-06 11:50:00 PST
See also Bug 32721, as that bug and this one can possibly be addressed with the similar patch to the grammar.
Comment 2 Jeff Walden (remove +bwo to email) 2011-01-24 07:32:52 PST

*** This bug has been marked as a duplicate of bug 42471 ***