Bug 155454 - Destructuring parameters are evaluated in the wrong scope
Summary: Destructuring parameters are evaluated in the wrong scope
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Saam Barati
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-14 13:21 PDT by Saam Barati
Modified: 2016-03-15 01:58 PDT (History)
13 users (show)

See Also:


Attachments
patch (18.20 KB, patch)
2016-03-14 15:39 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (22.31 KB, patch)
2016-03-14 16:42 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (22.55 KB, patch)
2016-03-14 16:44 PDT, Saam Barati
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Saam Barati 2016-03-14 13:21:42 PDT
i.e:

return (function({a=function(){
  return typeof b === 'undefined';
}}){
  var b = 1;
  return a();
}({}));
Comment 1 Saam Barati 2016-03-14 14:07:33 PDT
our computation of "isSimpleParameterList" is wrong.
Comment 2 Saam Barati 2016-03-14 15:39:15 PDT
Created attachment 274041 [details]
patch
Comment 3 WebKit Commit Bot 2016-03-14 15:41:25 PDT
Attachment 274041 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:838:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Caitlin Potter (:caitp) 2016-03-14 16:04:51 PDT
I would suggest adding tests involving arrow functions and default parameters --- there were some similar bugs in V8's implementation in these contexts due to incorrect scoping issues.

I'm not sure it affects JSC as well because of the different frontend approach, but it probably doesn't hurt to pass similar tests. 
https://github.com/v8/v8/blob/02e4d21f4ce799c7d4e3500fa2cf96fc447456ff/test/mjsunit/harmony/regress/regress-4395.js
Comment 5 Saam Barati 2016-03-14 16:07:39 PDT
(In reply to comment #4)
> I would suggest adding tests involving arrow functions and default
> parameters --- there were some similar bugs in V8's implementation in these
> contexts due to incorrect scoping issues.
> 
> I'm not sure it affects JSC as well because of the different frontend
> approach, but it probably doesn't hurt to pass similar tests. 
> https://github.com/v8/v8/blob/02e4d21f4ce799c7d4e3500fa2cf96fc447456ff/test/
> mjsunit/harmony/regress/regress-4395.js

Will do. Thanks.
Comment 6 Saam Barati 2016-03-14 16:42:47 PDT
Created attachment 274049 [details]
patch

added the v8 tests.
Comment 7 WebKit Commit Bot 2016-03-14 16:44:05 PDT
Attachment 274049 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:838:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 8 Saam Barati 2016-03-14 16:44:16 PDT
Created attachment 274050 [details]
patch
Comment 9 Saam Barati 2016-03-14 16:44:42 PDT
Comment on attachment 274050 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=274050&action=review

> Source/JavaScriptCore/tests/stress/v8-parameter-scoping.js:26
> +//  Copyright 2014, the V8 project authors. All rights reserved.
> +//  Redistribution and use in source and binary forms, with or without
> +//  modification, are permitted provided that the following conditions are
> +//  met:
> +//  
> +//      * Redistributions of source code must retain the above copyright
> +//        notice, this list of conditions and the following disclaimer.
> +//      * Redistributions in binary form must reproduce the above
> +//        copyright notice, this list of conditions and the following
> +//        disclaimer in the documentation and/or other materials provided
> +//        with the distribution.
> +//      * Neither the name of Google Inc. nor the names of its
> +//        contributors may be used to endorse or promote products derived
> +//        from this software without specific prior written permission.
> +//  
> +//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> +//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> +//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> +//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> +//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> +//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> +//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> +//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> +//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> +//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> +//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Is this ok?
Comment 10 WebKit Commit Bot 2016-03-14 16:46:40 PDT
Attachment 274050 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:838:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 1 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 11 Caitlin Potter (:caitp) 2016-03-14 17:31:49 PDT
I'm not a lawyer, but it matches the license text, so lgtm
Comment 12 Filip Pizlo 2016-03-14 17:35:59 PDT
(In reply to comment #9)
> Comment on attachment 274050 [details]
> patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=274050&action=review
> 
> > Source/JavaScriptCore/tests/stress/v8-parameter-scoping.js:26
> > +//  Copyright 2014, the V8 project authors. All rights reserved.
> > +//  Redistribution and use in source and binary forms, with or without
> > +//  modification, are permitted provided that the following conditions are
> > +//  met:
> > +//  
> > +//      * Redistributions of source code must retain the above copyright
> > +//        notice, this list of conditions and the following disclaimer.
> > +//      * Redistributions in binary form must reproduce the above
> > +//        copyright notice, this list of conditions and the following
> > +//        disclaimer in the documentation and/or other materials provided
> > +//        with the distribution.
> > +//      * Neither the name of Google Inc. nor the names of its
> > +//        contributors may be used to endorse or promote products derived
> > +//        from this software without specific prior written permission.
> > +//  
> > +//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> > +//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> > +//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> > +//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> > +//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> > +//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> > +//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> > +//  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> > +//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> > +//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> > +//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> 
> Is this ok?

Looks like BSD 3-clause to me, so I think that it's fine.
Comment 13 Geoffrey Garen 2016-03-14 20:26:26 PDT
Comment on attachment 274050 [details]
patch

r=me
Comment 14 WebKit Commit Bot 2016-03-15 01:58:47 PDT
Comment on attachment 274050 [details]
patch

Clearing flags on attachment: 274050

Committed r198206: <http://trac.webkit.org/changeset/198206>
Comment 15 WebKit Commit Bot 2016-03-15 01:58:52 PDT
All reviewed patches have been landed.  Closing bug.