mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 637572 - Implement Debugger.Source.prototype.sourceStart/Length; r=jimb
This commit is contained in:
parent
7d53f5862c
commit
a0ed8712fe
22
js/src/jit-test/tests/debug/Script-sourceStart-01.js
Normal file
22
js/src/jit-test/tests/debug/Script-sourceStart-01.js
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Script.prototype.sourceStart and Script.prototype.sourceLength should both be
|
||||
* a number.
|
||||
*/
|
||||
let g = newGlobal('new-compartment');
|
||||
let dbg = new Debugger(g);
|
||||
|
||||
var count = 0;
|
||||
function test(string, range) {
|
||||
dbg.onNewScript = function (script) {
|
||||
++count;
|
||||
assertEq(script.sourceStart, range[0]);
|
||||
assertEq(script.sourceLength, range[1]);
|
||||
};
|
||||
|
||||
g.eval(string);
|
||||
};
|
||||
|
||||
test("", [0, 0]);
|
||||
test("2 * 3", [0, 5]);
|
||||
test("2\n*\n3", [0, 5]);
|
||||
assertEq(count, 3);
|
32
js/src/jit-test/tests/debug/Script-sourceStart-02.js
Normal file
32
js/src/jit-test/tests/debug/Script-sourceStart-02.js
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* For function statements, Script.prototype.sourceStart and
|
||||
* Script.prototype.sourceLength should comprise both the opening '(' and the
|
||||
* closing '}'.
|
||||
*/
|
||||
let g = newGlobal('new-compartment');
|
||||
let dbg = new Debugger(g);
|
||||
|
||||
function test(string, ranges) {
|
||||
var index = 0;
|
||||
dbg.onNewScript = function (script) {
|
||||
function traverse(script) {
|
||||
script.getChildScripts().forEach(function (script) {
|
||||
assertEq(script.sourceStart, ranges[index][0]);
|
||||
assertEq(script.sourceLength, ranges[index][1]);
|
||||
++index;
|
||||
traverse(script);
|
||||
});
|
||||
}
|
||||
traverse(script);
|
||||
};
|
||||
|
||||
g.eval(string);
|
||||
assertEq(index, ranges.length);
|
||||
};
|
||||
|
||||
test("function f() {}", [[10, 5]]);
|
||||
test("function f() { function g() {} }", [[10, 22], [25, 5]]);
|
||||
test("function f() { function g() { function h() {} } }", [[10, 39], [25, 22], [40, 5]]);
|
||||
test("function f() { if (true) function g() {} }", [[10, 32], [35, 5]]);
|
||||
test("var o = { get p () {} }", [[16, 5]]);
|
||||
test("var o = { set p (x) {} }", [[16, 6]]);
|
31
js/src/jit-test/tests/debug/Script-sourceStart-03.js
Normal file
31
js/src/jit-test/tests/debug/Script-sourceStart-03.js
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* For arrow functions, Script.prototype.sourceStart and
|
||||
* Script.prototype.sourceLength should comprise the entire function expression
|
||||
* (including arguments)
|
||||
*/
|
||||
let g = newGlobal('new-compartment');
|
||||
let dbg = new Debugger(g);
|
||||
|
||||
function test(string, ranges) {
|
||||
var index = 0;
|
||||
dbg.onNewScript = function (script) {
|
||||
function traverse(script) {
|
||||
script.getChildScripts().forEach(function (script) {
|
||||
assertEq(script.sourceStart, ranges[index][0]);
|
||||
assertEq(script.sourceLength, ranges[index][1]);
|
||||
++index;
|
||||
traverse(script);
|
||||
});
|
||||
}
|
||||
traverse(script);
|
||||
};
|
||||
|
||||
g.eval(string);
|
||||
assertEq(index, ranges.length);
|
||||
};
|
||||
|
||||
test("() => {}", [[0, 8]]);
|
||||
test("(x, y) => { x * y }", [[0, 19]]);
|
||||
test("x => x * x", [[0, 10]]);
|
||||
test("x => x => x * x", [[0, 15], [5, 10]]);
|
||||
test("x => x => x => x * x", [[0, 20], [5, 15], [10, 10]]);
|
25
js/src/jit-test/tests/debug/Script-sourceStart-04.js
Normal file
25
js/src/jit-test/tests/debug/Script-sourceStart-04.js
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* For eval and Function constructors, Script.prototype.sourceStart and
|
||||
* Script.prototype.sourceLength should comprise the entire script (excluding
|
||||
* arguments in the case of Function constructors)
|
||||
*/
|
||||
let g = newGlobal('new-compartment');
|
||||
let dbg = new Debugger(g);
|
||||
|
||||
var count = 0;
|
||||
function test(string, range) {
|
||||
dbg.onNewScript = function (script) {
|
||||
++count;
|
||||
if (count % 2 == 0) {
|
||||
assertEq(script.sourceStart, range[0]);
|
||||
assertEq(script.sourceLength, range[1]);
|
||||
}
|
||||
}
|
||||
|
||||
g.eval(string);
|
||||
}
|
||||
|
||||
test("eval('2 * 3')", [0, 5]);
|
||||
test("new Function('2 * 3')", [0, 5]);
|
||||
test("new Function('x', 'x * x')", [0, 5]);
|
||||
assertEq(count, 6);
|
@ -2848,6 +2848,22 @@ DebuggerScript_getSource(JSContext *cx, unsigned argc, Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
DebuggerScript_getSourceStart(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
THIS_DEBUGSCRIPT_SCRIPT(cx, argc, vp, "(get sourceStart)", args, obj, script);
|
||||
args.rval().setNumber(script->sourceStart);
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
DebuggerScript_getSourceLength(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
THIS_DEBUGSCRIPT_SCRIPT(cx, argc, vp, "(get sourceEnd)", args, obj, script);
|
||||
args.rval().setNumber(script->sourceEnd - script->sourceStart);
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
DebuggerScript_getStaticLevel(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
@ -3485,6 +3501,8 @@ static const JSPropertySpec DebuggerScript_properties[] = {
|
||||
JS_PSG("startLine", DebuggerScript_getStartLine, 0),
|
||||
JS_PSG("lineCount", DebuggerScript_getLineCount, 0),
|
||||
JS_PSG("source", DebuggerScript_getSource, 0),
|
||||
JS_PSG("sourceStart", DebuggerScript_getSourceStart, 0),
|
||||
JS_PSG("sourceLength", DebuggerScript_getSourceLength, 0),
|
||||
JS_PSG("staticLevel", DebuggerScript_getStaticLevel, 0),
|
||||
JS_PSG("sourceMapURL", DebuggerScript_getSourceMapUrl, 0),
|
||||
JS_PS_END
|
||||
|
Loading…
Reference in New Issue
Block a user