Debugger tests: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 34: Line 34:


* Throwing from any other debugger callbacks, including <code>onDebuggerStatement</code>, will terminate the debuggee with an uncatchable error. So it is OK to call <code>assertEq</code> from <code>onDebuggerStatement</code>. Both jit_test.py and jstests.py will treat that as a test failure.
* Throwing from any other debugger callbacks, including <code>onDebuggerStatement</code>, will terminate the debuggee with an uncatchable error. So it is OK to call <code>assertEq</code> from <code>onDebuggerStatement</code>. Both jit_test.py and jstests.py will treat that as a test failure.
Any non-trivial Debugger test has to run code in the debuggee. We do that using its <code>eval</code> function:


  g.eval("debugger;");
  g.eval("debugger;");
If you understand cross-compartment wrappers, you can see how this works. <code>g</code> is a wrapper for a global object in another compartment, so <code>g.eval</code> is a wrapper for that global’s <code>eval</code> function. When we call <code>g.eval</code>, this happens:
* we enter <code>g</code>’s compartment, rewrapping the argument(s);
* we call <code>eval</code> in that compartment;
* we return to the caller’s compartment, rewrapping the return value or exception.
So this line of code should execute a debugger statement in <code>g</code>’s compartment, which should fire the <code>onDebuggerStatement</code> event and execute our callback code. The call to <code>evalInFrame</code> should return the [[Debugger#Completion_values|completion value]] <code>{return: 4}</code>.
Lastly, we check the result:
  assertEq(c.return, 4);
  assertEq(c.return, 4);
When jsdbg2 lands, the existing debugger tests will go under <code>js/src/jit-test/tests/debug</code>.
638

edits