Script-parameterNames.js (1254B)
1 load(libdir + "asserts.js"); 2 3 var g = newGlobal({newCompartment: true}); 4 var dbg = new Debugger; 5 var gDO = dbg.addDebuggee(g); 6 7 function check(expr, expected) { 8 let completion = gDO.executeInGlobal(expr); 9 if (completion.throw) 10 throw completion.throw.unsafeDereference(); 11 12 let fn = completion.return; 13 if (expected === undefined) 14 assertEq(fn.script.parameterNames, undefined); 15 else 16 assertDeepEq(fn.script.parameterNames, expected); 17 } 18 19 check('(function () {})', []); 20 check('(function (x) {})', ["x"]); 21 check('(function (x = 1) {})', ["x"]); 22 check('(function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) {})', 23 ["a","b","c","d","e","f","g","h","i","j","k","l","m", 24 "n","o","p","q","r","s","t","u","v","w","x","y","z"]); 25 check('(function (a, [b, c], {d, e:f}) { })', 26 ["a", undefined, undefined]); 27 check('(async function (a, b, c) {})', ["a", "b", "c"]); 28 check('(async function* (d, e, f) {})', ["d", "e", "f"]); 29 30 // Non-function scripts have |undefined| parameterNames. 31 var log = []; 32 dbg.onEnterFrame = function(frame) { 33 log.push(frame.script.parameterNames); 34 }; 35 g.evaluate("function foo(a, b) { return eval('1'); }; foo();"); 36 assertDeepEq(log, [undefined, ["a", "b"], undefined]); // global, function, eval