Open Pravv opened 4 years ago
Tested some versions of runtime:
test.js file:
module.exports = function() {
a = 1;
console.log(a);
};
Call:
PS E:\test> node --use-strict
Welcome to Node.js v12.8.1.
Type ".help" for more information.
> let z = require(".\\test");
undefined
> z()
1
Reproduced at: 12.4, 12.6, 12.8, 12.8.1, 12.12 OS: Win 10 x64
This was caused by b338edbb0ab1ae9823d1128ef9baa4295885b9d7 (the switch to CompileFunctionInContext()
). /cc @nodejs/v8 @hashseed @ryzokuken
Fix should be easy. Just change the language mode in ParseInfo depending on FLAG_use_strict.
@hashseed it looks like it's already done?
@targos hmm, weird. By that logic, the default should be strict mode. Let me try building and debugging to see what's happening exactly.
Any news on this? In Node.js v14.7.0 --use-strict
is not working, and execution is still not strict by default.
node 18.1 the problem is still there
Should have some warnings like
if(has_cli_flag_use_strict) {
switch(node_running_mode) {
case 'repl':
case 'script':
throw new InValidFlagError("repl and script does not support --use_strict")
case 'stdin':
case 'eval':
// OK with `--use_strict`
break
default:
throw new UnreachableCaseError()
}
}
The
--use-strict
flag doesn't apply strict mode to script. reproduction:expected behavior:
ReferenceError: a is not defined
is thrown. behavior: script executes without any issue.however it works as expected when node is started first and script is called from repl. <12 versions aren't affected.