| 1 |
// Test that the onNativeCall get additional info |
| 2 |
// when using inspectNativeCallArguments |
| 3 |
|
| 4 |
load(libdir + "asserts.js"); |
| 5 |
|
| 6 |
var g = newGlobal({ newCompartment: true }); |
| 7 |
var dbg = new Debugger(); |
| 8 |
var gdbg = dbg.addDebuggee(g); |
| 9 |
|
| 10 |
g.eval(` |
| 11 |
var x = [1]; |
| 12 |
var callArg = () => true; |
| 13 |
function f() { |
| 14 |
x.push(42, 26); |
| 15 |
x.find(callArg); |
| 16 |
x.toString.call(2); |
| 17 |
new Function("code"); |
| 18 |
} |
| 19 |
`); |
| 20 |
|
| 21 |
let rv = []; |
| 22 |
dbg.onNativeCall = (callee, reason, object, args) => { |
| 23 |
rv.push({ |
| 24 |
name: callee.name, |
| 25 |
cls: object?.class || null, |
| 26 |
args: args ? args.unsafeDereference().map(a => a.unsafeDereference ? a.unsafeDereference() : a) : null, |
| 27 |
}); |
| 28 |
}; |
| 29 |
|
| 30 |
g.f(); |
| 31 |
|
| 32 |
// Trace without native arguments |
| 33 |
assertEq(dbg.inspectNativeCallArguments, false); |
| 34 |
assertEq(rv.length, 5); |
| 35 |
assertDeepEq(rv, [ |
| 36 |
{ |
| 37 |
name: "push", |
| 38 |
cls: null, |
| 39 |
args: null, |
| 40 |
}, |
| 41 |
{ |
| 42 |
name: "find", |
| 43 |
cls: null, |
| 44 |
args: null, |
| 45 |
}, |
| 46 |
{ |
| 47 |
name: "call", |
| 48 |
cls: null, |
| 49 |
args: null, |
| 50 |
}, |
| 51 |
{ |
| 52 |
name: "toString", |
| 53 |
cls: null, |
| 54 |
args: null, |
| 55 |
}, |
| 56 |
{ |
| 57 |
name: "Function", |
| 58 |
cls:null, |
| 59 |
args:null, |
| 60 |
}, |
| 61 |
]); |
| 62 |
|
| 63 |
// Trace with native arguments |
| 64 |
rv = []; |
| 65 |
dbg.inspectNativeCallArguments = true; |
| 66 |
assertEq(dbg.inspectNativeCallArguments, true); |
| 67 |
g.f(); |
| 68 |
assertEq(rv.length, 5); |
| 69 |
assertDeepEq(rv, [ |
| 70 |
{ |
| 71 |
name: "push", |
| 72 |
cls: "Array", |
| 73 |
args: [42, 26], |
| 74 |
}, |
| 75 |
{ |
| 76 |
name: "find", |
| 77 |
cls: "Array", |
| 78 |
args: [g.callArg], |
| 79 |
}, |
| 80 |
{ |
| 81 |
name: "call", |
| 82 |
cls: "Function", |
| 83 |
args: [2], |
| 84 |
}, |
| 85 |
{ |
| 86 |
name: "toString", |
| 87 |
cls: null, |
| 88 |
args: [], |
| 89 |
}, |
| 90 |
{ |
| 91 |
name: "Function", |
| 92 |
cls: null, |
| 93 |
args:["code"], |
| 94 |
}, |
| 95 |
]); |