summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/class/definition/this-access-restriction-2.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/language/statements/class/definition/this-access-restriction-2.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/language/statements/class/definition/this-access-restriction-2.js')
-rw-r--r--js/src/tests/test262/language/statements/class/definition/this-access-restriction-2.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/class/definition/this-access-restriction-2.js b/js/src/tests/test262/language/statements/class/definition/this-access-restriction-2.js
new file mode 100644
index 0000000000..e1f855aa1c
--- /dev/null
+++ b/js/src/tests/test262/language/statements/class/definition/this-access-restriction-2.js
@@ -0,0 +1,90 @@
+// Copyright (C) 2014 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 14.5
+description: >
+ class this access restriction 2
+---*/
+class Base {
+ constructor(a, b) {
+ var o = new Object();
+ o.prp = a + b;
+ return o;
+ }
+}
+
+class Subclass extends Base {
+ constructor(a, b) {
+ var exn;
+ try {
+ this.prp1 = 3;
+ } catch (e) {
+ exn = e;
+ }
+ assert.sameValue(
+ exn instanceof ReferenceError,
+ true,
+ "The result of `exn instanceof ReferenceError` is `true`"
+ );
+ super(a, b);
+ assert.sameValue(this.prp, a + b, "The value of `this.prp` is `a + b`");
+ assert.sameValue(this.prp1, undefined, "The value of `this.prp1` is `undefined`");
+ assert.sameValue(
+ this.hasOwnProperty("prp1"),
+ false,
+ "`this.hasOwnProperty(\"prp1\")` returns `false`"
+ );
+ return this;
+ }
+}
+
+var b = new Base(1, 2);
+assert.sameValue(b.prp, 3, "The value of `b.prp` is `3`");
+
+
+var s = new Subclass(2, -1);
+assert.sameValue(s.prp, 1, "The value of `s.prp` is `1`");
+assert.sameValue(s.prp1, undefined, "The value of `s.prp1` is `undefined`");
+assert.sameValue(
+ s.hasOwnProperty("prp1"),
+ false,
+ "`s.hasOwnProperty(\"prp1\")` returns `false`"
+);
+
+class Subclass2 extends Base {
+ constructor(x) {
+ super(1,2);
+
+ if (x < 0) return;
+
+ var called = false;
+ function tmp() { called = true; return 3; }
+ var exn = null;
+ try {
+ super(tmp(),4);
+ } catch (e) { exn = e; }
+ assert.sameValue(
+ exn instanceof ReferenceError,
+ true,
+ "The result of `exn instanceof ReferenceError` is `true`"
+ );
+ assert.sameValue(called, true, "The value of `called` is `true`");
+ }
+}
+
+var s2 = new Subclass2(1);
+assert.sameValue(s2.prp, 3, "The value of `s2.prp` is `3`");
+
+var s3 = new Subclass2(-1);
+assert.sameValue(s3.prp, 3, "The value of `s3.prp` is `3`");
+
+assert.throws(TypeError, function() { Subclass.call(new Object(), 1, 2); });
+assert.throws(TypeError, function() { Base.call(new Object(), 1, 2); });
+
+class BadSubclass extends Base {
+ constructor() {}
+}
+
+assert.throws(ReferenceError, function() { new BadSubclass(); });
+
+reportCompare(0, 0);