-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with destructuring array assignment(?) #1187
Comments
I assume changes were made to implement new features or fix bugs and that those had an unexpected side effect |
ref. #1519, #1520
|
This code will reproduce it. // ElementGet.getElement() is not transformable.
var a = []; var b = 0; [a[b+1]] = [123];
// ElementGet.getTarget() is not transformable.
var a = []; [(NaN, a)[0]] = [123];
// PropertyGet.getTarget() is not transformable.
var a = {}; [(NaN, a).b] = [123]; This will fix it. diff --git a/rhino/src/main/java/org/mozilla/javascript/IRFactory.java b/rhino/src/main/java/org/mozilla/javascript/IRFactory.java
index 723f7d1..4841f3f 100644
--- a/rhino/src/main/java/org/mozilla/javascript/IRFactory.java
+++ b/rhino/src/main/java/org/mozilla/javascript/IRFactory.java
@@ -102,6 +102,7 @@ public final class IRFactory {
parser = new Parser(env, errorReporter);
astNodePos = new AstNodePosition(sourceString);
parser.currentPos = astNodePos;
+ parser.irFactory = this;
}
/** Transforms the tree into a lower-level IR suitable for codegen. */
@@ -129,7 +130,7 @@ public final class IRFactory {
// functions into the AstNode subclasses. OTOH that would make
// IR transformation part of the public AST API - desirable?
// Another possibility: create AstTransformer interface and adapter.
- private Node transform(AstNode node) {
+ Node transform(AstNode node) {
switch (node.getType()) {
case Token.ARRAYCOMP:
return transformArrayComp((ArrayComprehension) node);
diff --git a/rhino/src/main/java/org/mozilla/javascript/Parser.java b/rhino/src/main/java/org/mozilla/javascript/Parser.java
index 754dc43..e616f85 100644
--- a/rhino/src/main/java/org/mozilla/javascript/Parser.java
+++ b/rhino/src/main/java/org/mozilla/javascript/Parser.java
@@ -157,6 +157,8 @@ public class Parser {
private boolean defaultUseStrictDirective;
+ IRFactory irFactory;
+
// Exception to unwind
public static class ParserException extends RuntimeException {
private static final long serialVersionUID = 5882582646773765630L;
@@ -4236,11 +4238,11 @@ public class Parser {
// override getFirstChild/getLastChild and return the appropriate
// field, but that seems just as ugly as this casting.
if (left instanceof PropertyGet) {
- obj = ((PropertyGet) left).getTarget();
+ obj = irFactory.transform(((PropertyGet) left).getTarget());
id = ((PropertyGet) left).getProperty();
} else if (left instanceof ElementGet) {
- obj = ((ElementGet) left).getTarget();
- id = ((ElementGet) left).getElement();
+ obj = irFactory.transform(((ElementGet) left).getTarget());
+ id = irFactory.transform(((ElementGet) left).getElement());
} else {
// This branch is called during IRFactory transform pass.
obj = left.getFirstChild(); However, this is too tightly coupled to the |
The following cannot be evaluated and leads to an exception with 1.7R3 and later
var a = [1, 2]; var b = 0; [a[b+1], a[b]] = [a[b], a[b+1]]; a[0]
Exception:
But it is evaluated with 1.7R2 (to "2"). I really don't understand why this works in a very old version and fails in all newer versions.
The only thing that works is removing the "+" in the array access:
var a = [1, 2]; var b = 0; var c = 1; [a[c], a[b]] = [a[b], a[c]]; a[0]
Minimal Java example here (and attached)
https://github.com/ndeuma/rhino-bugtest
rhino-bugtest.zip
The text was updated successfully, but these errors were encountered: