Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging non-encoded javascript code #135

Closed
jurepetrovic opened this issue May 3, 2021 · 11 comments
Closed

Debugging non-encoded javascript code #135

jurepetrovic opened this issue May 3, 2021 · 11 comments

Comments

@jurepetrovic
Copy link

Hello,

I am trying to use bytenode in such way that some of the application files will be compiled
and some will stay in plain source code. I would like to have the ability to debug the
non-compiled files.

The compiled file loads the non-compiled one and this works ok, but the
ndb debugger will not break at the debugger statement if it is being launched
through compiled file.

Any idea on that?

@OsamaAbbas
Copy link
Collaborator

Can you provide a minimal setup that shows your issue?

@OsamaAbbas
Copy link
Collaborator

I have tried a small project with index.js that requires module1.jsc which will eventually require module2.js.

module1.jsc was compiled using bytenode -c module1.js as usual.

I tried both debugger; statement and manual breakpoints inside module2.js, both works just fine with me. The ndb debugger will break as expected.

I'm using Node v14.16.1.

@jurepetrovic
Copy link
Author

Thank you for the quick help!
Let me prepare the minimum example, we might discover something while preparing it.
I'm a bit suspicious - there are some eval() calls in the code...

Thanks,
Jure

@jurepetrovic
Copy link
Author

jurepetrovic commented May 5, 2021

Hello @OsamaAbbas,

I have prepared small setup with the code that I found suspicious, however it works fine.
https://github.com/jurepetrovic/encoding

You can do:
ndb simplay.loader.js
and the debugger statements are already inside.

However, I still have problems in the complete code. The points I noticed:

  • if there is no debugger statement, the code will execute correctly to the end.
  • if there is debugger statement the code will hang there, but the ndb debugger will not show anything.

Any clues?
Thanks a million,
jure

@jurepetrovic
Copy link
Author

jurepetrovic commented May 5, 2021

Hello @OsamaAbbas,

okay, now I have a working example. And I cannot figure it out.
Please check here: (https://github.com/jurepetrovic/encoding)

Running:

  • ndb simplay.loader.js works like a charm, the debugger will stop in simulworker.js, line 11.
  • ndb slotsimplay.loader.js will start and the debugger will hang on the same line, not showing anything.

My concern was there is an issue in this Thread loading logic. However, in that case simplay would not work properly.
What does slotsimplay.js contain to prevent proper debugging?

I'm using node v14.15.4

Thanks,
Jure

@jurepetrovic
Copy link
Author

Ok, I changed line 124 to change anonymous function to the classic declaration.
this. simulate = function() {}
https://github.com/jurepetrovic/encoding/blob/master/slotsimplay.js

However, I don't understand why anonymous functions can be a problem?

Thanks,
Jure

@OsamaAbbas
Copy link
Collaborator

Arrow functions have cause a few issues and bugs before. I don't know the exact reason, but I believe it is related to the way v8 handles them in the C++ source code. So there is nothing that can be done to fix them from bytenode or node itself.

I will add your case to the known issues and limitations in the README file soon.

Thank you for reporting and finding out the cause of the issue.

@jurepetrovic
Copy link
Author

Thank YOU for bytenode actually.

Is there any way to fix the case where the code does:
var code = fs.readFileSync("./file.js").toString();
eval(code);

yes, I know - but people still do this :)

Thanks,
Jure

@OsamaAbbas
Copy link
Collaborator

This code:

var code = fs.readFileSync("./file.js").toString();
eval(code);

Should work with bytenode. So if that code is in a file named script.js and you compiled it to script.jsc: it will work as usual.

The only place where toString() does not work is with function objects. If you have a function and your code depends on its string content (for analyzing purposes, or transpiling, or to send it to another context like in Puppeteer), then it won't work with bytenode and you will have to find another way. However, all these purposes are typical in tools and utilities, not in your everyday code.

@jurepetrovic
Copy link
Author

No, not this case :-)
The problem is, when you need "file.js" encoded

@OsamaAbbas
Copy link
Collaborator

No, not this case :-)
The problem is, when you need "file.js" encoded

This can't be done. If you want to protect file.js too, you have to change the previous code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants