Closed Bug 454969 Opened 18 years ago Closed 17 years ago

destructuring for-in loop fails in top-level scope

Categories

(Rhino Graveyard :: Core, defect)

x86
All
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: hannesw, Assigned: norrisboyd)

Details

Attachments

(1 file)

User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.0.1) Gecko/2008072820 Firefox/3.0.1 Build Identifier: Doing a for-in loop with a destructuring key-value assignment on a top-level scope currently throws a NullPointerException. Reproducible: Always Steps to Reproduce: Run the following in the Rhino shell: for (var [i, j] in this) print(i, j); Actual Results: Exception in thread "main" java.lang.NullPointerException at org.mozilla.javascript.ScriptableObject.getTopLevelScope(ScriptableObject.java:1514) at org.mozilla.javascript.ScriptRuntime.setObjectProtoAndParent(ScriptRuntime.java:3291) at org.mozilla.javascript.Context.newArray(Context.java:1439) at org.mozilla.javascript.ScriptRuntime.enumId(ScriptRuntime.java:2023) at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3581) at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2484) at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162) at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003) at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:173) at org.mozilla.javascript.tools.shell.Main.evaluateScript(Main.java:526) at org.mozilla.javascript.tools.shell.Main.processSource(Main.java:386) at org.mozilla.javascript.tools.shell.Main.processFiles(Main.java:179) at org.mozilla.javascript.tools.shell.Main$IProxy.run(Main.java:100) at org.mozilla.javascript.Context.call(Context.java:499) at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:511) at org.mozilla.javascript.tools.shell.Main.exec(Main.java:162) at org.mozilla.javascript.tools.shell.Main.main(Main.java:140)
The problem is that ScriptRuntime passes the parent scope of the current object to Context.newArray(), which is null for the top level scope.
Assignee: nobody → norrisboyd
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Committed patch to CVS HEAD: Checking in src/org/mozilla/javascript/ScriptRuntime.java; /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java,v <-- ScriptRuntime.java new revision: 1.306; previous revision: 1.305 done
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
I copied this fix to the 1.7R2 branch.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: