summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/class/superElemDelete.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/non262/class/superElemDelete.js')
-rw-r--r--js/src/tests/non262/class/superElemDelete.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/js/src/tests/non262/class/superElemDelete.js b/js/src/tests/non262/class/superElemDelete.js
new file mode 100644
index 0000000000..6132cbafc2
--- /dev/null
+++ b/js/src/tests/non262/class/superElemDelete.js
@@ -0,0 +1,68 @@
+// Make sure we get the proper side effects.
+// |delete super[expr]| applies ToPropertyKey on |expr| before throwing.
+
+class base {
+ constructor() { }
+}
+
+class derived extends base {
+ constructor() { super(); }
+ testDeleteElem() {
+ let sideEffect = 0;
+ let key = {
+ toString() {
+ sideEffect++;
+ return "";
+ }
+ };
+ assertThrowsInstanceOf(() => delete super[key], ReferenceError);
+ assertEq(sideEffect, 1);
+ }
+ testDeleteElemPropValFirst() {
+ // The deletion error is a reference error, but by munging the prototype
+ // chain, we can force a type error from JSOP_SUPERBASE.
+ let key = {
+ toString() {
+ Object.setPrototypeOf(derived.prototype, null);
+ return "";
+ }
+ };
+ delete super[key];
+ }
+}
+
+class derivedTestDeleteElem extends base {
+ constructor() {
+ let sideEffect = 0;
+ let key = {
+ toString() {
+ sideEffect++;
+ return "";
+ }
+ };
+
+ assertThrowsInstanceOf(() => delete super[key], ReferenceError);
+ assertEq(sideEffect, 0);
+
+ super();
+
+ assertThrowsInstanceOf(() => delete super[key], ReferenceError);
+ assertEq(sideEffect, 1);
+
+ Object.setPrototypeOf(derivedTestDeleteElem.prototype, null);
+
+ assertThrowsInstanceOf(() => delete super[key], TypeError);
+ assertEq(sideEffect, 2);
+
+ return {};
+ }
+}
+
+var d = new derived();
+d.testDeleteElem();
+assertThrowsInstanceOf(() => d.testDeleteElemPropValFirst(), TypeError);
+
+new derivedTestDeleteElem();
+
+if (typeof reportCompare === 'function')
+ reportCompare(0,0,"OK");