New issue
Advanced search Search tips

Issue 793539 link

Starred by 2 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Android , Windows , Chrome , Mac , Fuchsia
Pri: 2
Type: Bug



Sign in to add a comment

with statement can't get along with spread operator

Reported by hinass...@gmail.com, Dec 9 2017

Issue description

UserAgent: Mozilla/5.0 (X11; CrOS x86_64 9901.77.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.97 Safari/537.36
Platform: 9901.77.0 (Official Build) stable-channel sentry

Steps to reproduce the problem:
Evaluate the following:
   with ({ f : function () { return this } }) f(...[1], 5)
This is evaluated to [Windows] i.e. global scope.

What is the expected behavior?
Expected to be evaluated in the same way as
   with ({ f : function () { return this } }) f(1, 5)
This is evaluated to { f : function () { return this } }.

What went wrong?
semantic inconsistency

Did this work before? N/A 

Chrome version: 62.0.3202.97  Channel: stable
OS Version: 9901.77.0
Flash Version:
 
Components: -Blink Blink>JavaScript
Cc: mathias@chromium.org
Components: -Blink>JavaScript Blink>JavaScript>Language
Status: Available (was: Unconfirmed)
Should this even work?
Owner: gsat...@chromium.org
I’d expect the `{ f: … }` object as the result, not the global object. Other engines implement this correctly:

    $ eshost -e '(() => { with ({ f: function() { return this; } }) print(f(...[1], 2)); })()'
    #### Chakra
    [object Object]
    undefined

    #### JavaScriptCore
    [object Object]
    undefined

    #### SpiderMonkey
    [object Object]
    undefined

    #### V8 --harmony
    [object global]
    undefined

    #### V8
    [object global]
    undefined

    $ eshost -e '(() => { with ({ f: function() { return this; } }) print(f(...[1], 2).f); })()'
    #### Chakra
    function () { return this; }
    undefined

    #### JavaScriptCore
    function () { return this; }
    undefined

    #### SpiderMonkey
    function() { return this; }
    undefined

    #### V8 --harmony
    undefined
    undefined

    #### V8
    undefined
    undefined

When the second argument is removed, V8 behaves as expected.

Comment 4 by adamk@chromium.org, Dec 19 2017

Cc: adamk@chromium.org
Labels: OS-Android OS-Fuchsia OS-Linux OS-Mac OS-Windows
Status: Assigned (was: Available)
This is because spread calls which feature arguments after the spread are desugared into a call to Reflect.apply, and it has no access to the `with` context to be able to fill in the correct receiver.

(changing to "Assigned", since this has an owner, but gsathya, feel free to unassign an re-mark this as "Available" if desired).

Sign in to add a comment