Frame-arguments-06.js (1323B)
1 // Test extracting frame.arguments element getters and calling them in 2 // various awkward ways. 3 4 load(libdir + "asserts.js"); 5 6 var g = newGlobal({newCompartment: true}); 7 var dbg = Debugger(g); 8 var hits = 0; 9 var fframe, farguments, fgetter; 10 dbg.onDebuggerStatement = function (frame) { 11 if (hits === 0) { 12 fframe = frame; 13 farguments = frame.arguments; 14 fgetter = Object.getOwnPropertyDescriptor(farguments, "0").get; 15 assertEq(fgetter instanceof Function, true); 16 17 // Calling the getter without an appropriate this-object 18 // fails, but shouldn't assert or crash. 19 assertThrowsInstanceOf(function () { fgetter.call(Math); }, TypeError); 20 } else { 21 // Since fframe is still on the stack, fgetter can be applied to it. 22 assertEq(fframe.onStack, true); 23 assertEq(fgetter.call(farguments), 100); 24 25 // Since h was called without arguments, there is no argument 0. 26 assertEq(fgetter.call(frame.arguments), undefined); 27 } 28 hits++; 29 }; 30 31 g.eval("function h() { debugger; }"); 32 g.eval("function f(x) { debugger; h(); }"); 33 g.f(100); 34 assertEq(hits, 2); 35 36 // Now that fframe is no longer live, trying to get its arguments should throw. 37 assertEq(fframe.onStack, false); 38 assertThrowsInstanceOf(function () { fgetter.call(farguments); }, Error);