WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
CLOSED FIXED
166919
"this" missing after await in async arrow function
https://bugs.webkit.org/show_bug.cgi?id=166919
Summary
"this" missing after await in async arrow function
Shuan Zhao
Reported
2017-01-10 23:59:47 PST
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();
Attachments
Patch
(7.43 KB, patch)
2017-01-11 06:20 PST
,
GSkachkov
no flags
Details
Formatted Diff
Diff
Patch
(7.56 KB, patch)
2017-01-11 23:55 PST
,
GSkachkov
no flags
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
GSkachkov
Comment 1
2017-01-11 04:01:37 PST
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.
GSkachkov
Comment 2
2017-01-11 06:20:08 PST
Created
attachment 298574
[details]
Patch patch
GSkachkov
Comment 3
2017-01-11 23:55:06 PST
Created
attachment 298665
[details]
Patch Update readme
Saam Barati
Comment 4
2017-01-15 12:36:17 PST
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.
GSkachkov
Comment 5
2017-01-19 10:35:26 PST
All reviewed patches have been landed. Committed
r210925
: <
http://trac.webkit.org/changeset/210925
>
GSkachkov
Comment 6
2017-01-20 11:57:48 PST
Comment on
attachment 298665
[details]
Patch Clearing flags on attachment: 298665 Patch landed
GSkachkov
Comment 7
2017-01-20 12:02:11 PST
(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.
GSkachkov
Comment 8
2017-01-21 03:38:06 PST
Shuan Zhao, Thanks for filling and closing issue :-)! Saam Barati, Thanks for review!
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug