-
Notifications
You must be signed in to change notification settings - Fork 2
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
Module.wrap override breaks shadowing for globals #4
Comments
Hey Sage! Thanks for the report! When i run the following snippet with lya, it fails. let console = 1; But when i change var console = 1; This is possible because of an option in the code base that changes the way we declare the global identifiers in the prologue that we injected to every imported module. This happens in the following sections of the Lines 25 to 26 in 01a4163
Lines 418 to 421 in 01a4163
|
Thanks for the quick response! I'm aware of the option, but this error reproduces if you use
Yes, but I would not expect a user to change their code for the sake of a dynamic analysis tool. A program that uses Are you saying the point of this option is to create a workaround for the error? If so, what workaround would exist if the user does not have to change their code? |
Yes, that is true and logical. It is not so much a bug as the way that node.js operates. I mean the way that lya is written, it creates a prologue that re-declares global variable in module-level scope. The only possible ways to declare the variables are with
let pizza = 'amazing';
let pizza = 'amazing';
var pizza = 'amazing';
var pizza = 'amazing'; In our error case, i don't think there is a way to first declare something with
Yes, I agree. I don't expect the user to change their code for their dynamic analysis tool, but i think it is logical to expect some configurations to be passed to the dynamic analysis tool. There is only one way to mitigate this specific scenario without changing the users code, and that is to use the
The point of this option is to provide way to disable the |
@GNtousakis Your summary of the intended usage of
If Failing that, I suspect the issue can also be resolved by wrapping module code in a second IIFE, but I would need to understand how that impacts what you meant by "provides a deeper analysis on global variables scope". |
To add: It appears the reason behind function override(context) {
vm.runInThisContext = function runInThisContext(code, options) {
return vm.runInContext(code, context, options);
}
} Doing that creates a path where you don't need to tinker with CommonJS to make it work, and avoid the scoping issues. |
Create a
src.js
with the following.node src.js
runs without error because function-level shadowing of globals is permitted. That program would break withSyntaxError: Identifier 'require' has already been declared
if you replaceconsole
withrequire
.lya
breaks with the the same error forconsole
due to itsModule.wrap
override, regardless if it usesvar
orlet
as a variable declarator. This is because it injects known global identifiers into the same module function's scope.Is there a note somewhere that tells users that they cannot shadow any global identifiers used by Lya in this way?
The text was updated successfully, but these errors were encountered: