[Webkit-unassigned] [Bug 223533] Variable incorrectly hoisted when it has the same name as a parameter

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jan 10 19:05:52 PST 2023


https://bugs.webkit.org/show_bug.cgi?id=223533

Ross Kirsling <ross.kirsling at sony.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://bugs.webkit.org/sho
                   |                            |w_bug.cgi?id=164087

--- Comment #6 from Ross Kirsling <ross.kirsling at sony.com> ---
(Moving my December investigation comments over from Slack...)


This is a surprisingly tricky matter -- it's basically rooted in bug 164087, the fact that our implementation separates async and generator functions into "wrapper" and "body" functions.

This separation makes it incorrect for us to hoist var decls to the top of the body, since:
> async function f(foo) { print(foo); var foo; } f('blah');
would have hoisting behavior analogous to...
> function f(foo) { (function () { print(foo); var foo; })(); } f('blah');
when it would need to be like...
> function f(foo) { (function () { print(foo); })(); var foo; } f('blah');

It's not entirely clear what the appropriate solution is here.

1. If we really view the wrapper/body separation as a mistake, then the current problem would just be a direct result of that mistake.

2. If not, then we need magic to happen, relative to normal nested function behavior...but the magic can't depend on actually *checking* whether the var shadows a param, because we literally don't have that information when reparsing the body (i.e. hasDeclaredParameter isn't valid to call at that timing because the wrapper scope, where the params actually live, is already gone).

2a. Like, we can pretend that the real var decl was up in the wrapper scope and "unconditionally use" it in the body instead, but this falls apart for cases where there wasn't actually a param to capture (i.e. we end up setting to a global).

2b. So maybe it's that the param should come down to the body scope...but I'm not quite sure how we'd mean for this to happen. It's clear that a lot of work was done in order to propagate the `arguments` object down into the body, but then we're also taking great care to not bring any unnecessary individual params down, so it seems like we just end up at the same place: the body needs to be able to say that a given param is "necessary".

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20230111/a9faab97/attachment.htm>


More information about the webkit-unassigned mailing list