further as2/3 execution fixes

This commit is contained in:
honfika@gmail.com
2015-11-18 17:18:14 +01:00
parent 50f8c42af5
commit 9b03c3d5de
10 changed files with 246 additions and 45 deletions

View File

@@ -46,7 +46,7 @@ public class MBStringExtractActionItem extends ActionItem {
}
public MBStringExtractActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem value, GraphTargetItem index, GraphTargetItem count) {
super(instruction, lineStartIns, PRECEDENCE_PRIMARY, value);
super(instruction, lineStartIns, PRECEDENCE_PRIMARY, value);
this.index = index;
this.count = count;
}
@@ -80,10 +80,10 @@ public class MBStringExtractActionItem extends ActionItem {
public static String getResult(Object count, Object index, Object value) {
String str = EcmaScript.toString(value);
int idx = (int) (double) EcmaScript.toNumberAs2(index);
int idx = EcmaScript.toInt32(index);
idx--; // index seems to be 1 based
int cnt = (int) (double) EcmaScript.toNumberAs2(count);
int cnt = EcmaScript.toInt32(count);
/*if (idx < 0) {
idx = str.length() + idx;

View File

@@ -36,7 +36,7 @@ public class StringExtractActionItem extends ActionItem {
public GraphTargetItem count;
public StringExtractActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem value, GraphTargetItem index, GraphTargetItem count) {
super(instruction, lineStartIns, PRECEDENCE_PRIMARY, value);
super(instruction, lineStartIns, PRECEDENCE_PRIMARY, value);
this.index = index;
this.count = count;
}
@@ -69,10 +69,10 @@ public class StringExtractActionItem extends ActionItem {
public static String getResult(Object count, Object index, Object value) {
String str = EcmaScript.toString(value);
int idx = (int) (double) EcmaScript.toNumberAs2(index);
int idx = EcmaScript.toInt32(index);
idx--; // index seems to be 1 based
int cnt = (int) (double) EcmaScript.toNumberAs2(count);
int cnt = EcmaScript.toInt32(count);
/*if (idx < 0) {
idx = str.length() + idx;

View File

@@ -44,13 +44,13 @@ public class GtActionItem extends BinaryOpItem implements LogicalOpItem {
}
public static Object getResult(Object rightResult, Object leftResult) {
Object ret = EcmaScript.compare(rightResult, leftResult, true);
Object ret = EcmaScript.compare(leftResult, rightResult, true);
if (ret == Undefined.INSTANCE) {
return ret;
}
int reti = (int) ret;
return reti == -1;
return reti == 1;
}
@Override

View File

@@ -41,13 +41,13 @@ public class LeActionItem extends BinaryOpItem implements LogicalOpItem, Inverte
@Override
public Object getResult() {
Object ret = EcmaScript.compare(rightSide.getResult(), leftSide.getResult(), true);
Object ret = EcmaScript.compare(leftSide.getResult(), rightSide.getResult(), true);
if (ret == Undefined.INSTANCE) {
return ret;
}
int reti = (int) ret;
return reti != -1;
return reti != 1;
}
@Override

View File

@@ -38,10 +38,10 @@ public class ModuloActionItem extends BinaryOpItem {
}
public static Number getResult(Double rightResult, Double leftResult) {
if (Double.isNaN(rightResult) || Double.compare(rightResult, 0) == 0) {
if (Double.isNaN(leftResult) || Double.isNaN(rightResult) || Double.compare(rightResult, 0) == 0) {
return Double.NaN;
}
return ((long) (double) leftResult) % ((long) (double) rightResult);
return ((double) leftResult) % ((double) rightResult);
}
@Override

View File

@@ -188,6 +188,15 @@ public class EcmaScript {
if (sx.equals(sy)) {
return 0;
}
if (as2) {
// in AS2 an empty string is greater than a non-empty string...
if (sx.isEmpty()) {
return 1;
}
if (sy.isEmpty()) {
return -1;
}
}
if (sx.startsWith(sy)) {
return 1;
}