1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_functiongrips-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +var gDebuggee; 1.8 +var gClient; 1.9 +var gThreadClient; 1.10 + 1.11 +function run_test() 1.12 +{ 1.13 + initTestDebuggerServer(); 1.14 + gDebuggee = addTestGlobal("test-grips"); 1.15 + gDebuggee.eval(function stopMe(arg1) { 1.16 + debugger; 1.17 + }.toString()); 1.18 + 1.19 + gClient = new DebuggerClient(DebuggerServer.connectPipe()); 1.20 + gClient.connect(function() { 1.21 + attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) { 1.22 + gThreadClient = aThreadClient; 1.23 + test_named_function(); 1.24 + }); 1.25 + }); 1.26 + do_test_pending(); 1.27 +} 1.28 + 1.29 +function test_named_function() 1.30 +{ 1.31 + gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) { 1.32 + let args = aPacket.frame.arguments; 1.33 + 1.34 + do_check_eq(args[0].class, "Function"); 1.35 + do_check_eq(args[0].name, "stopMe"); 1.36 + do_check_eq(args[0].displayName, "stopMe"); 1.37 + 1.38 + let objClient = gThreadClient.pauseGrip(args[0]); 1.39 + objClient.getParameterNames(function(aResponse) { 1.40 + do_check_eq(aResponse.parameterNames.length, 1); 1.41 + do_check_eq(aResponse.parameterNames[0], "arg1"); 1.42 + 1.43 + gThreadClient.resume(test_inferred_name_function); 1.44 + }); 1.45 + 1.46 + }); 1.47 + 1.48 + gDebuggee.eval("stopMe(stopMe)"); 1.49 +} 1.50 + 1.51 +function test_inferred_name_function() { 1.52 + gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) { 1.53 + let args = aPacket.frame.arguments; 1.54 + 1.55 + do_check_eq(args[0].class, "Function"); 1.56 + // No name for an anonymous function, but it should have an inferred name. 1.57 + do_check_eq(args[0].name, undefined); 1.58 + do_check_eq(args[0].displayName, "o.m"); 1.59 + 1.60 + let objClient = gThreadClient.pauseGrip(args[0]); 1.61 + objClient.getParameterNames(function(aResponse) { 1.62 + do_check_eq(aResponse.parameterNames.length, 3); 1.63 + do_check_eq(aResponse.parameterNames[0], "foo"); 1.64 + do_check_eq(aResponse.parameterNames[1], "bar"); 1.65 + do_check_eq(aResponse.parameterNames[2], "baz"); 1.66 + 1.67 + gThreadClient.resume(test_anonymous_function); 1.68 + }); 1.69 + }); 1.70 + 1.71 + gDebuggee.eval("var o = { m: function(foo, bar, baz) { } }; stopMe(o.m)"); 1.72 +} 1.73 + 1.74 +function test_anonymous_function() { 1.75 + gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) { 1.76 + let args = aPacket.frame.arguments; 1.77 + 1.78 + do_check_eq(args[0].class, "Function"); 1.79 + // No name for an anonymous function, and no inferred name, either. 1.80 + do_check_eq(args[0].name, undefined); 1.81 + do_check_eq(args[0].displayName, undefined); 1.82 + 1.83 + let objClient = gThreadClient.pauseGrip(args[0]); 1.84 + objClient.getParameterNames(function(aResponse) { 1.85 + do_check_eq(aResponse.parameterNames.length, 3); 1.86 + do_check_eq(aResponse.parameterNames[0], "foo"); 1.87 + do_check_eq(aResponse.parameterNames[1], "bar"); 1.88 + do_check_eq(aResponse.parameterNames[2], "baz"); 1.89 + 1.90 + gThreadClient.resume(function() { 1.91 + finishClient(gClient); 1.92 + }); 1.93 + }); 1.94 + }); 1.95 + 1.96 + gDebuggee.eval("stopMe(function(foo, bar, baz) { })"); 1.97 +} 1.98 +