Skip to content
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

Implement Symbol.prototype and other related Symbol and type coersion changes #1611

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
28 changes: 21 additions & 7 deletions rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -3926,18 +3926,32 @@ public static boolean compare(Object val1, Object val2, int op) {
if (val1 instanceof Number && val2 instanceof Number) {
return compare((Number) val1, (Number) val2, op);
} else {
if ((val1 instanceof Symbol) || (val2 instanceof Symbol)) {
if ((isSymbol(val1)) || (isSymbol(val2))) {
throw typeErrorById("msg.compare.symbol");
}
if (val1 instanceof Scriptable) {
val1 = ((Scriptable) val1).getDefaultValue(NumberClass);
}
if (val2 instanceof Scriptable) {
val2 = ((Scriptable) val2).getDefaultValue(NumberClass);
}
val1 = toPrimitive(val1, Optional.of(NumberClass));
val2 = toPrimitive(val2, Optional.of(NumberClass));
if (val1 instanceof CharSequence && val2 instanceof CharSequence) {
return compareTo(val1.toString(), val2.toString(), op);
}
if (val1 instanceof BigInteger && val2 instanceof CharSequence) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can have one 'val1 instanceof CharSequence' base if with another if inside....

final BigInteger ny;
try {
ny = toBigInt(val2.toString());
} catch (EcmaError e) {
return false;
}
return compareTo((BigInteger) val1, ny, op);
}
if (val1 instanceof CharSequence && val2 instanceof BigInteger) {
final BigInteger nx;
try {
nx = toBigInt(val1.toString());
} catch (EcmaError e) {
return false;
}
return compareTo(nx, (BigInteger) val2, op);
}
return compare(toNumeric(val1), toNumeric(val2), op);
}
}
Expand Down
14 changes: 4 additions & 10 deletions tests/testsrc/test262.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5112,12 +5112,9 @@ language/expressions/generators 232/290 (80.0%)
yield-star-after-newline.js
yield-star-before-newline.js

language/expressions/greater-than 2/49 (4.08%)
bigint-and-incomparable-string.js
bigint-and-string.js
language/expressions/greater-than 0/49 (0.0%)

language/expressions/greater-than-or-equal 1/43 (2.33%)
bigint-and-incomparable-string.js
language/expressions/greater-than-or-equal 0/43 (0.0%)

language/expressions/grouping 0/9 (0.0%)

Expand Down Expand Up @@ -5160,12 +5157,9 @@ language/expressions/left-shift 4/45 (8.89%)
bigint-wrapped-values.js
order-of-evaluation.js

language/expressions/less-than 1/45 (2.22%)
bigint-and-incomparable-string.js
language/expressions/less-than 0/45 (0.0%)

language/expressions/less-than-or-equal 2/47 (4.26%)
bigint-and-incomparable-string.js
bigint-and-string.js
language/expressions/less-than-or-equal 0/47 (0.0%)

language/expressions/logical-and 1/18 (5.56%)
tco-right.js {unsupported: [tail-call-optimization]}
Expand Down