test_functiongrips-01.js (1818B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 add_task( 7 threadFrontTest(async ({ threadFront, debuggee }) => { 8 // Test named function 9 function evalCode() { 10 debuggee.eval( 11 // These arguments are tested. 12 // eslint-disable-next-line no-unused-vars 13 function stopMe(arg1) { 14 debugger; 15 }.toString() 16 ); 17 debuggee.eval("stopMe(stopMe)"); 18 } 19 20 const packet1 = await executeOnNextTickAndWaitForPause( 21 () => evalCode(), 22 threadFront 23 ); 24 25 const args1 = packet1.frame.arguments; 26 27 Assert.equal(args1[0].class, "Function"); 28 Assert.equal(args1[0].name, "stopMe"); 29 Assert.equal(args1[0].displayName, "stopMe"); 30 31 await threadFront.resume(); 32 33 // Test inferred name function 34 const packet2 = await executeOnNextTickAndWaitForPause( 35 () => 36 debuggee.eval( 37 "var o = { m: function(foo, bar, baz) { } }; stopMe(o.m)" 38 ), 39 threadFront 40 ); 41 42 const args2 = packet2.frame.arguments; 43 44 Assert.equal(args2[0].class, "Function"); 45 // No name for an anonymous function, but it should have an inferred name. 46 Assert.equal(args2[0].name, undefined); 47 Assert.equal(args2[0].displayName, "m"); 48 49 await threadFront.resume(); 50 51 // Test anonymous function 52 const packet3 = await executeOnNextTickAndWaitForPause( 53 () => debuggee.eval("stopMe(function(foo, bar, baz) { })"), 54 threadFront 55 ); 56 57 const args3 = packet3.frame.arguments; 58 59 Assert.equal(args3[0].class, "Function"); 60 // No name for an anonymous function, and no inferred name, either. 61 Assert.equal(args3[0].name, undefined); 62 Assert.equal(args3[0].displayName, undefined); 63 64 await threadFront.resume(); 65 }) 66 );