summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Object-script-lazy.js
blob: 68af0e297307d08cd5c37a9490119cb60d2f7b1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Asking for the script of a Debugger.Object should work, even when lazy
// functions are involved.

// Note that we never hand out the scripts of non-debuggee functions, and
// putting a compartment in debug mode automatically de-lazifies all its
// functions. (This ensures that findScripts works, too.)
//
// So here we create a reference to a non-debuggee function, verify that we
// can't access its interesting properties, make it a debuggee, and verify
// that everything becomes available.

// Create functions f, g in a non-debuggee compartment.
var g1 = newGlobal({newCompartment: true});
g1.eval('function f() { return "from f"; }');
g1.eval('function g() { return "from g"; }');
g1.eval('this.h = f.bind(g, 42, "foo");');

// Create a debuggee compartment with CCWs referring to f and g.
var g2 = newGlobal({newCompartment: true});
var dbg = new Debugger;
var g2w = dbg.addDebuggee(g2);
g2.f = g1.f;
g2.g = g1.g;
g2.h = g1.h;

// At this point, g1.f should still be a lazy function. Unwrapping a D.O
// referring to g2's CCW of f should yield a D.O referring to f directly.
// Asking for that second D.O's script should yield null, because it's not
// a debuggee.
var fDO = g2w.getOwnPropertyDescriptor('f').value;
assertEq(fDO.unwrap().class, "Function");
assertEq(fDO.unwrap().script, null);

// Similarly for g1.g, and asking for its parameter names.
var gDO = g2w.getOwnPropertyDescriptor('g').value;
assertEq(gDO.unwrap().parameterNames, undefined);

// Similarly for g1.h, and asking for its bound function properties.
var hDO = g2w.getOwnPropertyDescriptor('h').value;
assertEq(hDO.unwrap().class, "BoundFunctionObject");
assertEq(hDO.unwrap().isBoundFunction, true);
assertEq(hDO.unwrap().isArrowFunction, undefined);
assertEq(hDO.unwrap().boundTargetFunction, undefined);
assertEq(hDO.unwrap().boundThis, undefined);
assertEq(hDO.unwrap().boundArguments, undefined);

// Add g1 as a debuggee, and verify that we can get everything.
dbg.addDebuggee(g1);
assertEq(fDO.unwrap().script instanceof Debugger.Script, true);
assertEq(gDO.unwrap().parameterNames instanceof Array, true);
assertEq(hDO.unwrap().isBoundFunction, true);
assertEq(hDO.unwrap().isArrowFunction, undefined);
assertEq(hDO.unwrap().boundTargetFunction, fDO.unwrap());
assertEq(hDO.unwrap().boundThis, gDO.unwrap());
assertEq(hDO.unwrap().boundArguments.length, 2);
assertEq(hDO.unwrap().boundArguments[0], 42);
assertEq(hDO.unwrap().boundArguments[1], "foo");