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

Using of rest argument binding in inner function, breaks it #327

Closed
mstoykov opened this issue Sep 11, 2021 · 1 comment
Closed

Using of rest argument binding in inner function, breaks it #327

mstoykov opened this issue Sep 11, 2021 · 1 comment
Labels

Comments

@mstoykov
Copy link
Contributor

Original report grafana/k6#2131.

Smallest reproduction:

function f(...rest) {
         () => rest; // remove this line to fix.
         return rest.length;
}
f(1,2) // this returns 0 not 2

as shown there having adding another variable to which to using rest and then using that in the lambda fixes it including that the following works:

function f(...rest) {
         const alias =  rest;
         return (() => alias.length)();
}
f(1,2) // this returns 2 actually

but doesn't work if in this case you just use rest instead.

This doesn't seem related to lambdas as it also doesn't appear to be working with functions.

I would guess some optimizations somewhere as calling eval before the lambda fixes it.

Another thing that I noticed (that might be a completely separate issue) is that

function f(...rest) {
         eval(rest[0]) // not the missing ;
         () => rest; 
         return rest.length;
}
f(1,2) // this returns 0 not 2

returned Line 3:3 Malformed arrow function parameter list but I don't know if this isn't really how it should work 🤷

@dop251 dop251 closed this as completed in 994d93d Sep 11, 2021
@dop251 dop251 added the bug label Sep 11, 2021
@dop251
Copy link
Owner

dop251 commented Sep 11, 2021

Thanks for reporting. The other issue that you mention is not a bug, ASI does not apply to this case, so it's interpreted as eval(rest[0])() => rest

Gabri3l added a commit to mongodb-forks/goja that referenced this issue Feb 4, 2022
…formats, ... (#47)

* Fixed typed arrays' defineProperty and indexing. Fixes dop251#308.
* Fix Proxy creation panicing on target not callable
* Do not modify sb for variadic calls as it breaks local variables resolution. Instead place a marker on stack and use it to count the number of args. Fixes dop251#311.
* Support patterns in catch clause. See dop251#305
* Fixed the handling of Symbol properties in destructuring assignments. Fixes dop251#312.
* Ensure ToPropertyKey happens earlier when assigning computed keys. Fixes dop251#312.
* Aligned detached buffer semantics with the latest specs. Fixes dop251#315.
* More typed arrays fixes
* Fixed accessor and property key function names. Fixes dop251#314.
* Fixed possible panic when sorting non-standard arrays.
* Added nil-safety checks for values returned by get*() methods
* Fixed panics in parser on some invalid inputs. Fixes dop251#318.
* Arrow function (dop251#319)
* Implemented arrow functions. See dop251#304.
* Define the name property for anonymous functions (including arrow functions)
* Treat "arguments" as a lexical binding to match the latest specification
* Allow arrow functions to contain 'use strict' for simple parameter lists. Fixes dop251#323.
* Fixed argument variable reference resolution in stashless functions
* Treat date-only formats as UTC and date-time as local timezone. Added support for additional datetime formats. Fixes dop251#281, fixes dop251#292.
* Use correct createArgsRest variant when arguments are not in stash. Fixes dop251#327
* Fixed formatting for go 1.17
* Report 'length' as own property for Go slices. Fixes dop251#328.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants