Skip to content

Commit

Permalink
Improved code coverage for super tests
Browse files Browse the repository at this point in the history
Co-authored-by: Satish Srinivasan <[email protected]>
  • Loading branch information
andreabergia and 0xe committed Dec 9, 2024
1 parent 55352ac commit 2d7d455
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions rhino/src/test/java/org/mozilla/javascript/SuperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 2d7d455

Please sign in to comment.