My test code is as follows. 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();
Hmm, it seems that find route of issue. At start execution of arrow function we load _this_ from virtual scope and put it to _this_ register, but when we suspend async arrow function and resume after await, we resume with value from generator.@generatorThis, that is empty. I'll try to prepare fix during today.
Created attachment 298574 [details] Patch patch
Created attachment 298665 [details] Patch Update readme
Comment on attachment 298665 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=298665&action=review r=me > Source/JavaScriptCore/ChangeLog:10 > + Async arrow function can be suspende and during resuming shold be use _this_ from "suspende" => "suspended" "and during resuming shold be use _this_" => "and when resumed should use _this_" > JSTests/stress/async-arrow-functions-lexical-binding-in-class.js:52 > asyncThisPropBody() { Can you also add some tests where we bind various "this" values and make sure we get the correct result.
All reviewed patches have been landed. Committed r210925: <http://trac.webkit.org/changeset/210925>
Comment on attachment 298665 [details] Patch Clearing flags on attachment: 298665 Patch landed
(In reply to comment #0) > My test code is as follows. > > 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(); Shuan Zhao, Could you please check if issue is fixed and close it? I don't have permissions to do this.
Shuan Zhao, Thanks for filling and closing issue :-)! Saam Barati, Thanks for review!