toolkit/devtools/server/tests/unit/test_stepping-06.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/server/tests/unit/test_stepping-06.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Check that stepping out of a function returns the right return value.
     1.9 + */
    1.10 +
    1.11 +var gDebuggee;
    1.12 +var gClient;
    1.13 +var gThreadClient;
    1.14 +
    1.15 +function run_test()
    1.16 +{
    1.17 +  initTestDebuggerServer();
    1.18 +  gDebuggee = addTestGlobal("test-stack");
    1.19 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.20 +  gClient.connect(function () {
    1.21 +    attachTestTabAndResume(gClient, "test-stack", function (aResponse, aTabClient, aThreadClient) {
    1.22 +      gThreadClient = aThreadClient;
    1.23 +      // XXX: We have to do an executeSoon so that the error isn't caught and
    1.24 +      // reported by DebuggerClient.requester (because we are using the local
    1.25 +      // transport and share a stack) which causes the test to fail.
    1.26 +      Services.tm.mainThread.dispatch({
    1.27 +        run: test_simple_stepping
    1.28 +      }, Ci.nsIThread.DISPATCH_NORMAL);
    1.29 +    });
    1.30 +  });
    1.31 +  do_test_pending();
    1.32 +}
    1.33 +
    1.34 +function test_simple_stepping()
    1.35 +{
    1.36 +  gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.37 +    gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.38 +      // Check that the return value is 10.
    1.39 +      do_check_eq(aPacket.type, "paused");
    1.40 +      do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 4);
    1.41 +      do_check_eq(aPacket.why.type, "resumeLimit");
    1.42 +      do_check_eq(aPacket.why.frameFinished.return, 10);
    1.43 +
    1.44 +      gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.45 +        gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.46 +          // Check that the return value is undefined.
    1.47 +          do_check_eq(aPacket.type, "paused");
    1.48 +          do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 7);
    1.49 +          do_check_eq(aPacket.why.type, "resumeLimit");
    1.50 +          do_check_eq(aPacket.why.frameFinished.return.type, "undefined");
    1.51 +
    1.52 +          gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.53 +            gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.54 +              // Check that the exception was thrown.
    1.55 +              do_check_eq(aPacket.type, "paused");
    1.56 +              do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 12);
    1.57 +              do_check_eq(aPacket.why.type, "resumeLimit");
    1.58 +              do_check_eq(aPacket.why.frameFinished.throw, "ah");
    1.59 +
    1.60 +              gThreadClient.resume(function () {
    1.61 +                finishClient(gClient);
    1.62 +              });
    1.63 +            });
    1.64 +            gThreadClient.stepOut();
    1.65 +          });
    1.66 +          gThreadClient.resume();
    1.67 +        });
    1.68 +        gThreadClient.stepOut();
    1.69 +      });
    1.70 +      gThreadClient.resume();
    1.71 +    });
    1.72 +    gThreadClient.stepOut();
    1.73 +
    1.74 +  });
    1.75 +
    1.76 +  gDebuggee.eval("var line0 = Error().lineNumber;\n" +
    1.77 +                 "function f() {\n" +                   // line0 + 1
    1.78 +                 "  debugger;\n" +                      // line0 + 2
    1.79 +                 "  var a = 10;\n" +                    // line0 + 3
    1.80 +                 "  return a;\n" +                      // line0 + 4
    1.81 +                 "}\n" +                                // line0 + 5
    1.82 +                 "function g() {\n" +                   // line0 + 6
    1.83 +                 "  debugger;\n" +                      // line0 + 7
    1.84 +                 "}\n" +                                // line0 + 8
    1.85 +                 "function h() {\n" +                   // line0 + 9
    1.86 +                 "  debugger;\n" +                      // line0 + 10
    1.87 +                 "  throw 'ah';\n" +                    // line0 + 11
    1.88 +                 "  return 2;\n" +                      // line0 + 12
    1.89 +                 "}\n" +                                // line0 + 13
    1.90 +                 "f();\n" +                             // line0 + 14
    1.91 +                 "g();\n" +                             // line0 + 15
    1.92 +                 "try { h() } catch (ex) { };\n");      // line0 + 16
    1.93 +}

mercurial