[Webkit-unassigned] [Bug 160955] [ES2016] Allow assignment in for-in head in not-strict mode

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Aug 23 11:43:11 PDT 2016


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

--- Comment #12 from GSkachkov <gskachkov at gmail.com> ---
(In reply to comment #11)
> Comment on attachment 286712 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=286712&action=review
> 
> r=me with one request:
> 
> Can you see what should be done for the following type of programs:
> ```
> function foo() {
>     {
>         let x = 50;
>         for (var x = 25 in {}) { }
>         // what is x here?
>     }
>     // and what is x here?
> }
> foo();
> 
> and
> 
> function foo() {
>     {
>         const x = 50;
>         for (var x = 25 in {}) { }
>        // Should we throw a const assignment error?
>     }
> }
> foo();
> ```
> Currently, both Firefox and Chrome throw syntax errors for these programs.
> However, I suspect that's not the correct behavior as defined by the spec.
> If it is, we should also throw a syntax error. If it isn't, we should make
> sure we do the right thing. I suspect that in the first example,
> in the "let x" scope, x should be 25. In the "var" scope of the function, I
> suspect x should be undefined. But who knows.
> 
> > Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:2560
> > +void ForInNode::emitResolveVariable(BytecodeGenerator& generator, RegisterID* propertyName, const Identifier& ident)
> 
> Suggestion: An alternative to defining a method is you can just use a local
> lambda inside the ::emitLoopHeader that does this.

Hmm, it is good question.
I think it should behave in the same way as work without for..in, and this annex to spec should not modify this behavior so it currently work in this way
function foo() {
    {
         let x = 50;
         var x = 25;
         debug(x); // 25
     }
     debug(x); // undefined
}
foo();
//////////////////////
function foo() {
    {
         const x = 50;
         var x = 25;
         debug(x); // Syntax Error
     }
     debug(x); // undefined
}
foo();
with for..in it works in the same way.
Should I add tests for this cases?

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20160823/a3613417/attachment.html>


More information about the webkit-unassigned mailing list