mostafa / goja Goto Github PK
View Code? Open in Web Editor NEWThis project forked from dop251/goja
ECMAScript/JavaScript engine in pure Go
License: MIT License
This project forked from dop251/goja
ECMAScript/JavaScript engine in pure Go
License: MIT License
Consider the case, we set two breakpoints as following:
function HelloDebugger() {
var o = { // <--- set breakpoint here
a : 123,
b : 666
};
}
function AAA() { return HelloDebugger(); }
function BBB() {
return AAA(); // <--- set breakpoint here
}
BBB();
Currently, we will break on return AAA();
for second time after we break inside HelloDebugger()
.
This seems OK if we run the in the plain code.
Consider the for
-loop, this behavior will confuse users.
There are two problems when I call step in
command.
s
command twice.debug[10]> l
7 }
8
9 let i = 1;
10 console.log(i)
> 11 test(i)
12
13 i = 2
14 console.log(i)
15 console.log(test(i) + 1);
debug[10]> s
debug[11]> l
7 }
8
9 let i = 1;
10 console.log(i)
> 11 test(i)
12
13 i = 2
14 console.log(i)
15 console.log(test(i) + 1);
debug[11]> s
debug[12]> l
7 }
8
9 let i = 1;
10 console.log(i)
> 11 test(i)
12
13 i = 2
14 console.log(i)
15 console.log(test(i) + 1);
debug[12]> s
debug[0]> l
> 1
2 function test(val) {
3 val += 10
4 let test = 1
5 let pest = 2
debug[0]> n
debug[1]> l
1
2 function test(val) {
> 3 val += 10
4 let test = 1
5 let pest = 2
6 return val + 2
7 }
debug[1]> n
debug[10]> l
2 function test(val) {
3 val += 10
4 let test = 1
5 let pest = 2
> 6 return val + 2
7 }
8
9 let i = 1;
10 console.log(i)
I'll describe the detail first. Also I have know why this occurred. But I have no idea how to fix it. Please help me. @mostafa
I have tried three cases to make true this is a problem about builtins, rather than arrow-function or nested arrow-function.
In this case, there are 3 function calls:
testClosure
created a NewFunc
(s, v) => {...}
created a NewArrowFunc
() => {...}
created a NewArrowFunc
The debugger can break on line 2 and line 3, but not on line 5.
1
2 function testClosure() {
3 return (() => {
4 const base = 10;
5 return [ 1, 2, 3, 4, 5 ].reduce((s, v) => {
6 s += v + base;
7 {
8 let x = 123;
9 s += x;
10 {
11 let x = -123;
12 s += x;
13 }
14 }
15 return s;
16 })
17 })()
18 }
19
20 testClosure()
The debug info seems like this(0xc00029f560 (s, v) => {...} prg is runned explicitly):
newFunc: {0xc00029f560 (s, v) => {...}
newFunc: {0xc00029f500 () => {...}
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f3e0, dbg.vm.pc: 0, offset: 0, filename: test.js, line: 1
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f3e0, dbg.vm.pc: 1, offset: 0, filename: test.js, line: 1
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f3e0, dbg.vm.pc: 2, offset: 233, filename: test.js, line: 20
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f3e0, dbg.vm.pc: 3, offset: 244, filename: test.js, line: 20
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f440, dbg.vm.pc: 0, offset: 0, filename: test.js, line: 1
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f440, dbg.vm.pc: 1, offset: 0, filename: test.js, line: 1
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f440, dbg.vm.pc: 2, offset: 0, filename: test.js, line: 1
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f440, dbg.vm.pc: 3, offset: 223, filename: test.js, line: 17
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f500, dbg.vm.pc: 0, offset: 0, filename: test.js, line: 1
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f500, dbg.vm.pc: 1, offset: 0, filename: test.js, line: 1
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f500, dbg.vm.pc: 2, offset: 52, filename: test.js, line: 4
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f500, dbg.vm.pc: 3, offset: 73, filename: test.js, line: 5
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f500, dbg.vm.pc: 4, offset: 73, filename: test.js, line: 5
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f500, dbg.vm.pc: 5, offset: 73, filename: test.js, line: 5
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f500, dbg.vm.pc: 6, offset: 73, filename: test.js, line: 5
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f500, dbg.vm.pc: 7, offset: 73, filename: test.js, line: 5
dbg.vm: 0xc000402c60, dbg.vm.prg: 0xc00029f500, dbg.vm.pc: 8, offset: 73, filename: test.js, line: 5
Take the following code as a test case. I leave a blank line here:
1
2 function test() {
3 var a = true;
4 let b = true;
5 return a;
6 }
7 test();
8 test();
When I record the vm.debugger.Filename()
and vm.debugger.Line()
in debug()
function, I found there is no record on the var
and let
lines(3rd and 4th). Insteadly, there are many records on line 1:
[case4] current filename: test.js, line: 1
[case4] current filename: test.js, line: 1
[case3] current filename: test.js, line: 7
[case1] current filename: test.js, line: 7
[case4] current filename: test.js, line: 1
[case4] current filename: test.js, line: 1
[case4] current filename: test.js, line: 1
[case4] current filename: test.js, line: 1
[case4] current filename: test.js, line: 1
[case4] current filename: test.js, line: 1
[case4] current filename: test.js, line: 5
[case4] current filename: test.js, line: 5
[case2] current filename: test.js, line: 7
[case3] current filename: test.js, line: 8
...
I guess this may be caused by lack of some record in goja pc to line mapping? Do you have any clue?
Take the following code as a test case. I leave a blank line here:
1
2 function test() {
3 var a = true;
4 let b = true;
5 return a;
6 }
7 test();
8 test();
When I set a breakpoint on line 8 and I will break there for two times. I think this may be caused by the goja itself send back the last line return value as the vm.result
.
The walked line tracing record(I have removed continuous repeated records):
[case4] current filename: test.js, line: 1
[case4] current filename: test.js, line: 7
[case4] current filename: test.js, line: 1
[case4] current filename: test.js, line: 5
[case4] current filename: test.js, line: 7
[case3] current filename: test.js, line: 8
[case4] current filename: test.js, line: 1
[case4] current filename: test.js, line: 5
[case3] current filename: test.js, line: 8
Some debugger like gdb has command info variables
to list "All global and static variable names". Or using info locals
to list "Local variables of current stack frame".
If integerated with IDE like VS Code, there is window to show both locals and globals.
I know we can print single variable by invoking print
command, which is implemented by calling getValue()
. This function looks up variables from nested stashes and global object. I found even if I defined a local variable with let
, the value would be found in global object finally.
Do you have any plan to add these commands? Or can you give me any advice on how to implement this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.