diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/jit-test/tests/debug/Script-isInCatchScope.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/tests/debug/Script-isInCatchScope.js')
-rw-r--r-- | js/src/jit-test/tests/debug/Script-isInCatchScope.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/Script-isInCatchScope.js b/js/src/jit-test/tests/debug/Script-isInCatchScope.js new file mode 100644 index 000000000..0aabc5da4 --- /dev/null +++ b/js/src/jit-test/tests/debug/Script-isInCatchScope.js @@ -0,0 +1,68 @@ +// Test if isInCatchScope properly detects catch blocks. + +let g = newGlobal(); +let dbg = new Debugger(g); + +function test(string, mustBeCaught) { + let index = 0; + dbg.onExceptionUnwind = function (frame) { + let willBeCaught = false; + do { + if (frame.script.isInCatchScope(frame.offset)) { + willBeCaught = true; + break; + } + frame = frame.older; + } while (frame != null); + assertEq(willBeCaught, mustBeCaught[index++]); + }; + + try { + g.eval(string); + } catch (ex) {} + assertEq(index, mustBeCaught.length); +} + +// Should correctly detect catch blocks +test("throw new Error();", [false]); +test("try { throw new Error(); } catch (e) {}", [true]); +test("try { throw new Error(); } finally {}", [false, false]); +test("try { throw new Error(); } catch (e) {} finally {}", [true]); + +// Source of the exception shouldn't matter +test("(null)();", [false]); +test("try { (null)(); } catch (e) {}", [true]); +test("try { (null)(); } finally {}", [false, false]); +test("try { (null)(); } catch (e) {} finally {}", [true]); + +// Should correctly detect catch blocks in functions +test("function f() { throw new Error(); } f();", [false, false]); +test("function f() { try { throw new Error(); } catch (e) {} } f();", [true]); +test("function f() { try { throw new Error(); } finally {} } f();", [false, false, false]); +test("function f() { try { throw new Error(); } catch (e) {} finally {} } f();", [true]); + +// Should correctly detect catch blocks in evals +test("eval('throw new Error();')", [false, false]); +test("eval('try { throw new Error(); } catch (e) {}');", [true]); +test("eval('try { throw new Error(); } finally {}');", [false, false, false]); +test("eval('try { throw new Error(); } catch (e) {} finally {}');", [true]); + +// Should correctly detect rethrows +test("try { throw new Error(); } catch (e) { throw e; }", [true, false]); +test("try { try { throw new Error(); } catch (e) { throw e; } } catch (e) {}", [true, true]); +test("try { try { throw new Error(); } finally {} } catch (e) {}", [true, true]); +test("function f() { try { throw new Error(); } catch (e) { throw e; } } f();", [true, false, false]); +test("function f() { try { try { throw new Error(); } catch (e) { throw e; } } catch (e) {} } f();", [true, true]); +test("function f() { try { try { throw new Error(); } finally {} } catch (e) {} } f();", [true, true]); +test("eval('try { throw new Error(); } catch (e) { throw e; }')", [true, false, false]); +test("eval('try { try { throw new Error(); } catch (e) { throw e; } } catch (e) {}')", [true, true]); + +// Should correctly detect catch blocks across frame boundaries +test("function f() { throw new Error(); } try { f(); } catch (e) {}", [true, true]); +test("function f() { throw new Error(); } try { f(); } catch (e) { throw e; }", [true, true, false]); +test("try { eval('throw new Error()'); } catch (e) {}", [true, true]); +test("try { eval('throw new Error()'); } catch (e) { throw e; }", [true, true, false]); + +// Should correctly detect catch blocks just before and just after throws +test("throw new Error; try {} catch (e) {}", [false]); +test("try {} catch (e) {} throw new Error();", [false]); |