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/ShadowRealms/error.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/ShadowRealms/error.js')
-rw-r--r-- | js/src/tests/non262/ShadowRealms/error.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/js/src/tests/non262/ShadowRealms/error.js b/js/src/tests/non262/ShadowRealms/error.js new file mode 100644 index 0000000000..0d0a559b28 --- /dev/null +++ b/js/src/tests/non262/ShadowRealms/error.js @@ -0,0 +1,102 @@ +// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) + +let sr = new ShadowRealm(); + +try { + sr.evaluate("throw new Error('hi')"); + assertEq(true, false, "Should have thrown"); +} catch (e) { + assertEq(e instanceof TypeError, true, "Correct type of error") + assertEq(/Error: hi/.test(e.message), true, "Should have included information from thrown error"); +} + +try { + sr.evaluate("throw new Error('∂å∂')"); + assertEq(true, false, "Should have thrown"); +} catch (e) { + assertEq(e instanceof TypeError, true, "Correct type of error") + assertEq(/Error: ∂å∂/.test(e.message), true, "Should have included information from thrown error, UTF-8 Pass through."); +} + +try { + sr.evaluate("throw {name: 'Hello', message: 'goodbye'}"); + assertEq(true, false, "Should have thrown"); +} catch (e) { + assertEq(e instanceof TypeError, true, "Correct type of error") + assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic fillin message, non-string"); +} + +try { + sr.evaluate("throw {name: 10, message: 11}"); + assertEq(true, false, "Should have thrown"); +} catch (e) { + assertEq(e instanceof TypeError, true, "Correct type of error") + assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic fillin message, non-string"); +} + + +try { + sr.evaluate("throw { get name() { return 'holy'; }, get message() { return 'smokes' } }"); + assertEq(true, false, "Should have thrown"); +} catch (e) { + assertEq(e instanceof TypeError, true, "Correct type of error") + assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message, getters"); +} + +// Wrapped Functions +try { + var wrapped = sr.evaluate("() => { throw new Error('hi') }"); + assertEq(!!wrapped, true, "Wrapped created"); + wrapped(); + assertEq(true, false, "Should have thrown"); +} catch (e) { + assertEq(e instanceof TypeError, true, "Correct type of error") + assertEq(/Error: hi/.test(e.message), true, "Should have included information from thrown error"); +} + +try { + var wrapped = sr.evaluate("() => { throw new Error('∂å∂') } "); + assertEq(!!wrapped, true, "Wrapped created"); + wrapped(); + assertEq(true, false, "Should have thrown"); +} catch (e) { + assertEq(e instanceof TypeError, true, "Correct type of error") + assertEq(/Error: ∂å∂/.test(e.message), true, "Should have included information from thrown error, UTF-8 Pass through."); +} + +try { + var wrapped = sr.evaluate("() => { throw {name: 'Hello', message: 'goodbye'} } "); + assertEq(!!wrapped, true, "Wrapped created"); + wrapped(); + assertEq(true, false, "Should have thrown"); +} catch (e) { + assertEq(e instanceof TypeError, true, "Correct type of error") + assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message"); +} + +try { + var wrapped = sr.evaluate("() => { throw {name: 10, message: 11} } "); + assertEq(!!wrapped, true, "Wrapped created"); + wrapped(); + assertEq(true, false, "Should have thrown"); +} catch (e) { + assertEq(e instanceof TypeError, true, "Correct type of error") + print(e.message) + assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message"); +} + + +try { + var wrapped = sr.evaluate("() => { throw { get name() { return 'holy'; }, get message() { return 'smokes' } } } "); + assertEq(!!wrapped, true, "Wrapped created"); + wrapped(); + assertEq(true, false, "Should have thrown"); +} catch (e) { + assertEq(e instanceof TypeError, true, "Correct type of error") + assertEq(/uncaught exception: Object/.test(e.message), true, "Should get generic error message"); +} + + + +if (typeof reportCompare === 'function') + reportCompare(true, true);
\ No newline at end of file |