Closed
Bug 508527
Opened 15 years ago
Closed 15 years ago
missing array elements contribute to the length of the array
Categories
(Rhino Graveyard :: Core, defect)
Rhino Graveyard
Core
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: rspeyer, Assigned: norrisboyd)
References
Details
Attachments
(1 file, 2 obsolete files)
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.196 Safari/532.0 Build Identifier: Rhino 1.7 release 2 2009 03 22 From 11.1.4 of the spec: "Array elements may be elided at the beginning, middle or end of the element list. Whenever a comma in the element list is not preceded by an AssignmentExpression (i.e., a comma at the beginning or after another comma), the missing array element contributes to the length of the Array and increases the index of subsequent elements. Elided array elements are not defined. If an element is elided at the end of an array, that element does not contribute to the length of the Array." Reproducible: Always Actual Results: js> [,1,2].length 3 js> [1,,2].length 3 js> [1,2,].length 2 js> [,].length 0 js> [1,,].length 1 Expected Results: js> [,1,2].length 3 js> [1,,2].length 3 js> [1,2,].length 2 js> [,].length 1 js> [1,,].length 2
Replacement for attachment 392691 [details] [diff] [review]. Added doctests.
Attachment #392691 -
Attachment is obsolete: true
Assignee | ||
Comment 3•15 years ago
|
||
You need to explicitly create a NativeArray rather than relying upon cx.newObject. The older code was written before it was explicitly standardized that array literals should call the standard built-in constructor. With your patch the following happens: js> function Array() { print('hi'); } js> var a = [] hi Exception in thread "main" java.lang.ClassCastException: org.mozilla.javascript.NativeObject cannot be cast to org.mozilla.javascript.NativeArray at org.mozilla.javascript.ScriptRuntime.newArrayLiteral(ScriptRuntime.java:3469) at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:2059) at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:845) at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164) at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3090) at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175) at org.mozilla.javascript.tools.shell.Main.evaluateScript(Main.java:563) at org.mozilla.javascript.tools.shell.Main.processSource(Main.java:424) at org.mozilla.javascript.tools.shell.Main.processFiles(Main.java:196) at org.mozilla.javascript.tools.shell.Main$IProxy.run(Main.java:117) at org.mozilla.javascript.Context.call(Context.java:522) at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:535) at org.mozilla.javascript.tools.shell.Main.exec(Main.java:179) at org.mozilla.javascript.tools.shell.Main.main(Main.java:157)
Assignee: nobody → norrisboyd
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attachment #392692 -
Attachment is obsolete: true
Assignee | ||
Comment 5•15 years ago
|
||
Checking in src/org/mozilla/javascript/ScriptRuntime.java; /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java,v <-- ScriptRuntime.java new revision: 1.319; previous revision: 1.318 done Checking in testsrc/doctests/array.length.doctest; /cvsroot/mozilla/js/rhino/testsrc/doctests/array.length.doctest,v <-- array.length.doctest initial revision: 1.1 done
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•