Bug 185156 - JavaScriptCore should throw SyntaxError when a variable is already declared inside the "with" scope
Summary: JavaScriptCore should throw SyntaxError when a variable is already declared i...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 11
Hardware: Unspecified Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-30 20:07 PDT by baac
Modified: 2018-08-08 08:57 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description baac 2018-04-30 20:07:27 PDT
Hi,

there is an inconsistency when a variable is declared twice as "var" and "let" inside the "with" scope. JavaScriptCore should not accept the redeclaration and indicate an error.

OS: Ubuntu 17.10
JavaScriptCore: 606.1.9.4

Step to reproduce:

with({}) {
   var a;
   let a;
}

Actual result:
Pass without failures

Expected result:
SyntaxError: Cannot declare a variable twice

V8 and SpiderMonkey raises an exception as expected.
Comment 1 Saam Barati 2018-04-30 22:30:20 PDT
This is surprising given:

if (b) {
    var a;
    let a;
}

Is not a syntax error. Since with scopes don't require a block as their statement, e.g
```with({}) 20;```
is valid, I would guess this might be a bug in those other engines.

Can you point me to where the spec says this should be a syntax error?
Comment 2 isol2 2018-08-08 08:57:46 PDT
Hi Saam, sorry for delay... baac left from our project she did not answered your question in time.

We reported this issue on JSC and Chakra already confirmed after discussion (https://github.com/Microsoft/ChakraCore/issues/5076).

Another similar case can be found in this code:
{
let x;
eval('var x;');
}

JSC and Chakra should not hoist the var past the let declaration without throwing redeclaration. V8 and Spidermonkey throws a SyntaxError as expected.


cinfuzz