class-default-constructor-01.js (1189B)
1 // We should be able to retrieve the script of a class's default constructor. 2 3 var g = newGlobal({newCompartment: true}); 4 var dbg = new Debugger; 5 var gDO = dbg.addDebuggee(g); 6 7 // Class definitions go in the global's lexical environment, so we can't use 8 // getOwnPropertyDescriptor or g.X to retrieve their constructor. 9 // 10 // Derived clasess use a different script, so check those too. 11 gDO.executeInGlobal(` // 1729 12 class X {}; // 1730 13 // 1731 14 // 1732 15 class Y extends X {}; // 1733 16 `, { lineNumber: 1729 }); 17 18 function check(name, text, startLine) { 19 print(`checking ${name}`); 20 var desc = gDO.executeInGlobal(name).return; 21 assertEq(desc.class, 'Function'); 22 assertEq(desc.name, name); 23 var script = desc.script; 24 assertEq(script instanceof Debugger.Script, true, 25 "default constructor's script should be available"); 26 assertEq(script.startLine, startLine, 27 "default constructor's starting line should be set"); 28 var source = script.source; 29 assertEq(source.text.substr(script.sourceStart, script.sourceLength), text); 30 } 31 32 check('X', 'class X {}', 1730); 33 check('Y', 'class Y extends X {}', 1733);