js/src/jit-test/tests/debug/Script-isInCatchScope.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // Test if isInCatchScope properly detects catch blocks.
michael@0 2
michael@0 3 let g = newGlobal();
michael@0 4 let dbg = new Debugger(g);
michael@0 5
michael@0 6 function test(string, mustBeCaught) {
michael@0 7 let index = 0;
michael@0 8 dbg.onExceptionUnwind = function (frame) {
michael@0 9 let willBeCaught = false;
michael@0 10 do {
michael@0 11 if (frame.script.isInCatchScope(frame.offset)) {
michael@0 12 willBeCaught = true;
michael@0 13 break;
michael@0 14 }
michael@0 15 frame = frame.older;
michael@0 16 } while (frame != null);
michael@0 17 assertEq(willBeCaught, mustBeCaught[index++]);
michael@0 18 };
michael@0 19
michael@0 20 try {
michael@0 21 g.eval(string);
michael@0 22 } catch (ex) {}
michael@0 23 assertEq(index, mustBeCaught.length);
michael@0 24 }
michael@0 25
michael@0 26 // Should correctly detect catch blocks
michael@0 27 test("throw new Error();", [false]);
michael@0 28 test("try { throw new Error(); } catch (e) {}", [true]);
michael@0 29 test("try { throw new Error(); } finally {}", [false, false]);
michael@0 30 test("try { throw new Error(); } catch (e) {} finally {}", [true]);
michael@0 31
michael@0 32 // Source of the exception shouldn't matter
michael@0 33 test("(null)();", [false]);
michael@0 34 test("try { (null)(); } catch (e) {}", [true]);
michael@0 35 test("try { (null)(); } finally {}", [false, false]);
michael@0 36 test("try { (null)(); } catch (e) {} finally {}", [true]);
michael@0 37
michael@0 38 // Should correctly detect catch blocks in functions
michael@0 39 test("function f() { throw new Error(); } f();", [false, false]);
michael@0 40 test("function f() { try { throw new Error(); } catch (e) {} } f();", [true]);
michael@0 41 test("function f() { try { throw new Error(); } finally {} } f();", [false, false, false]);
michael@0 42 test("function f() { try { throw new Error(); } catch (e) {} finally {} } f();", [true]);
michael@0 43
michael@0 44 // Should correctly detect catch blocks in evals
michael@0 45 test("eval('throw new Error();')", [false, false]);
michael@0 46 test("eval('try { throw new Error(); } catch (e) {}');", [true]);
michael@0 47 test("eval('try { throw new Error(); } finally {}');", [false, false, false]);
michael@0 48 test("eval('try { throw new Error(); } catch (e) {} finally {}');", [true]);
michael@0 49
michael@0 50 // Should correctly detect rethrows
michael@0 51 test("try { throw new Error(); } catch (e) { throw e; }", [true, false]);
michael@0 52 test("try { try { throw new Error(); } catch (e) { throw e; } } catch (e) {}", [true, true]);
michael@0 53 test("try { try { throw new Error(); } finally {} } catch (e) {}", [true, true]);
michael@0 54 test("function f() { try { throw new Error(); } catch (e) { throw e; } } f();", [true, false, false]);
michael@0 55 test("function f() { try { try { throw new Error(); } catch (e) { throw e; } } catch (e) {} } f();", [true, true]);
michael@0 56 test("function f() { try { try { throw new Error(); } finally {} } catch (e) {} } f();", [true, true]);
michael@0 57 test("eval('try { throw new Error(); } catch (e) { throw e; }')", [true, false, false]);
michael@0 58 test("eval('try { try { throw new Error(); } catch (e) { throw e; } } catch (e) {}')", [true, true]);
michael@0 59
michael@0 60 // Should correctly detect catch blocks across frame boundaries
michael@0 61 test("function f() { throw new Error(); } try { f(); } catch (e) {}", [true, true]);
michael@0 62 test("function f() { throw new Error(); } try { f(); } catch (e) { throw e; }", [true, true, false]);
michael@0 63 test("try { eval('throw new Error()'); } catch (e) {}", [true, true]);
michael@0 64 test("try { eval('throw new Error()'); } catch (e) { throw e; }", [true, true, false]);
michael@0 65
michael@0 66 // Should correctly detect catch blocks just before and just after throws
michael@0 67 test("throw new Error; try {} catch (e) {}", [false]);
michael@0 68 test("try {} catch (e) {} throw new Error();", [false]);

mercurial