New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 598394 link

Starred by 3 users

Issue metadata

Status: WontFix
Owner:
Closed: Jul 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug-Regression



Sign in to add a comment

Inconsistent behavior in javascript Uncaught SyntaxError: Identifier '*****' has already been declared

Reported by djcavan...@gmail.com, Mar 28 2016

Issue description

Chrome Version       : 49.0.2623.110 (64-bit)
URLs (if applicable) : 
Other browsers tested: 
  Add OK or FAIL, along with the version, after other browsers where you
have tested this issue:
     Safari: OK
    Firefox: OK
         IE: OK

What steps will reproduce the problem?
(1) load the following html into browser and watch console output
<!DOCTYPE html>
<html>
<body>
<script>
    //test a
    var a = '';
    function a(){
        
    }
    console.log('no errors yet 9');
    //test b
    if (true) {
        var b = '';
        function b () {
            
        }
    }
    console.log('no errors yet 16');
</script>
</body>
</html>

What is the expected result?
Legacy javascript code should still function
Consistent behavior when overwriting a variable inside an if statement and outside.


What happens instead?
Legacy code similar to the example provided no longer functions in chrome
Error received when variable overwrites a function inside an if statement
no error received when overwriting in other contexts


Please provide any additional information below. Attach a screenshot if
possible.

 
Screen Shot 2016-03-28 at 12.43.51 PM.png
549 KB View Download
Occurs on OSX and Windows 7
Cc: brajkumar@chromium.org
Labels: Needs-Feedback OS-All
Tested on Windows 7 using chrome latest stable M49-49.0.2623.110 by loading the provided html file and observed the error displayed in the console as shown in the above snap shot.

Tested the same on chrome M45-45.0.2442.0 and observed no error instead of that displayed result saying "no errors yet 9, no errors yet 16" as seen in the snap shot.

djcavanagh@ Could you please confirm is this is the expected behavior of this issue? If yes, please let us know it will be helpful to investigate this issue further.

thanks!

598394.JPG
41.2 KB View Download
Yes, that is the expected behavior.

Thanks
Project Member

Comment 4 by sheriffbot@chromium.org, Mar 31 2016

Labels: -Needs-Feedback Needs-Review
Owner: brajkumar@chromium.org
Thank you for providing more feedback. Adding requester "brajkumar@chromium.org" for another review and adding "Needs-Review" label for tracking.

For more details visit https://sites.google.com/a/chromium.org/dev/issue-tracking/autotriage - Your friendly Sheriffbot
The stricter syntax checking killed my program having this code:

function something() {
 var myfunc1;
 var myfunc2;

 function myfunc1() {
  myfunc2();
 }

 function myfunc2() {
  //...
 }
}

I used the var myfunc declarations, because JSLINT does not allow using functions defined after the function call.

Without the forward declaration, the code structure gets messy and writing functions calling each other is no longer possible.

And I really think Google should not make changes to the JS parser that kill legacy programms at all.

Thanks

Components: Blink>JavaScript
Labels: -Type-Bug -Needs-Review M-52 hasbisect Type-Bug-Regression
Owner: mythria@chromium.org
Status: Assigned (was: Unconfirmed)
Bisect Information:
=====================
Good build: 49.0.2613.0 
Bad Build : 49.0.2615.0 

Change Log URL: https://chromium.googlesource.com/chromium/src/+log/58c142c6eccd0287edcf0194391f785e45a8de92..a4231e4994a90b513122bdb9a58069d26938849f

v8-autoroll:
https://chromium.googlesource.com/v8/v8/+log/5041f175..aca25b0c

From the above V8 log suspecting below

Review URL: https://codereview.chromium.org/1561603002

mythria@ - Assigning to you, Could you please check whether this is caused with respect to your change, if not please help us in assigning it to the right owner.

Thanks!
 https://codereview.chromium.org/1561603002 may not be the cause of this problem. It is behind a flag that is not enabled by default.
Reduced test case for reproducing with d8. 

function f() {
  var a;
  function a() { // This works
  }

 {
   var b;
   function b() { // This gives syntax error.
   }
 } 
}
f();
Cc: adamk@chromium.org
@admak could this be related to recent changes with legacy constants?

Comment 10 by adamk@chromium.org, Apr 21 2016

Cc: mythria@chromium.org
Owner: littledan@chromium.org
This is due to our changes for ES2015 sloppy mode block scoping of function declarations, but it looks like we might have a bug. Investigating...

Comment 11 by adamk@chromium.org, Apr 21 2016

Cc: -adamk@chromium.org littledan@chromium.org
Owner: adamk@chromium.org
To the reporter: Is this causing issues in a production website you're aware of? Or is it simply the mismatch with JSLINT behavior that you're reporting? If the latter, I'd recommend taking it up with JSLINT, as using vars to make the linter "happy" doesn't make much sense to me: function declarations are always hoisted to the top of their scope.

We are following the spec here (to be exact, the second bullet of https://tc39.github.io/ecma262/#sec-block-static-semantics-early-errors). Other browsers have a mish-mash of behaviors.

Firefox: doesn't throw, but does for the very similar "{var x; let x;}". In Nightly, does throw (they're now following the spec too, apparently).
Edge: doesn't throw for this case or for "{var x; let x;}"
WebKit (nightly): same as Edge
Project Member

Comment 12 by sheriffbot@chromium.org, Jun 1 2016

Labels: -M-52 M-53 MovedFrom-52
Moving this nonessential bug to the next milestone.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Project Member

Comment 13 by sheriffbot@chromium.org, Jul 14 2016

Labels: -M-53 MovedFrom-53
This issue has been moved once and is lower than Pri-1. Removing the milestone.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot

Comment 14 by adamk@chromium.org, Jul 14 2016

Status: WontFix (was: Assigned)
Marking as WontFix since the reported behavior is per spec.

Sign in to add a comment