michael@0: /* michael@0: * For function statements, Script.prototype.sourceStart and michael@0: * Script.prototype.sourceLength should comprise both the opening '(' and the michael@0: * closing '}'. michael@0: */ michael@0: let g = newGlobal(); michael@0: let dbg = new Debugger(g); michael@0: michael@0: function test(string, ranges) { michael@0: var index = 0; michael@0: dbg.onNewScript = function (script) { michael@0: function traverse(script) { michael@0: script.getChildScripts().forEach(function (script) { michael@0: assertEq(script.sourceStart, ranges[index][0]); michael@0: assertEq(script.sourceLength, ranges[index][1]); michael@0: ++index; michael@0: traverse(script); michael@0: }); michael@0: } michael@0: traverse(script); michael@0: }; michael@0: michael@0: g.eval(string); michael@0: assertEq(index, ranges.length); michael@0: }; michael@0: michael@0: test("function f() {}", [[10, 5]]); michael@0: test("function f() { function g() {} }", [[10, 22], [25, 5]]); michael@0: test("function f() { function g() { function h() {} } }", [[10, 39], [25, 22], [40, 5]]); michael@0: test("function f() { if (true) function g() {} }", [[10, 32], [35, 5]]); michael@0: test("var o = { get p () {} }", [[16, 5]]); michael@0: test("var o = { set p (x) {} }", [[16, 6]]);