Bug 189799 - [JSC] ForStatement should call CreatePerIterationEnvironment before first iteration
Summary: [JSC] ForStatement should call CreatePerIterationEnvironment before first ite...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Alexey Shvayka
URL:
Keywords: InRadar
: 257677 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-09-20 12:56 PDT by Dasa Paddock
Modified: 2023-10-23 10:32 PDT (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dasa Paddock 2018-09-20 12:56:54 PDT
Test code:

let callback1;
let callbacks2 = new Array();
let callbacks3 = new Array();

for (
    let i = (callback1 = () => i, 0);
    callbacks2.push(() => i), i < 5;
    callbacks3.push(() => i), i++) {
    // loop body
    i++;
}

console.log(callback1());
console.log(callbacks2[0]());
console.log(callbacks3[0]());

Expected output (works in Chrome and Firefox)

0
1
3

Actual output in Safari TP 65:

1
1
3

Note: I found this test code at: https://github.com/Microsoft/TypeScript/issues/17632
Comment 1 Radar WebKit Bug Importer 2018-09-24 10:36:03 PDT
<rdar://problem/44730906>
Comment 2 Saam Barati 2018-09-24 11:19:26 PDT
Thanks for the report. It looks like Chrome and Firefox are correct w.r.t the spec:
https://tc39.github.io/ecma262/#sec-for-statement-runtime-semantics-labelledevaluation
Comment 3 Rick Waldron 2020-09-03 06:25:42 PDT
Just marking this as "covered" in Test262. https://github.com/tc39/test262/blob/master/test/language/statements/for/scope-body-lex-open.js
Comment 4 Dasa Paddock 2022-02-09 13:45:29 PST
I'm not sure when this was fixed, but I'm unable to repro in Safari 15.3.
Comment 5 Dasa Paddock 2022-02-09 13:48:37 PST
Sorry for the noise, this is still broken in Safari 15.3 and Safari TP 139.
Comment 6 Dasa Paddock 2023-08-22 17:09:49 PDT
This is still broken in Safari TP 177.
Comment 7 Alexey Shvayka 2023-10-11 16:53:22 PDT
*** Bug 257677 has been marked as a duplicate of this bug. ***
Comment 8 Alexey Shvayka 2023-10-22 16:03:56 PDT
Pull request: https://github.com/WebKit/WebKit/pull/19403
Comment 9 EWS 2023-10-23 10:32:43 PDT
Committed 269653@main (f32cd0f7cb79): <https://commits.webkit.org/269653@main>

Reviewed commits have been landed. Closing PR #19403 and removing active labels.