diff --git a/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java b/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java index b04245fd6d..9e7a040600 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java +++ b/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java @@ -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) { + 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); } } diff --git a/tests/testsrc/test262.properties b/tests/testsrc/test262.properties index 92d56a3a69..2d4bca63ca 100644 --- a/tests/testsrc/test262.properties +++ b/tests/testsrc/test262.properties @@ -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%) @@ -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]}