diff --git a/rhino/src/test/java/org/mozilla/javascript/ScriptRuntimeEvalSpecialTest.java b/rhino/src/test/java/org/mozilla/javascript/ScriptRuntimeEvalSpecialTest.java index b841dabe16..dd2ad6f56b 100644 --- a/rhino/src/test/java/org/mozilla/javascript/ScriptRuntimeEvalSpecialTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/ScriptRuntimeEvalSpecialTest.java @@ -22,7 +22,7 @@ public void worksWithUndefined() { } private static void canUseEvalSpecialWithThisSetTo(Object thisArg) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { ScriptableObject scope = cx.initStandardObjects(); Object o = diff --git a/rhino/src/test/java/org/mozilla/javascript/SuperTest.java b/rhino/src/test/java/org/mozilla/javascript/SuperTest.java index ea3d8e0f69..6060fd2cbc 100644 --- a/rhino/src/test/java/org/mozilla/javascript/SuperTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/SuperTest.java @@ -2,7 +2,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -25,60 +24,49 @@ void superIsNotAKeywordUntilES6() { @Test void superIsAKeywordInES6AndCannotBeUsedAsVariableName() { - assertIsSyntaxErrorES6("var super = 42;", "missing variable name (test#1)"); + Utils.assertEvaluatorExceptionES6("missing variable name (test#1)", "var super = 42;"); } @Test void isSyntaxErrorIfHasSuperCall() { - assertIsSyntaxErrorES6( - "({ method() { super(); }});", - "super should be inside a shorthand function (test#1)"); + Utils.assertEvaluatorExceptionES6( + "super should be inside a shorthand function (test#1)", + "({ method() { super(); }});"); } @Test void superCannotBeUsedInAPropertyValue() { - assertIsSyntaxErrorES6( - "var o = { a: super.b }", - "super should be inside a shorthand function (test#1)"); + Utils.assertEvaluatorExceptionES6( + "super should be inside a shorthand function (test#1)", + "var o = { a: super.b }"); } @Test void superCannotBeUsedInAComputedPropertyName() { - assertIsSyntaxErrorES6( - "var o = { [super.x]: 42 }", - "super should be inside a shorthand function (test#1)"); + Utils.assertEvaluatorExceptionES6( + "super should be inside a shorthand function (test#1)", + "var o = { [super.x]: 42 }"); } @Test void superCannotBeUsedInANonShorthandMethod() { - assertIsSyntaxErrorES6( - "var o = { f: function() { super.x } }", - "super should be inside a shorthand function (test#1)"); + Utils.assertEvaluatorExceptionES6( + "super should be inside a shorthand function (test#1)", + "var o = { f: function() { super.x } }"); } @Test void superCannotHaveOptionalPropertyAccess() { - assertIsSyntaxErrorES6( - "var o = { f() { super?.x } }", - "super is not allowed in an optional chaining expression (test#1)"); + Utils.assertEvaluatorExceptionES6( + "super is not allowed in an optional chaining expression (test#1)", + "var o = { f() { super?.x } }"); } @Test void superNestedInAFunctionInsideAMethodIsNotAllowed() { - assertIsSyntaxErrorES6( - "var o = { f() {\n" + " (function() { super.x; })() \n" + "} }", - "super should be inside a shorthand function (test#2)"); - } - - private void assertIsSyntaxErrorES6(String source, String expected) { - try (Context cx = Context.enter()) { - cx.setLanguageVersion(Context.VERSION_ES6); - EvaluatorException err = - assertThrows( - EvaluatorException.class, - () -> cx.compileString(source, "test", 1, null)); - assertEquals(expected, err.getMessage()); - } + Utils.assertEvaluatorExceptionES6( + "super should be inside a shorthand function (test#2)", + "var o = { f() {\n" + " (function() { super.x; })() \n" + "} }"); } } @@ -97,7 +85,8 @@ void byName() { + "};\n" + "Object.setPrototypeOf(b, a);\n" + "b.f();"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -112,7 +101,8 @@ void byIndex() { + "};\n" + "Object.setPrototypeOf(b, a);\n" + "b.f();"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -127,7 +117,8 @@ void byIndexNegative() { + "};\n" + "Object.setPrototypeOf(b, a);\n" + "b.f();"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -142,7 +133,8 @@ void byIndexFractional() { + "};\n" + "Object.setPrototypeOf(b, a);\n" + "b.f();"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -158,7 +150,8 @@ void byElementString() { + "};\n" + "Object.setPrototypeOf(b, a);\n" + "b.f();"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -174,7 +167,8 @@ void byElementIndex() { + "};\n" + "Object.setPrototypeOf(b, a);\n" + "b.f();"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -191,7 +185,8 @@ void byElementSymbol() { + "};\n" + "Object.setPrototypeOf(b, a);\n" + "b.f();"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -207,7 +202,8 @@ void getter() { + "\n" + "Object.setPrototypeOf(b, a);\n" + "b.f;"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -218,7 +214,8 @@ void getterWithThis() { + "const b = { x: 'b', get y() { return super['y'] + 'y'; } };\n" + "Object.setPrototypeOf(b, a);\n" + "b.y;"; - Utils.assertWithAllOptimizationLevelsES6("bxy", script); + + Utils.assertWithAllModes_ES6("bxy", script); } @Test @@ -229,7 +226,8 @@ void superInDefaultArguments() { + "const b = { x: 'b', f(p = super.x) { return p; } };\n" + "Object.setPrototypeOf(b, a);\n" + "b.f();"; - Utils.assertWithAllOptimizationLevelsES6("a", script); + + Utils.assertWithAllModes_ES6("a", script); } @Test @@ -246,7 +244,8 @@ void usesHomeObjectAndIgnoresThis1() { + "Object.setPrototypeOf(b, a);\n" + "var fn = b.f;\n" + "fn()\n"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -266,7 +265,8 @@ void usesHomeObjectAndIgnoresThis2() { + "var d = { fn };\n" + "Object.setPrototypeOf(d, c)\n" + "d.fn()\n"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -285,7 +285,8 @@ void nestedObjects() { + "};\n" + "Object.setPrototypeOf(obj, protoY);\n" + "obj.f();"; - Utils.assertWithAllOptimizationLevelsES6("xy", script); + + Utils.assertWithAllModes_ES6("xy", script); } @Test @@ -304,7 +305,8 @@ void nestedObjectsLambda() { + "};\n" + "Object.setPrototypeOf(obj, protoY);\n" + "obj.f();"; - Utils.assertWithAllOptimizationLevelsES6("xy", script); + + Utils.assertWithAllModes_ES6("xy", script); } @Test @@ -320,7 +322,8 @@ void getPropNoWarnPropertyFound() { + "};\n" + "Object.setPrototypeOf(b, a);\n" + "b.f();"; - Utils.assertWithAllOptimizationLevelsES6("number", script); + + Utils.assertWithAllModes_ES6("number", script); } @Test @@ -336,7 +339,8 @@ void getPropNoWarnPropertyMissing() { + "};\n" + "Object.setPrototypeOf(b, a);\n" + "b.f();"; - Utils.assertWithAllOptimizationLevelsES6("undefined", script); + + Utils.assertWithAllModes_ES6("undefined", script); } @Test @@ -352,7 +356,7 @@ protected boolean hasFeature(Context cx, int featureIndex) { } }; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( factory, cx -> { AtomicBoolean warningReported = new AtomicBoolean(false); @@ -426,7 +430,8 @@ void propertyNotFoundInSuper() { + " x: 42\n" + "};\n" + "o.f();"; - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, script); + + Utils.assertWithAllModes_ES6(Undefined.instance, script); } @Test @@ -441,7 +446,8 @@ void propertyNotFoundInSuperByElement() { + " }" + "};\n" + "o.f();"; - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, script); + + Utils.assertWithAllModes_ES6(Undefined.instance, script); } @Test @@ -455,7 +461,8 @@ void propertyNotFoundInSuperByIndex() { + " }" + "};\n" + "o.f();"; - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, script); + + Utils.assertWithAllModes_ES6(Undefined.instance, script); } @Test @@ -469,24 +476,9 @@ void prototypeIsNull() { + "};\n" + "Object.setPrototypeOf(obj, null);\n" + "obj.method();"; - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - EcmaError error = - assertThrows( - EcmaError.class, - () -> - cx.evaluateString( - cx.initStandardObjects(), - script, - "test", - 1, - null)); - assertEquals( - "TypeError: Cannot read property \"x\" from null (test#3)", - error.getMessage()); - return null; - }); + + Utils.assertEcmaErrorES6( + "TypeError: Cannot read property \"x\" from null (test#3)", script); } } @@ -504,7 +496,8 @@ void byName() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();" + "object.x + ':' + proto.x"; - Utils.assertWithAllOptimizationLevelsES6("new:proto", script); + + Utils.assertWithAllModes_ES6("new:proto", script); } @Test @@ -519,7 +512,8 @@ void byIndex() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();" + "object[42] + ':' + proto[42]"; - Utils.assertWithAllOptimizationLevelsES6("new:proto", script); + + Utils.assertWithAllModes_ES6("new:proto", script); } @Test @@ -534,7 +528,8 @@ void byIndexNegative() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();" + "object[-1] + ':' + proto[-1]"; - Utils.assertWithAllOptimizationLevelsES6("new:proto", script); + + Utils.assertWithAllModes_ES6("new:proto", script); } @Test @@ -549,7 +544,8 @@ void byIndexFractional() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();" + "object[0.1] + ':' + proto[0.1]"; - Utils.assertWithAllOptimizationLevelsES6("new:proto", script); + + Utils.assertWithAllModes_ES6("new:proto", script); } @Test @@ -564,7 +560,8 @@ void byElementString() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();" + "object.x+ ':' + proto.x"; - Utils.assertWithAllOptimizationLevelsES6("new:proto", script); + + Utils.assertWithAllModes_ES6("new:proto", script); } @Test @@ -579,7 +576,8 @@ void byElementIndex() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();" + "object[42] + ':' + proto[42]"; - Utils.assertWithAllOptimizationLevelsES6("new:proto", script); + + Utils.assertWithAllModes_ES6("new:proto", script); } @Test @@ -595,7 +593,8 @@ void byElementSymbol() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();" + "object[s] + ':' + proto[s]"; - Utils.assertWithAllOptimizationLevelsES6("new:proto", script); + + Utils.assertWithAllModes_ES6("new:proto", script); } @Test @@ -613,7 +612,8 @@ void setter() { + "Object.setPrototypeOf(object, proto);\n" + "object.f = 1;\n" + "object.x + ':' + proto.x"; - Utils.assertWithAllOptimizationLevelsES6("1:0", script); + + Utils.assertWithAllModes_ES6("1:0", script); } @Test @@ -634,7 +634,8 @@ void setterWithThis() { + "Object.setPrototypeOf(object, proto);\n" + "object.x = 1;\n" + "object._x + ':' + proto._x"; - Utils.assertWithAllOptimizationLevelsES6("1:0", script); + + Utils.assertWithAllModes_ES6("1:0", script); } @Test @@ -650,13 +651,14 @@ void propertyNotFoundInSuper() { + "};\n" + "o.f();\n" + "o.x + ':' + Object.prototype.x"; - Utils.assertWithAllOptimizationLevelsES6("1:undefined", script); + + Utils.assertWithAllModes_ES6("1:undefined", script); } @Test void superPropertyNotWritableIgnoredSilentlyInNonStrictMode() { String script = - "\n" + "" + "var proto = { x: 'proto' };\n" + "var object = {\n" + " x: 'obj',\n" @@ -666,14 +668,14 @@ void superPropertyNotWritableIgnoredSilentlyInNonStrictMode() { + "Object.defineProperty(proto, 'x', {writable: false});\n" + "object.f();\n" + "object.x + ':' + proto.x"; - ; - Utils.assertWithAllOptimizationLevelsES6("obj:proto", script); + + Utils.assertWithAllModes_ES6("obj:proto", script); } @Test void thisPropertyNotWritableIgnoredSilentlyInNonStrictMode() { String script = - "\n" + "" + "var proto = { x: 'proto' };\n" + "var object = {\n" + " x: 'obj',\n" @@ -683,14 +685,14 @@ void thisPropertyNotWritableIgnoredSilentlyInNonStrictMode() { + "Object.defineProperty(object, 'x', {writable: false});\n" + "object.f();\n" + "object.x + ':' + proto.x"; - ; - Utils.assertWithAllOptimizationLevelsES6("obj:proto", script); + + Utils.assertWithAllModes_ES6("obj:proto", script); } @Test void superPropertyNotWritableInStrictIsError() { String script = - "\n" + "" + "'use strict';\n" + "var proto = { x: 'proto' };\n" + "var object = {\n" @@ -701,14 +703,15 @@ void superPropertyNotWritableInStrictIsError() { + "Object.defineProperty(proto, 'x', {writable: false});\n" + "object.f();\n" + "object.x + ':' + proto.x"; - ; - assertThrowsTypeErrorCannotWriteProperty(script); + + Utils.assertEcmaErrorES6( + "TypeError: Cannot modify readonly property: x. (test#5)", script); } @Test void thisPropertyNotWritableInStrictIsError() { String script = - "\n" + "" + "'use strict';\n" + "var proto = { x: 'proto' };\n" + "var object = {\n" @@ -719,29 +722,9 @@ void thisPropertyNotWritableInStrictIsError() { + "Object.defineProperty(object, 'x', {writable: false});\n" + "object.f();\n" + "object.x + ':' + proto.x"; - ; - assertThrowsTypeErrorCannotWriteProperty(script); - } - private void assertThrowsTypeErrorCannotWriteProperty(String script) { - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - EcmaError error = - assertThrows( - EcmaError.class, - () -> - cx.evaluateString( - cx.initStandardObjects(), - script, - "test", - 1, - null)); - assertEquals( - "TypeError: Cannot modify readonly property: x. (test#6)", - error.getMessage()); - return null; - }); + Utils.assertEcmaErrorES6( + "TypeError: Cannot modify readonly property: x. (test#5)", script); } @Test @@ -755,30 +738,15 @@ void prototypeIsNull() { + "};\n" + "Object.setPrototypeOf(obj, null);\n" + "obj.method();"; - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - EcmaError error = - assertThrows( - EcmaError.class, - () -> - cx.evaluateString( - cx.initStandardObjects(), - script, - "test", - 1, - null)); - assertEquals( - "TypeError: Cannot set property \"x\" of null to \"42\" (test#3)", - error.getMessage()); - return null; - }); + + Utils.assertEcmaErrorES6( + "TypeError: Cannot set property \"x\" of null to \"42\" (test#3)", script); } @Test void missingPropertyPrototypeSealedCreatesItOnTheThisObject() { String script = - "\n" + "" + "var proto = {};\n" + "var object = {\n" + " f() { super.x = 1; }\n" @@ -787,14 +755,14 @@ void missingPropertyPrototypeSealedCreatesItOnTheThisObject() { + "Object.seal(proto);\n" + "object.f();\n" + "object.x + ':' + proto.x"; - ; - Utils.assertWithAllOptimizationLevelsES6("1:undefined", script); + + Utils.assertWithAllModes_ES6("1:undefined", script); } @Test void missingPropertyThisSealedIsIgnoredSilentlyInNonStrictMode() { String script = - "\n" + "" + "var proto = {};\n" + "var object = {\n" + " f() { super.x = 1; }\n" @@ -803,14 +771,14 @@ void missingPropertyThisSealedIsIgnoredSilentlyInNonStrictMode() { + "Object.seal(object);\n" + "object.f();\n" + "object.x + ':' + proto.x"; - ; - Utils.assertWithAllOptimizationLevelsES6("undefined:undefined", script); + + Utils.assertWithAllModes_ES6("undefined:undefined", script); } @Test void missingPropertyThisSealedIsErrorInStrictMode() { String script = - "\n" + "" + "'use strict';\n" + "var proto = {};\n" + "var object = {\n" @@ -820,25 +788,10 @@ void missingPropertyThisSealedIsErrorInStrictMode() { + "Object.seal(object);\n" + "object.f();\n" + "object.x + ':' + proto.x"; - ; - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - EcmaError error = - assertThrows( - EcmaError.class, - () -> - cx.evaluateString( - cx.initStandardObjects(), - script, - "test", - 1, - null)); - assertEquals( - "TypeError: Cannot add properties to this object because extensible is false. (test#5)", - error.getMessage()); - return null; - }); + + Utils.assertEcmaErrorES6( + "TypeError: Cannot add properties to this object because extensible is false. (test#4)", + script); } @Test @@ -854,7 +807,8 @@ void modifyOperatorByName() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();" + "object.x + ':' + proto.x"; - Utils.assertWithAllOptimizationLevelsES6("proto1:proto", script); + + Utils.assertWithAllModes_ES6("proto1:proto", script); } @Test @@ -871,7 +825,8 @@ void modifyOperatorByKey() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();" + "object.x + ':' + proto.x"; - Utils.assertWithAllOptimizationLevelsES6("proto1:proto", script); + + Utils.assertWithAllModes_ES6("proto1:proto", script); } @Test @@ -893,7 +848,8 @@ void deleteNotAllowed() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();\n" + "catchHit + ':' + getterCalled"; - Utils.assertWithAllOptimizationLevelsES6("true:false", script); + + Utils.assertWithAllModes_ES6("true:false", script); } @Test @@ -916,7 +872,8 @@ void deleteSuperFirstEvaluatesPropertyKey() { + "Object.setPrototypeOf(object, proto);\n" + "object.f();\n" + "catchHit + ':' + gCalled"; - Utils.assertWithAllOptimizationLevelsES6("true:true", script); + + Utils.assertWithAllModes_ES6("true:true", script); } @Test @@ -931,7 +888,8 @@ void memberIncrementPostfix() { + "Object.setPrototypeOf(object, proto);\n" + "var f = object.f();" + "f + ':' + object.x + ':' + proto.x"; - Utils.assertWithAllOptimizationLevelsES6("1:2:1", script); + + Utils.assertWithAllModes_ES6("1:2:1", script); } @Test @@ -946,7 +904,8 @@ void memberIncrementPrefix() { + "Object.setPrototypeOf(object, proto);\n" + "var f = object.f();" + "f + ':' + object.x + ':' + proto.x"; - Utils.assertWithAllOptimizationLevelsES6("2:2:1", script); + + Utils.assertWithAllModes_ES6("2:2:1", script); } @Test @@ -961,7 +920,8 @@ void elementDecrementPostfix() { + "Object.setPrototypeOf(object, proto);\n" + "var f = object.f();" + "f + ':' + object[0] + ':' + proto[0]"; - Utils.assertWithAllOptimizationLevelsES6("1:0:1", script); + + Utils.assertWithAllModes_ES6("1:0:1", script); } @Test @@ -976,7 +936,8 @@ void elementDecrementPrefix() { + "Object.setPrototypeOf(object, proto);\n" + "var f = object.f();" + "f + ':' + object[0] + ':' + proto[0]"; - Utils.assertWithAllOptimizationLevelsES6("0:0:1", script); + + Utils.assertWithAllModes_ES6("0:0:1", script); } } @@ -998,7 +959,8 @@ void methodsAreResolvedOnSuperObject() { + "};\n" + "Object.setPrototypeOf(obj, proto);\n" + "obj.f();"; - Utils.assertWithAllOptimizationLevelsES6("prototype1", script); + + Utils.assertWithAllModes_ES6("prototype1", script); } // All the n-arguments variants are necessary because we have optimized code paths in @@ -1023,7 +985,8 @@ void thisIsSetCorrectly0Args() { + "};\n" + "Object.setPrototypeOf(object, proto);\n" + "object.g();"; - Utils.assertWithAllOptimizationLevelsES6("object", script); + + Utils.assertWithAllModes_ES6("object", script); } @Test @@ -1044,7 +1007,8 @@ void thisIsSetCorrectly1Arg() { + "};\n" + "Object.setPrototypeOf(object, proto);\n" + "object.g();"; - Utils.assertWithAllOptimizationLevelsES6("object:a", script); + + Utils.assertWithAllModes_ES6("object:a", script); } @Test @@ -1065,7 +1029,8 @@ void thisIsSetCorrectly2Args() { + "};\n" + "Object.setPrototypeOf(object, proto);\n" + "object.g();"; - Utils.assertWithAllOptimizationLevelsES6("object:a:b", script); + + Utils.assertWithAllModes_ES6("object:a:b", script); } @Test @@ -1086,7 +1051,8 @@ void thisIsSetCorrectlyNArgs() { + "};\n" + "Object.setPrototypeOf(object, proto);\n" + "object.g();"; - Utils.assertWithAllOptimizationLevelsES6("object:a:b:c", script); + + Utils.assertWithAllModes_ES6("object:a:b:c", script); } @Test @@ -1106,7 +1072,8 @@ void lastScratchScriptableIsCleanedUpProperly() { + "};\n" + "Object.setPrototypeOf(object, proto);\n" + "object.f3();"; - Utils.assertWithAllOptimizationLevelsES6("f2f1", script); + + Utils.assertWithAllModes_ES6("f2f1", script); } @Test @@ -1127,7 +1094,8 @@ void thisIsSetCorrectlyForTemplateLiteralCall() { + "};\n" + "Object.setPrototypeOf(object, proto);\n" + "object.f();"; - Utils.assertWithAllOptimizationLevelsES6("object", script); + + Utils.assertWithAllModes_ES6("object", script); } @Test @@ -1143,12 +1111,13 @@ void nestedLambdaCaptureSuper() { + "var object = {\n" + " x: 'object',\n" + " f() {\n" - + " return () => { return super.f(); } ;\n" + + " return () => { return super.f(); };\n" + " }\n" + "};\n" + "Object.setPrototypeOf(object, proto);\n" + "object.f()();"; - Utils.assertWithAllOptimizationLevelsES6("object", script); + + Utils.assertWithAllModes_ES6("object", script); } @Test @@ -1164,12 +1133,13 @@ void doublyNestedLambdaCaptureSuper() { + "var object = {\n" + " x: 'object',\n" + " f() {\n" - + " return () => { return () => { return super.f(); } } ;\n" + + " return () => { return () => { return super.f(); } };\n" + " }\n" + "};\n" + "Object.setPrototypeOf(object, proto);\n" + "object.f()()();"; - Utils.assertWithAllOptimizationLevelsES6("object", script); + + Utils.assertWithAllModes_ES6("object", script); } } @@ -1194,7 +1164,8 @@ void propertyGet() { + "Object.setPrototypeOf(c, b);\n" + "Object.setPrototypeOf(b, a);\n" + "c.f();"; - Utils.assertWithAllOptimizationLevelsES6("b", script); + + Utils.assertWithAllModes_ES6("b", script); } @Test @@ -1210,7 +1181,7 @@ void propertyGetter() { + "Object.setPrototypeOf(c, b);\n" + "Object.setPrototypeOf(b, a);\n" + "c.f();"; - Utils.assertWithAllOptimizationLevelsES6("bb", script); + Utils.assertWithAllModes_ES6("bb", script); } @Test @@ -1228,7 +1199,8 @@ void propertySet() { + "Object.setPrototypeOf(c, b);\n" + "Object.setPrototypeOf(b, a);\n" + "c.f();"; - Utils.assertWithAllOptimizationLevelsES6("a", script); + + Utils.assertWithAllModes_ES6("a", script); } } @@ -1249,7 +1221,8 @@ void evalInsideMethodCanAccessSuper() { + "};\n" + "Object.setPrototypeOf(object, proto);\n" + "object.f();"; - Utils.assertWithAllOptimizationLevelsES6("proto", script); + + Utils.assertWithAllModes_ES6("proto", script); } @Test @@ -1267,7 +1240,8 @@ void evalFromLambdaInMethodCanAccessSuper() { + "};\n" + "Object.setPrototypeOf(object, proto);\n" + "object.f()();"; - Utils.assertWithAllOptimizationLevelsES6("proto", script); + + Utils.assertWithAllModes_ES6("proto", script); } @Test @@ -1280,47 +1254,17 @@ void superCannotBeUsedAsMethodInEval() { + " }\n" + "};" + "o.f();"; - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - EcmaError error = - assertThrows( - EcmaError.class, - () -> - cx.evaluateString( - cx.initStandardObjects(), - script, - "test", - 1, - null)); - assertEquals( - "SyntaxError: super should be inside a shorthand function (test#3(eval)#1)", - error.getMessage()); - return null; - }); + + Utils.assertEcmaErrorES6( + "SyntaxError: super should be inside a shorthand function (test#3(eval)#1)", + script); } @Test void evalOutsideMethodCannotAccessSuper() { - String script = "eval('super.x')"; - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - EcmaError error = - assertThrows( - EcmaError.class, - () -> - cx.evaluateString( - cx.initStandardObjects(), - script, - "test", - 1, - null)); - assertEquals( - "SyntaxError: super should be inside a shorthand function (test#1(eval)#1)", - error.getMessage()); - return null; - }); + Utils.assertEcmaErrorES6( + "SyntaxError: super should be inside a shorthand function (test#1(eval)#1)", + "eval('super.x')"); } @Test @@ -1333,24 +1277,9 @@ void evalInFunctionInsideMethodDoesNotAllowSuper() { + " }\n" + "};" + "o.f();"; - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - EcmaError error = - assertThrows( - EcmaError.class, - () -> - cx.evaluateString( - cx.initStandardObjects(), - script, - "test", - 1, - null)); - assertEquals( - "SyntaxError: super should be inside a shorthand function (test#3(eval)#1)", - error.getMessage()); - return null; - }); + Utils.assertEcmaErrorES6( + "SyntaxError: super should be inside a shorthand function (test#3(eval)#1)", + script); } } } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ApplyOnPrimitiveNumberTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ApplyOnPrimitiveNumberTest.java index b409315160..4d6826fb29 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ApplyOnPrimitiveNumberTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ApplyOnPrimitiveNumberTest.java @@ -23,7 +23,7 @@ public class ApplyOnPrimitiveNumberTest { public void testIt() { final String script = "var fn = function() { return this; }\n" + "fn.apply(1)"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { final ScriptableObject scope = _cx.initStandardObjects(); final Object result = _cx.evaluateString(scope, script, "test script", 0, null); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/BigIntTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/BigIntTest.java index 2e8b2235bb..b3b8bafb3b 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/BigIntTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/BigIntTest.java @@ -26,23 +26,23 @@ public void parse() throws IOException { @Test public void compareWithString() { - Utils.assertWithAllOptimizationLevelsES6(true, "9007199254740992n < '9007199254740993'"); - Utils.assertWithAllOptimizationLevelsES6(true, "9007199254740992n <= '9007199254740993'"); - Utils.assertWithAllOptimizationLevelsES6(true, "9007199254740993n <= '9007199254740993'"); - Utils.assertWithAllOptimizationLevelsES6(true, "9007199254740993n == '9007199254740993'"); - Utils.assertWithAllOptimizationLevelsES6(true, "9007199254740993n >= '9007199254740993'"); - Utils.assertWithAllOptimizationLevelsES6(true, "9007199254740993n >= '9007199254740992'"); - Utils.assertWithAllOptimizationLevelsES6(true, "9007199254740993n > '9007199254740992'"); + Utils.assertWithAllModes_ES6(true, "9007199254740992n < '9007199254740993'"); + Utils.assertWithAllModes_ES6(true, "9007199254740992n <= '9007199254740993'"); + Utils.assertWithAllModes_ES6(true, "9007199254740993n <= '9007199254740993'"); + Utils.assertWithAllModes_ES6(true, "9007199254740993n == '9007199254740993'"); + Utils.assertWithAllModes_ES6(true, "9007199254740993n >= '9007199254740993'"); + Utils.assertWithAllModes_ES6(true, "9007199254740993n >= '9007199254740992'"); + Utils.assertWithAllModes_ES6(true, "9007199254740993n > '9007199254740992'"); } @Test public void compareStringWith() { - Utils.assertWithAllOptimizationLevelsES6(true, "'9007199254740992' < 9007199254740993n"); - Utils.assertWithAllOptimizationLevelsES6(true, "'9007199254740992' <= 9007199254740993n"); - Utils.assertWithAllOptimizationLevelsES6(true, "'9007199254740993' <= 9007199254740993n"); - Utils.assertWithAllOptimizationLevelsES6(true, "'9007199254740993' == 9007199254740993n"); - Utils.assertWithAllOptimizationLevelsES6(true, "'9007199254740993' >= 9007199254740993n"); - Utils.assertWithAllOptimizationLevelsES6(true, "'9007199254740993' >= 9007199254740992n"); - Utils.assertWithAllOptimizationLevelsES6(true, "'9007199254740993' > 9007199254740992n"); + Utils.assertWithAllModes_ES6(true, "'9007199254740992' < 9007199254740993n"); + Utils.assertWithAllModes_ES6(true, "'9007199254740992' <= 9007199254740993n"); + Utils.assertWithAllModes_ES6(true, "'9007199254740993' <= 9007199254740993n"); + Utils.assertWithAllModes_ES6(true, "'9007199254740993' == 9007199254740993n"); + Utils.assertWithAllModes_ES6(true, "'9007199254740993' >= 9007199254740993n"); + Utils.assertWithAllModes_ES6(true, "'9007199254740993' >= 9007199254740992n"); + Utils.assertWithAllModes_ES6(true, "'9007199254740993' > 9007199254740992n"); } } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug409702Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug409702Test.java index 649fead8e3..9974cddeda 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug409702Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug409702Test.java @@ -5,10 +5,7 @@ /** */ package org.mozilla.javascript.tests; -import static org.junit.Assert.assertEquals; - import org.junit.Test; -import org.mozilla.javascript.Scriptable; /** * See https://bugzilla.mozilla.org/show_bug.cgi?id=409702 @@ -33,25 +30,13 @@ public final void a() {} @Test public void adapter() { - final int value = 12; - String source = - "var instance = " - + " new JavaAdapter(" + String script = + "var instance = new JavaAdapter(" + Foo.Subclass.class.getName() + "," - + "{ b: function () { return " - + value - + "; } });" + + "{ b: function () { return 12; } });" + "instance.b();"; - Utils.runWithAllOptimizationLevels( - cx -> { - final Scriptable scope = cx.initStandardObjects(); - - Object result = cx.evaluateString(scope, source, "source", 1, null); - assertEquals(Integer.valueOf(value), result); - - return null; - }); + Utils.assertWithAllModes(12, script); } } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug412433Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug412433Test.java index ae34b718db..35671301bb 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug412433Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug412433Test.java @@ -6,7 +6,6 @@ package org.mozilla.javascript.tests; import org.junit.Test; -import org.mozilla.javascript.ScriptableObject; /** * See https://bugzilla.mozilla.org/show_bug.cgi?id=412433 @@ -17,12 +16,6 @@ public class Bug412433Test { @Test public void malformedJavascript2() { - Utils.runWithAllOptimizationLevels( - cx -> { - ScriptableObject scope = cx.initStandardObjects(); - cx.evaluateString(scope, "\"\".split(/[/?,/&]/)", "", 0, null); - - return null; - }); + Utils.assertWithAllModes("", "'' + \"\".split(/[/?,/&]/)"); } } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug419940Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug419940Test.java index 1989db8b39..d0d396034a 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug419940Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug419940Test.java @@ -4,10 +4,7 @@ package org.mozilla.javascript.tests; -import static org.junit.Assert.assertEquals; - import org.junit.Test; -import org.mozilla.javascript.Scriptable; /** * See https://bugzilla.mozilla.org/show_bug.cgi?id=419940 @@ -15,8 +12,6 @@ * @author Norris Boyd */ public class Bug419940Test { - static final int value = 12; - public abstract static class BaseFoo { public abstract int doSomething(); } @@ -24,21 +19,14 @@ public abstract static class BaseFoo { public static class Foo extends BaseFoo { @Override public int doSomething() { - return value; + return 12; } } @Test public void adapter() { - String source = "(new JavaAdapter(" + Foo.class.getName() + ", {})).doSomething();"; - - Utils.runWithAllOptimizationLevels( - cx -> { - Scriptable scope = cx.initStandardObjects(); - Object result = cx.evaluateString(scope, source, "source", 1, null); - assertEquals(Integer.valueOf(value), result); + String script = "(new JavaAdapter(" + Foo.class.getName() + ", {})).doSomething();"; - return null; - }); + Utils.assertWithAllModes(12, script); } } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug783797Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug783797Test.java index 312d844500..23678ea412 100755 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug783797Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug783797Test.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; -import static org.mozilla.javascript.tests.Utils.runWithAllOptimizationLevels; +import static org.mozilla.javascript.tests.Utils.runWithAllModes; import org.junit.Test; import org.mozilla.javascript.Context; @@ -51,7 +51,7 @@ private static void assertFALSE(Object actual) { @Test public void getElem() { String fn = "function test(){ return ''['foo'] }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -75,7 +75,7 @@ public void run( @Test public void getProp() { String fn = "function test(){ return ''.foo }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -99,7 +99,7 @@ public void run( @Test public void getPropNoWarn1() { String fn = "function test(){ if (''.foo) return true; return false; }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -120,7 +120,7 @@ public void run( @Test public void getPropNoWarn2() { String fn = "function test(){ if (''.foo) return true; return false; }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -141,7 +141,7 @@ public void run( @Test public void setElem() { String fn = "function test(){ ''['foo'] = '_' }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -171,7 +171,7 @@ public void run( @Test public void setProp() { String fn = "function test(){ ''.foo = '_' }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -201,7 +201,7 @@ public void run( @Test public void setElemIncDec() { String fn = "function test(){ ''['foo']++ }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -231,7 +231,7 @@ public void run( @Test public void setPropIncDec() { String fn = "function test(){ ''.foo++ }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -261,7 +261,7 @@ public void run( @Test public void setElemOp1() { String fn = "function test(){ return ''['foo'] += '_' }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -291,7 +291,7 @@ public void run( @Test public void setPropOp1() { String fn = "function test(){ return ''.foo += '_' }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -325,7 +325,7 @@ public void run( @Test public void setElemOp2() { String fn = "function test(){ return ''['foo'] += '_' }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -359,7 +359,7 @@ public void run( @Test public void setPropOp2() { String fn = "function test(){ return ''.foo += '_' }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -383,7 +383,7 @@ public void run( @Test public void getElemCall() { String fn = "function test(){ return ''['foo']() }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -413,7 +413,7 @@ public void run( @Test public void getPropCall() { String fn = "function test(){ return ''.foo() }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -444,7 +444,7 @@ public void run( public void enum1() { String fn = "function test(){ for (var k in '') if (k == 'foo') return true; return false; }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -466,7 +466,7 @@ public void run( public void enum2() { String fn = "function test(){ for (var k in '') if (k == 'foo') return true; return false; }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -487,7 +487,7 @@ public void run( @Test public void parent() { String fn = "function test(){}"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -506,7 +506,7 @@ public void run( @Test public void returnThis() { String fn = "function test(){ return this }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -528,7 +528,7 @@ public void run( @Test public void returnThisNested() { String fn = "function test(){ return (function(){ return this })() }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -550,7 +550,7 @@ public void run( @Test public void returnThisNestedCall() { String fn = "function test(o){ return (function(){ return this }).call(o) }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -583,7 +583,7 @@ public void run( @Test public void nameStringPrototype() { String fn = "function test(){ return String.prototype }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -616,7 +616,7 @@ public void run( @Test public void nameStringPrototypeNested() { String fn = "function test(){ return (function(){ return String.prototype })() }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -649,7 +649,7 @@ public void run( @Test public void thisStringPrototype() { String fn = "function test(){ return this.String.prototype }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -682,7 +682,7 @@ public void run( @Test public void thisProto() { String fn = "function test(){ return this.__proto__ }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -707,7 +707,7 @@ public void run( @Test public void stringLiteralProto() { String fn = "function test(){ return ''.__proto__ }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -740,7 +740,7 @@ public void run( @Test public void thisProtoNested() { String fn = "function test(){ return (function(){ return this.__proto__ }).call('') }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { @@ -773,7 +773,7 @@ public void run( @Test public void stringLiteralProtoNested() { String fn = "function test(){ return (function(){ return ''.__proto__ })() }"; - runWithAllOptimizationLevels( + runWithAllModes( action( fn, new Action() { diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java index ac8f64d057..76e617b053 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java @@ -28,7 +28,7 @@ public void largeMethod() { scriptSource.append("a = a + 1;"); } - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { Script script = _cx.compileString(scriptSource.toString(), "test-source", 1, null); @@ -47,7 +47,7 @@ public void largeMethod() { scriptSource.append("a = a + 1;"); } - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { Script script = _cx.compileString(scriptSource.toString(), "test-source", 1, null); @@ -59,7 +59,7 @@ public void largeMethod() { return null; }); - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { try { Script script = @@ -93,7 +93,7 @@ public void manyExceptionHandlers() { scriptSource.append("try { a = a + 1; } catch(e) { alert(e); }"); } - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { final Scriptable scope = _cx.initStandardObjects(); Assert.assertEquals( @@ -115,7 +115,7 @@ public void largeVarList() { scriptSource.append("var a" + i + ";"); } - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { Script script = _cx.compileString(scriptSource.toString(), "test-source", 1, null); @@ -134,7 +134,7 @@ public void largeVarList() { scriptSource.append("var a" + i + ";"); } - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { Script script = _cx.compileString(scriptSource.toString(), "test-source", 1, null); @@ -149,7 +149,7 @@ public void largeVarList() { return null; }); - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { try { Script script = @@ -184,7 +184,7 @@ public void largeLocalVarList() { } scriptSource.append("return 'done'; }"); - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { Script script = _cx.compileString(scriptSource.toString(), "test-source", 1, null); @@ -206,7 +206,7 @@ public void largeLocalVarList() { } scriptSource.append("return 'done'; }"); - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { Script script = _cx.compileString(scriptSource.toString(), "test-source", 1, null); @@ -221,7 +221,7 @@ public void largeLocalVarList() { return null; }); - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { try { Script script = @@ -255,7 +255,7 @@ public void tooManyMethods() { scriptSource.append("function foo" + i + "() { return 7; }\n"); } - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { Script script = _cx.compileString(scriptSource.toString(), "test-source", 1, null); @@ -274,7 +274,7 @@ public void tooManyMethods() { scriptSource.append("function foo" + i + "() { return 7; }\n"); } - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { Script script = _cx.compileString(scriptSource.toString(), "test-source", 1, null); @@ -289,7 +289,7 @@ public void tooManyMethods() { return null; }); - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { try { Script script = diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/DecompileTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/DecompileTest.java index 96d9c959c7..043e85e55d 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/DecompileTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/DecompileTest.java @@ -25,7 +25,7 @@ public class DecompileTest { @Test public void newObject0Arg() { final String source = "var x = new Date().getTime();"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Script script = cx.compileString(source, "my script", 0, null); Assert.assertEquals(source, cx.decompileScript(script, 4).trim()); @@ -36,7 +36,7 @@ public void newObject0Arg() { @Test public void bigInt() { final String source = "var x = 123n;"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); final Script script = cx.compileString(source, "my script", 0, null); @@ -48,7 +48,7 @@ public void bigInt() { @Test public void templateLiteral() { final String source = "var x = `test${1}`;"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); final Script script = cx.compileString(source, "my script", 0, null); @@ -60,7 +60,7 @@ public void templateLiteral() { @Test public void taggedTemplateLiteral() { final String source = "var x = (() => { } )`test${2}\\unicode`;"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); final Script script = cx.compileString(source, "my script", 0, null); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/DeletePropertyTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/DeletePropertyTest.java index c89630f70f..d22708e60a 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/DeletePropertyTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/DeletePropertyTest.java @@ -5,7 +5,7 @@ package org.mozilla.javascript.tests; import org.junit.Test; -import org.mozilla.javascript.ScriptableObject; +import org.mozilla.javascript.Undefined; /** * Test for delete that should apply for properties defined in prototype chain. See @@ -27,11 +27,6 @@ public void deletePropInPrototype() throws Exception { + "[].foo();\n" + "[][1]();\n"; - Utils.runWithAllOptimizationLevels( - _cx -> { - final ScriptableObject scope = _cx.initStandardObjects(); - final Object result = _cx.evaluateString(scope, script, "test script", 0, null); - return null; - }); + Utils.assertWithAllModes(Undefined.instance, script); } } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ErrorHandlingTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ErrorHandlingTest.java index 6c70e2700a..3ac879cff4 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ErrorHandlingTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ErrorHandlingTest.java @@ -108,14 +108,14 @@ public void javaErrorThrown() { @Test public void stackProvider() { String nl = System.lineSeparator(); - Utils.assertWithAllOptimizationLevels(Undefined.instance, "Error.stack"); - Utils.assertWithAllOptimizationLevels("\tat test.js:0" + nl, "new Error().stack"); - Utils.assertWithAllOptimizationLevels(Undefined.instance, "EvalError.stack"); - Utils.assertWithAllOptimizationLevels("\tat test.js:0" + nl, "new EvalError('foo').stack"); + Utils.assertWithAllModes(Undefined.instance, "Error.stack"); + Utils.assertWithAllModes("\tat test.js:0" + nl, "new Error().stack"); + Utils.assertWithAllModes(Undefined.instance, "EvalError.stack"); + Utils.assertWithAllModes("\tat test.js:0" + nl, "new EvalError('foo').stack"); } private void testIt(final String script, final Consumer exception) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { try { final ScriptableObject scope = cx.initStandardObjects(); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java index e6add2db78..41d7a16b82 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java @@ -75,7 +75,7 @@ public void mozillaStack() { } private void testIt(final String script, final Object expected) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { try { final ScriptableObject scope = cx.initStandardObjects(); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ForEachForOfTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ForEachForOfTest.java index d8947dc3bd..242bf3b236 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ForEachForOfTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ForEachForOfTest.java @@ -69,7 +69,7 @@ public void forOfStrict() { } private static void testList(final String script) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); final Scriptable scope = cx.initStandardObjects(); @@ -86,7 +86,7 @@ private static void testList(final String script) { } private static void testArray(final String script) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); final Scriptable scope = cx.initStandardObjects(); @@ -103,7 +103,7 @@ private static void testArray(final String script) { } private static void testSet(final String script) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); final Scriptable scope = cx.initStandardObjects(); @@ -121,7 +121,7 @@ private static void testSet(final String script) { } private static void testMap(final String script) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); final Scriptable scope = cx.initStandardObjects(); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/FunctionTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/FunctionTest.java index 6edf137ec7..7ef0bfd10a 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/FunctionTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/FunctionTest.java @@ -5,10 +5,7 @@ /** */ package org.mozilla.javascript.tests; -import static org.junit.Assert.assertEquals; - import org.junit.Test; -import org.mozilla.javascript.Scriptable; /** * Unit tests for Function. @@ -24,7 +21,7 @@ public class FunctionTest { */ @Test public void functionWithSlashSlash() { - assertEvaluates(true, "new Function('return true//;').call()"); + Utils.assertWithAllModes(true, "new Function('return true//;').call()"); } @Test @@ -39,7 +36,7 @@ public void functionHasNameOfVarStrictMode() throws Exception { + "foo();\n" + "result;"; - assertEvaluates("-outer abc = 1-inner abc = function", script); + Utils.assertWithAllModes("-outer abc = 1-inner abc = function", script); } @Test @@ -59,7 +56,7 @@ public void innerFunctionWithSameName() throws Exception { + "b();\n" + "result;"; - assertEvaluates("ab", script); + Utils.assertWithAllModes("ab", script); } @Test @@ -76,7 +73,7 @@ public void innerFunctionWithSameNameAsOutsideStrict() throws Exception { + "a();\n" + "result;"; - assertEvaluates("a", script); + Utils.assertWithAllModes("a", script); } @Test @@ -92,7 +89,7 @@ public void secondFunctionWithSameNameStrict() throws Exception { + "func();\n" + "result;"; - assertEvaluates("functionfunc(){result+=norm(func);}outer", script); + Utils.assertWithAllModes("functionfunc(){result+=norm(func);}outer", script); } @Test @@ -137,16 +134,6 @@ public void functioNamesExceptionsStrict() throws Exception { + "result;"; // assertEvaluates("f1f2f3!f4f5!f6!f7!f8f10f11f12!f10f11f12f13", script); - assertEvaluates("f1f2f3!f4f5!f6!f7!f8f10f11f12f11f12f13", script); - } - - private static void assertEvaluates(final Object expected, final String source) { - Utils.runWithAllOptimizationLevels( - cx -> { - final Scriptable scope = cx.initStandardObjects(); - final Object rep = cx.evaluateString(scope, source, "test.js", 0, null); - assertEquals(expected, rep); - return null; - }); + Utils.assertWithAllModes("f1f2f3!f4f5!f6!f7!f8f10f11f12f11f12f13", script); } } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/GlobalParseXTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/GlobalParseXTest.java index aae6894c4d..9a4e29b868 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/GlobalParseXTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/GlobalParseXTest.java @@ -5,10 +5,7 @@ /** */ package org.mozilla.javascript.tests; -import static org.junit.Assert.assertEquals; - import org.junit.Test; -import org.mozilla.javascript.Scriptable; /** * Tests for global functions parseFloat and parseInt. @@ -37,8 +34,8 @@ public void parseFloatAndIntWhiteSpaces() { } private void testParseFloatWhiteSpaces(final String prefix) { - assertEvaluates("789", "String(parseInt('" + prefix + "789 '))"); - assertEvaluates("7.89", "String(parseFloat('" + prefix + "7.89 '))"); + Utils.assertWithAllModes("789", "String(parseInt('" + prefix + "789 '))"); + Utils.assertWithAllModes("7.89", "String(parseFloat('" + prefix + "7.89 '))"); } /** @@ -70,16 +67,6 @@ public void parseFloatTrailingNoise() { } private static void testParseFloat(final String expected, final String value) { - assertEvaluates(expected, "String(parseFloat('" + value + "'))"); - } - - private static void assertEvaluates(final Object expected, final String source) { - Utils.runWithAllOptimizationLevels( - cx -> { - final Scriptable scope = cx.initStandardObjects(); - final Object rep = cx.evaluateString(scope, source, "test.js", 0, null); - assertEquals(expected, rep); - return null; - }); + Utils.assertWithAllModes(expected, "String(parseFloat('" + value + "'))"); } } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/InterfaceAdapterTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/InterfaceAdapterTest.java index d922a566b8..f14073b3c6 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/InterfaceAdapterTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/InterfaceAdapterTest.java @@ -27,7 +27,7 @@ public static String joinString(String a) { } private void testIt(String js, Object expected) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final ScriptableObject scope = cx.initStandardObjects(); scope.put("list", scope, createList()); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/IterableTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/IterableTest.java index 157ed273c3..70441b2297 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/IterableTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/IterableTest.java @@ -93,7 +93,7 @@ public boolean has(Symbol key, Scriptable start) { */ @Test public void forOfUsingNonSymbolScriptable() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); @@ -127,7 +127,7 @@ public void forOfUsingNonSymbolScriptable() { */ @Test public void forOfUsingNonIterable() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); @@ -157,7 +157,7 @@ public void forOfUsingNonIterable() { */ @Test public void forOfUsingArrayIterator() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/LookupSetterTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/LookupSetterTest.java index 8099314f5f..886af58235 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/LookupSetterTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/LookupSetterTest.java @@ -128,7 +128,7 @@ public String run(final Context cx) { } }; - Utils.runWithAllOptimizationLevels(action); + Utils.runWithAllModes(action); } public static class Foo extends ScriptableObject { diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/NativeRegExpTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/NativeRegExpTest.java index ab0d918765..29ebb69bfd 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/NativeRegExpTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/NativeRegExpTest.java @@ -15,7 +15,7 @@ public class NativeRegExpTest { @Test public void openBrace() { final String script = "/0{0/"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( _cx -> { final ScriptableObject scope = _cx.initStandardObjects(); final Object result = _cx.evaluateString(scope, script, "test script", 0, null); @@ -339,7 +339,7 @@ private static void testEvaluate(final String expected, final String regex) { + "res += regex.sticky;\n" + "res"; - Utils.assertWithAllOptimizationLevelsES6(expected, script); + Utils.assertWithAllModes_ES6(expected, script); } /** @@ -358,7 +358,7 @@ public void stickyTest() throws Exception { + "res = res + '-' + regex.test(str);\n" + "res = res + '-' + regex.lastIndex;\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("true-9-false-0-false-0", script); + Utils.assertWithAllModes_ES6("true-9-false-0-false-0", script); } /** @@ -371,7 +371,7 @@ public void stickyStartOfLine() throws Exception { + "regex.lastIndex = 2;\n" + "var res = '' + regex.test('..foo');\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("false", script); + Utils.assertWithAllModes_ES6("false", script); } /** @@ -386,7 +386,7 @@ public void stickyStartOfLineMultiline() throws Exception { + "regex.lastIndex = 2;\n" + "res = res + '-' + regex.test('.\\nfoo');\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("false-true", script); + Utils.assertWithAllModes_ES6("false-true", script); } /** @@ -401,7 +401,7 @@ public void matchGlobal() throws Exception { + "res = res + '-' + result[1];\n" + "res = res + '-' + result[2];\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("3-a-a-a", script); + Utils.assertWithAllModes_ES6("3-a-a-a", script); } /** @@ -416,7 +416,7 @@ public void matchGlobalSymbol() throws Exception { + "res = res + '-' + result[1];\n" + "res = res + '-' + result[2];\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("3-a-a-a", script); + Utils.assertWithAllModes_ES6("3-a-a-a", script); } /** @@ -429,7 +429,7 @@ public void matchDotAll() throws Exception { + "var res = '' + result.length;\n" + "res = res + '-' + result[0];\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("1-bar\nfoo", script); + Utils.assertWithAllModes_ES6("1-bar\nfoo", script); } /** @@ -442,7 +442,7 @@ public void matchSticky() throws Exception { + "var res = '' + result.length;\n" + "res = res + '-' + result[0];\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("1-a", script); + Utils.assertWithAllModes_ES6("1-a", script); } /** @@ -455,7 +455,7 @@ public void matchStickySymbol() throws Exception { + "var res = '' + result.length;\n" + "res = res + '-' + result[0];\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("1-a", script); + Utils.assertWithAllModes_ES6("1-a", script); } /** @@ -469,7 +469,7 @@ public void matchStickyAndGlobal() throws Exception { + "res = res + '-' + result[0];\n" + "res = res + '-' + result[1];\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("2-a-a", script); + Utils.assertWithAllModes_ES6("2-a-a", script); } /** @@ -483,7 +483,7 @@ public void matchStickyAndGlobalSymbol() throws Exception { + "res = res + '-' + result[0];\n" + "res = res + '-' + result[1];\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("2-a-a", script); + Utils.assertWithAllModes_ES6("2-a-a", script); } /** @@ -499,7 +499,7 @@ public void flagsPropery() throws Exception { + "res = res + '-' + get.enumerable;\n" + "res = res + '-' + get.writable;\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("0-undefined-true-false-undefined", script); + Utils.assertWithAllModes_ES6("0-undefined-true-false-undefined", script); } /** @@ -507,25 +507,24 @@ public void flagsPropery() throws Exception { */ @Test public void objectToString() throws Exception { - Utils.assertWithAllOptimizationLevelsES6( - "/undefined/undefined", "RegExp.prototype.toString.call({})"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6("/undefined/undefined", "RegExp.prototype.toString.call({})"); + Utils.assertWithAllModes_ES6( "/Foo/undefined", "RegExp.prototype.toString.call({source: 'Foo'})"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "/undefined/gy", "RegExp.prototype.toString.call({flags: 'gy'})"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "/Foo/g", "RegExp.prototype.toString.call({source: 'Foo', flags: 'g'})"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "/Foo/g", "RegExp.prototype.toString.call({source: 'Foo', flags: 'g', sticky: true})"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Method \"toString\" called on incompatible object", "try { RegExp.prototype.toString.call(''); } catch (e) { ('' + e).substr(0, 58) }"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Method \"toString\" called on incompatible object", "try { RegExp.prototype.toString.call(undefined); } catch (e) { ('' + e).substr(0, 58) }"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Method \"toString\" called on incompatible object", "var toString = RegExp.prototype.toString; try { toString(); } catch (e) { ('' + e).substr(0, 58) }"); } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/NativeStringTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/NativeStringTest.java index 94c3b27dad..86b092921e 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/NativeStringTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/NativeStringTest.java @@ -25,9 +25,8 @@ public class NativeStringTest { */ @Test public void toLowerCaseApply() { - Utils.assertWithAllOptimizationLevels( - "hello", "var x = String.toLowerCase; x.apply('HELLO')"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes("hello", "var x = String.toLowerCase; x.apply('HELLO')"); + Utils.assertWithAllModes( "hello", "String.toLowerCase('HELLO')"); // first patch proposed to #492359 was breaking this } @@ -36,7 +35,7 @@ public void toLowerCaseApply() { public void toLocaleLowerCase() { String js = "'\\u0130'.toLocaleLowerCase()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -47,7 +46,7 @@ public void toLocaleLowerCase() { return null; }); - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -63,7 +62,7 @@ public void toLocaleLowerCase() { public void toLocaleLowerCaseIgnoreParams() { String js = "'\\u0130'.toLocaleLowerCase('en')"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -74,7 +73,7 @@ public void toLocaleLowerCaseIgnoreParams() { return null; }); - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/OverloadTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/OverloadTest.java index 24ac009449..c97b700bb5 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/OverloadTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/OverloadTest.java @@ -50,7 +50,7 @@ public void jsFunctionToInterface() { } private static void assertEvaluates(final Object expected, final String source) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); final Object rep = cx.evaluateString(scope, source, "test.js", 0, null); @@ -61,7 +61,7 @@ private static void assertEvaluates(final Object expected, final String source) private static void assertThrows( final Class exceptionClass, final String source) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); try { diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/PrimitiveTypeScopeResolutionTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/PrimitiveTypeScopeResolutionTest.java index 6cb2523970..db7988628a 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/PrimitiveTypeScopeResolutionTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/PrimitiveTypeScopeResolutionTest.java @@ -59,7 +59,7 @@ public void elementAccess() { } private void testWithTwoScopes(final String scriptScope1, final String scriptScope2) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope1 = cx.initStandardObjects(new MySimpleScriptableObject("scope1")); @@ -126,7 +126,7 @@ public void functionObjectPrimitiveToObject() throws Exception { final String scriptScope1 = "String.prototype.foo = 'from 1'; scope2.f()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope1 = cx.initStandardObjects(new MySimpleScriptableObject("scope1")); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java index 7638cc24bd..305286805a 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java @@ -16,7 +16,7 @@ public class ScriptRuntimeEquivalentValuesTest { @Test public void equivalentValuesUndefined() throws Exception { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); try { @@ -40,7 +40,7 @@ public void equivalentValuesUndefined() throws Exception { @Test public void equivalentValuesNull() throws Exception { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); try { diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java index 1886412f36..939dc90936 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java @@ -1,12 +1,8 @@ package org.mozilla.javascript.tests; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -91,10 +87,8 @@ public class ToNumberConversionsTest { public static Collection data() { List cases = new ArrayList<>(); - for (boolean interpreted : new boolean[] {false, true}) { - for (Object[] test : TESTS) { - cases.add(new Object[] {test[0], test[1], interpreted}); - } + for (Object[] test : TESTS) { + cases.add(new Object[] {test[0], test[1]}); } return cases; @@ -106,56 +100,37 @@ public static Collection data() { @Parameterized.Parameter(1) public String source; - @Parameterized.Parameter(2) - public boolean interpreted; - @SuppressWarnings("ConstantConditions") private boolean execute(Context cx, Scriptable scope, String script) { return (Boolean) cx.evaluateString(scope, script, "inline", 1, null); } - public Context cx; - public Scriptable scope; - - @Before - public void setup() { - cx = Context.enter(); - cx.setInterpretedMode(interpreted); - cx.setLanguageVersion(Context.VERSION_ES6); - scope = cx.initSafeStandardObjects(); - } - - @After - public void tearDown() { - Context.exit(); - } - @Test public void cumberConstructor() { String script = String.format("%seq(Number(\"%s\"), %s)", PRELUDE, source, expected); - assertTrue( - "Number('" + source + "') doesn't produce " + expected, execute(cx, scope, script)); + Utils.assertWithAllModes_ES6( + "Number('" + source + "') doesn't produce " + expected, true, script); } @Test public void coercion() { String script = String.format("%seq(+(\"%s\"), %s)", PRELUDE, source, expected); - assertTrue("+('" + source + "') doesn't produce " + expected, execute(cx, scope, script)); + Utils.assertWithAllModes_ES6( + "+('" + source + "') doesn't produce " + expected, true, script); } @Test public void isNaN() { String script = String.format("%seq(isNaN(\"%s\"), isNaN(%s))", PRELUDE, source, expected); - assertTrue( - "isNaN('" + source + "') !== isNaN(" + expected + ")", execute(cx, scope, script)); + Utils.assertWithAllModes_ES6( + "isNaN('" + source + "') !== isNaN(" + expected + ")", true, script); } @Test public void isFinite() { String script = String.format("%seq(isFinite(\"%s\"), isFinite(%s))", PRELUDE, source, expected); - assertTrue( - "isFinite('" + source + "') !== isFinite(" + expected + ")", - execute(cx, scope, script)); + Utils.assertWithAllModes_ES6( + "isFinite('" + source + "') !== isFinite(" + expected + ")", true, script); } } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/TypeOfTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/TypeOfTest.java index edd77275b6..18e38d4f51 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/TypeOfTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/TypeOfTest.java @@ -70,7 +70,7 @@ public void bug453360() throws Exception { } private static void doTest(String expected, final String script, final Scriptable obj) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); scope.put("myObj", scope, obj); diff --git a/tests/src/test/java/org/mozilla/javascript/tests/ComputedPropertiesTest.java b/tests/src/test/java/org/mozilla/javascript/tests/ComputedPropertiesTest.java index 09daa0850d..467a5dc1e9 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/ComputedPropertiesTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/ComputedPropertiesTest.java @@ -4,199 +4,106 @@ package org.mozilla.javascript.tests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; - import org.junit.Test; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.EvaluatorException; -import org.mozilla.javascript.ScriptableObject; public class ComputedPropertiesTest { @Test public void objectWithComputedPropertiesWorks() { - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - String script = - "\n" - + "function f(x) { return x; }\n" - + "\n" - + "var o = {\n" - + " a: 1,\n" - + " 0: 2,\n" - + " [-1]: 3\n," - + " [f('b')]: 4\n" - + "};\n" - + "o.a + o[0] + o['-1'] + o.b"; - - ScriptableObject scope = cx.initStandardObjects(); - Object value = cx.evaluateString(scope, script, "test", 1, null); - assertTrue(value instanceof Number); - assertEquals(10, ((Number) value).intValue()); - return null; - }); + String script = + "function f(x) { return x; }\n" + + "var o = {\n" + + " a: 1,\n" + + " 0: 2,\n" + + " [-1]: 3\n," + + " [f('b')]: 4\n" + + "};\n" + + "o.a + o[0] + o['-1'] + o.b"; + Utils.assertWithAllModes_ES6(10, script); } @Test public void canCoerceFunctionToString() { - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - String script = - "\n" - + "function f(x) {\n" - + " var o = {\n" - + " 1: true,\n" - + " [2]: false,\n" - + " [g(x)]: 3\n" - + " };\n" - + "}\n" - + "f.toString()"; - - ScriptableObject scope = cx.initStandardObjects(); - Object value = cx.evaluateString(scope, script, "test", 1, null); - assertTrue(value instanceof String); - assertEquals( - "function f(x) {\n" - + " var o = {\n" - + " 1: true,\n" - + " [2]: false,\n" - + " [g(x)]: 3\n" - + " };\n" - + "}", - value); - return null; - }); + String script = + "function f(x) {\n" + + " var o = {\n" + + " 1: true,\n" + + " [2]: false,\n" + + " [g(x)]: 3\n" + + " };\n" + + "}\n" + + "f.toString()"; + String expected = + "function f(x) {\n" + + " var o = {\n" + + " 1: true,\n" + + " [2]: false,\n" + + " [g(x)]: 3\n" + + " };\n" + + "}"; + + Utils.assertWithAllModes_ES6(expected, script); } @Test public void computedPropertiesWithSideEffectsWork() { - Utils.runWithAllOptimizationLevels( - cx -> { - ; - cx.setLanguageVersion(Context.VERSION_ES6); - String script = - "'use strict';\n" - + "var x = 0;\n" - + "var o = {\n" - + " [++x]: 'x',\n" - + " a: ++x,\n" - + " [++x]: 'y'\n" - + "};\n" - + "o[1] + o.a + o[3]"; - - ScriptableObject scope = cx.initStandardObjects(); - Object value = cx.evaluateString(scope, script, "test", 1, null); - assertEquals("x2y", value); - return null; - }); + String script = + "'use strict';\n" + + "var x = 0;\n" + + "var o = {\n" + + " [++x]: 'x',\n" + + " a: ++x,\n" + + " [++x]: 'y'\n" + + "};\n" + + "o[1] + o.a + o[3]"; + Utils.assertWithAllModes_ES6("x2y", script); } @Test public void computedPropertyNameForGetterSetterWork() { - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - String script = "var o = { get ['x' + 1]() { return 42; }}; o.x1"; - - ScriptableObject scope = cx.initStandardObjects(); - Object value = cx.evaluateString(scope, script, "test", 1, null); - assertTrue(value instanceof Number); - assertEquals(42, ((Number) value).intValue()); - return null; - }); + Utils.assertWithAllModes_ES6(42, "var o = { get ['x' + 1]() { return 42; }}; o.x1"); } @Test public void computedPropertyNameAsSymbolForGetterSetterWork() { - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - String script = - "var o = { get [Symbol.toStringTag]() { return 'foo'; }}; o.toString()"; - - ScriptableObject scope = cx.initStandardObjects(); - Object value = cx.evaluateString(scope, script, "test", 1, null); - assertEquals("[object foo]", value); - return null; - }); + Utils.assertWithAllModes_ES6( + "[object foo]", + "var o = { get [Symbol.toStringTag]() { return 'foo'; }}; o.toString()"); } @Test public void yieldWorksForPropertyValues() { - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - String script = - "\n" - + "function *gen() {\n" - + " ({x: yield 1});\n" - + "}\n" - + "var g = gen()\n" - + "var res1 = g.next();\n" - + "var res2 = g.next();\n" - + "res1.value === 1 && !res1.done && res2.done\n"; - - ScriptableObject scope = cx.initStandardObjects(); - Object value = cx.evaluateString(scope, script, "test", 1, null); - assertEquals(Boolean.TRUE, value); - return null; - }); + String script = + "function *gen() {\n" + + " ({x: yield 1});\n" + + "}\n" + + "var g = gen()\n" + + "var res1 = g.next();\n" + + "var res2 = g.next();\n" + + "res1.value === 1 && !res1.done && res2.done\n"; + + Utils.assertWithAllModes_ES6(Boolean.TRUE, script); } @Test public void cannotParseInvalidUnclosedBracket() { - String script = "o = { [3 : 2 }"; - - try (Context cx = Context.enter()) { - cx.setLanguageVersion(Context.VERSION_ES6); - EvaluatorException ex = - assertThrows( - EvaluatorException.class, - () -> cx.compileString(script, "test", 1, null)); - assertEquals("invalid property id (test#1)", ex.getMessage()); - } + Utils.assertEvaluatorExceptionES6("invalid property id (test#1)", "o = { [3 : 2 }"); } @Test public void notSupportedUnderVersionLesserThanEsLatest() { - String script = "o = { [1] : 2 }"; - - try (Context cx = Context.enter()) { - cx.setLanguageVersion(Context.VERSION_1_8); - EvaluatorException ex = - assertThrows( - EvaluatorException.class, - () -> cx.compileString(script, "test", 1, null)); - assertEquals("invalid property id (test#1)", ex.getMessage()); - } + Utils.assertEvaluatorException_1_8("invalid property id (test#1)", "o = { [1] : 2 }"); } @Test public void unsupportedInDestructuringInFunctionArguments() { - String script = "function({ [a]: b }) {};"; - assertComputedPropertiesAreUnsupportedInDestructuring( - script, "Unsupported computed property in destructuring. (test#1)"); + Utils.assertEvaluatorExceptionES6( + "Unsupported computed property in destructuring. (test#1)", + "function({ [a]: b }) {};"); } @Test public void unsupportedInDestructuringInVariableDeclaration() { - String script = "var { [a]: b } = {};"; - assertComputedPropertiesAreUnsupportedInDestructuring( - script, "Unsupported computed property in destructuring. (test#1)"); - } - - private void assertComputedPropertiesAreUnsupportedInDestructuring( - String script, String message) { - try (Context cx = Context.enter()) { - cx.setLanguageVersion(Context.VERSION_ES6); - EvaluatorException ex = - assertThrows( - EvaluatorException.class, - () -> cx.compileString(script, "test", 1, null)); - assertEquals(message, ex.getMessage()); - } + Utils.assertEvaluatorExceptionES6( + "Unsupported computed property in destructuring. (test#1)", "var { [a]: b } = {};"); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/CovariantReturnTypeTest.java b/tests/src/test/java/org/mozilla/javascript/tests/CovariantReturnTypeTest.java index 34e1972733..4e974993c6 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/CovariantReturnTypeTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/CovariantReturnTypeTest.java @@ -94,7 +94,7 @@ public void setValue5(Integer value5) { @Test public void checkIt() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Global scope = new Global(); scope.init(cx); diff --git a/tests/src/test/java/org/mozilla/javascript/tests/DefaultParametersTest.java b/tests/src/test/java/org/mozilla/javascript/tests/DefaultParametersTest.java index 6d6c2eef4e..48b1f032d9 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/DefaultParametersTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/DefaultParametersTest.java @@ -11,50 +11,50 @@ public class DefaultParametersTest { @Test public void functionDefaultArgsBasic() throws Exception { final String script = "function foo(a = 2) { return a; }"; - Utils.assertWithAllOptimizationLevelsES6(32, script + "\nfoo(32)"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "\nfoo()"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "\nfoo(undefined)"); + Utils.assertWithAllModes_ES6(32, script + "\nfoo(32)"); + Utils.assertWithAllModes_ES6(2, script + "\nfoo()"); + Utils.assertWithAllModes_ES6(2, script + "\nfoo(undefined)"); } @Test public void functionDefaultArgsBasicCall() throws Exception { final String script = "function b() { return 2; }; function foo(a = b()) { return a; }"; - Utils.assertWithAllOptimizationLevelsES6(32, script + "\nfoo(32)"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "\nfoo()"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "\nfoo(undefined)"); + Utils.assertWithAllModes_ES6(32, script + "\nfoo(32)"); + Utils.assertWithAllModes_ES6(2, script + "\nfoo()"); + Utils.assertWithAllModes_ES6(2, script + "\nfoo(undefined)"); } @Test public void functionDefaultArgsBasicArrow() throws Exception { final String script = "((a = 2, b) => { return a; })"; - Utils.assertWithAllOptimizationLevelsES6(32, script + "(32, 12)"); - Utils.assertWithAllOptimizationLevelsES6(12, script + "(12)"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "()"); + Utils.assertWithAllModes_ES6(32, script + "(32, 12)"); + Utils.assertWithAllModes_ES6(12, script + "(12)"); + Utils.assertWithAllModes_ES6(2, script + "()"); } @Test public void functionDefaultArgsArrayArrow() throws Exception { final String script = "(([a = 2, b = 1] = [1, 2]) => { return a + b; })"; - Utils.assertWithAllOptimizationLevelsES6(3, script + "()"); - Utils.assertWithAllOptimizationLevelsES6(5, script + "([4,])"); - Utils.assertWithAllOptimizationLevelsES6(6, script + "([,4])"); + Utils.assertWithAllModes_ES6(3, script + "()"); + Utils.assertWithAllModes_ES6(5, script + "([4,])"); + Utils.assertWithAllModes_ES6(6, script + "([,4])"); } @Test public void functionDefaultArgsMulti() throws Exception { final String script = "function foo(a = 2, b = 23) { return a + b; }"; - Utils.assertWithAllOptimizationLevelsES6(55, script + "\nfoo(32)"); - Utils.assertWithAllOptimizationLevelsES6(25, script + "\nfoo()"); - Utils.assertWithAllOptimizationLevelsES6(34, script + "\nfoo(32, 2)"); - Utils.assertWithAllOptimizationLevelsES6(25, script + "\nfoo(undefined, undefined)"); + Utils.assertWithAllModes_ES6(55, script + "\nfoo(32)"); + Utils.assertWithAllModes_ES6(25, script + "\nfoo()"); + Utils.assertWithAllModes_ES6(34, script + "\nfoo(32, 2)"); + Utils.assertWithAllModes_ES6(25, script + "\nfoo(undefined, undefined)"); } @Test public void functionDefaultArgsUsage() throws Exception { final String script = "function foo(a = 2, b = a * 2) { return a + b; }"; - Utils.assertWithAllOptimizationLevelsES6(96, script + "\nfoo(32)"); - Utils.assertWithAllOptimizationLevelsES6(6, script + "\nfoo()"); - Utils.assertWithAllOptimizationLevelsES6(34, script + "\nfoo(32, 2)"); + Utils.assertWithAllModes_ES6(96, script + "\nfoo(32)"); + Utils.assertWithAllModes_ES6(6, script + "\nfoo()"); + Utils.assertWithAllModes_ES6(34, script + "\nfoo(32, 2)"); } @Test @@ -80,9 +80,9 @@ public void CoverInitName() throws Exception { public void functionDefaultArgsObjectArrow() throws Exception { final String script = "(({x = 1} = {x: 2}) => {\n return x;\n})"; - Utils.assertWithAllOptimizationLevelsES6(1, script + "({})"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "()"); - Utils.assertWithAllOptimizationLevelsES6(3, script + "({x: 3})"); + Utils.assertWithAllModes_ES6(1, script + "({})"); + Utils.assertWithAllModes_ES6(2, script + "()"); + Utils.assertWithAllModes_ES6(3, script + "({x: 3})"); } @Test @@ -95,7 +95,7 @@ public void letExprDestructuring() throws Exception { + " return x; " + " }" + " })()"; - Utils.assertWithAllOptimizationLevelsES6(12, script); + Utils.assertWithAllModes_ES6(12, script); } @Test @@ -104,8 +104,8 @@ public void normObjectLiteralDestructuringFunCall() throws Exception { final String script = "function a() { return 2;}; let {x = a()} = {x: 12}; x"; final String script2 = "function a() { return 2;}; let {x = 12} = {x: a()}; x"; - Utils.assertWithAllOptimizationLevelsES6(12, script); - Utils.assertWithAllOptimizationLevelsES6(2, script2); + Utils.assertWithAllModes_ES6(12, script); + Utils.assertWithAllModes_ES6(2, script2); } @Test @@ -120,10 +120,10 @@ public void normDefaultParametersObjectDestructuringFunCall() throws Exception { final String script4 = "function a() { return 12;}; function b({x = 1} = {x: a()}) { return x }; b()\n"; - Utils.assertWithAllOptimizationLevelsES6(1, script); - Utils.assertWithAllOptimizationLevelsES6(12, script2); - Utils.assertWithAllOptimizationLevelsES6(121, script3); - Utils.assertWithAllOptimizationLevelsES6(12, script4); + Utils.assertWithAllModes_ES6(1, script); + Utils.assertWithAllModes_ES6(12, script2); + Utils.assertWithAllModes_ES6(121, script3); + Utils.assertWithAllModes_ES6(12, script4); } @Test @@ -138,17 +138,17 @@ public void normDefaultParametersArrayDestructuringFunCall() throws Exception { final String script4 = "function a() { return 12;}; function b([x = 1] = [a()]) { return x }; b()\n"; - Utils.assertWithAllOptimizationLevelsES6(1, script); - Utils.assertWithAllOptimizationLevelsES6(12, script2); - Utils.assertWithAllOptimizationLevelsES6(121, script3); - Utils.assertWithAllOptimizationLevelsES6(12, script4); + Utils.assertWithAllModes_ES6(1, script); + Utils.assertWithAllModes_ES6(12, script2); + Utils.assertWithAllModes_ES6(121, script3); + Utils.assertWithAllModes_ES6(12, script4); } @Test public void normDefaultParametersFunCall() throws Exception { // JavaScript final String script = "function a() { return 12;}; function b(x = a()) { return x }; b()"; - Utils.assertWithAllOptimizationLevelsES6(12, script); + Utils.assertWithAllModes_ES6(12, script); } @Test @@ -161,7 +161,7 @@ public void letExprDestructuringFunCall() throws Exception { + " return x; " + " }" + " })()"; - Utils.assertWithAllOptimizationLevelsES6(4, script); + Utils.assertWithAllModes_ES6(4, script); } @Test @@ -179,7 +179,7 @@ public void letExprUnresolvableRefDestructuring() throws Exception { public void destructuringNestedArray() throws Exception { // JavaScript final String script = "let [[y], x] = [[4], 3]; x + y"; - Utils.assertWithAllOptimizationLevelsES6(7, script); + Utils.assertWithAllModes_ES6(7, script); } @Test @@ -195,7 +195,7 @@ public void getIntPropArg() throws Exception { final String script = "function foo([gen = function () { return 2; }, xGen = function* x() { yield 2; }] = []) {\n" + " return gen() + xGen().next().value; }"; - Utils.assertWithAllOptimizationLevelsES6(4, script + "; foo()"); + Utils.assertWithAllModes_ES6(4, script + "; foo()"); } @Test @@ -203,7 +203,7 @@ public void getIntErrPropArg() throws Exception { final String script = "var e = 0; var b = 'hello'; var { f: y = ++e } = { f: { get: function() {}}}; " + "Object.keys(y).includes('get') && Object.keys(y).length == 1"; - Utils.assertWithAllOptimizationLevelsES6(true, script); + Utils.assertWithAllModes_ES6(true, script); } @Test @@ -211,7 +211,7 @@ public void getIntPropArgParenExpr() throws Exception { final String script = "const [cover = (function () {}), xCover = (0, function() {})] = [];\n" + "cover.name == 'cover' && xCover.name == 'xCover' ? 4 : -1"; - Utils.assertWithAllOptimizationLevelsES6(-1, script); + Utils.assertWithAllModes_ES6(-1, script); } @Test @@ -219,13 +219,13 @@ public void getIntProp() throws Exception { final String script = "const { gen = function () { return 2;}, xGen = function* () { yield 2;} } = {};\n" + "gen() + xGen().next().value"; - Utils.assertWithAllOptimizationLevelsES6(4, script); + Utils.assertWithAllModes_ES6(4, script); } @Test public void getIntPropExhausted() throws Exception { final String script = "const [x = 23] = []; x"; - Utils.assertWithAllOptimizationLevelsES6(23, script); + Utils.assertWithAllModes_ES6(23, script); } @Test @@ -239,7 +239,7 @@ public void functionDefaultArgsMultiFollowUsage() throws Exception { + " return a; " + "}\n" + "\n"; - Utils.assertWithAllOptimizationLevelsES6(24, script + "\nf(24)"); + Utils.assertWithAllModes_ES6(24, script + "\nf(24)"); Utils.assertEcmaErrorES6( "ReferenceError: \"go\" is not defined.", "function f() { go() }; var f1 = f()"); Utils.assertEcmaErrorES6("ReferenceError: \"go\" is not defined.", script + "\nf()"); @@ -255,9 +255,9 @@ public void functionDefaultArgsMultiReferEarlier() throws Exception { @Test public void functionConstructor() throws Exception { final String script = "const f = new Function('a=2', 'b=a', 'return a + b');"; - Utils.assertWithAllOptimizationLevelsES6(4, script + "f()"); - Utils.assertWithAllOptimizationLevelsES6(6, script + "f(3)"); - Utils.assertWithAllOptimizationLevelsES6(16, script + "f(3, 13)"); + Utils.assertWithAllModes_ES6(4, script + "f()"); + Utils.assertWithAllModes_ES6(6, script + "f(3)"); + Utils.assertWithAllModes_ES6(16, script + "f(3, 13)"); } @Test @@ -267,16 +267,16 @@ public void destructuringAssigmentDefaultArray() throws Exception { + " return x + y + z;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6(7, script + "f()"); - Utils.assertWithAllOptimizationLevelsES6(7, script + "f([])"); - Utils.assertWithAllOptimizationLevelsES6(4, script + "f([], [])"); - Utils.assertWithAllOptimizationLevelsES6(8, script + "f([2])"); - Utils.assertWithAllOptimizationLevelsES6(5, script + "f([2], [])"); - Utils.assertWithAllOptimizationLevelsES6(8, script + "f([], [5])"); - Utils.assertWithAllOptimizationLevelsES6(6, script + "f([2, 3], [])"); - Utils.assertWithAllOptimizationLevelsES6(9, script + "f([2, 3], [4])"); - Utils.assertWithAllOptimizationLevelsES6(7, script + "f([2], [3])"); - Utils.assertWithAllOptimizationLevelsES6(9, script + "f([2, 3])"); + Utils.assertWithAllModes_ES6(7, script + "f()"); + Utils.assertWithAllModes_ES6(7, script + "f([])"); + Utils.assertWithAllModes_ES6(4, script + "f([], [])"); + Utils.assertWithAllModes_ES6(8, script + "f([2])"); + Utils.assertWithAllModes_ES6(5, script + "f([2], [])"); + Utils.assertWithAllModes_ES6(8, script + "f([], [5])"); + Utils.assertWithAllModes_ES6(6, script + "f([2, 3], [])"); + Utils.assertWithAllModes_ES6(9, script + "f([2, 3], [4])"); + Utils.assertWithAllModes_ES6(7, script + "f([2], [3])"); + Utils.assertWithAllModes_ES6(9, script + "f([2, 3])"); } @Test @@ -292,15 +292,15 @@ public void destructuringAssigmentInFunctionsWithObjectDefaults() throws Excepti @Test public void destructuringTest() throws Exception { final String script = "function f([x]) { return x; }; f([1]);"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + Utils.assertWithAllModes_ES6(1, script); } @Test public void destructuringAssignmentDefaultArray() throws Exception { final String script = "var [a = 10] = []; a"; final String script2 = "var [a = 10] = [1]; a"; - Utils.assertWithAllOptimizationLevelsES6(10, script); - Utils.assertWithAllOptimizationLevelsES6(1, script2); + Utils.assertWithAllModes_ES6(10, script); + Utils.assertWithAllModes_ES6(1, script2); } @Test @@ -309,72 +309,72 @@ public void destructuringAssignmentDefaultObject() throws Exception { final String script3 = "var a = 20; var {a: b = 10} = {hello: 3}; b+a"; final String script4 = "var a = 30; var {a: b = 10} = {}; b+a"; Utils.assertEcmaErrorES6("ReferenceError", script1); - Utils.assertWithAllOptimizationLevelsES6(30, script3); - Utils.assertWithAllOptimizationLevelsES6(40, script4); + Utils.assertWithAllModes_ES6(30, script3); + Utils.assertWithAllModes_ES6(40, script4); } @Test public void destructuringHookTest() throws Exception { final String script = "function f([x]) { return x == undefined ? 2 : x; }; f([1]);"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + Utils.assertWithAllModes_ES6(1, script); } @Test public void destructuringAssigmentRealRealBasicArray() throws Exception { final String script = "function f([x] = [1]) {\n return x;\n }"; - Utils.assertWithAllOptimizationLevelsES6(1, script + "f()"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "f([2])"); - Utils.assertWithAllOptimizationLevelsES6(42, script + "f([]) == undefined ? 42 : 0"); + Utils.assertWithAllModes_ES6(1, script + "f()"); + Utils.assertWithAllModes_ES6(2, script + "f([2])"); + Utils.assertWithAllModes_ES6(42, script + "f([]) == undefined ? 42 : 0"); } @Test public void destructuringAssigmentRealBasicArray() throws Exception { final String script = "function f([x = 1]) {\n return x;\n }"; - Utils.assertWithAllOptimizationLevelsES6(1, script + "f([])"); - Utils.assertWithAllOptimizationLevelsES6(3, script + "f([3])"); + Utils.assertWithAllModes_ES6(1, script + "f([])"); + Utils.assertWithAllModes_ES6(3, script + "f([3])"); Utils.assertEcmaErrorES6("TypeError", script + "f()"); } @Test public void destructuringAssigmentBasicArray() throws Exception { final String script = "function f([x = 1] = [2]) {\n return x;\n }"; - Utils.assertWithAllOptimizationLevelsES6(1, script + "f([])"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "f()"); - Utils.assertWithAllOptimizationLevelsES6(3, script + "f([3])"); + Utils.assertWithAllModes_ES6(1, script + "f([])"); + Utils.assertWithAllModes_ES6(2, script + "f()"); + Utils.assertWithAllModes_ES6(3, script + "f([3])"); } @Test public void destructuringAssigmentBasicObject() throws Exception { final String script = "function f({x = 1} = {x: 2}) {\n return x;\n }"; - Utils.assertWithAllOptimizationLevelsES6(1, script + "f({})"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "f()"); - Utils.assertWithAllOptimizationLevelsES6(3, script + "f({x: 3})"); + Utils.assertWithAllModes_ES6(1, script + "f({})"); + Utils.assertWithAllModes_ES6(2, script + "f()"); + Utils.assertWithAllModes_ES6(3, script + "f({x: 3})"); } @Test public void destructuringAssigmentRealBasicObject() throws Exception { final String script = "function f({x = 1}) {\n return x;\n }"; - Utils.assertWithAllOptimizationLevelsES6(1, script + "f({})"); + Utils.assertWithAllModes_ES6(1, script + "f({})"); Utils.assertEcmaErrorES6("TypeError", script + "f()"); - Utils.assertWithAllOptimizationLevelsES6(3, script + "f({x: 3})"); + Utils.assertWithAllModes_ES6(3, script + "f({x: 3})"); } @Test public void destructuringAssigmentDefaultObject() throws Exception { final String script = "function f({ z = 3, x = 2 } = {}) {\n return z;\n}\n"; - Utils.assertWithAllOptimizationLevelsES6(3, script + "f()"); - Utils.assertWithAllOptimizationLevelsES6(3, script + "f({})"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "f({z: 2})"); + Utils.assertWithAllModes_ES6(3, script + "f()"); + Utils.assertWithAllModes_ES6(3, script + "f({})"); + Utils.assertWithAllModes_ES6(2, script + "f({z: 2})"); } @Test public void destructuringAssigmentDefaultObjectWithDefaults() throws Exception { final String script = "function f({ z = 3, x = 2 } = {z: 4, x: 5}) {\n return z;\n}\n"; - Utils.assertWithAllOptimizationLevelsES6(4, script + "f()"); - Utils.assertWithAllOptimizationLevelsES6(3, script + "f({})"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "f({z: 2})"); + Utils.assertWithAllModes_ES6(4, script + "f()"); + Utils.assertWithAllModes_ES6(3, script + "f({})"); + Utils.assertWithAllModes_ES6(2, script + "f({z: 2})"); } @Test @@ -387,9 +387,9 @@ public void deeplyNestedObjectLiteral() throws Exception { + " }\n" + " }\n" + " \n"; - Utils.assertWithAllOptimizationLevelsES6("hello", script + "b"); - Utils.assertWithAllOptimizationLevelsES6("world", script + "a"); - Utils.assertWithAllOptimizationLevelsES6("hello", script + "d.b"); + Utils.assertWithAllModes_ES6("hello", script + "b"); + Utils.assertWithAllModes_ES6("world", script + "a"); + Utils.assertWithAllModes_ES6("hello", script + "d.b"); } @Test @@ -409,12 +409,12 @@ public void defaultParametersWithArgumentsObject() throws Exception { + "function h(a = 55) {\n" + " return arguments.length;\n" + "}\n"; - Utils.assertWithAllOptimizationLevelsES6(10, script + "f(10)"); - Utils.assertWithAllOptimizationLevelsES6(55, script + "f()"); - Utils.assertWithAllOptimizationLevelsES6(10, script + "g(10)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, script + "g()"); - Utils.assertWithAllOptimizationLevelsES6(0, script + "h()"); - Utils.assertWithAllOptimizationLevelsES6(1, script + "h(10)"); + Utils.assertWithAllModes_ES6(10, script + "f(10)"); + Utils.assertWithAllModes_ES6(55, script + "f()"); + Utils.assertWithAllModes_ES6(10, script + "g(10)"); + Utils.assertWithAllModes_ES6(Undefined.instance, script + "g()"); + Utils.assertWithAllModes_ES6(0, script + "h()"); + Utils.assertWithAllModes_ES6(1, script + "h(10)"); } @Test @@ -425,8 +425,8 @@ public void functionDefaultArgsArray() throws Exception { + " return array;\n" + "}\n" + "\n"; - Utils.assertWithAllOptimizationLevelsES6(1, script + "append(1)[0]"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "append(2)[0]"); + Utils.assertWithAllModes_ES6(1, script + "append(1)[0]"); + Utils.assertWithAllModes_ES6(2, script + "append(2)[0]"); } @Test @@ -438,8 +438,8 @@ public void functionDefaultArgsObject() throws Exception { + "}\n" + "\n"; - Utils.assertWithAllOptimizationLevelsES6(1, script + "append('a', 1)['a']"); - Utils.assertWithAllOptimizationLevelsES6(2, script + "append('a', 2)['a']"); + Utils.assertWithAllModes_ES6(1, script + "append('a', 1)['a']"); + Utils.assertWithAllModes_ES6(2, script + "append('a', 2)['a']"); } @Test diff --git a/tests/src/test/java/org/mozilla/javascript/tests/ForTest.java b/tests/src/test/java/org/mozilla/javascript/tests/ForTest.java index 07218bc236..3bd9e9af6d 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/ForTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/ForTest.java @@ -12,6 +12,6 @@ public class ForTest { /** Test for issue #645. There was a NPE. */ @Test public void forInit() { - Utils.assertWithAllOptimizationLevels(Undefined.instance, "for(({});;){ break; }"); + Utils.assertWithAllModes(Undefined.instance, "for(({});;){ break; }"); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/LambdaAccessorSlotTest.java b/tests/src/test/java/org/mozilla/javascript/tests/LambdaAccessorSlotTest.java index 51097fe5e8..7ad4caa694 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/LambdaAccessorSlotTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/LambdaAccessorSlotTest.java @@ -15,7 +15,7 @@ public class LambdaAccessorSlotTest { @Test public void testGetterProperty() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -40,7 +40,7 @@ public void testGetterProperty() { @Test public void testThrowIfNeitherGetterOrSetterAreDefined() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); var error = @@ -59,7 +59,7 @@ public void testThrowIfNeitherGetterOrSetterAreDefined() { @Test public void testCanUpdateValueUsingSetter() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -90,7 +90,7 @@ public void testCanUpdateValueUsingSetter() { @Test public void testOnlyGetterCanBeAccessed() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -119,7 +119,7 @@ public void testOnlyGetterCanBeAccessed() { @Test public void testRedefineExistingProperty() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); var sh = new StatusHolder("PENDING"); @@ -148,7 +148,7 @@ public void testRedefineExistingProperty() { @Test public void testWhenNoSetterDefined_InStrictMode_WillThrowException() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -183,7 +183,7 @@ public void testWhenNoSetterDefined_InStrictMode_WillThrowException() { @Test public void testWhenNoSetterDefined_InNormalMode_NoErrorButValueIsNotChanged() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -213,7 +213,7 @@ public void testWhenNoSetterDefined_InNormalMode_NoErrorButValueIsNotChanged() { @Test public void testSetterOnly_WillModifyUnderlyingValue() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -240,7 +240,7 @@ public void testSetterOnly_WillModifyUnderlyingValue() { @Test public void testGetterUsing_getOwnPropertyDescriptor() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -263,7 +263,7 @@ public void testGetterUsing_getOwnPropertyDescriptor() { @Test public void testSetterOnlyUsing_getOwnPropertyDescriptor() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -292,7 +292,7 @@ public void testSetterOnlyUsing_getOwnPropertyDescriptor() { @Test public void testSetValueUsing_getOwnPropertyDescriptor() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -320,7 +320,7 @@ public void testSetValueUsing_getOwnPropertyDescriptor() { @Test public void testSetterOnlyUsing_getOwnPropertyDescriptor_ErrorOnGet() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -351,7 +351,7 @@ public void testSetterOnlyUsing_getOwnPropertyDescriptor_ErrorOnGet() { @Test public void testRedefineExistingProperty_ChangingConfigurableAttr_ShouldFailValidation() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); var sh = new StatusHolder("PENDING"); @@ -386,7 +386,7 @@ public void testRedefineExistingProperty_ChangingConfigurableAttr_ShouldFailVali @Test public void testRedefineExistingProperty_ModifyingNotConfigurableProperty_ShouldFailValidation() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); var sh = new StatusHolder("PENDING"); @@ -424,7 +424,7 @@ public void testRedefineExistingProperty_ChangingConfigurableAttr_ShouldFailVali @Test public void testSetterOnlyUsing_getOwnPropertyDescriptor_InStrictMode_ErrorOnGet() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -456,7 +456,7 @@ public void testSetterOnlyUsing_getOwnPropertyDescriptor_InStrictMode_ErrorOnGet @Test public void testGetterOnlyUsing_getOwnPropertyDescriptor_ErrorOnSet() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) @@ -484,7 +484,7 @@ public void testGetterOnlyUsing_getOwnPropertyDescriptor_ErrorOnSet() { @Test public void testGetterOnlyUsing_getOwnPropertyDescriptor_InStrictMode_ErrorOnSet() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { Scriptable scope = cx.initStandardObjects(); StatusHolder.init(scope) diff --git a/tests/src/test/java/org/mozilla/javascript/tests/LambdaFunctionTest.java b/tests/src/test/java/org/mozilla/javascript/tests/LambdaFunctionTest.java index 0554f87823..2730a55776 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/LambdaFunctionTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/LambdaFunctionTest.java @@ -37,8 +37,7 @@ public void cleanup() { } private void eval(String source) { - Utils.runWithAllOptimizationLevels( - ignored -> cx.evaluateString(root, source, "test.js", 1, null)); + Utils.runWithAllModes(ignored -> cx.evaluateString(root, source, "test.js", 1, null)); } @Test diff --git a/tests/src/test/java/org/mozilla/javascript/tests/NativeObjectTest.java b/tests/src/test/java/org/mozilla/javascript/tests/NativeObjectTest.java index a17e955309..ca2b995b20 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/NativeObjectTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/NativeObjectTest.java @@ -25,7 +25,7 @@ public void freeze_captureStackTrace() throws Exception { + "Error.captureStackTrace(myError);\n" + "Object.freeze(myError);\n" + "myError.stack.trim();"; - Utils.assertWithAllOptimizationLevelsTopLevelScopeES6("at test.js:1", script); + Utils.assertWithAllModesTopLevelScope_ES6("at test.js:1", script); } /** @@ -42,8 +42,7 @@ public void getOwnPropertyDescriptor_captureStackTrace() throws Exception { + "var desc = Object.getOwnPropertyDescriptor(myError, 'stack');\n" + "var res = '' + desc.get + '-' + desc.set + '-' + desc.value;\n" + "res = res.replace(/(\\n|\\r)/gm, '');"; - Utils.assertWithAllOptimizationLevelsTopLevelScopeES6( - "undefined-undefined-\tat test.js:1", script); + Utils.assertWithAllModesTopLevelScope_ES6("undefined-undefined-\tat test.js:1", script); } /** @@ -59,7 +58,7 @@ public void getOwnPropertyDescriptorAttributes_captureStackTrace() throws Except + "Error.captureStackTrace(myError);\n" + "var desc = Object.getOwnPropertyDescriptor(myError, 'stack');\n" + "desc.writable + ' ' + desc.configurable + ' ' + desc.enumerable"; - Utils.assertWithAllOptimizationLevelsTopLevelScopeES6("true true false", script); + Utils.assertWithAllModesTopLevelScope_ES6("true true false", script); } public static class JavaObj { diff --git a/tests/src/test/java/org/mozilla/javascript/tests/NullishCoalescingOpTest.java b/tests/src/test/java/org/mozilla/javascript/tests/NullishCoalescingOpTest.java index 7e1ec06ccd..54b7159cfd 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/NullishCoalescingOpTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/NullishCoalescingOpTest.java @@ -1,31 +1,18 @@ package org.mozilla.javascript.tests; -import static org.junit.Assert.assertThrows; - import org.junit.Test; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.EvaluatorException; -import org.mozilla.javascript.Scriptable; public class NullishCoalescingOpTest { @Test public void testNullishCoalescingOperatorRequiresES6() { - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_DEFAULT); - Scriptable scope = cx.initStandardObjects(); - assertThrows( - EvaluatorException.class, - () -> cx.evaluateString(scope, "true ?? false", "test.js", 0, null)); - return null; - }); + Utils.assertEvaluatorException_1_8("syntax error (test#1)", "true ?? false"); } @Test public void testNullishCoalescingBasic() { - Utils.assertWithAllOptimizationLevelsES6("val", "'val' ?? 'default string'"); - Utils.assertWithAllOptimizationLevelsES6("default string", "null ?? 'default string'"); - Utils.assertWithAllOptimizationLevelsES6("default string", "undefined ?? 'default string'"); + Utils.assertWithAllModes_ES6("val", "'val' ?? 'default string'"); + Utils.assertWithAllModes_ES6("default string", "null ?? 'default string'"); + Utils.assertWithAllModes_ES6("default string", "undefined ?? 'default string'"); } @Test @@ -45,8 +32,7 @@ public void testNullishCoalescingShortCircuit() { @Test public void testNullishCoalescingPrecedence() { - Utils.assertWithAllOptimizationLevelsES6( - "yes", "3 == 3 ? 'yes' ?? 'default string' : 'no'"); + Utils.assertWithAllModes_ES6("yes", "3 == 3 ? 'yes' ?? 'default string' : 'no'"); } @Test @@ -56,7 +42,7 @@ public void testNullishCoalescingEvalOnce() { + "function f() { runs++; return 3; } \n" + "var eval1 = f() ?? 42; \n" + "runs"; - Utils.assertWithAllOptimizationLevelsES6(1, script); + Utils.assertWithAllModes_ES6(1, script); } @Test @@ -66,34 +52,24 @@ public void testNullishCoalescingDoesNotEvaluateRightHandSideIfNotNecessary() { + "function f() { runs++; return 3; } \n" + "var eval1 = 42 ?? f(); \n" + "runs"; - Utils.assertWithAllOptimizationLevelsES6(0, script); + Utils.assertWithAllModes_ES6(0, script); } @Test public void testNullishCoalescingDoesNotLeakVariables() { String script = "$0 = false; true ?? true; $0"; - Utils.assertWithAllOptimizationLevelsES6(false, script); + Utils.assertWithAllModes_ES6(false, script); } @Test public void testNullishAssignmentRequiresES6() { - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_DEFAULT); - Scriptable scope = cx.initStandardObjects(); - assertThrows( - EvaluatorException.class, - () -> - cx.evaluateString( - scope, "a = true; a ??= false", "test.js", 0, null)); - return null; - }); + Utils.assertEvaluatorException_1_8("syntax error (test#1)", "a = true; a ??= false"); } @Test public void testNullishAssignment() { - Utils.assertWithAllOptimizationLevelsES6(true, "a = true; a ??= false; a"); - Utils.assertWithAllOptimizationLevelsES6(false, "a = undefined; a ??= false; a"); - Utils.assertWithAllOptimizationLevelsES6(false, "a = null; a ??= false; a"); + Utils.assertWithAllModes_ES6(true, "a = true; a ??= false; a"); + Utils.assertWithAllModes_ES6(false, "a = undefined; a ??= false; a"); + Utils.assertWithAllModes_ES6(false, "a = null; a ??= false; a"); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/ObserveInstructionCountTest.java b/tests/src/test/java/org/mozilla/javascript/tests/ObserveInstructionCountTest.java index a17ffd554b..f50385c784 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/ObserveInstructionCountTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/ObserveInstructionCountTest.java @@ -76,7 +76,7 @@ protected Object doTopCall( } private static void baseCase(String source) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( new MyFactory(), cx -> { assertTrue(cx instanceof MyContext); @@ -128,7 +128,7 @@ public void longRunningRegExp() { /** see https://github.com/mozilla/rhino/issues/1497 */ @Test public void regExpObserved() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( new ContextFactory() { @Override protected Context makeContext() { diff --git a/tests/src/test/java/org/mozilla/javascript/tests/OptionalChainingOperatorTest.java b/tests/src/test/java/org/mozilla/javascript/tests/OptionalChainingOperatorTest.java index 75f6d6eab2..1457f52afd 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/OptionalChainingOperatorTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/OptionalChainingOperatorTest.java @@ -1,77 +1,60 @@ package org.mozilla.javascript.tests; -import static org.junit.Assert.assertThrows; - import org.junit.Test; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.EvaluatorException; -import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Undefined; public class OptionalChainingOperatorTest { @Test public void requiresES6() { - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_DEFAULT); - Scriptable scope = cx.initStandardObjects(); - assertThrows( - EvaluatorException.class, - () -> cx.evaluateString(scope, "a?.b", "test.js", 0, null)); - return null; - }); + Utils.assertEvaluatorException_1_8("syntax error (test#1)", "a?.b"); } @Test public void simplePropertyAccess() { - Utils.assertWithAllOptimizationLevelsES6("val", "var a = {b: 'val'}; a?.b"); - Utils.assertWithAllOptimizationLevelsES6("val", "var a = {b: {c: 'val'}}; a?.b?.c"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "var a = null; a?.b"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "var a = undefined; a?.b"); + Utils.assertWithAllModes_ES6("val", "var a = {b: 'val'}; a?.b"); + Utils.assertWithAllModes_ES6("val", "var a = {b: {c: 'val'}}; a?.b?.c"); + Utils.assertWithAllModes_ES6(Undefined.instance, "var a = null; a?.b"); + Utils.assertWithAllModes_ES6(Undefined.instance, "var a = undefined; a?.b"); } @Test public void specialRef() { - Utils.assertWithAllOptimizationLevelsES6( - true, "var a = {}; a?.__proto__ === Object.prototype"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "var a = null; a?.__proto__"); - Utils.assertWithAllOptimizationLevelsES6( - Undefined.instance, "var a = undefined; a?.__proto__"); + Utils.assertWithAllModes_ES6(true, "var a = {}; a?.__proto__ === Object.prototype"); + Utils.assertWithAllModes_ES6(Undefined.instance, "var a = null; a?.__proto__"); + Utils.assertWithAllModes_ES6(Undefined.instance, "var a = undefined; a?.__proto__"); } @Test public void afterExpression() { - Utils.assertWithAllOptimizationLevelsES6(1, "var a = {b: 'x'}; a.b?.length"); - Utils.assertWithAllOptimizationLevelsES6( - Undefined.instance, "var a = {b: 'x'}; a.c?.length"); - Utils.assertWithAllOptimizationLevelsES6( - Undefined.instance, "var a = [1, 2, 3]; a[42]?.name"); + Utils.assertWithAllModes_ES6(1, "var a = {b: 'x'}; a.b?.length"); + Utils.assertWithAllModes_ES6(Undefined.instance, "var a = {b: 'x'}; a.c?.length"); + Utils.assertWithAllModes_ES6(Undefined.instance, "var a = [1, 2, 3]; a[42]?.name"); } @Test public void expressions() { - Utils.assertWithAllOptimizationLevelsES6(true, "o = {a: true}; o?.['a']"); - Utils.assertWithAllOptimizationLevelsES6(true, "o = {[42]: true}; o?.[42]"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "o = null; o?.['a']"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "o = undefined; o?.['a']"); + Utils.assertWithAllModes_ES6(true, "o = {a: true}; o?.['a']"); + Utils.assertWithAllModes_ES6(true, "o = {[42]: true}; o?.[42]"); + Utils.assertWithAllModes_ES6(Undefined.instance, "o = null; o?.['a']"); + Utils.assertWithAllModes_ES6(Undefined.instance, "o = undefined; o?.['a']"); } @Test public void expressionsAreNotEvaluatedIfNotNecessary() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( 1, "var counter = 0;\n" + "function f() { ++counter; return 0; }\n" + "var o = {}\n" + "o?.[f()];\n" + "counter\n"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( 0, "var counter = 0;\n" + "function f() { ++counter; return 0; }\n" + "null?.[f()];\n" + "counter\n"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( 0, "var counter = 0;\n" + "function f() { ++counter; return 0; }\n" @@ -81,7 +64,7 @@ public void expressionsAreNotEvaluatedIfNotNecessary() { @Test public void leftHandSideIsEvaluatedOnlyOnce() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( 1, "var counter = 0;\n" + "function f() {\n" @@ -94,13 +77,13 @@ public void leftHandSideIsEvaluatedOnlyOnce() { @Test public void doesNotLeakVariables() { - Utils.assertWithAllOptimizationLevelsES6(false, "$0 = false; o = {}; o?.x; $0"); + Utils.assertWithAllModes_ES6(false, "$0 = false; o = {}; o?.x; $0"); } @Test public void shortCircuits() { - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = undefined; a?.b.c"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = {}; a.b?.c.d.e"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = undefined; a?.b.c"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {}; a.b?.c.d.e"); } @Test @@ -108,134 +91,121 @@ public void standardFunctionCall() { // Various combination of arguments for compiled mode, where we have special cases for 0, 1, // and 2 args - Utils.assertWithAllOptimizationLevelsES6(1, "function f() {return 1;} f?.()"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "f = null; f?.()"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "f = undefined; f?.()"); + Utils.assertWithAllModes_ES6(1, "function f() {return 1;} f?.()"); + Utils.assertWithAllModes_ES6(Undefined.instance, "f = null; f?.()"); + Utils.assertWithAllModes_ES6(Undefined.instance, "f = undefined; f?.()"); - Utils.assertWithAllOptimizationLevelsES6(1, "function f(x) {return x;} f?.(1)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "f = null; f?.(1)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "f = undefined; f?.(1)"); + Utils.assertWithAllModes_ES6(1, "function f(x) {return x;} f?.(1)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "f = null; f?.(1)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "f = undefined; f?.(1)"); - Utils.assertWithAllOptimizationLevelsES6(2, "function f(x, y) {return y;} f?.(1, 2)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "f = null; f?.(1, 2)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "f = undefined; f?.(1, 2)"); + Utils.assertWithAllModes_ES6(2, "function f(x, y) {return y;} f?.(1, 2)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "f = null; f?.(1, 2)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "f = undefined; f?.(1, 2)"); - Utils.assertWithAllOptimizationLevelsES6(3, "function f(x, y, z) {return z;} f?.(1, 2, 3)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "f = null; f?.(1, 2, 3)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "f = undefined; f?.(1, 2, 3)"); + Utils.assertWithAllModes_ES6(3, "function f(x, y, z) {return z;} f?.(1, 2, 3)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "f = null; f?.(1, 2, 3)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "f = undefined; f?.(1, 2, 3)"); } @Test public void standardFunctionCallWithParentScope() { // Needed because there are some special paths in ScriptRuntime when we have a parent scope. // A "with" block is the easiest way to get one. - Utils.assertWithAllOptimizationLevelsES6( - 1, "function f(x) {return x;} x = {}; with (x) { f?.(1) }"); - Utils.assertWithAllOptimizationLevelsES6( - Undefined.instance, "x = {}; with (x) { f = null; f?.(1) }"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6(1, "function f(x) {return x;} x = {}; with (x) { f?.(1) }"); + Utils.assertWithAllModes_ES6(Undefined.instance, "x = {}; with (x) { f = null; f?.(1) }"); + Utils.assertWithAllModes_ES6( Undefined.instance, "x = {}; with (x) { f = undefined; f?.(1) }"); } @Test public void specialFunctionCall() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( 1, "a = { __parent__: function(x) {return x;} }; a.__parent__?.(1)"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( Undefined.instance, "a = { __parent__: null }; a.__parent__?.(1)"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( Undefined.instance, "a = { __parent__: undefined }; a.__parent__?.(1)"); } @Test public void memberFunctionCall() { - Utils.assertWithAllOptimizationLevelsES6(1, "a = { f: function() {return 1;} }; a.f?.()"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = {f: null}; a.f?.()"); - Utils.assertWithAllOptimizationLevelsES6( - Undefined.instance, "a = {f: undefined}; a.f?.(1)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = {}; a.f?.()"); - - Utils.assertWithAllOptimizationLevelsES6(1, "a = { f: function(x) {return x;} }; a.f?.(1)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = {f: null}; a.f?.(1)"); - Utils.assertWithAllOptimizationLevelsES6( - Undefined.instance, "a = {f: undefined}; a.f?.(1)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = {}; a.f?.(1)"); - - Utils.assertWithAllOptimizationLevelsES6( - 2, "a = { f: function(x, y) {return y;} }; a.f?.(1, 2)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = {f: null}; a.f?.(1, 2)"); - Utils.assertWithAllOptimizationLevelsES6( - Undefined.instance, "a = {f: undefined}; a.f?.(1, 2)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = {}; a.f?.(1, 2)"); - - Utils.assertWithAllOptimizationLevelsES6( - 3, "a = { f: function(x, y, z) {return z;} }; a.f?.(1, 2, 3)"); - Utils.assertWithAllOptimizationLevelsES6( - Undefined.instance, "a = {f: null}; a.f?.(1, 2, 3)"); - Utils.assertWithAllOptimizationLevelsES6( - Undefined.instance, "a = {f: undefined}; a.f?.(1, 2, 3)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = {}; a.f?.(1, 2, 3)"); + Utils.assertWithAllModes_ES6(1, "a = { f: function() {return 1;} }; a.f?.()"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {f: null}; a.f?.()"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {f: undefined}; a.f?.(1)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {}; a.f?.()"); + + Utils.assertWithAllModes_ES6(1, "a = { f: function(x) {return x;} }; a.f?.(1)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {f: null}; a.f?.(1)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {f: undefined}; a.f?.(1)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {}; a.f?.(1)"); + + Utils.assertWithAllModes_ES6(2, "a = { f: function(x, y) {return y;} }; a.f?.(1, 2)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {f: null}; a.f?.(1, 2)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {f: undefined}; a.f?.(1, 2)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {}; a.f?.(1, 2)"); + + Utils.assertWithAllModes_ES6(3, "a = { f: function(x, y, z) {return z;} }; a.f?.(1, 2, 3)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {f: null}; a.f?.(1, 2, 3)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {f: undefined}; a.f?.(1, 2, 3)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {}; a.f?.(1, 2, 3)"); } @Test public void expressionFunctionCall() { - Utils.assertWithAllOptimizationLevelsES6(1, "a = [ function(x) {return x;} ]; a[0]?.(1)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = [null]; a[0]?.(1)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = [undefined]; a[0]?.(1)"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = []; a[0]?.(1)"); + Utils.assertWithAllModes_ES6(1, "a = [ function(x) {return x;} ]; a[0]?.(1)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = [null]; a[0]?.(1)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = [undefined]; a[0]?.(1)"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = []; a[0]?.(1)"); } @Test public void specialCall() { - Utils.assertWithAllOptimizationLevelsES6( - 1, "eval = function () { return 1 };\n" + "eval?.()"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "eval = null;\n" + "eval?.()"); - Utils.assertWithAllOptimizationLevelsES6( - Undefined.instance, "eval = undefined;\n" + "eval?.()"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "delete eval;\n" + "eval?.()"); + Utils.assertWithAllModes_ES6(1, "eval = function () { return 1 };\n" + "eval?.()"); + Utils.assertWithAllModes_ES6(Undefined.instance, "eval = null;\n" + "eval?.()"); + Utils.assertWithAllModes_ES6(Undefined.instance, "eval = undefined;\n" + "eval?.()"); + Utils.assertWithAllModes_ES6(Undefined.instance, "delete eval;\n" + "eval?.()"); } @Test public void shortCircuitsFunctionCalls() { - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = undefined; a?.b()"); - Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, "a = {}; a.b?.c().d()"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = undefined; a?.b()"); + Utils.assertWithAllModes_ES6(Undefined.instance, "a = {}; a.b?.c().d()"); } @Test public void shortCircuitArgumentEvaluation() { - Utils.assertWithAllOptimizationLevelsES6(1, "c = 0; f = function(x){}; f?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(0, "c = 0; f = undefined; f?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(0, "c = 0; f = null; f?.(c++); c"); + Utils.assertWithAllModes_ES6(1, "c = 0; f = function(x){}; f?.(c++); c"); + Utils.assertWithAllModes_ES6(0, "c = 0; f = undefined; f?.(c++); c"); + Utils.assertWithAllModes_ES6(0, "c = 0; f = null; f?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(1, "c = 0; a = {f: function() {}}; a.f?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(0, "c = 0; a = {f: undefined}; a.f?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(0, "c = 0; a = {f: null}; a.f?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(0, "c = 0; a = {}; a.f?.(c++); c"); + Utils.assertWithAllModes_ES6(1, "c = 0; a = {f: function() {}}; a.f?.(c++); c"); + Utils.assertWithAllModes_ES6(0, "c = 0; a = {f: undefined}; a.f?.(c++); c"); + Utils.assertWithAllModes_ES6(0, "c = 0; a = {f: null}; a.f?.(c++); c"); + Utils.assertWithAllModes_ES6(0, "c = 0; a = {}; a.f?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(1, "c = 0; a = [function() {}]; a[0]?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(0, "c = 0; a = [undefined]; a[0]?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(0, "c = 0; a = [null]; a[0]?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(0, "c = 0; a = []; a[0]?.(c++); c"); + Utils.assertWithAllModes_ES6(1, "c = 0; a = [function() {}]; a[0]?.(c++); c"); + Utils.assertWithAllModes_ES6(0, "c = 0; a = [undefined]; a[0]?.(c++); c"); + Utils.assertWithAllModes_ES6(0, "c = 0; a = [null]; a[0]?.(c++); c"); + Utils.assertWithAllModes_ES6(0, "c = 0; a = []; a[0]?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( 1, "c = 0; a = {__parent__: function() {}}; a.__parent__?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( 0, "c = 0; a = {__parent__: undefined}; a.__parent__?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6( - 0, "c = 0; a = {__parent__: null}; a.__parent__?.(c++); c"); - Utils.assertWithAllOptimizationLevelsES6(0, "c = 0; a = {}; a.__parent__.f?.(c++); c"); + Utils.assertWithAllModes_ES6(0, "c = 0; a = {__parent__: null}; a.__parent__?.(c++); c"); + Utils.assertWithAllModes_ES6(0, "c = 0; a = {}; a.__parent__.f?.(c++); c"); } @Test public void toStringOfOptionalChaining() { - Utils.assertWithAllOptimizationLevelsES6( - "function f() { a?.b }", "function f() { a?.b } f.toString()"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6("function f() { a?.b }", "function f() { a?.b } f.toString()"); + Utils.assertWithAllModes_ES6( "function f() { a?.() }", "function f() { a?.() } f.toString()"); } @Test public void optionalChainingOperatorFollowedByDigitsIsAHook() { - Utils.assertWithAllOptimizationLevelsES6(0.5, "true ?.5 : false"); + Utils.assertWithAllModes_ES6(0.5, "true ?.5 : false"); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/SecurityControllerTest.java b/tests/src/test/java/org/mozilla/javascript/tests/SecurityControllerTest.java index d0dc4e5faa..4d80404b2d 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/SecurityControllerTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/SecurityControllerTest.java @@ -128,7 +128,7 @@ public boolean visibleToScripts(String fullClassName) { /** Compiles and runs the script with the given protection domain. */ private void runScript(String scriptSourceText, ProtectionDomain pd) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( context -> { context.setClassShutter(new PolicyClassShutter()); Scriptable scope = context.initStandardObjects(global); diff --git a/tests/src/test/java/org/mozilla/javascript/tests/StackTraceTest.java b/tests/src/test/java/org/mozilla/javascript/tests/StackTraceTest.java index 5abf43c1ae..04afb945fb 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/StackTraceTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/StackTraceTest.java @@ -119,7 +119,7 @@ public void failureStackTraceV8() { private static void runWithExpectedStackTrace( final String _source, final String _expectedStackTrace) { - Utils.runWithOptimizationLevel( + Utils.runWithMode( cx -> { final Scriptable scope = cx.initStandardObjects(); try { @@ -130,6 +130,6 @@ private static void runWithExpectedStackTrace( } throw new RuntimeException("Exception expected!"); }, - -1); + true); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/backwardcompat/BackwardParseInt.java b/tests/src/test/java/org/mozilla/javascript/tests/backwardcompat/BackwardParseInt.java index c990edfc51..fb3657f3fc 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/backwardcompat/BackwardParseInt.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/backwardcompat/BackwardParseInt.java @@ -1,38 +1,37 @@ package org.mozilla.javascript.tests.backwardcompat; import org.junit.Test; -import org.mozilla.javascript.Context; import org.mozilla.javascript.tests.Utils; public class BackwardParseInt { @Test public void parseIntOctal_1_4() { - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_4, 7, "parseInt('07');"); - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_4, 7, "parseInt('007');"); - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_4, -56, "parseInt('-070');"); - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_4, Double.NaN, "parseInt('08');"); - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_4, 0, "parseInt('008');"); - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_4, Double.NaN, "parseInt('-090');"); + Utils.assertWithAllModes_1_4(7, "parseInt('07');"); + Utils.assertWithAllModes_1_4(7, "parseInt('007');"); + Utils.assertWithAllModes_1_4(-56, "parseInt('-070');"); + Utils.assertWithAllModes_1_4(Double.NaN, "parseInt('08');"); + Utils.assertWithAllModes_1_4(0, "parseInt('008');"); + Utils.assertWithAllModes_1_4(Double.NaN, "parseInt('-090');"); } @Test public void parseIntOctal_1_5() { - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_5, 7, "parseInt('07');"); - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_5, 7, "parseInt('007');"); - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_5, -70, "parseInt('-070');"); - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_5, 8, "parseInt('08');"); - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_5, 8, "parseInt('008');"); - Utils.assertWithAllOptimizationLevels(Context.VERSION_1_5, -90, "parseInt('-090');"); + Utils.assertWithAllModes_1_5(7, "parseInt('07');"); + Utils.assertWithAllModes_1_5(7, "parseInt('007');"); + Utils.assertWithAllModes_1_5(-70, "parseInt('-070');"); + Utils.assertWithAllModes_1_5(8, "parseInt('08');"); + Utils.assertWithAllModes_1_5(8, "parseInt('008');"); + Utils.assertWithAllModes_1_5(-90, "parseInt('-090');"); } @Test public void parseIntOctal_ES6() { - Utils.assertWithAllOptimizationLevelsES6(7, "parseInt('07');"); - Utils.assertWithAllOptimizationLevelsES6(7, "parseInt('007');"); - Utils.assertWithAllOptimizationLevelsES6(-70, "parseInt('-070');"); - Utils.assertWithAllOptimizationLevelsES6(8, "parseInt('08');"); - Utils.assertWithAllOptimizationLevelsES6(8, "parseInt('008');"); - Utils.assertWithAllOptimizationLevelsES6(-90, "parseInt('-090');"); + Utils.assertWithAllModes_ES6(7, "parseInt('07');"); + Utils.assertWithAllModes_ES6(7, "parseInt('007');"); + Utils.assertWithAllModes_ES6(-70, "parseInt('-070');"); + Utils.assertWithAllModes_ES6(8, "parseInt('08');"); + Utils.assertWithAllModes_ES6(8, "parseInt('008');"); + Utils.assertWithAllModes_ES6(-90, "parseInt('-090');"); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/backwardcompat/BackwardUseStrict.java b/tests/src/test/java/org/mozilla/javascript/tests/backwardcompat/BackwardUseStrict.java index f66d4e486a..57bb6bff49 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/backwardcompat/BackwardUseStrict.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/backwardcompat/BackwardUseStrict.java @@ -42,7 +42,7 @@ public static void init() throws IOException { @Test public void strictIgnored() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_1_8); try { @@ -59,7 +59,7 @@ public void strictIgnored() { @Test public void strictHonored() { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); try { diff --git a/tests/src/test/java/org/mozilla/javascript/tests/commonjs/module/ComplianceTest.java b/tests/src/test/java/org/mozilla/javascript/tests/commonjs/module/ComplianceTest.java index 2718722e6e..045109b1b5 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/commonjs/module/ComplianceTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/commonjs/module/ComplianceTest.java @@ -66,7 +66,7 @@ private static Require createRequire(File dir, Context cx, Scriptable scope) @Test public void require() throws Throwable { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); ScriptableObject.putProperty(scope, "print", new Print(scope)); diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es2022/NativeObjectTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es2022/NativeObjectTest.java index d9891febc7..4f540ea093 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es2022/NativeObjectTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es2022/NativeObjectTest.java @@ -14,7 +14,7 @@ public class NativeObjectTest { public void hasStringOwn() { final String code = "let result = Object.hasOwn({ test: '123' }, 'test');\n" + "'result = ' + result"; - Utils.assertWithAllOptimizationLevelsES6("result = true", code); + Utils.assertWithAllModes_ES6("result = true", code); } @Test @@ -22,14 +22,14 @@ public void hasUndefinedOwn() { final String code = "let result = Object.hasOwn({ test: undefined }, 'test');\n" + "'result = ' + result;"; - Utils.assertWithAllOptimizationLevelsES6("result = true", code); + Utils.assertWithAllModes_ES6("result = true", code); } @Test public void hasNullOwn() { final String code = "let result = Object.hasOwn({ test: null }, 'test');\n" + "'result = ' + result;"; - Utils.assertWithAllOptimizationLevelsES6("result = true", code); + Utils.assertWithAllModes_ES6("result = true", code); } @Test @@ -38,14 +38,14 @@ public void hasArrayPropertyOwn() { "let dessert = [\"cake\", \"coffee\", \"chocolate\"];\n" + "let result = Object.hasOwn(dessert, 2);\n" + "'result = ' + result;"; - Utils.assertWithAllOptimizationLevelsES6("result = true", code); + Utils.assertWithAllModes_ES6("result = true", code); } @Test public void hasNoOwn() { final String code = "let result = Object.hasOwn({ cake: 123 }, 'test');\n" + "'result = ' + result"; - Utils.assertWithAllOptimizationLevelsES6("result = false", code); + Utils.assertWithAllModes_ES6("result = false", code); } @Test @@ -55,7 +55,7 @@ public void createHasOwn() { + "foo.prop = 'test';\n" + "var result = Object.hasOwn(foo, 'prop');\n" + "'result = ' + result;"; - Utils.assertWithAllOptimizationLevelsES6("result = true", code); + Utils.assertWithAllModes_ES6("result = true", code); } @Test @@ -63,7 +63,7 @@ public void createNoHasOwn() { final String code = "var result = Object.hasOwn(Object.create({ q: 321 }), 'q');\n" + "'result = ' + result; "; - Utils.assertWithAllOptimizationLevelsES6("result = false", code); + Utils.assertWithAllModes_ES6("result = false", code); } @Test @@ -74,6 +74,6 @@ public void calledTest() { + " Object.hasOwn(null, { toString() { called = true } });\n" + "} catch (e) {}\n" + "'called = ' + called;"; - Utils.assertWithAllOptimizationLevelsES6("called = false", code); + Utils.assertWithAllModes_ES6("called = false", code); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es5/FunctionApplyArrayLikeArguments.java b/tests/src/test/java/org/mozilla/javascript/tests/es5/FunctionApplyArrayLikeArguments.java index a94f93d01c..fa1c2b00ad 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es5/FunctionApplyArrayLikeArguments.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es5/FunctionApplyArrayLikeArguments.java @@ -15,15 +15,15 @@ public class FunctionApplyArrayLikeArguments { @Test public void arrayLikeArgumentsOfFunctionApply() { - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes( Undefined.instance, "function test() { return arguments[0]; } test.apply(this, {});"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes( "banana", "function test() { return arguments[0]; } test.apply(this, {'length':1, '0':'banana'});"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes( "lala", "function test() { return arguments[0]; } test.apply(this, {'length':'1', '0':'lala'});"); @@ -31,11 +31,11 @@ public void arrayLikeArgumentsOfFunctionApply() { "TypeError: second argument to Function.prototype.apply must be an array", "function test() { return arguments[0]; } test.apply(2,2);"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes( Undefined.instance, "function test() { return arguments[0]; } test.apply(this,{'length':'abc', '0':'banana'});"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes( Undefined.instance, "function test() { return arguments[0]; } test.apply(this,{'length':function(){return 1;}, '0':'banana'});"); } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es5/GeneratorToStringTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es5/GeneratorToStringTest.java index b2cfdfc561..7188dbedb3 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es5/GeneratorToStringTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es5/GeneratorToStringTest.java @@ -6,7 +6,7 @@ public class GeneratorToStringTest { @Test public void generatorsTest() { - Utils.assertWithAllOptimizationLevelsTopLevelScopeES6( + Utils.assertWithAllModesTopLevelScope_ES6( "function* f() {\n" + " yield 1;\n" + " }", "function* f() {\n" + " yield 1;\n" + " }; f.toString();"); } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es5/NativeArrayTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es5/NativeArrayTest.java index 46dd783d13..8a0c616b99 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es5/NativeArrayTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es5/NativeArrayTest.java @@ -15,7 +15,7 @@ public void concatNull() { "try { " + " Array.prototype.concat.call(null, [1]);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -24,14 +24,14 @@ public void copyWithinNull() { "try { " + " Array.prototype.copyWithin.call(null, 1, 3);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void entriesNull() { final String script = "try { " + " Array.prototype.entries.call(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -40,7 +40,7 @@ public void everyNull() { "try { " + " Array.prototype.every.call(null, null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -49,7 +49,7 @@ public void fillNull() { "try { " + " Array.prototype.fill.call(null, 0, 2, 4);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -58,14 +58,14 @@ public void filterNull() { "try { " + " Array.prototype.filter.call(null, null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void findNull() { final String script = "try { " + " Array.prototype.find.call(null, null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -74,7 +74,7 @@ public void findIndexNull() { "try { " + " Array.prototype.findIndex.call(null, null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -83,28 +83,28 @@ public void includesNull() { "try { " + " Array.prototype.includes.call(null, 1);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void indexOfNull() { final String script = "try { " + " Array.prototype.indexOf.call(null, 1);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void joinNull() { final String script = "try { " + " Array.prototype.join.call(null, 1);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void keysNull() { final String script = "try { " + " Array.prototype.keys.call(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -113,28 +113,28 @@ public void lastIndexOfNull() { "try { " + " Array.prototype.lastIndexOf.call(null, 1);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void mapNull() { final String script = "try { " + " Array.prototype.map.call(null, null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void popNull() { final String script = "try { " + " Array.prototype.map.call(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void pushNull() { final String script = "try { " + " Array.prototype.push.call(null, 1);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -143,7 +143,7 @@ public void reduceNull() { "try { " + " Array.prototype.reduce.call(null, null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -152,42 +152,42 @@ public void reduceRightNull() { "try { " + " Array.prototype.reduceRight.call(null, null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void reverseNull() { final String script = "try { " + " Array.prototype.reverse.call(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void shiftNull() { final String script = "try { " + " Array.prototype.shift.call(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void sliceNull() { final String script = "try { " + " Array.prototype.slice.call(null, 7);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void someNull() { final String script = "try { " + " Array.prototype.some.call(null, null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void sortNull() { final String script = "try { " + " Array.prototype.sort.call(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -196,7 +196,7 @@ public void spliceNull() { "try { " + " Array.prototype.splice.call(null, 1, 0, '#');" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -205,21 +205,21 @@ public void toLocaleStringNull() { "try { " + " Array.prototype.toLocaleString.call(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void toSourceNull() { final String script = "try { " + " Array.prototype.toSource.call(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void toStringNull() { final String script = "try { " + " Array.prototype.toString.call(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test @@ -228,13 +228,13 @@ public void unshiftNull() { "try { " + " Array.prototype.unshift.call(null, 4, 5);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } @Test public void valuesNull() { final String script = "try { " + " Array.prototype.values.call(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es5/ObjectIsPrototypeOfTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es5/ObjectIsPrototypeOfTest.java index 46028f85ff..a99744cb08 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es5/ObjectIsPrototypeOfTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es5/ObjectIsPrototypeOfTest.java @@ -18,7 +18,7 @@ public void isPrototypeOfUndefined() { "try { " + " Object.prototype.isPrototypeOf.call(undefined, []);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert undefined to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert undefined to an object.", script); } @Test @@ -27,6 +27,6 @@ public void isPrototypeOfNull() { "try { " + " Object.prototype.isPrototypeOf.call(null, []);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels_1_8("Cannot convert null to an object.", script); + Utils.assertWithAllModes_1_8("Cannot convert null to an object.", script); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es5/StrictTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es5/StrictTest.java index 1f2f9cae27..24d3d90499 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es5/StrictTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es5/StrictTest.java @@ -17,7 +17,7 @@ public void functionCtor() { + "Function('with(this) { }')();" + "})();" + "'done'"; - Utils.assertWithAllOptimizationLevels("done", script); + Utils.assertWithAllModes("done", script); } @Test @@ -28,6 +28,6 @@ public void newFunction() { + "new Function('with(this) { }')();" + "})();" + "'done'"; - Utils.assertWithAllOptimizationLevels("done", script); + Utils.assertWithAllModes("done", script); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/ArgumentsTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/ArgumentsTest.java index aa14cdc499..0e7fe16d5a 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/ArgumentsTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/ArgumentsTest.java @@ -18,7 +18,7 @@ public void argumentsSymbolIterator() { + "}" + "foo()"; - Utils.assertWithAllOptimizationLevelsES6(true, code); + Utils.assertWithAllModes_ES6(true, code); } @Test @@ -29,7 +29,7 @@ public void argumentsSymbolIterator2() { + "}" + "foo()"; - Utils.assertWithAllOptimizationLevelsES6(true, code); + Utils.assertWithAllModes_ES6(true, code); } @Test @@ -44,6 +44,6 @@ public void argumentsForOf() { + "}" + "foo(1, 2, 3, 5)"; - Utils.assertWithAllOptimizationLevelsES6("1235", code); + Utils.assertWithAllModes_ES6("1235", code); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/ArrayDestructuringTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/ArrayDestructuringTest.java index d86d771ca2..7e8cb7fedd 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/ArrayDestructuringTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/ArrayDestructuringTest.java @@ -12,19 +12,18 @@ public class ArrayDestructuringTest { /** Test for issue #662. There was a ClassCastException. */ @Test public void strangeCase() { - Utils.assertWithAllOptimizationLevels("", "var a = ''; [a.x] = ''; a"); + Utils.assertWithAllModes("", "var a = ''; [a.x] = ''; a"); } /** Test for issue #662. */ @Test public void strangeCase2() { - Utils.assertWithAllOptimizationLevels("", "[1..h]=''"); + Utils.assertWithAllModes("", "[1..h]=''"); } /** Test for issue #662. */ @Test public void strangeCase3() { - Utils.assertWithAllOptimizationLevels( - 123, "[0..toString.h] = [123]; Number.prototype.toString.h"); + Utils.assertWithAllModes(123, "[0..toString.h] = [123]; Number.prototype.toString.h"); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/BoundFunctionTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/BoundFunctionTest.java index 1ac50aaaff..6b8a784fd4 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/BoundFunctionTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/BoundFunctionTest.java @@ -16,6 +16,6 @@ public class BoundFunctionTest { public void ctorCallableThis() { String code = "function foo() {};\n" + " foo.bind({}).name;"; - Utils.assertWithAllOptimizationLevelsES6("bound foo", code); + Utils.assertWithAllModes_ES6("bound foo", code); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/ES6IteratorTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/ES6IteratorTest.java index acc118f4ec..789b7d3715 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/ES6IteratorTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/ES6IteratorTest.java @@ -19,6 +19,6 @@ public void valueDone() { + " res = res + p + ' ';\n" + " }\n"; - Utils.assertWithAllOptimizationLevelsES6("value done ", code); + Utils.assertWithAllModes_ES6("value done ", code); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/FunctionNullSetTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/FunctionNullSetTest.java index 620e21f505..65156d63c9 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/FunctionNullSetTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/FunctionNullSetTest.java @@ -64,7 +64,7 @@ public Object run(final Context cx) { } }; - Utils.runWithAllOptimizationLevels(action); + Utils.runWithAllModes(action); } public static class MyHostObject extends ScriptableObject { diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/FunctionsRestParametersTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/FunctionsRestParametersTest.java index 513d2d668d..fcba362eae 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/FunctionsRestParametersTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/FunctionsRestParametersTest.java @@ -22,7 +22,7 @@ public void oneRestArg() { + "}\n" + "rest(1, 'abc', 2, '##').toString();\n"; - Utils.assertWithAllOptimizationLevelsES6("1,abc,2,##", code); + Utils.assertWithAllModes_ES6("1,abc,2,##", code); } @Test @@ -35,7 +35,7 @@ public void oneRestArgActivation() { + "}\n" + " rest(1, 'abc', 2, '##').toString();\n"; - Utils.assertWithAllOptimizationLevelsES6("1,abc,2,##", code); + Utils.assertWithAllModes_ES6("1,abc,2,##", code); } @Test @@ -47,7 +47,7 @@ public void oneRestArgNothingProvided() { + "var r = rest();\n" + "'' + Array.isArray(r) + '-' + r.length;\n"; - Utils.assertWithAllOptimizationLevelsES6("true-0", code); + Utils.assertWithAllModes_ES6("true-0", code); } @Test @@ -61,7 +61,7 @@ public void oneRestArgNothingProvidedActivation() { + "var r = rest();\n" + "'' + Array.isArray(r) + '-' + r.length;\n"; - Utils.assertWithAllOptimizationLevelsES6("true-0", code); + Utils.assertWithAllModes_ES6("true-0", code); } @Test @@ -73,7 +73,7 @@ public void oneRestArgOneProvided() { + "var r = rest('xy');\n" + "'' + Array.isArray(r) + '-' + r.length;\n"; - Utils.assertWithAllOptimizationLevelsES6("true-1", code); + Utils.assertWithAllModes_ES6("true-1", code); } @Test @@ -87,7 +87,7 @@ public void oneRestArgOneProvidedActivation() { + "var r = rest('xy');\n" + "'' + Array.isArray(r) + '-' + r.length;\n"; - Utils.assertWithAllOptimizationLevelsES6("true-1", code); + Utils.assertWithAllModes_ES6("true-1", code); } @Test @@ -98,7 +98,7 @@ public void twoRestArg() { + "}\n" + "rest(1, 'abc', 2, '##').toString();\n"; - Utils.assertWithAllOptimizationLevelsES6("abc,2,##", code); + Utils.assertWithAllModes_ES6("abc,2,##", code); } @Test @@ -111,7 +111,7 @@ public void twoRestArgActivation() { + "}\n" + "rest(1, 'abc', 2, '##').toString();\n"; - Utils.assertWithAllOptimizationLevelsES6("abc,2,##", code); + Utils.assertWithAllModes_ES6("abc,2,##", code); } @Test @@ -122,7 +122,7 @@ public void twoRestArgNothingProvided() { + "}\n" + "rest();\n"; - Utils.assertWithAllOptimizationLevelsES6("undefined - true-0", code); + Utils.assertWithAllModes_ES6("undefined - true-0", code); } @Test @@ -135,7 +135,7 @@ public void twoRestArgNothingProvidedActivation() { + "}\n" + "rest();\n"; - Utils.assertWithAllOptimizationLevelsES6("undefined - true-0", code); + Utils.assertWithAllModes_ES6("undefined - true-0", code); } @Test @@ -146,7 +146,7 @@ public void twoRestArgOneProvided() { + "}\n" + "rest('77');"; - Utils.assertWithAllOptimizationLevelsES6("77 - true-0", code); + Utils.assertWithAllModes_ES6("77 - true-0", code); } @Test @@ -159,7 +159,7 @@ public void twoRestArgOneProvidedActivation() { + "}\n" + "rest('77');"; - Utils.assertWithAllOptimizationLevelsES6("77 - true-0", code); + Utils.assertWithAllModes_ES6("77 - true-0", code); } @Test @@ -170,7 +170,7 @@ public void arguments() { + "}\n" + "'' + rest('77') + '-' + rest(1, 2, 3, 4);\n"; - Utils.assertWithAllOptimizationLevelsES6("1-4", code); + Utils.assertWithAllModes_ES6("1-4", code); } @Test @@ -183,7 +183,7 @@ public void argumentsActivation() { + "}\n" + "'' + rest('77') + '-' + rest(1, 2, 3, 4);\n"; - Utils.assertWithAllOptimizationLevelsES6("1-4", code); + Utils.assertWithAllModes_ES6("1-4", code); } @Test @@ -194,7 +194,7 @@ public void argLength() { + "}\n" + " rest(1,2) + '-' + rest(1) + '-' + rest();\n"; - Utils.assertWithAllOptimizationLevelsES6("2-1-0", code); + Utils.assertWithAllModes_ES6("2-1-0", code); } @Test @@ -207,7 +207,7 @@ public void argLengthActivation() { + "}\n" + " rest(1,2) + '-' + rest(1) + '-' + rest();\n"; - Utils.assertWithAllOptimizationLevelsES6("2-1-0", code); + Utils.assertWithAllModes_ES6("2-1-0", code); } @Test @@ -217,7 +217,7 @@ public void length() { + "function foo2(arg, ...restArgs) {}\n" + "foo1.length + '-' + foo2.length;\n"; - Utils.assertWithAllOptimizationLevelsES6("0-1", code); + Utils.assertWithAllModes_ES6("0-1", code); } @Test @@ -228,7 +228,7 @@ public void string1() { + "}\n" + "rest.toString();\n"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "function rest(...restArgs) {\n return restArgs.length;\n}", code); } @@ -240,7 +240,7 @@ public void string2() { + "}\n" + "rest.toString();\n"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "function rest( arg , ...restArgs ) {\n return restArgs.length;\n}", code); } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/Issue1297FunctionNameTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/Issue1297FunctionNameTest.java index f9df9af9bf..ad9fbaa152 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/Issue1297FunctionNameTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/Issue1297FunctionNameTest.java @@ -18,6 +18,6 @@ public void canSetFunctionName() { + "Object.defineProperty(X, 'name', {value: 'y', configurable: true, writable: true});" + "X.name"; - Utils.assertWithAllOptimizationLevels("y", code); + Utils.assertWithAllModes("y", code); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeArray2Test.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeArray2Test.java index 11c5f8684e..8f10d04f36 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeArray2Test.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeArray2Test.java @@ -18,7 +18,7 @@ public void concatLimitSpreadable() { + " '' + e;\n" + "};"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Array length 9,007,199,254,740,992 exceeds supported capacity limit.", js); } @@ -39,6 +39,6 @@ public void concatLimitSpreadable2() { + " '' + e;\n" + "};"; - Utils.assertWithAllOptimizationLevelsES6("Error: get failed", js); + Utils.assertWithAllModes_ES6("Error: get failed", js); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeArray3Test.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeArray3Test.java index 558a4bc6e5..3abe1c5064 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeArray3Test.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeArray3Test.java @@ -14,28 +14,28 @@ public class NativeArray3Test { public void iteratorPrototype() { String code = "Array.prototype.values === [][Symbol.iterator]"; - Utils.assertWithAllOptimizationLevelsES6(true, code); + Utils.assertWithAllModes_ES6(true, code); } @Test public void iteratorInstances() { String code = "[1, 2][Symbol.iterator] === [][Symbol.iterator]"; - Utils.assertWithAllOptimizationLevelsES6(true, code); + Utils.assertWithAllModes_ES6(true, code); } @Test public void iteratorPrototypeName() { String code = "Array.prototype.values.name;"; - Utils.assertWithAllOptimizationLevelsES6("values", code); + Utils.assertWithAllModes_ES6("values", code); } @Test public void iteratorInstanceName() { String code = "[][Symbol.iterator].name;"; - Utils.assertWithAllOptimizationLevelsES6("values", code); + Utils.assertWithAllModes_ES6("values", code); } @Test @@ -52,6 +52,6 @@ public void redefineIterator() { + "res += arr[Symbol.iterator].toString().includes('return i;');\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("false - true - false", code); + Utils.assertWithAllModes_ES6("false - true - false", code); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeDateTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeDateTest.java index 4286fe0df7..fbac2a4729 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeDateTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeDateTest.java @@ -133,7 +133,7 @@ public void ctorDateTimeStringNewYork() { } private static void ctorDateTimeString(final String expected, final String js) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -169,7 +169,7 @@ public void ctorDateTimeBerlin() { public void ctorDateTimeBerlinDaylightSavingTime() { String js = "new Date('2021-07-18T22:23').toISOString()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -198,7 +198,7 @@ public void ctorDateTimeNewYork() { private static void ctorDateTime(final String expected, final String tz) { final String js = "new Date('2021-12-18T22:23').toISOString()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -247,7 +247,7 @@ public void ctorDateJST() { private static void ctorDate(final String expected, final String tz) { final String js = "new Date('2021-12-18').toISOString()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -261,14 +261,13 @@ private static void ctorDate(final String expected, final String tz) { @Test public void ctorInt() { - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes( "2000-02-28T23:59:59.000Z", "new Date(951782399000).toISOString()"); } @Test public void ctorDouble() { - Utils.assertWithAllOptimizationLevels( - "2035-11-30T01:46:40.000Z", "new Date(208e10).toISOString()"); + Utils.assertWithAllModes("2035-11-30T01:46:40.000Z", "new Date(208e10).toISOString()"); } @Test @@ -346,7 +345,7 @@ public void toLocaleArray() { } private static void toLocale(final String expected, final String js) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -395,7 +394,7 @@ public void toDateStringJST() { private static void toDateString(final String expected, final String tz) { final String js = "new Date('Sat, 18 Dec 2021 22:23:00 UTC').toDateString()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -446,7 +445,7 @@ public void toTimeStringJST() { private static void toTimeString(final String expected, final String tz) { final String js = "new Date('Sat, 18 Dec 2021 22:23:00 UTC').toTimeString()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -495,7 +494,7 @@ public void toUTCStringJST() { private static void toUTCString(final String expected, final String tz) { final String js = "new Date('Sat, 18 Dec 2021 22:23:00 UTC').toUTCString()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); @@ -544,7 +543,7 @@ public void timezoneOffsetJST() { private static void timezoneOffset(final int expected, final String tz) { final String js = "new Date(0).getTimezoneOffset()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { final Scriptable scope = cx.initStandardObjects(); cx.setLanguageVersion(Context.VERSION_ES6); diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeFunctionTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeFunctionTest.java index 65765f79c4..cd6c17b948 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeFunctionTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeFunctionTest.java @@ -19,7 +19,7 @@ public void functionPrototypeLength() { + "var res = 'configurable: ' + desc.configurable;\n" + "res += ' enumerable: ' + desc.enumerable;\n" + "res += ' writable: ' + desc.writable;"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "configurable: true enumerable: false writable: false", code); } @@ -30,7 +30,7 @@ public void functionPrototypeName() { + "var res = 'configurable: ' + desc.configurable;\n" + "res += ' enumerable: ' + desc.enumerable;\n" + "res += ' writable: ' + desc.writable;"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "configurable: true enumerable: false writable: false", code); } @@ -42,7 +42,7 @@ public void functionLength() { + "var res = 'configurable: ' + desc.configurable;\n" + "res += ' enumerable: ' + desc.enumerable;\n" + "res += ' writable: ' + desc.writable;"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "configurable: true enumerable: false writable: false", code); } @@ -54,13 +54,13 @@ public void functionName() { + "var res = 'configurable: ' + desc.configurable;\n" + "res += ' enumerable: ' + desc.enumerable;\n" + "res += ' writable: ' + desc.writable;"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "configurable: true enumerable: false writable: false", code); } @Test public void functionNameJavaObject() throws Exception { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); final Scriptable scope = cx.initStandardObjects(); diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeNumberPropertyTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeNumberPropertyTest.java index 0bc8e3de59..230a854329 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeNumberPropertyTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeNumberPropertyTest.java @@ -15,7 +15,7 @@ public void definingAProperty() { + "try { " + " '' + func(-334918463);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("undefined", code); + Utils.assertWithAllModes_ES6("undefined", code); } @Test @@ -29,7 +29,7 @@ public void definingAPropertyStrict() { + "try { " + " '' + func(-334918463);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "Cannot set property \"snippetText\" of -334918463 to \"abc\"", code); } @@ -42,7 +42,7 @@ public void extensible() { + "try { " + " func(-334918463);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("false true", code); + Utils.assertWithAllModes_ES6("false true", code); } @Test @@ -55,7 +55,7 @@ public void extensibleStrict() { + "try { " + " func(-334918463);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("false true", code); + Utils.assertWithAllModes_ES6("false true", code); } @Test @@ -67,7 +67,7 @@ public void sealed() { + "try { " + " func(-334918463);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("true false", code); + Utils.assertWithAllModes_ES6("true false", code); } @Test @@ -80,6 +80,6 @@ public void sealedStrict() { + "try { " + " func(-334918463);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("true false", code); + Utils.assertWithAllModes_ES6("true false", code); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeObjectTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeObjectTest.java index 0025864b4c..c1c72a506c 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeObjectTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeObjectTest.java @@ -368,7 +368,7 @@ public void issue943Realm() { String[] prefixes = {"", "'use strict;'\n"}; for (final String prefix : prefixes) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); @@ -386,7 +386,7 @@ public void issue943Realm() { private static void evaluateAndAssert(final String script, final Object expected) { String[] prefixes = {"", "'use strict;'\n"}; for (final String prefix : prefixes) { - Utils.assertWithAllOptimizationLevelsES6(expected, prefix + script); + Utils.assertWithAllModes_ES6(expected, prefix + script); } } @@ -407,7 +407,7 @@ public void definePropertyUsingConsString() throws Exception { + " var p = new f();\n" + " log = log + ' / ' + (p instanceof f);"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeProxyTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeProxyTest.java index 0a329fd42b..e20a5d287e 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeProxyTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeProxyTest.java @@ -7,14 +7,14 @@ public class NativeProxyTest { @Test public void testToString() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "function Proxy() {\n\t[native code, arity=2]\n}\n", "Proxy.toString()"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "[object Object]", "Object.prototype.toString.call(new Proxy({}, {}))"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "[object Array]", "Object.prototype.toString.call(new Proxy([], {}))"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "[object Array]", "Object.prototype.toString.call(new Proxy(new Proxy([], {}), {}))"); } @@ -30,52 +30,52 @@ public void testToStringRevoke() { + " '' + e;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Illegal operation attempted on a revoked proxy", String.format(js, "{}", "rev.proxy")); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Illegal operation attempted on a revoked proxy", String.format(js, "[]", "rev.proxy")); } @Test public void prototype() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "false", "'' + Object.hasOwnProperty.call(Proxy, 'prototype')"); - Utils.assertWithAllOptimizationLevelsES6("2", "'' + Proxy.length"); + Utils.assertWithAllModes_ES6("2", "'' + Proxy.length"); } @Test public void ctorMissingArgs() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Proxy.ctor: At least 2 arguments required, but only 0 passed", "try { new Proxy() } catch(e) { '' + e }"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Proxy.ctor: At least 2 arguments required, but only 1 passed", "try { new Proxy({}) } catch(e) { '' + e }"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Expected argument of type object, but instead had type undefined", "try { new Proxy(undefined, {}) } catch(e) { '' + e }"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Expected argument of type object, but instead had type object", "try { new Proxy(null, {}) } catch(e) { '' + e }"); } @Test public void ctorWrongArgs() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Expected argument of type object, but instead had type symbol", "try { new Proxy({}, Symbol()) } catch(e) { '' + e }"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Expected argument of type object, but instead had type symbol", "try { new Proxy(Symbol(), {}) } catch(e) { '' + e }"); } @Test public void ctorAsFunction() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: The constructor for Proxy may not be invoked as a function", "try { Proxy() } catch(e) { '' + e }"); } @@ -100,7 +100,7 @@ public void construct() { + "+ ' ' + (_P === P)" + "+ ' ' + _args.length + ' ' + _args[0] + ' ' + _args[1]"; - Utils.assertWithAllOptimizationLevelsES6("true true true 2 1 4", js); + Utils.assertWithAllModes_ES6("true true true 2 1 4", js); } @Test @@ -120,7 +120,7 @@ public void apply() { + "var x = ' ' + proxy1(1, 2);\n" + "res + x"; - Utils.assertWithAllOptimizationLevelsES6(" Calculate sum: 1,2 21", js); + Utils.assertWithAllModes_ES6(" Calculate sum: 1,2 21", js); } @Test @@ -146,7 +146,7 @@ public void applyParameters() { + "+ ' ' + (_context === context)" + "+ ' ' + _args.length + ' ' + _args[0] + ' ' + _args[1]"; - Utils.assertWithAllOptimizationLevelsES6("true true true 2 1 4", js); + Utils.assertWithAllModes_ES6("true true true 2 1 4", js); } @Test @@ -170,7 +170,7 @@ public void applyTrapIsNull() { + "+ ' ' + (_context === context)" + "+ ' ' + res"; - Utils.assertWithAllOptimizationLevelsES6("1 true 3", js); + Utils.assertWithAllModes_ES6("1 true 3", js); } @Test @@ -182,7 +182,7 @@ public void applyWithoutHandler() { + "var proxy1 = new Proxy(sum, {});\n" + "proxy1(1, 2);"; - Utils.assertWithAllOptimizationLevelsES6(3, js); + Utils.assertWithAllModes_ES6(3, js); } @Test @@ -200,7 +200,7 @@ public void defineProperty() { + "var proxy1 = new Proxy(o, handler);\n" + "Object.defineProperty(proxy1, 'p', { value: 42, writable: false });\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("[object Object] p false undefined undefined", js); + Utils.assertWithAllModes_ES6("[object Object] p false undefined undefined", js); } @Test @@ -214,7 +214,7 @@ public void definePropertyTrapReturnsFalse() { + "});\n" + "'' + Reflect.defineProperty(p, 'attr', {})" + "+ ' ' + Object.getOwnPropertyDescriptor(target, 'attr')"; - Utils.assertWithAllOptimizationLevelsES6("false undefined", js); + Utils.assertWithAllModes_ES6("false undefined", js); } @Test @@ -239,7 +239,7 @@ public void definePropertyTrapReturnsFalse() { + "} catch(e) {\n" + " '' + e;\n" + "}\n"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: proxy can't define an incompatible property descriptor", js); } @@ -262,7 +262,7 @@ public void definePropertyDescAndTargetPropertyDescriptorNotCompatibleAndTrapRes + "} catch(e) {\n" + " '' + e;\n" + "}\n"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: proxy can't define an incompatible property descriptor", js); } @@ -287,7 +287,7 @@ public void definePropertyDescAndTargetPropertyDescriptorNotCompatibleAndTrapRes + "} catch(e) {\n" + " '' + e;\n" + "}\n"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: proxy can't define an incompatible property descriptor", js); } @@ -298,7 +298,7 @@ public void definePropertyWithoutHandler() { + "var proxy1 = new Proxy(o, {});\n" + "proxy1.p = 42;\n" + "'' + o.p;"; - Utils.assertWithAllOptimizationLevelsES6("42", js); + Utils.assertWithAllModes_ES6("42", js); } @Test @@ -313,7 +313,7 @@ public void definePropertyFreezedWithoutHandler() { + "} catch(e) {\n" + " '' + e;" + "}\n"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Cannot add properties to this object because extensible is false.", js); } @@ -328,7 +328,7 @@ public void definePropertyHandlerNotFunction() { + "} catch(e) {\n" + " '' + e;" + "}\n"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: defineProperty is not a function, it is number.", js); } @@ -343,7 +343,7 @@ public void definePropertyHandlerNull() { + "} catch(e) {\n" + " '' + e;" + "}\n"; - Utils.assertWithAllOptimizationLevelsES6("42", js); + Utils.assertWithAllModes_ES6("42", js); } @Test @@ -357,7 +357,7 @@ public void definePropertyHandlerUndefined() { + "} catch(e) {\n" + " '' + e;" + "}\n"; - Utils.assertWithAllOptimizationLevelsES6("42", js); + Utils.assertWithAllModes_ES6("42", js); } @Test @@ -367,7 +367,7 @@ public void deletePropertyWithoutHandler() { + "var proxy1 = new Proxy(o, {});\n" + "delete proxy1.p;\n" + "'' + o.p;"; - Utils.assertWithAllOptimizationLevelsES6("undefined", js); + Utils.assertWithAllModes_ES6("undefined", js); } @Test @@ -391,7 +391,7 @@ public void getOwnPropertyDescriptor() { + "+ ' ' + result.writable " + "+ ' ' + (result.get === fn) " + "+ ' ' + (result.set === undefined)"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "undefined 7 [value,writable,enumerable,configurable] true true false false true", js); } @@ -406,7 +406,7 @@ public void getOwnPropertyDescriptorResultUndefined() { + " }\n" + " });\n" + "'' + Object.getOwnPropertyDescriptor(p, 'attr');"; - Utils.assertWithAllOptimizationLevelsES6("undefined", js); + Utils.assertWithAllModes_ES6("undefined", js); } @Test @@ -425,8 +425,7 @@ public void getOwnPropertyDescriptorWithoutHandler() { + "+ ' ' + result.configurable" + "+ ' ' + (result.get === fn)" + "+ ' ' + (result.set === undefined)"; - Utils.assertWithAllOptimizationLevelsES6( - "[get,set,enumerable,configurable] false true true true", js); + Utils.assertWithAllModes_ES6("[get,set,enumerable,configurable] false true true true", js); } @Test @@ -447,7 +446,7 @@ public void isExtensible() { + "var x = Object.isExtensible(proxy1);\n" + "res += ' ' + x;\n" + "res += ' ' + x;\n"; - Utils.assertWithAllOptimizationLevelsES6(" a true true true", js); + Utils.assertWithAllModes_ES6(" a true true true", js); } @Test @@ -462,7 +461,7 @@ public void isExtensibleWithoutHandler() { + "var proxy2 = new Proxy(o2, {});\n" + "result += ' ' + Object.isExtensible(o2) + '-' + Object.isExtensible(proxy2);\n"; - Utils.assertWithAllOptimizationLevelsES6("true-true false-false false-false", js); + Utils.assertWithAllModes_ES6("true-true false-false false-false", js); } @Test @@ -477,7 +476,7 @@ public void preventExtensionsTrapReturnsNoBoolean() { + "var res = '' + Reflect.preventExtensions(p);\n" + "Object.preventExtensions(target);\n" + "res += ' ' + Reflect.preventExtensions(p);\n"; - Utils.assertWithAllOptimizationLevelsES6("false false", js); + Utils.assertWithAllModes_ES6("false false", js); } @Test @@ -486,7 +485,7 @@ public void preventExtensionsTrapIsUndefined() { "var target = {};\n" + "var p = new Proxy(target, {});\n" + "'' + Reflect.preventExtensions(p);"; - Utils.assertWithAllOptimizationLevelsES6("true", js); + Utils.assertWithAllModes_ES6("true", js); } @Test @@ -503,7 +502,7 @@ public void ownKeys() { + "var proxy1 = new Proxy(o, handler);\n" + "var x = Object.keys(proxy1);\n" + "res += ' ' + x;\n"; - Utils.assertWithAllOptimizationLevelsES6("true d", js); + Utils.assertWithAllModes_ES6("true d", js); } @Test @@ -516,7 +515,7 @@ public void ownKeysTrapUndefined() { + "var p = new Proxy(target, {});\n" + "var keys = Object.getOwnPropertyNames(p);\n" + "'' + keys[0] + ' ' + keys[1] + ' ' + keys.length"; - Utils.assertWithAllOptimizationLevelsES6("foo bar 2", js); + Utils.assertWithAllModes_ES6("foo bar 2", js); } @Test @@ -528,7 +527,7 @@ public void ownKeysArrayInTrapResult() { + " }\n" + "});\n" + "try { Object.keys(p); } catch(e) { '' + e }\n"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: proxy [[OwnPropertyKeys]] must return an array with only string and symbol elements", js); } @@ -545,7 +544,7 @@ public void ownKeysWithoutHandler() { + "var proxy2 = new Proxy(a1, {});\n" + "'' + Object.keys(proxy1)" + "+ ' ' + Object.keys(proxy2)"; - Utils.assertWithAllOptimizationLevelsES6("p1,p2 ", js); + Utils.assertWithAllModes_ES6("p1,p2 ", js); } @Test @@ -568,13 +567,13 @@ public void ownKeysWithoutHandler2() { + "var a1 = [];\n" + "var proxy1 = new Proxy(o1, {});\n" + "'' + Object.keys(proxy1)"; - Utils.assertWithAllOptimizationLevelsES6("0,6,8,55,773,s1,str,-1,s2,str2", js); + Utils.assertWithAllModes_ES6("0,6,8,55,773,s1,str,-1,s2,str2", js); } @Test public void ownKeysWithoutHandlerEmptyObj() { String js = "var proxy1 = new Proxy({}, {});\n" + "'' + Object.keys(proxy1).length"; - Utils.assertWithAllOptimizationLevelsES6("0", js); + Utils.assertWithAllModes_ES6("0", js); } @Test @@ -584,19 +583,19 @@ public void ownKeysWithoutHandlerDeleteObj() { + "delete o.d;\n" + "var proxy1 = new Proxy(o, {});\n" + "'' + Object.keys(proxy1).length"; - Utils.assertWithAllOptimizationLevelsES6("0", js); + Utils.assertWithAllModes_ES6("0", js); } @Test public void ownKeysWithoutHandlerEmptyArray() { String js = "var proxy1 = new Proxy([], {});\n" + "'' + Object.keys(proxy1)"; - Utils.assertWithAllOptimizationLevelsES6("", js); + Utils.assertWithAllModes_ES6("", js); } @Test public void ownKeysWithoutHandlerArray() { String js = "var proxy1 = new Proxy([, , 2], {});\n" + "'' + Object.keys(proxy1)"; - Utils.assertWithAllOptimizationLevelsES6("2", js); + Utils.assertWithAllModes_ES6("2", js); } @Test @@ -607,7 +606,7 @@ public void ownKeysWithoutHandlerNotEnumerable() { + "Object.defineProperty(o, 'p2', { get: function() {}, enumerable: false });\n" + "var proxy1 = new Proxy(o, {});\n" + "'' + Object.keys(proxy1)"; - Utils.assertWithAllOptimizationLevelsES6("", js); + Utils.assertWithAllModes_ES6("", js); } @Test @@ -628,7 +627,7 @@ public void hasTargetNotExtensible() { + "Object.preventExtensions(target);\n" + "try { 'attr' in p; } catch(e) { '' + e }\n"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: proxy can't report an existing own property 'attr' as non-existent on a non-extensible object", js); } @@ -652,7 +651,7 @@ public void hasHandlerCallsIn() { + "+ ' ' + ('attr' === _prop)" + "+ ' ' + ('attr' in p)"; - Utils.assertWithAllOptimizationLevelsES6("false false false false", js); + Utils.assertWithAllModes_ES6("false false false false", js); } @Test @@ -663,7 +662,7 @@ public void hasWithoutHandler() { + "'' + ('p' in proxy1)" + "+ ' ' + ('p2' in proxy1)" + "+ ' ' + ('toString' in proxy1)"; - Utils.assertWithAllOptimizationLevelsES6("true false true", js); + Utils.assertWithAllModes_ES6("true false true", js); } @Test @@ -676,7 +675,7 @@ public void hasSymbolWithoutHandler() { + "var proxy1 = new Proxy(o, {});\n" + "'' + (s1 in proxy1)" + "+ ' ' + (2 in proxy1)"; - Utils.assertWithAllOptimizationLevelsES6("true false", js); + Utils.assertWithAllModes_ES6("true false", js); } @Test @@ -689,7 +688,7 @@ public void getTrapIsNullTargetIsProxy() { + "'' + stringProxy.length" + " + ' ' + stringProxy[0]" + " + ' ' + stringProxy[4];"; - Utils.assertWithAllOptimizationLevelsES6("3 s undefined", js); + Utils.assertWithAllModes_ES6("3 s undefined", js); } @Test @@ -712,7 +711,7 @@ public void getTrapIsNullTargetIsProxy2() { + " + ' ' + proxy[10]" + " + ' ' + Object.create(proxy).foo" + " + ' ' + proxy.bar;"; - Utils.assertWithAllOptimizationLevelsES6("1 2 3 undefined", js); + Utils.assertWithAllModes_ES6("1 2 3 undefined", js); } @Test @@ -729,13 +728,13 @@ public void setTrap() { + "proxy.foo = [1, 2, 3];\n" + "res"; - Utils.assertWithAllOptimizationLevelsES6("1,2,3 true", js); + Utils.assertWithAllModes_ES6("1,2,3 true", js); } @Test public void getPropertyByIntWithoutHandler() { String js = "var a = ['zero', 'one'];" + "var proxy1 = new Proxy(a, {});\n" + "proxy1[1];"; - Utils.assertWithAllOptimizationLevelsES6("one", js); + Utils.assertWithAllModes_ES6("one", js); } @Test @@ -755,7 +754,7 @@ public void getProperty() { + "result += ', ' + proxy2.p;\n" + "result += ', ' + proxy2.u;\n"; - Utils.assertWithAllOptimizationLevelsES6("value 1!, foo!, 42, undefined", js); + Utils.assertWithAllModes_ES6("value 1!, foo!, 42, undefined", js); } @Test @@ -783,7 +782,7 @@ public void getPropertyParameters() { + "p['attr'];\n" + "res + ' ' + (_prop == 'attr')"; - Utils.assertWithAllOptimizationLevelsES6("true true true true true", js); + Utils.assertWithAllModes_ES6("true true true true true", js); } @Test @@ -803,7 +802,7 @@ public void getPropertyWithoutHandler() { + "result += ', ' + proxy2.p;\n" + "result += ', ' + proxy2.u;\n"; - Utils.assertWithAllOptimizationLevelsES6("value 1, undefined, foo, 42, undefined", js); + Utils.assertWithAllModes_ES6("value 1, undefined, foo, 42, undefined", js); } @Test @@ -814,7 +813,7 @@ public void getPrototypeOfNull() { + " getPrototypeOf: null,\n" + "});\n" + "'' + Object.getPrototypeOf(plainObjectProxy);\n"; - Utils.assertWithAllOptimizationLevelsES6("null", js); + Utils.assertWithAllModes_ES6("null", js); } @Test @@ -826,13 +825,13 @@ public void setPrototypeOfWithoutHandler() { + "result += ' ' + Reflect.setPrototypeOf(o1, null);\n" + "var o2 = {};\n" + "result += ' ' + Reflect.setPrototypeOf(Object.freeze(o2), null);\n"; - Utils.assertWithAllOptimizationLevelsES6("true true false", js); + Utils.assertWithAllModes_ES6("true true false", js); } @Test public void setPrototypeOfCycleWithoutHandler() { String js = "var o1 = {};\n" + "'' + Reflect.setPrototypeOf(o1, o1);\n"; - Utils.assertWithAllOptimizationLevelsES6("false", js); + Utils.assertWithAllModes_ES6("false", js); } @Test @@ -844,7 +843,7 @@ public void setPrototypeOfCycleComplexWithoutHandler() { + "'' + Reflect.setPrototypeOf(o1, o2)" + "+ ' ' + Reflect.setPrototypeOf(o2, o3)" + "+ ' ' + Reflect.setPrototypeOf(o3, o1)"; - Utils.assertWithAllOptimizationLevelsES6("true true false", js); + Utils.assertWithAllModes_ES6("true true false", js); } @Test @@ -860,20 +859,20 @@ public void setPrototypeOfSameWithoutHandler() { + "'' + Reflect.setPrototypeOf(o1, Object.prototype)" + "+ ' ' + Reflect.setPrototypeOf(o2, null)" + "+ ' ' + Reflect.setPrototypeOf(o3, proto)"; - Utils.assertWithAllOptimizationLevelsES6("true true true", js); + Utils.assertWithAllModes_ES6("true true true", js); } @Test public void typeof() { - Utils.assertWithAllOptimizationLevelsES6("object", "typeof new Proxy({}, {})"); - Utils.assertWithAllOptimizationLevelsES6("function", "typeof new Proxy(function() {}, {})"); + Utils.assertWithAllModes_ES6("object", "typeof new Proxy({}, {})"); + Utils.assertWithAllModes_ES6("function", "typeof new Proxy(function() {}, {})"); } @Test public void typeofRevocable() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "object", "var rev = Proxy.revocable({}, {}); rev.revoke(); typeof rev.proxy"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "function", "var rev = Proxy.revocable(function() {}, {}); rev.revoke(); typeof rev.proxy"); @@ -882,7 +881,7 @@ public void typeofRevocable() { + "revocableTarget.revoke();\n" + "var revocable = Proxy.revocable(revocableTarget.proxy, {});\n" + "'' + typeof revocable.proxy;\n"; - Utils.assertWithAllOptimizationLevelsES6("function", js); + Utils.assertWithAllModes_ES6("function", js); } @Test @@ -894,12 +893,12 @@ public void revocableFunctionIsAnonymous() { + "+ ' ' + desc.writable " + "+ ' ' + desc.enumerable " + "+ ' ' + desc.configurable"; - Utils.assertWithAllOptimizationLevelsES6("undefined false false true", js); + Utils.assertWithAllModes_ES6("undefined false false true", js); } @Test public void revocableGetPrototypeOf() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Illegal operation attempted on a revoked proxy", "var rev = Proxy.revocable({}, {}); rev.revoke(); " + "try { Object.getPrototypeOf(rev.proxy); } catch(e) { '' + e }"); @@ -926,7 +925,7 @@ public void keysFailsWithOwnKeysOverwritten() { + " '' + e;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: proxy can't skip a non-configurable property 'prop'", js); } @@ -952,6 +951,6 @@ public void keysPreventExtensions() { + " '' + e;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6(true, js); + Utils.assertWithAllModes_ES6(true, js); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeReflectTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeReflectTest.java index efabb74f9c..dfc6453cab 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeReflectTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeReflectTest.java @@ -7,42 +7,38 @@ public class NativeReflectTest { @Test public void testToString() { - Utils.assertWithAllOptimizationLevelsES6("[object Reflect]", "Reflect.toString()"); + Utils.assertWithAllModes_ES6("[object Reflect]", "Reflect.toString()"); } @Test public void apply() { - Utils.assertWithAllOptimizationLevelsES6( - 1.0, "Reflect.apply(Math.floor, undefined, [1.75])"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6(1.0, "Reflect.apply(Math.floor, undefined, [1.75])"); + Utils.assertWithAllModes_ES6( "hello", "Reflect.apply(String.fromCharCode, undefined, [104, 101, 108, 108, 111])"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( 4, "Reflect.apply(RegExp.prototype.exec, /ab/, ['confabulation']).index"); - Utils.assertWithAllOptimizationLevelsES6("i", "Reflect.apply(''.charAt, 'ponies', [3])"); + Utils.assertWithAllModes_ES6("i", "Reflect.apply(''.charAt, 'ponies', [3])"); } @Test public void applyString() { - Utils.assertWithAllOptimizationLevelsES6( - "foo", "Reflect.apply(String.prototype.toString, 'foo', [])"); - Utils.assertWithAllOptimizationLevelsES6( - "oo", "Reflect.apply(String.prototype.substring, 'foo', [1])"); + Utils.assertWithAllModes_ES6("foo", "Reflect.apply(String.prototype.toString, 'foo', [])"); + Utils.assertWithAllModes_ES6("oo", "Reflect.apply(String.prototype.substring, 'foo', [1])"); } @Test public void applyNumber() { - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "1.234567e+3", "Reflect.apply(Number.prototype.toExponential, 1234.567, [])"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "1.23e+3", "Reflect.apply(Number.prototype.toExponential, 1234.567, [2])"); } @Test public void applyBoolean() { - Utils.assertWithAllOptimizationLevelsES6( - "true", "Reflect.apply(Boolean.prototype.toString, true, [])"); - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6("true", "Reflect.apply(Boolean.prototype.toString, true, [])"); + Utils.assertWithAllModes_ES6( "false", "Reflect.apply(Boolean.prototype.toString, false, [])"); } @@ -67,13 +63,13 @@ public void applyDetails() { + "+ ' ' + results.args[1]" + "+ ' ' + results.args[2]" + "+ ' ' + results.args[3]"; - Utils.assertWithAllOptimizationLevelsES6("1 true 4 arg1 2 undefined null", js); + Utils.assertWithAllModes_ES6("1 true 4 arg1 2 undefined null", js); } @Test public void applyMissingArgs() { String js = "try {\n" + " Reflect.apply();\n" + "} catch(e) {\n" + " '' + e;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Reflect.apply: At least 3 arguments required, but only 0 passed", js); } @@ -85,7 +81,7 @@ public void applyTargetNotFunction() { + "} catch(e) {\n" + " '' + e;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: [object Object] is not a function, it is object.", js); } @@ -98,7 +94,7 @@ public void applyArgumentsListNotFunction() { + "} catch(e) {\n" + " '' + e;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: Expected argument of type object, but instead had type symbol", js); } @@ -107,7 +103,7 @@ public void construct() { String js = "var d = Reflect.construct(Date, [1776, 6, 4]);\n" + "'' + (d instanceof Date) + ' ' + d.getFullYear();"; - Utils.assertWithAllOptimizationLevelsES6("true 1776", js); + Utils.assertWithAllModes_ES6("true 1776", js); } @Test @@ -123,7 +119,7 @@ public void constructNewTarget() { + "'' + (Object.getPrototypeOf(result) === Array.prototype)" + " + ' ' + (internPrototype === Array.prototype)" + " + ' ' + (result.o === o)"; - Utils.assertWithAllOptimizationLevelsES6("true true true", js); + Utils.assertWithAllModes_ES6("true true true", js); } @Test @@ -134,7 +130,7 @@ public void constructNoConstructorNumber() { + "} catch(e) {\n" + " '' + e;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6("TypeError: \"number\" is not a constructor.", js); + Utils.assertWithAllModes_ES6("TypeError: \"number\" is not a constructor.", js); } @Test @@ -145,7 +141,7 @@ public void constructNoConstructorNull() { + "} catch(e) {\n" + " '' + e;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6("TypeError: \"object\" is not a constructor.", js); + Utils.assertWithAllModes_ES6("TypeError: \"object\" is not a constructor.", js); } @Test @@ -156,7 +152,7 @@ public void constructNoConstructorObject() { + "} catch(e) {\n" + " '' + e;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6("TypeError: \"object\" is not a constructor.", js); + Utils.assertWithAllModes_ES6("TypeError: \"object\" is not a constructor.", js); } @Test @@ -167,8 +163,7 @@ public void constructNoConstructorFunction() { + "} catch(e) {\n" + " '' + e;\n" + "}"; - Utils.assertWithAllOptimizationLevelsES6( - "TypeError: \"function\" is not a constructor.", js); + Utils.assertWithAllModes_ES6("TypeError: \"function\" is not a constructor.", js); } @Test @@ -184,7 +179,7 @@ public void constructorArgs() { + "Reflect.construct(foo, [1, 2]);\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("foo - 1 2 ", script); + Utils.assertWithAllModes_ES6("foo - 1 2 ", script); } @Test @@ -206,14 +201,14 @@ public void constructorArgsWithTarget() { + "Reflect.construct(foo, [6, 7, 8], bar);\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6("foo - 6 7 8 ", script); + Utils.assertWithAllModes_ES6("foo - 6 7 8 ", script); } @Test public void defineProperty() { String js = "var o = {};\n" + "'' + Reflect.defineProperty(o, 'p', { value: 42 }) + ' ' + o.p;"; - Utils.assertWithAllOptimizationLevelsES6("true 42", js); + Utils.assertWithAllModes_ES6("true 42", js); } @Test @@ -223,7 +218,7 @@ public void definePropertyWithoutValue() { + "'' + Reflect.defineProperty(o, 'p', {})" + "+ ' ' + Reflect.has(o, 'p')" + "+ ' ' + o.p;"; - Utils.assertWithAllOptimizationLevelsES6("true true undefined", js); + Utils.assertWithAllModes_ES6("true true undefined", js); } @Test @@ -232,7 +227,7 @@ public void definePropertyFreezed() { "var o = {};\n" + "Object.freeze(o);\n" + "'' + Reflect.defineProperty(o, 'p', { value: 42 }) + ' ' + o.p;"; - Utils.assertWithAllOptimizationLevelsES6("false undefined", js); + Utils.assertWithAllModes_ES6("false undefined", js); } @Test @@ -242,7 +237,7 @@ public void deleteProperty() { + "'' + Reflect.deleteProperty(o, 'p')" + "+ ' ' + Reflect.has(o, 'p')" + "+ ' ' + o.p;"; - Utils.assertWithAllOptimizationLevelsES6("true false undefined", js); + Utils.assertWithAllModes_ES6("true false undefined", js); } @Test @@ -260,8 +255,7 @@ public void getOwnPropertyDescriptor() { + "+ ' ' + result.configurable" + "+ ' ' + (result.get === fn)" + "+ ' ' + (result.set === undefined)"; - Utils.assertWithAllOptimizationLevelsES6( - "[get,set,enumerable,configurable] false true true true", js); + Utils.assertWithAllModes_ES6("[get,set,enumerable,configurable] false true true true", js); } @Test @@ -274,7 +268,7 @@ public void isExtensible() { + "var o2 = Object.seal({});\n" + "result += ' ' + Reflect.isExtensible(o2);\n"; - Utils.assertWithAllOptimizationLevelsES6("true false false", js); + Utils.assertWithAllModes_ES6("true false false", js); } @Test @@ -287,7 +281,7 @@ public void ownKeys() { + "var a1 = [];\n" + "'' + Reflect.ownKeys(o1)" + "+ ' ' + Reflect.ownKeys(a1)"; - Utils.assertWithAllOptimizationLevelsES6("p1,p2 length", js); + Utils.assertWithAllModes_ES6("p1,p2 length", js); } @Test @@ -309,31 +303,31 @@ public void ownKeys2() { + "};\n" + "var a1 = [];\n" + "'' + Reflect.ownKeys(o1)"; - Utils.assertWithAllOptimizationLevelsES6("0,6,8,55,773,s1,str,-1,s2,str2", js); + Utils.assertWithAllModes_ES6("0,6,8,55,773,s1,str,-1,s2,str2", js); } @Test public void ownKeysEmptyObj() { String js = "'' + Reflect.ownKeys({}).length"; - Utils.assertWithAllOptimizationLevelsES6("0", js); + Utils.assertWithAllModes_ES6("0", js); } @Test public void ownKeysDeleteObj() { String js = "var o = { d: 42 };\n" + "delete o.d;\n" + "'' + Reflect.ownKeys(o).length"; - Utils.assertWithAllOptimizationLevelsES6("0", js); + Utils.assertWithAllModes_ES6("0", js); } @Test public void ownKeysEmptyArray() { String js = "'' + Reflect.ownKeys([])"; - Utils.assertWithAllOptimizationLevelsES6("length", js); + Utils.assertWithAllModes_ES6("length", js); } @Test public void ownKeysArray() { String js = "'' + Reflect.ownKeys([, , 2])"; - Utils.assertWithAllOptimizationLevelsES6("2,length", js); + Utils.assertWithAllModes_ES6("2,length", js); } @Test @@ -343,7 +337,7 @@ public void ownKeysNotEnumerable() { + "Object.defineProperty(o, 'p1', { value: 42, enumerable: false });\n" + "Object.defineProperty(o, 'p2', { get: function() {}, enumerable: false });\n" + "'' + Reflect.ownKeys(o)"; - Utils.assertWithAllOptimizationLevelsES6("p1,p2", js); + Utils.assertWithAllModes_ES6("p1,p2", js); } @Test @@ -353,7 +347,7 @@ public void has() { + "'' + Reflect.has(o1, 'p')" + "+ ' ' + Reflect.has(o1, 'p2')" + "+ ' ' + Reflect.has(o1, 'toString')"; - Utils.assertWithAllOptimizationLevelsES6("true false true", js); + Utils.assertWithAllModes_ES6("true false true", js); } @Test @@ -365,13 +359,13 @@ public void hasSymbol() { + "o[s1] = 42;\n" + "'' + Reflect.has(o, s1)" + "+ ' ' + Reflect.has(o, 2)"; - Utils.assertWithAllOptimizationLevelsES6("true false", js); + Utils.assertWithAllModes_ES6("true false", js); } @Test public void hasProto() { String js = "var o1 = { p: 42 }\n" + "'' + typeof Reflect.has.__proto__"; - Utils.assertWithAllOptimizationLevelsES6("function", js); + Utils.assertWithAllModes_ES6("function", js); } @Test @@ -385,7 +379,7 @@ public void getOwnPropertyDescriptorSymbol() { + "+ ' ' + result.enumerable" + "+ ' ' + result.configurable" + "+ ' ' + result.writable"; - Utils.assertWithAllOptimizationLevelsES6("42 true true true", js); + Utils.assertWithAllModes_ES6("42 true true true", js); } @Test @@ -394,13 +388,13 @@ public void getOwnPropertyDescriptorUndefinedProperty() { "var o = Object.create({p: 1});\n" + "var result = Reflect.getOwnPropertyDescriptor(o, 'p');\n" + "'' + (result === undefined)"; - Utils.assertWithAllOptimizationLevelsES6("true", js); + Utils.assertWithAllModes_ES6("true", js); } @Test public void getPropertyByInt() { String js = "var a = ['zero', 'one']\n" + "Reflect.get(a, 1);"; - Utils.assertWithAllOptimizationLevelsES6("one", js); + Utils.assertWithAllModes_ES6("one", js); } @Test @@ -418,7 +412,7 @@ public void getProperty() { + "result += ', ' + Reflect.get(o2, 'p');\n" + "result += ', ' + Reflect.get(o2, 'u');\n"; - Utils.assertWithAllOptimizationLevelsES6("value 1, undefined, foo, 42, undefined", js); + Utils.assertWithAllModes_ES6("value 1, undefined, foo, 42, undefined", js); } @Test @@ -430,13 +424,13 @@ public void setPrototypeOf() { + "result += ' ' + Reflect.setPrototypeOf(o1, null);\n" + "var o2 = {};\n" + "result += ' ' + Reflect.setPrototypeOf(Object.freeze(o2), null);\n"; - Utils.assertWithAllOptimizationLevelsES6("true true false", js); + Utils.assertWithAllModes_ES6("true true false", js); } @Test public void setPrototypeOfCycle() { String js = "var o1 = {};\n" + "'' + Reflect.setPrototypeOf(o1, o1);\n"; - Utils.assertWithAllOptimizationLevelsES6("false", js); + Utils.assertWithAllModes_ES6("false", js); } @Test @@ -448,7 +442,7 @@ public void setPrototypeOfCycleComplex() { + "'' + Reflect.setPrototypeOf(o1, o2)" + "+ ' ' + Reflect.setPrototypeOf(o2, o3)" + "+ ' ' + Reflect.setPrototypeOf(o3, o1)"; - Utils.assertWithAllOptimizationLevelsES6("true true false", js); + Utils.assertWithAllModes_ES6("true true false", js); } @Test @@ -464,6 +458,6 @@ public void setPrototypeOfSame() { + "'' + Reflect.setPrototypeOf(o1, Object.prototype)" + "+ ' ' + Reflect.setPrototypeOf(o2, null)" + "+ ' ' + Reflect.setPrototypeOf(o3, proto)"; - Utils.assertWithAllOptimizationLevelsES6("true true true", js); + Utils.assertWithAllModes_ES6("true true true", js); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeRegExpTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeRegExpTest.java index db60117d27..9cd0ece772 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeRegExpTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeRegExpTest.java @@ -14,34 +14,33 @@ public class NativeRegExpTest { @Test public void regExIsCallableForBackwardCompatibility() { - Utils.assertWithAllOptimizationLevels_1_8("1", "var a = new RegExp('1'); a(1).toString();"); - Utils.assertWithAllOptimizationLevels_1_8( - "{1234},1234", "/^\\{(.*)\\}$/('{1234}').toString();"); - Utils.assertWithAllOptimizationLevels_1_8(null, "RegExp('a|b','g')()"); - Utils.assertWithAllOptimizationLevels_1_8(null, "new /z/();"); - Utils.assertWithAllOptimizationLevels_1_8("", "(new new RegExp).toString()"); + Utils.assertWithAllModes_1_8("1", "var a = new RegExp('1'); a(1).toString();"); + Utils.assertWithAllModes_1_8("{1234},1234", "/^\\{(.*)\\}$/('{1234}').toString();"); + Utils.assertWithAllModes_1_8(null, "RegExp('a|b','g')()"); + Utils.assertWithAllModes_1_8(null, "new /z/();"); + Utils.assertWithAllModes_1_8("", "(new new RegExp).toString()"); } @Test public void regExMinusInRangeBorderCases() { - Utils.assertWithAllOptimizationLevels_1_8( + Utils.assertWithAllModes_1_8( "axbxc d efg 1 23", "var r = 'a-b_c d efg 1 23';\n" + "r.replace(/[_-]+/g, 'x');"); - Utils.assertWithAllOptimizationLevels_1_8( + Utils.assertWithAllModes_1_8( "axbxcxdxefgx1x23", "var r = 'a-b_c d efg 1 23';\n" + "r.replace(/[_-\\s]+/g, 'x');"); - Utils.assertWithAllOptimizationLevels_1_8( + Utils.assertWithAllModes_1_8( "x x x x x", "var r = 'a-b_c d efg 1 23';\n" + "r.replace(/[_-\\S]+/g, 'x');"); - Utils.assertWithAllOptimizationLevels_1_8( + Utils.assertWithAllModes_1_8( "x x x x x", "var r = 'a-b_c d efg 1 23';\n" + "r.replace(/[_-\\w]+/g, 'x');"); - Utils.assertWithAllOptimizationLevels_1_8( + Utils.assertWithAllModes_1_8( "axbxcxdxefgx1x23", "var r = 'a-b_c d efg 1 23';\n" + "r.replace(/[_-\\W]+/g, 'x');"); - Utils.assertWithAllOptimizationLevels_1_8( + Utils.assertWithAllModes_1_8( "axbxc d efg x x", "var r = 'a-b_c d efg 1 23';\n" + "r.replace(/[_-\\d]+/g, 'x');"); - Utils.assertWithAllOptimizationLevels_1_8( + Utils.assertWithAllModes_1_8( "x1x23", "var r = 'a-b_c d efg 1 23';\n" + "r.replace(/[_-\\D]+/g, 'x');"); - Utils.assertWithAllOptimizationLevels_1_8( + Utils.assertWithAllModes_1_8( "x-bxc d efg 1 23", "var r = 'a-b_c d efg 1 23';\n" + "r.replace(/[_-\\a]+/g, 'x');"); } @@ -68,16 +67,15 @@ public void lastIndexReadonly() { + " Object.defineProperty(r, 'lastIndex', { writable: false });" + " r.exec('abc');" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels( - "Cannot modify readonly property: lastIndex.", script); + Utils.assertWithAllModes("Cannot modify readonly property: lastIndex.", script); } @Test public void search() { - Utils.assertWithAllOptimizationLevelsES6(1, "'abc'.search(/b/);"); - Utils.assertWithAllOptimizationLevelsES6(1, "/b/[Symbol.search]('abc');"); - Utils.assertWithAllOptimizationLevelsES6(-1, "'abc'.search(/d/);"); - Utils.assertWithAllOptimizationLevelsES6(-1, "/d/[Symbol.search]('abc');"); + Utils.assertWithAllModes_ES6(1, "'abc'.search(/b/);"); + Utils.assertWithAllModes_ES6(1, "/b/[Symbol.search]('abc');"); + Utils.assertWithAllModes_ES6(-1, "'abc'.search(/d/);"); + Utils.assertWithAllModes_ES6(-1, "/d/[Symbol.search]('abc');"); } @Test @@ -96,7 +94,7 @@ public void canCreateRegExpPassingExistingRegExp() { + " pattern.multiline === re.multiline &&" + " pattern.global === re.global && " + " pattern.ignoreCase === re.ignoreCase"; - Utils.assertWithAllOptimizationLevels(true, script); + Utils.assertWithAllModes(true, script); } @Test @@ -108,7 +106,7 @@ public void canCreateRegExpPassingExistingRegExpAndUndefinedFlags() { + " pattern.multiline === re.multiline &&" + " pattern.global === re.global && " + " pattern.ignoreCase === re.ignoreCase"; - Utils.assertWithAllOptimizationLevels(true, script); + Utils.assertWithAllModes(true, script); } @Test @@ -129,6 +127,6 @@ public void canCreateRegExpPassingExistingRegExpAndNewFlagsEs6() { + "pattern.lastIndex = 42;\n" + "var re = new RegExp(pattern, \"g\");\n" + "re.global && re.lastIndex === 0"; - Utils.assertWithAllOptimizationLevelsES6(true, script); + Utils.assertWithAllModes_ES6(true, script); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeString2Test.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeString2Test.java index d36ecc64c1..55157c60a1 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeString2Test.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NativeString2Test.java @@ -29,50 +29,50 @@ public void getOwnPropertyDescriptorWithIndex() { + " res += desc.configurable;" + " res += ';';" + " res;"; - Utils.assertWithAllOptimizationLevelsES6("true;h;false;true;false;", js); + Utils.assertWithAllModes_ES6("true;h;false;true;false;", js); } @Test public void normalizeNoParam() { - Utils.assertWithAllOptimizationLevels("123", "'123'.normalize()"); + Utils.assertWithAllModes("123", "'123'.normalize()"); } @Test public void normalizeNoUndefined() { - Utils.assertWithAllOptimizationLevels("123", "'123'.normalize(undefined)"); + Utils.assertWithAllModes("123", "'123'.normalize(undefined)"); } @Test public void normalizeNoNull() { String js = "try { " + " '123'.normalize(null);" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes( "The normalization form should be one of 'NFC', 'NFD', 'NFKC', 'NFKD'.", js); } @Test public void replaceReplacementAsString() { - Utils.assertWithAllOptimizationLevels( - Context.VERSION_DEFAULT, "1null3", "'123'.replace('2', /x/);"); - Utils.assertWithAllOptimizationLevelsES6("1/x/3", "'123'.replace('2', /x/);"); + Utils.assertWithAllModes( + Context.VERSION_DEFAULT, null, "1null3", "'123'.replace('2', /x/);"); + Utils.assertWithAllModes_ES6("1/x/3", "'123'.replace('2', /x/);"); } @Test public void indexOfEmpty() { - Utils.assertWithAllOptimizationLevels(0, "'1234'.indexOf('', 0);"); - Utils.assertWithAllOptimizationLevels(1, "'1234'.indexOf('', 1);"); - Utils.assertWithAllOptimizationLevels(4, "'1234'.indexOf('', 4);"); - Utils.assertWithAllOptimizationLevels(4, "'1234'.indexOf('', 5);"); - Utils.assertWithAllOptimizationLevels(4, "'1234'.indexOf('', 42);"); + Utils.assertWithAllModes(0, "'1234'.indexOf('', 0);"); + Utils.assertWithAllModes(1, "'1234'.indexOf('', 1);"); + Utils.assertWithAllModes(4, "'1234'.indexOf('', 4);"); + Utils.assertWithAllModes(4, "'1234'.indexOf('', 5);"); + Utils.assertWithAllModes(4, "'1234'.indexOf('', 42);"); } @Test public void includesEmpty() { - Utils.assertWithAllOptimizationLevels(true, "'1234'.includes('');"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.includes('', 0);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.includes('', 1);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.includes('', 4);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.includes('', 5);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.includes('', 42);"); + Utils.assertWithAllModes(true, "'1234'.includes('');"); + Utils.assertWithAllModes(true, "'1234'.includes('', 0);"); + Utils.assertWithAllModes(true, "'1234'.includes('', 1);"); + Utils.assertWithAllModes(true, "'1234'.includes('', 4);"); + Utils.assertWithAllModes(true, "'1234'.includes('', 5);"); + Utils.assertWithAllModes(true, "'1234'.includes('', 42);"); } @Test @@ -89,19 +89,19 @@ public void includesRegExpMatch() { + "res += ' # ' + '/./'.includes(regExp);\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: First argument to String.prototype.includes must not be a regular expression # true", js); } @Test public void startsWithEmpty() { - Utils.assertWithAllOptimizationLevels(true, "'1234'.startsWith('');"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.startsWith('', 0);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.startsWith('', 1);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.startsWith('', 4);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.startsWith('', 5);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.startsWith('', 42);"); + Utils.assertWithAllModes(true, "'1234'.startsWith('');"); + Utils.assertWithAllModes(true, "'1234'.startsWith('', 0);"); + Utils.assertWithAllModes(true, "'1234'.startsWith('', 1);"); + Utils.assertWithAllModes(true, "'1234'.startsWith('', 4);"); + Utils.assertWithAllModes(true, "'1234'.startsWith('', 5);"); + Utils.assertWithAllModes(true, "'1234'.startsWith('', 42);"); } @Test @@ -118,19 +118,19 @@ public void startsWithRegExpMatch() { + "res += ' # ' + '/./'.includes(regExp);\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: First argument to String.prototype.startsWith must not be a regular expression # true", js); } @Test public void endsWithEmpty() { - Utils.assertWithAllOptimizationLevels(true, "'1234'.endsWith('');"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.endsWith('', 0);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.endsWith('', 1);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.endsWith('', 4);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.endsWith('', 5);"); - Utils.assertWithAllOptimizationLevels(true, "'1234'.endsWith('', 42);"); + Utils.assertWithAllModes(true, "'1234'.endsWith('');"); + Utils.assertWithAllModes(true, "'1234'.endsWith('', 0);"); + Utils.assertWithAllModes(true, "'1234'.endsWith('', 1);"); + Utils.assertWithAllModes(true, "'1234'.endsWith('', 4);"); + Utils.assertWithAllModes(true, "'1234'.endsWith('', 5);"); + Utils.assertWithAllModes(true, "'1234'.endsWith('', 42);"); } @Test @@ -147,24 +147,21 @@ public void endsWithRegExpMatch() { + "res += ' # ' + '/./'.includes(regExp);\n" + "res;"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "TypeError: First argument to String.prototype.startsWith must not be a regular expression # true", js); } @Test public void tagify() { - Utils.assertWithAllOptimizationLevels("tester", "'tester'.big()"); - Utils.assertWithAllOptimizationLevels("\"tester\"", "'\"tester\"'.big()"); - Utils.assertWithAllOptimizationLevels( - "tester", "'tester'.fontsize()"); - Utils.assertWithAllOptimizationLevels( - "tester", "'tester'.fontsize(null)"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes("tester", "'tester'.big()"); + Utils.assertWithAllModes("\"tester\"", "'\"tester\"'.big()"); + Utils.assertWithAllModes("tester", "'tester'.fontsize()"); + Utils.assertWithAllModes("tester", "'tester'.fontsize(null)"); + Utils.assertWithAllModes( "tester", "'tester'.fontsize(undefined)"); - Utils.assertWithAllOptimizationLevels( - "tester", "'tester'.fontsize(123)"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes("tester", "'tester'.fontsize(123)"); + Utils.assertWithAllModes( "tester", "'tester'.fontsize('\"123\"')"); } @@ -188,7 +185,7 @@ public void tagifyPrototypeNull() { String js = "try { String.prototype." + call + ".call(null);} catch (e) { e.message }"; String expected = "String.prototype." + call + " method called on null or undefined"; - Utils.assertWithAllOptimizationLevelsES6(expected, js); + Utils.assertWithAllModes_ES6(expected, js); } } @@ -213,70 +210,68 @@ public void tagifyPrototypeUndefined() { "try { String.prototype." + call + ".call(undefined);} catch (e) { e.message }"; String expected = "String.prototype." + call + " method called on null or undefined"; - Utils.assertWithAllOptimizationLevelsES6(expected, js); + Utils.assertWithAllModes_ES6(expected, js); } } @Test public void stringReplace() { - Utils.assertWithAllOptimizationLevels("xyz", "''.replace('', 'xyz')"); - Utils.assertWithAllOptimizationLevels("1", "'121'.replace('21', '')"); - Utils.assertWithAllOptimizationLevels("xyz121", "'121'.replace('', 'xyz')"); - Utils.assertWithAllOptimizationLevels("a$c21", "'121'.replace('1', 'a$c')"); - Utils.assertWithAllOptimizationLevels("a121", "'121'.replace('1', 'a$&')"); - Utils.assertWithAllOptimizationLevels("a$c21", "'121'.replace('1', 'a$$c')"); - Utils.assertWithAllOptimizationLevels("abaabe", "'abcde'.replace('cd', 'a$`')"); - Utils.assertWithAllOptimizationLevels("a21", "'121'.replace('1', 'a$`')"); - Utils.assertWithAllOptimizationLevels("abaee", "'abcde'.replace('cd', \"a$'\")"); - Utils.assertWithAllOptimizationLevels("aba", "'abcd'.replace('cd', \"a$'\")"); - Utils.assertWithAllOptimizationLevels("aba$0", "'abcd'.replace('cd', 'a$0')"); - Utils.assertWithAllOptimizationLevels("aba$1", "'abcd'.replace('cd', 'a$1')"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes("xyz", "''.replace('', 'xyz')"); + Utils.assertWithAllModes("1", "'121'.replace('21', '')"); + Utils.assertWithAllModes("xyz121", "'121'.replace('', 'xyz')"); + Utils.assertWithAllModes("a$c21", "'121'.replace('1', 'a$c')"); + Utils.assertWithAllModes("a121", "'121'.replace('1', 'a$&')"); + Utils.assertWithAllModes("a$c21", "'121'.replace('1', 'a$$c')"); + Utils.assertWithAllModes("abaabe", "'abcde'.replace('cd', 'a$`')"); + Utils.assertWithAllModes("a21", "'121'.replace('1', 'a$`')"); + Utils.assertWithAllModes("abaee", "'abcde'.replace('cd', \"a$'\")"); + Utils.assertWithAllModes("aba", "'abcd'.replace('cd', \"a$'\")"); + Utils.assertWithAllModes("aba$0", "'abcd'.replace('cd', 'a$0')"); + Utils.assertWithAllModes("aba$1", "'abcd'.replace('cd', 'a$1')"); + Utils.assertWithAllModes( "abCD", "'abcd'.replace('cd', function (matched) { return matched.toUpperCase() })"); - Utils.assertWithAllOptimizationLevels("", "'123456'.replace(/\\d+/, '')"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes("", "'123456'.replace(/\\d+/, '')"); + Utils.assertWithAllModes( "123ABCD321abcd", "'123abcd321abcd'.replace(/[a-z]+/, function (matched) { return matched.toUpperCase() })"); } @Test public void stringReplaceAll() { - Utils.assertWithAllOptimizationLevels("xyz", "''.replaceAll('', 'xyz')"); - Utils.assertWithAllOptimizationLevels("1", "'12121'.replaceAll('21', '')"); - Utils.assertWithAllOptimizationLevels("xyz1xyz2xyz1xyz", "'121'.replaceAll('', 'xyz')"); - Utils.assertWithAllOptimizationLevels("a$c2a$c", "'121'.replaceAll('1', 'a$c')"); - Utils.assertWithAllOptimizationLevels("a12a1", "'121'.replaceAll('1', 'a$&')"); - Utils.assertWithAllOptimizationLevels("a$c2a$c", "'121'.replaceAll('1', 'a$$c')"); - Utils.assertWithAllOptimizationLevels("aaadaaabcda", "'abcdabc'.replaceAll('bc', 'a$`')"); - Utils.assertWithAllOptimizationLevels("a2a12", "'121'.replaceAll('1', 'a$`')"); - Utils.assertWithAllOptimizationLevels("aadabcdaa", "'abcdabc'.replaceAll('bc', \"a$'\")"); - Utils.assertWithAllOptimizationLevels("aadabcdaa", "'abcdabc'.replaceAll('bc', \"a$'\")"); - Utils.assertWithAllOptimizationLevels("aa$0daa$0", "'abcdabc'.replaceAll('bc', 'a$0')"); - Utils.assertWithAllOptimizationLevels("aa$1daa$1", "'abcdabc'.replaceAll('bc', 'a$1')"); - Utils.assertWithAllOptimizationLevels("", "'123456'.replaceAll(/\\d+/g, '')"); - Utils.assertWithAllOptimizationLevels("123456", "'123456'.replaceAll(undefined, '')"); - Utils.assertWithAllOptimizationLevels("afoobarb", "'afoob'.replaceAll(/(foo)/g, '$1bar')"); - Utils.assertWithAllOptimizationLevels("foobarb", "'foob'.replaceAll(/(foo)/gy, '$1bar')"); - Utils.assertWithAllOptimizationLevels("hllo", "'hello'.replaceAll(/(h)e/gy, '$1')"); - Utils.assertWithAllOptimizationLevels("$1llo", "'hello'.replaceAll(/he/g, '$1')"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes("xyz", "''.replaceAll('', 'xyz')"); + Utils.assertWithAllModes("1", "'12121'.replaceAll('21', '')"); + Utils.assertWithAllModes("xyz1xyz2xyz1xyz", "'121'.replaceAll('', 'xyz')"); + Utils.assertWithAllModes("a$c2a$c", "'121'.replaceAll('1', 'a$c')"); + Utils.assertWithAllModes("a12a1", "'121'.replaceAll('1', 'a$&')"); + Utils.assertWithAllModes("a$c2a$c", "'121'.replaceAll('1', 'a$$c')"); + Utils.assertWithAllModes("aaadaaabcda", "'abcdabc'.replaceAll('bc', 'a$`')"); + Utils.assertWithAllModes("a2a12", "'121'.replaceAll('1', 'a$`')"); + Utils.assertWithAllModes("aadabcdaa", "'abcdabc'.replaceAll('bc', \"a$'\")"); + Utils.assertWithAllModes("aadabcdaa", "'abcdabc'.replaceAll('bc', \"a$'\")"); + Utils.assertWithAllModes("aa$0daa$0", "'abcdabc'.replaceAll('bc', 'a$0')"); + Utils.assertWithAllModes("aa$1daa$1", "'abcdabc'.replaceAll('bc', 'a$1')"); + Utils.assertWithAllModes("", "'123456'.replaceAll(/\\d+/g, '')"); + Utils.assertWithAllModes("123456", "'123456'.replaceAll(undefined, '')"); + Utils.assertWithAllModes("afoobarb", "'afoob'.replaceAll(/(foo)/g, '$1bar')"); + Utils.assertWithAllModes("foobarb", "'foob'.replaceAll(/(foo)/gy, '$1bar')"); + Utils.assertWithAllModes("hllo", "'hello'.replaceAll(/(h)e/gy, '$1')"); + Utils.assertWithAllModes("$1llo", "'hello'.replaceAll(/he/g, '$1')"); + Utils.assertWithAllModes( "I$want$these$periods$to$be$$s", "'I.want.these.periods.to.be.$s'.replaceAll(/\\./g, '$')"); - Utils.assertWithAllOptimizationLevels("food bar", "'foo bar'.replaceAll(/foo/g, '$&d')"); - Utils.assertWithAllOptimizationLevels("foo foo ", "'foo bar'.replaceAll(/bar/g, '$`')"); - Utils.assertWithAllOptimizationLevels(" bar bar", "'foo bar'.replaceAll(/foo/g, '$\\'')"); - Utils.assertWithAllOptimizationLevels("$' bar", "'foo bar'.replaceAll(/foo/g, '$$\\'')"); - Utils.assertWithAllOptimizationLevels("ad$0db", "'afoob'.replaceAll(/(foo)/g, 'd$0d')"); - Utils.assertWithAllOptimizationLevels( - "ad$0db", "'afkxxxkob'.replace(/(f)k(.*)k(o)/g, 'd$0d')"); - Utils.assertWithAllOptimizationLevels( - "ad$0dbd$0dc", "'afoobfuoc'.replaceAll(/(f.o)/g, 'd$0d')"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes("food bar", "'foo bar'.replaceAll(/foo/g, '$&d')"); + Utils.assertWithAllModes("foo foo ", "'foo bar'.replaceAll(/bar/g, '$`')"); + Utils.assertWithAllModes(" bar bar", "'foo bar'.replaceAll(/foo/g, '$\\'')"); + Utils.assertWithAllModes("$' bar", "'foo bar'.replaceAll(/foo/g, '$$\\'')"); + Utils.assertWithAllModes("ad$0db", "'afoob'.replaceAll(/(foo)/g, 'd$0d')"); + Utils.assertWithAllModes("ad$0db", "'afkxxxkob'.replace(/(f)k(.*)k(o)/g, 'd$0d')"); + Utils.assertWithAllModes("ad$0dbd$0dc", "'afoobfuoc'.replaceAll(/(f.o)/g, 'd$0d')"); + Utils.assertWithAllModes( "123FOOBAR321BARFOO123", "'123foobar321barfoo123'.replace(/[a-z]+/g, function (matched) { return matched.toUpperCase() })"); - Utils.assertWithAllOptimizationLevels( + Utils.assertWithAllModes( "TypeError: replaceAll must be called with a global RegExp", "try { 'hello'.replaceAll(/he/i, 'x'); } catch (e) { '' + e }"); } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NumericSeparatorTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NumericSeparatorTest.java index 50b9a38fce..1de71f1635 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NumericSeparatorTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NumericSeparatorTest.java @@ -16,13 +16,13 @@ public class NumericSeparatorTest { /** Special Tokenizer test for numeric constant at end. */ @Test public void numericAtEndOneDigit() { - Utils.assertWithAllOptimizationLevelsES6(1, "1"); + Utils.assertWithAllModes_ES6(1, "1"); } /** Special Tokenizer test for numeric constant at end. */ @Test public void numericAtEndManyDigits() { - Utils.runWithOptimizationLevel( + Utils.runWithMode( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); @@ -32,10 +32,10 @@ public void numericAtEndManyDigits() { return null; }, - -1); + true); // the byte code generator adds a cast to integer - Utils.runWithOptimizationLevel( + Utils.runWithMode( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); @@ -45,19 +45,7 @@ public void numericAtEndManyDigits() { return null; }, - 0); - - Utils.runWithOptimizationLevel( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - ScriptableObject scope = cx.initStandardObjects(); - - Object result = cx.evaluateString(scope, "1234", "test", 1, null); - assertEquals(1234, result); - - return null; - }, - 1); + false); } /** Special Tokenizer test for numeric separator constant at end. */ diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/ObjectSealFreezeTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/ObjectSealFreezeTest.java index 71d7de64a3..6ab71c42d1 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/ObjectSealFreezeTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/ObjectSealFreezeTest.java @@ -25,7 +25,7 @@ public void sealWriteToExistingWritableProperty() { + "try { " + " foo();" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("Rhino", script); + Utils.assertWithAllModes_ES6("Rhino", script); } @Test @@ -42,7 +42,7 @@ public void sealWriteToExistingWritablePropertyStrict() { + "try { " + " foo();" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("Rhino", script); + Utils.assertWithAllModes_ES6("Rhino", script); } @Test @@ -59,7 +59,7 @@ public void sealWriteToExistingSymbolProperty() { + "try { " + " foo();" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("Rhino", script); + Utils.assertWithAllModes_ES6("Rhino", script); } @Test @@ -77,7 +77,7 @@ public void sealWriteToExistingSymbolPropertyStrict() { + "try { " + " foo();" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("Rhino", script); + Utils.assertWithAllModes_ES6("Rhino", script); } @Test @@ -93,7 +93,7 @@ public void freezeWriteToExistingWritableProperty() { + "try { " + " foo();" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("abc", script); + Utils.assertWithAllModes_ES6("abc", script); } @Test @@ -110,7 +110,7 @@ public void freezeWriteToExistingWritablePropertyStrict() { + "try { " + " foo();" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "Cannot add properties to this object because extensible is false.", script); } @@ -128,7 +128,7 @@ public void freezeWriteToExistingSymbolProperty() { + "try { " + " foo();" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("abc", script); + Utils.assertWithAllModes_ES6("abc", script); } @Test @@ -146,7 +146,7 @@ public void freezeWriteToExistingSymbolPropertyStrict() { + "try { " + " foo();" + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "Cannot add properties to this object because extensible is false.", script); } @@ -168,7 +168,7 @@ public void objectConstructorForNonExtensibleFunctions() { + " return res;\n" + "};" + " foo();"; - Utils.assertWithAllOptimizationLevelsES6( + Utils.assertWithAllModes_ES6( "a.isExtensible = false\nfunction\ntrue\nb.isExtensible = false", script); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/PromiseTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/PromiseTest.java index 0692973303..6ca5135464 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/PromiseTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/PromiseTest.java @@ -21,7 +21,7 @@ public void ctorCallableThis() { + " });\n" + " r += ' done';\n" + " r;"; - Utils.assertWithAllOptimizationLevelsTopLevelScopeES6("[object global] done", script); + Utils.assertWithAllModesTopLevelScope_ES6("[object global] done", script); } @Test @@ -34,6 +34,6 @@ public void ctorCallableThisStrict() { + " });\n" + " r += ' done';\n" + " r;"; - Utils.assertWithAllOptimizationLevelsES6("true done", script); + Utils.assertWithAllModes_ES6("true done", script); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/PropertyTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/PropertyTest.java index 16d5810474..a721c1b5cc 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/PropertyTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/PropertyTest.java @@ -13,7 +13,7 @@ public class PropertyTest { @Test public void prototypeProperty() throws Exception { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); @@ -49,7 +49,7 @@ public void prototypeProperty() throws Exception { @Test public void redefineGetterProperty() throws Exception { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); @@ -86,7 +86,7 @@ public void redefineGetterProperty() throws Exception { @Test public void redefineSetterProperty() throws Exception { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/Symbol3Test.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/Symbol3Test.java index b81c9538ba..0c680df38f 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/Symbol3Test.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/Symbol3Test.java @@ -23,18 +23,18 @@ public void scriptRuntimeTypeofSymbolKey() { + " return '' + sym.length + ' ' + typeof sym[0];" + "}" + "foo()"; - Utils.assertWithAllOptimizationLevelsES6("1 symbol", code); + Utils.assertWithAllModes_ES6("1 symbol", code); } @Test public void scriptRuntimeTypeofSymbol() { final String code = "typeof Symbol.toStringTag"; - Utils.assertWithAllOptimizationLevelsES6("symbol", code); + Utils.assertWithAllModes_ES6("symbol", code); } @Test public void symbolProperty() throws Exception { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/TypedArrayJavaTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/TypedArrayJavaTest.java index c104c54416..d9d8ecaed8 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/TypedArrayJavaTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/TypedArrayJavaTest.java @@ -112,7 +112,7 @@ private static void allTypes(String script, String expected) throws Exception { "Uint8ClampedArray" }; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); ScriptableObject scope = cx.initStandardObjects(); diff --git a/tests/src/test/java/org/mozilla/javascript/tests/intl402/NativeStringTest.java b/tests/src/test/java/org/mozilla/javascript/tests/intl402/NativeStringTest.java index 1582ad6819..37567b1af6 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/intl402/NativeStringTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/intl402/NativeStringTest.java @@ -33,7 +33,7 @@ protected boolean hasFeature(Context cx, int featureIndex) { public void toLocaleLowerCase() { String js = "'\\u0130'.toLocaleLowerCase()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( contextFactoryIntl402, cx -> { final Scriptable scope = cx.initStandardObjects(); @@ -45,7 +45,7 @@ public void toLocaleLowerCase() { return null; }); - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( contextFactoryIntl402, cx -> { final Scriptable scope = cx.initStandardObjects(); @@ -70,7 +70,7 @@ public void toLocaleLowerCaseParam() { public void toLocaleUpperCase() { String js = "'\\u0069'.toLocaleUpperCase()"; - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( contextFactoryIntl402, cx -> { final Scriptable scope = cx.initStandardObjects(); @@ -82,7 +82,7 @@ public void toLocaleUpperCase() { return null; }); - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( contextFactoryIntl402, cx -> { final Scriptable scope = cx.initStandardObjects(); @@ -104,7 +104,7 @@ public void toLocaleUpperCaseParam() { } private void assertEvaluatesES6(final Object expected, final String source) { - Utils.runWithAllOptimizationLevels( + Utils.runWithAllModes( contextFactoryIntl402, cx -> { final Scriptable scope = cx.initStandardObjects(); diff --git a/testutils/src/main/java/org/mozilla/javascript/tests/Utils.java b/testutils/src/main/java/org/mozilla/javascript/tests/Utils.java index e3be1c6f8f..4baeaa53ba 100644 --- a/testutils/src/main/java/org/mozilla/javascript/tests/Utils.java +++ b/testutils/src/main/java/org/mozilla/javascript/tests/Utils.java @@ -39,43 +39,24 @@ static void executeScript(String script, boolean interpreted) { interpreted); } - /** Runs the action successively with all available optimization levels */ - public static void runWithAllOptimizationLevels(final ContextAction action) { + /** Runs the action successively with interpreted and optimized mode */ + public static void runWithAllModes(final ContextAction action) { runWithMode(action, false); runWithMode(action, true); } - /** Runs the action successively with all available optimization levels */ - public static void runWithAllOptimizationLevels( + /** Runs the action successively with interpreted and optimized mode */ + public static void runWithAllModes( final ContextFactory contextFactory, final ContextAction action) { runWithMode(contextFactory, action, false); runWithMode(contextFactory, action, true); } - /** Runs the provided action at the given optimization level */ - public static void runWithOptimizationLevel( - final ContextAction action, final int optimizationLevel) { - runWithOptimizationLevel(new ContextFactory(), action, optimizationLevel); - } - /** Runs the provided action at the given interpretation mode */ public static void runWithMode(final ContextAction action, final boolean interpretedMode) { runWithMode(new ContextFactory(), action, interpretedMode); } - /** Runs the provided action at the given optimization level */ - @SuppressWarnings("deprecation") - public static void runWithOptimizationLevel( - final ContextFactory contextFactory, - final ContextAction action, - final int optimizationLevel) { - - try (final Context cx = contextFactory.enterContext()) { - cx.setOptimizationLevel(optimizationLevel); - action.run(cx); - } - } - /** Runs the provided action at the given interpretation mode */ public static void runWithMode( final ContextFactory contextFactory, @@ -112,8 +93,30 @@ public static boolean isJavaVersionAtLeast(int desiredVersion) { * @param expected the expected result * @param script the javascript script to execute */ - public static void assertWithAllOptimizationLevels(final Object expected, final String script) { - assertWithAllOptimizationLevels(-1, expected, script); + public static void assertWithAllModes(final Object expected, final String script) { + assertWithAllModes(-1, null, expected, script); + } + + /** + * Execute the provided script and assert the result. Before the execution the language version + * is set to {@link Context#VERSION_1_4}. + * + * @param expected the expected result + * @param script the javascript script to execute + */ + public static void assertWithAllModes_1_4(final Object expected, final String script) { + assertWithAllModes(Context.VERSION_1_4, null, expected, script); + } + + /** + * Execute the provided script and assert the result. Before the execution the language version + * is set to {@link Context#VERSION_1_5}. + * + * @param expected the expected result + * @param script the javascript script to execute + */ + public static void assertWithAllModes_1_5(final Object expected, final String script) { + assertWithAllModes(Context.VERSION_1_5, null, expected, script); } /** @@ -123,9 +126,8 @@ public static void assertWithAllOptimizationLevels(final Object expected, final * @param expected the expected result * @param script the javascript script to execute */ - public static void assertWithAllOptimizationLevels_1_8( - final Object expected, final String script) { - assertWithAllOptimizationLevels(Context.VERSION_1_8, expected, script); + public static void assertWithAllModes_1_8(final Object expected, final String script) { + assertWithAllModes(Context.VERSION_1_8, null, expected, script); } /** @@ -135,9 +137,21 @@ public static void assertWithAllOptimizationLevels_1_8( * @param expected the expected result * @param script the javascript script to execute */ - public static void assertWithAllOptimizationLevelsES6( - final Object expected, final String script) { - assertWithAllOptimizationLevels(Context.VERSION_ES6, expected, script); + public static void assertWithAllModes_ES6(final Object expected, final String script) { + assertWithAllModes(Context.VERSION_ES6, null, expected, script); + } + + /** + * Execute the provided script and assert the result. Before the execution the language version + * is set to {@link Context#VERSION_ES6}. + * + * @param message the message to be used if this fails + * @param expected the expected result + * @param script the javascript script to execute + */ + public static void assertWithAllModes_ES6( + final String message, final Object expected, final String script) { + assertWithAllModes(Context.VERSION_ES6, message, expected, script); } /** @@ -145,12 +159,16 @@ public static void assertWithAllOptimizationLevelsES6( * * @param languageVersion the language version constant from @{@link Context} or -1 to not * change the language version at all + * @param message the message to be used if this fails * @param expected the expected result * @param script the javascript script to execute */ - public static void assertWithAllOptimizationLevels( - final int languageVersion, final Object expected, final String script) { - runWithAllOptimizationLevels( + public static void assertWithAllModes( + final int languageVersion, + final String message, + final Object expected, + final String script) { + runWithAllModes( cx -> { if (languageVersion > -1) { cx.setLanguageVersion(languageVersion); @@ -160,6 +178,7 @@ public static void assertWithAllOptimizationLevels( if (expected instanceof Integer && res instanceof Double) { assertEquals( + message, ((Integer) expected).doubleValue(), ((Double) res).doubleValue(), 0.00001); @@ -167,20 +186,21 @@ public static void assertWithAllOptimizationLevels( } if (expected instanceof Double && res instanceof Integer) { assertEquals( + message, ((Double) expected).doubleValue(), ((Integer) res).doubleValue(), 0.00001); return null; } - assertEquals(expected, res); + assertEquals(message, expected, res); return null; }); } - public static void assertWithAllOptimizationLevelsTopLevelScopeES6( + public static void assertWithAllModesTopLevelScope_ES6( final Object expected, final String script) { - runWithAllOptimizationLevels( + runWithAllModes( cx -> { cx.setLanguageVersion(Context.VERSION_ES6); Scriptable scope = cx.initStandardObjects(new TopLevel()); @@ -257,7 +277,13 @@ private static void assertException( final Class expectedThrowable, final String expectedMessage, String js) { - Utils.runWithAllOptimizationLevels( + + // to avoid false positives because we use startsWith() + assertTrue( + "expectedMessage can't be empty", + expectedMessage != null && !expectedMessage.isEmpty()); + + Utils.runWithAllModes( cx -> { if (languageVersion > -1) { cx.setLanguageVersion(languageVersion);