Object-script-lazy.js (2448B)
1 // Asking for the script of a Debugger.Object should work, even when lazy 2 // functions are involved. 3 4 // Note that we never hand out the scripts of non-debuggee functions, and 5 // putting a compartment in debug mode automatically de-lazifies all its 6 // functions. (This ensures that findScripts works, too.) 7 // 8 // So here we create a reference to a non-debuggee function, verify that we 9 // can't access its interesting properties, make it a debuggee, and verify 10 // that everything becomes available. 11 12 // Create functions f, g in a non-debuggee compartment. 13 var g1 = newGlobal({newCompartment: true}); 14 g1.eval('function f() { return "from f"; }'); 15 g1.eval('function g() { return "from g"; }'); 16 g1.eval('this.h = f.bind(g, 42, "foo");'); 17 18 // Create a debuggee compartment with CCWs referring to f and g. 19 var g2 = newGlobal({newCompartment: true}); 20 var dbg = new Debugger; 21 var g2w = dbg.addDebuggee(g2); 22 g2.f = g1.f; 23 g2.g = g1.g; 24 g2.h = g1.h; 25 26 // At this point, g1.f should still be a lazy function. Unwrapping a D.O 27 // referring to g2's CCW of f should yield a D.O referring to f directly. 28 // Asking for that second D.O's script should yield null, because it's not 29 // a debuggee. 30 var fDO = g2w.getOwnPropertyDescriptor('f').value; 31 assertEq(fDO.unwrap().class, "Function"); 32 assertEq(fDO.unwrap().script, null); 33 34 // Similarly for g1.g, and asking for its parameter names. 35 var gDO = g2w.getOwnPropertyDescriptor('g').value; 36 assertEq(gDO.unwrap().parameterNames, undefined); 37 38 // Similarly for g1.h, and asking for its bound function properties. 39 var hDO = g2w.getOwnPropertyDescriptor('h').value; 40 assertEq(hDO.unwrap().class, "BoundFunctionObject"); 41 assertEq(hDO.unwrap().isBoundFunction, true); 42 assertEq(hDO.unwrap().isArrowFunction, undefined); 43 assertEq(hDO.unwrap().boundTargetFunction, undefined); 44 assertEq(hDO.unwrap().boundThis, undefined); 45 assertEq(hDO.unwrap().boundArguments, undefined); 46 47 // Add g1 as a debuggee, and verify that we can get everything. 48 dbg.addDebuggee(g1); 49 assertEq(fDO.unwrap().script instanceof Debugger.Script, true); 50 assertEq(gDO.unwrap().parameterNames instanceof Array, true); 51 assertEq(hDO.unwrap().isBoundFunction, true); 52 assertEq(hDO.unwrap().isArrowFunction, undefined); 53 assertEq(hDO.unwrap().boundTargetFunction, fDO.unwrap()); 54 assertEq(hDO.unwrap().boundThis, gDO.unwrap()); 55 assertEq(hDO.unwrap().boundArguments.length, 2); 56 assertEq(hDO.unwrap().boundArguments[0], 42); 57 assertEq(hDO.unwrap().boundArguments[1], "foo");