Closed Bug 423557 Opened 17 years ago Closed 14 years ago

Compiler chokes on keywords as object properties

Categories

(Rhino Graveyard :: Compiler, defect)

x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: cwolves, Assigned: hannesw)

Details

Attachments

(1 file)

User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12 Build Identifier: rhino1_6R7 The following snippets cause compiler errors, all are valid: var x = {int:5}; var x = {for:5}; var x = {continue:5}; var x = {while:5}; ...etc var x = {'int': 5}; // passes this, but... alert(x.int); // fails Reproducible: Always Steps to Reproduce: 1. 2. 3.
I know alert isn't valid, I wasn't thinking about it. Change that to whatever, the "x.int" still breaks.
Severity: normal → critical
Okay, looking into this more I found that Rhino follows the ECMAScript Grammar on this while every browser I've tested (FF, Opera, Safari, IE) allows the behavior. I suppose the question is what Rhino should be following closer :-) A simple browser test: javascript:alert({int:5}.int); From ECMA-262 E3: ReservedWord :: See section 7.5.1 Keyword FutureReservedWord NullLiteral BooleanLiteral Keyword :: one of See section 7.5.2 break else new var case finally return void catch for switch while continue function this with default if throw delete in try do instanceof typeof FutureReservedWord :: one of See section 7.5.3 abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws const goto private transient debugger implements protected volatile double import public Identifier :: IdentifierName but not ReservedWord
Severity: critical → normal
IE6 permits this: var foo = {int: 5} but NOT any of the following: var foo = {return: 5} var foo = {for: 5} var foo = {while: 5} var foo = {if: 5} So technically IE is only permitting non-keyword reserved words as identifiers. (Haven't verified it for all keywords, but that's my hunch.)
This patch allows all keywords as property ids if Context.FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER is enabled. In the meantime all major browsers allow this, so it's time to catch up.
Assignee: nobody → hannes
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Committed my patch. Checking in src/org/mozilla/javascript/Token.java; /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/Token.java,v <-- Token.java new revision: 1.47; previous revision: 1.46 done Checking in src/org/mozilla/javascript/Parser.java; /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/Parser.java,v <-- Parser.java new revision: 1.157; previous revision: 1.156 done RCS file: /cvsroot/mozilla/js/rhino/testsrc/doctests/423557.doctest,v done Checking in testsrc/doctests/423557.doctest; /cvsroot/mozilla/js/rhino/testsrc/doctests/423557.doctest,v <-- 423557.doctest initial revision: 1.1 done
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: