Summary: | Calling async arrow function which is in a class's member function will cause error | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Shuan Zhao <hszhsh> | ||||
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> | ||||
Status: | RESOLVED FIXED | ||||||
Severity: | Normal | CC: | caitp, commit-queue, gskachkov, keith_miller, lzsoft.cja, mark.lam, msaboff, saam, ysuzuki | ||||
Priority: | P2 | ||||||
Version: | WebKit Nightly Build | ||||||
Hardware: | All | ||||||
OS: | All | ||||||
Attachments: |
|
Description
Shuan Zhao
2017-01-09 23:12:50 PST
I think root of the issue because property @derivedConstructor is not put to the virtual scope in testFunc. When we implemented simple arrow function we check if we super used inside and do put derivedConstructor to the virtual scope, before it it used within arrow function. So I think solution is adding additional check (generator.isSuperUsedInInnerArrowFunction()) in this line https://github.com/WebKit/webkit/blob/master/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp#L3505 If I'll try to prepare fix, but it will be later today. Created attachment 298461 [details]
Patch
Fix for the issue
Comment on attachment 298461 [details] Patch Clearing flags on attachment: 298461 Committed r210558: <http://trac.webkit.org/changeset/210558> All reviewed patches have been landed. Closing bug. I see this issue is solved, but there's another problem. I have updated the test code: function runSomething(callback) { callback(); } class Test { testFunc() { this.prop = "123"; runSomething(async () => { console.log("callback " + this.prop); // It's ok here await sleep(2); console.log("callback end " + this.prop); // TypeError: undefined is not an object (evaluating 'this.prop') }); } } let t = new Test(); t.testFunc(); Is it another bug? The code above is ok with V8. (In reply to comment #5) > I see this issue is solved, but there's another problem. I have updated the > test code: > > function runSomething(callback) { > callback(); > } > > class Test { > testFunc() { > this.prop = "123"; > runSomething(async () => { > console.log("callback " + this.prop); // It's ok here > await sleep(2); > console.log("callback end " + this.prop); // TypeError: undefined is not > an object (evaluating 'this.prop') > }); > } > } > > let t = new Test(); > t.testFunc(); > > Is it another bug? The code above is ok with V8. Yeah, unfortunately it is another bug. Async arrow function 'lost' _this_, by some reason, during restore state after await. This bug is confirmed fixed in Safari Tech Preview as on May 21st, 2017. However, the current Safari macOS/iOS (10.1.1/10.3.2) still has it. Is there an ETA for the fix to be landed on normal Safari? In other words, how often does the push happens from Safari Tech Preview to Safari? Thanks! (In reply to JingAn Chen from comment #7) > This bug is confirmed fixed in Safari Tech Preview as on May 21st, 2017. > However, the current Safari macOS/iOS (10.1.1/10.3.2) still has it. Is there > an ETA for the fix to be landed on normal Safari? In other words, how often > does the push happens from Safari Tech Preview to Safari? Thanks! This is the WebKit bug tracker. We don't comment on Safari release plans here. |