diff --git a/rhino/src/test/java/org/mozilla/javascript/SuperTest.java b/rhino/src/test/java/org/mozilla/javascript/SuperTest.java index 6dd22df461..ea3d8e0f69 100644 --- a/rhino/src/test/java/org/mozilla/javascript/SuperTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/SuperTest.java @@ -115,6 +115,36 @@ void byIndex() { Utils.assertWithAllOptimizationLevelsES6(1, script); } + @Test + void byIndexNegative() { + String script = + "" + + "var a = { [-1]: 1 };" + + "var b = {\n" + + " f() {\n" + + " return super[-1];\n" + + " }\n" + + "};\n" + + "Object.setPrototypeOf(b, a);\n" + + "b.f();"; + Utils.assertWithAllOptimizationLevelsES6(1, script); + } + + @Test + void byIndexFractional() { + String script = + "" + + "var a = { [0.1]: 1 };" + + "var b = {\n" + + " f() {\n" + + " return super[0.1];\n" + + " }\n" + + "};\n" + + "Object.setPrototypeOf(b, a);\n" + + "b.f();"; + Utils.assertWithAllOptimizationLevelsES6(1, script); + } + @Test void byElementString() { String script = @@ -399,6 +429,35 @@ void propertyNotFoundInSuper() { Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, script); } + @Test + void propertyNotFoundInSuperByElement() { + // super is implicitly Object.prototype here + String script = + "" + + "const xAsString = 'x';\n" + + "const o = {\n" + + " f() {\n" + + " return super[xAsString];\n" + + " }" + + "};\n" + + "o.f();"; + Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, script); + } + + @Test + void propertyNotFoundInSuperByIndex() { + // super is implicitly Object.prototype here + String script = + "" + + "const o = {\n" + + " f() {\n" + + " return super[2];\n" + + " }" + + "};\n" + + "o.f();"; + Utils.assertWithAllOptimizationLevelsES6(Undefined.instance, script); + } + @Test void prototypeIsNull() { String script = @@ -463,6 +522,36 @@ void byIndex() { Utils.assertWithAllOptimizationLevelsES6("new:proto", script); } + @Test + void byIndexNegative() { + String script = + "" + + "var proto = { [-1]: 'proto' };" + + "var object = {\n" + + " [-1]: 'obj',\n" + + " f() { super[-1] = 'new'; }\n" + + "};\n" + + "Object.setPrototypeOf(object, proto);\n" + + "object.f();" + + "object[-1] + ':' + proto[-1]"; + Utils.assertWithAllOptimizationLevelsES6("new:proto", script); + } + + @Test + void byIndexFractional() { + String script = + "" + + "var proto = { [0.1]: 'proto' };" + + "var object = {\n" + + " [0.1]: 'obj',\n" + + " f() { super[0.1] = 'new'; }\n" + + "};\n" + + "Object.setPrototypeOf(object, proto);\n" + + "object.f();" + + "object[0.1] + ':' + proto[0.1]"; + Utils.assertWithAllOptimizationLevelsES6("new:proto", script); + } + @Test void byElementString() { String script =