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

v8: Parse issue with code snippet: "{ a: 1 } { a: 1 }" #8481

Closed
princejwesley opened this issue Sep 10, 2016 · 3 comments
Closed

v8: Parse issue with code snippet: "{ a: 1 } { a: 1 }" #8481

princejwesley opened this issue Sep 10, 2016 · 3 comments
Labels
v8 engine Issues and PRs related to the V8 dependency.

Comments

@princejwesley
Copy link
Contributor

  • Version: master, v6.5.0
  • Platform: Darwin Princes-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
  • Subsystem: v8 (version tested: 5.1.281.81 & 5.1.281.82) (vm & repl modules are affected)

While working on #8195, I come across this v8 issue.

// with vm & repl
const vm = require('vm');
const script = vm.createScript("{ a: 1 } { a: 1 }", { displayErrors: true });
const output = script.runInThisContext({ displayErrors: true }); 
console.log(output); // returns 1 instead of throwing syntax error

// when used directly
{ a: 1 } { a: 1 } // no error
// when used with other constructs
console.log({ a: 1 } { a: 1 }) // Throws SyntaxError: missing ) after argument list
Chrome behaviour

Canary (64-bit)(55.0.2856.0) is buggy where as the latest version (52.0.2743.116) works fine.

cc: @nodejs/v8

@princejwesley princejwesley added the v8 engine Issues and PRs related to the V8 dependency. label Sep 10, 2016
@addaleax
Copy link
Member

I think this is expected behaviour… V8 interprets the {} as code blocks and the a: as labels (MDN), i.e. as:

{
a:
  1;
}
{
a:
  1;
}

That’s valid, even if not very meaningful, JS code. You can’t put arbitrary code blocks as function parameters, so V8 is right to complain about the console.log example.

@princejwesley
Copy link
Contributor Author

princejwesley commented Sep 10, 2016

@addaleax so the last chrome browser(v52.0.2743.116) is buggy and the canary has correct behaviour. right? Feel free to close it if you are sure about it 👍

image

edit: Firefox is also having same behaviour, seems legit.

@addaleax
Copy link
Member

I think so, yeah. Firefox also returns 1 for that statement, that seems like a good indicator to me. :)

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

No branches or pull requests

2 participants