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

--use-strict flag doesn't apply strict mode to script #30039

Open
Pravv opened this issue Oct 19, 2019 · 8 comments
Open

--use-strict flag doesn't apply strict mode to script #30039

Pravv opened this issue Oct 19, 2019 · 8 comments
Labels
confirmed-bug Issues with confirmed bugs. v8 engine Issues and PRs related to the V8 dependency.

Comments

@Pravv
Copy link

Pravv commented Oct 19, 2019

  • Node 12.*:
  • Windows 64bit, Debian 64bit:

The --use-strict flag doesn't apply strict mode to script.
reproduction:

echo a = 1 > test.js && node --use-strict test

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.

node --use-strict
Welcome to Node.js v12.12.0.
Type ".help" for more information.
> a = 1
Thrown:
ReferenceError: a is not defined
>
@SaltyMonkey
Copy link

SaltyMonkey commented Oct 19, 2019

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

@addaleax addaleax added confirmed-bug Issues with confirmed bugs. v8 engine Issues and PRs related to the V8 dependency. labels Oct 19, 2019
@addaleax
Copy link
Member

This was caused by b338edb (the switch to CompileFunctionInContext()). /cc @nodejs/v8 @hashseed @ryzokuken

@hashseed
Copy link
Member

Fix should be easy. Just change the language mode in ParseInfo depending on FLAG_use_strict.

@targos
Copy link
Member

targos commented Oct 22, 2019

@hashseed it looks like it's already done?

Refs: https://github.com/v8/v8/blob/16b83b1b4a30f4c71b3114a19926169190785f2c/src/codegen/compiler.cc#L2079-L2164

@ryzokuken
Copy link
Contributor

@targos hmm, weird. By that logic, the default should be strict mode. Let me try building and debugging to see what's happening exactly.

@alexfernandez
Copy link

alexfernandez commented Aug 10, 2020

Any news on this? In Node.js v14.7.0 --use-strict is not working, and execution is still not strict by default.

teneightfive added a commit to ministryofjustice/hmpps-book-secure-move-frontend that referenced this issue Apr 23, 2021
An issue was created to re-enable strict mode when running the app.

This change re-enabes strict mode. There does seem to be a current
[issue](nodejs/node#30039) with Node v14
and strict mode but this change will support the use of it once
the bug is fixed.

Closes #32
@DVLP
Copy link

DVLP commented Jun 17, 2022

node 18.1 the problem is still there

@loynoir
Copy link

loynoir commented May 12, 2023

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()
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

9 participants