GithubHelp home page GithubHelp logo

mostafa / goja Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dop251/goja

1.0 1.0 0.0 1.55 MB

ECMAScript/JavaScript engine in pure Go

License: MIT License

Go 99.73% Makefile 0.01% Perl 0.24% Shell 0.02%

goja's People

Contributors

adamkeys avatar danieldocu avatar dennwc avatar dop251 avatar gballet avatar mostafa avatar mstoykov avatar noctarius avatar notsatvrn avatar nwidger avatar olegator77 avatar palumacil avatar panzhongxian avatar profer avatar slavikm avatar steve-gray avatar vanackere avatar zupa-hu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

goja's Issues

Can't break on `return const_value` statement.

I added a recursive function testcase when testing the breakpoint in #15 , set a breakpoin on the return 1; statement(line 184) and tried to reach it, but failed.

This may also be caused by that the sourcemap doesn't record enough infomation?

Remove the second time stop on the parent function.

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.

@mostafa

Step in command doesn't skip to function immediately.

There are two problems when I call step in command.

  1. Doesn't skip to the function immediately. As you can see, I typed s command twice.
  2. The function start line should be line 2 rather than current line 1 (This may be a common problem with many debug command.)
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)

Can't stop inside builtin function's paramter functions.

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:

  1. line 2: testClosure created a NewFunc
  2. line 5: (s, v) => {...} created a NewArrowFunc
  3. line 3: () => {...} 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

Duplicated on first line? Maybe caused by that goja doesn't add declaration to pc->line map?

@mostafa

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?

Break on last return line twice.

@mostafa

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

Support `info variables`-like command.

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.