diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/PrivateName/illegal-delete.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.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/non262/PrivateName/illegal-delete.js')
-rw-r--r-- | js/src/tests/non262/PrivateName/illegal-delete.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/js/src/tests/non262/PrivateName/illegal-delete.js b/js/src/tests/non262/PrivateName/illegal-delete.js new file mode 100644 index 0000000000..464b7dd685 --- /dev/null +++ b/js/src/tests/non262/PrivateName/illegal-delete.js @@ -0,0 +1,94 @@ +// |reftest| skip-if(!xulRuntime.shell) -- needs newGlobal() + +class A { + #x = {a: 1}; + b = null; + es(s) { + eval(s); + } +} + +var a = new A; +a.b = new A; + +assertThrowsInstanceOf(() => a.es('delete this.#x'), SyntaxError); +assertThrowsInstanceOf(() => a.es('delete (this.#x)'), SyntaxError); +assertThrowsInstanceOf(() => a.es('delete this?.#x'), SyntaxError); +assertThrowsInstanceOf(() => a.es('delete this?.b.#x'), SyntaxError); +// Should be OK +a.es('delete (0, this.#x.a)') +a.es('delete this?.b.#x.a') + + +// Make sure the above works in a different context, with emphasis on +// lazy/syntax parsing. +function eval_and_report(str) { + var classTest = ` + class B { + #x = {a: 1}; + b = null; + test() { + ${str}; + } + } + var b = new B; + b.b = new B; + b.test(); + `; + + var str = ` + function f(run) { + if (run) { + ${classTest} + } + } + f(run)`; + + + var throws = []; + // Evalutate in a new global; has the advantage that it makes successes + // idempotent. + var g = newGlobal(); + g.run = false; + + try { + // The idea is that this is a full parse + evaluate(classTest, {global: g}); + } catch (e) { + throws.push(e); + } + + try { + // The idea is this is a lazy parse; however, fields currently + // disable lazy parsing, so right now + evaluate(str, {global: g}); + } catch (e) { + throws.push(e); + } + + return throws; +} + +function assertSyntaxError(str) { + var exceptions = eval_and_report(str); + assertEq(exceptions.length, 2); + for (var e of exceptions) { + assertEq(/SyntaxError/.test(e.name), true); + } +} + +function assertNoSyntaxError(str) { + var exceptions = eval_and_report(str); + assertEq(exceptions.length, 0); +} + +assertSyntaxError('delete this.#x'); +assertSyntaxError('delete (this.#x)'); +assertSyntaxError('delete this?.#x'); +assertSyntaxError('delete this?.b.#x'); +// Should be OK +assertNoSyntaxError('delete (0, this.#x.a)') +assertNoSyntaxError('delete this?.b.#x.a') + + +if (typeof reportCompare === 'function') reportCompare(0, 0); |