WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
188212
Add self.queueMicrotask(f) on DOMWindow
https://bugs.webkit.org/show_bug.cgi?id=188212
Summary
Add self.queueMicrotask(f) on DOMWindow
Ryosuke Niwa
Reported
2018-07-31 20:32:26 PDT
See
https://github.com/whatwg/html/issues/512
Attachments
Patch
(16.42 KB, patch)
2018-08-01 07:22 PDT
,
Yusuke Suzuki
no flags
Details
Formatted Diff
Diff
Patch
(10.79 KB, patch)
2018-08-01 20:09 PDT
,
Yusuke Suzuki
no flags
Details
Formatted Diff
Diff
Patch
(11.78 KB, patch)
2018-08-01 20:19 PDT
,
Yusuke Suzuki
no flags
Details
Formatted Diff
Diff
Patch
(11.79 KB, patch)
2018-08-01 20:21 PDT
,
Yusuke Suzuki
rniwa
: review+
Details
Formatted Diff
Diff
Show Obsolete
(3)
View All
Add attachment
proposed patch, testcase, etc.
Yusuke Suzuki
Comment 1
2018-08-01 07:22:16 PDT
Created
attachment 346275
[details]
Patch
Ryosuke Niwa
Comment 2
2018-08-01 14:43:33 PDT
Comment on
attachment 346275
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=346275&action=review
> Source/WebCore/workers/WorkerGlobalScope.cpp:256 > + postTask([callback = WTFMove(callback)](ScriptExecutionContext&) {
How can this be correct? Microtasks & tasks are completely different concepts & timing.
Domenic Denicola
Comment 3
2018-08-01 14:49:25 PDT
Spec:
https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#microtask-queuing
Tests:
https://github.com/web-platform-tests/wpt/pull/6334
Ryosuke Niwa
Comment 4
2018-08-01 14:53:56 PDT
Comment on
attachment 346275
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=346275&action=review
>> Source/WebCore/workers/WorkerGlobalScope.cpp:256 >> + postTask([callback = WTFMove(callback)](ScriptExecutionContext&) { > > How can this be correct? Microtasks & tasks are completely different concepts & timing.
I think we need to hook into JSC's microtask queue instead here.
Yusuke Suzuki
Comment 5
2018-08-01 19:44:28 PDT
Comment on
attachment 346275
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=346275&action=review
>>> Source/WebCore/workers/WorkerGlobalScope.cpp:256 >>> + postTask([callback = WTFMove(callback)](ScriptExecutionContext&) { >> >> How can this be correct? Microtasks & tasks are completely different concepts & timing. > > I think we need to hook into JSC's microtask queue instead here.
"How can this be correct? Microtasks & tasks are completely different concepts & timing." Yes, this is correct in terms of our current implementation. Unfortunately, our Worker does not support Microtasks as our main thread does. So this code is the same to the current Worker's microtask queuing mechanism. We can find that JSWorkerGlobalScopeBase::queueTaskToEventLoop does the same thing, while JSDOMWindowBase::queueTaskToEventLoop posts microtasks correctly. "I think we need to hook into JSC's microtask queue instead here." The current approach against using JSC's microtask queue has Pros and Cons. Pros: - It skips one level indirection (JSC -> WebCore through function pointer) - It leverages binding VoidCallback type checking instead of manually typechecking in custom binding code Cons: - It does not use JSC's microtask stack, consistency Given that this `self.queueMicrotask` is performance-sensitive (If it is not performance-sensitive, we can just use `Promise.resolve().then(callback)`), and I prefer non-custom binding code, I took the current approach in this patch. But if the consistency is preferable, we can use JSC's stack in binding custom code. I'll upload this version.
Ryosuke Niwa
Comment 6
2018-08-01 19:58:26 PDT
Here's a problem though. If the worker ever supports a feature which schedules a task, then all microtasks are supposed to be drained before such a task is executed. The proposed patch doesn't implement this semantics. I don't think we want to be in the business of auditing everything worker supports and making sure they never schedules a task.
Yusuke Suzuki
Comment 7
2018-08-01 20:03:59 PDT
(In reply to Ryosuke Niwa from
comment #6
)
> Here's a problem though. > > If the worker ever supports a feature which schedules a task, then all > microtasks are supposed to be drained before such a task is executed. The > proposed patch doesn't implement this semantics. > > I don't think we want to be in the business of auditing everything worker > supports and making sure they never schedules a task.
OK, then, I'll implement only DOM window version for now.
Yusuke Suzuki
Comment 8
2018-08-01 20:09:44 PDT
Created
attachment 346353
[details]
Patch
Yusuke Suzuki
Comment 9
2018-08-01 20:19:31 PDT
Created
attachment 346354
[details]
Patch
Yusuke Suzuki
Comment 10
2018-08-01 20:21:27 PDT
Created
attachment 346355
[details]
Patch
Ryosuke Niwa
Comment 11
2018-08-01 20:26:17 PDT
Comment on
attachment 346355
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=346355&action=review
> Source/JavaScriptCore/runtime/JSJob.cpp:-48 > - virtual ~JSJobMicrotask()
Where did the destructor go?
> Source/WebCore/page/DOMWindow.idl:92 > + [Custom] void queueMicrotask(VoidCallback callback);
So we're not gonna implement the one in worker??
Ryosuke Niwa
Comment 12
2018-08-01 20:28:17 PDT
Comment on
attachment 346355
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=346355&action=review
> Source/JavaScriptCore/runtime/JSJob.cpp:60 > +Ref<Microtask> createJSJob(VM& vm, JSValue job)
I think we should call this createJSTask instead to use the consistent terminology.
Yusuke Suzuki
Comment 13
2018-08-01 20:28:30 PDT
Comment on
attachment 346355
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=346355&action=review
>> Source/JavaScriptCore/runtime/JSJob.cpp:-48 >> - virtual ~JSJobMicrotask() > > Where did the destructor go?
Microtask has `virtual ~Microtask()`, so this is not necessary.
>> Source/WebCore/page/DOMWindow.idl:92 >> + [Custom] void queueMicrotask(VoidCallback callback); > > So we're not gonna implement the one in worker??
Yes, we will implement it after MicrotaskQueue is adopted in worker environments.
Ryosuke Niwa
Comment 14
2018-08-01 20:29:24 PDT
Comment on
attachment 346355
[details]
Patch Sounds good to me.
Ryosuke Niwa
Comment 15
2018-08-01 20:29:43 PDT
Let's file a bug for the worker one so that we don't forget though.
Yusuke Suzuki
Comment 16
2018-08-01 20:33:14 PDT
Comment on
attachment 346355
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=346355&action=review
>> Source/JavaScriptCore/runtime/JSJob.cpp:60 >> +Ref<Microtask> createJSJob(VM& vm, JSValue job) > > I think we should call this createJSTask instead to use the consistent terminology.
The interesting thing is that this "Job" is a word used in ECMA262 :P
https://tc39.github.io/ecma262/#sec-enqueuejob
Using a word "microtask" in WebKit tree consistently sounds fine. Fixed.
>>> Source/WebCore/page/DOMWindow.idl:92 >>> + [Custom] void queueMicrotask(VoidCallback callback); >> >> So we're not gonna implement the one in worker?? > > Yes, we will implement it after MicrotaskQueue is adopted in worker environments.
The interesting thing is that this "Job" is a word used in ECMA262 :P
https://tc39.github.io/ecma262/#sec-enqueuejob
Using a word "microtask" in WebKit tree consistently sounds fine. Fixed.
Yusuke Suzuki
Comment 17
2018-08-01 20:37:10 PDT
(In reply to Ryosuke Niwa from
comment #15
)
> Let's file a bug for the worker one so that we don't forget though.
OK, filed in
bug 188246
and
bug 188247
Ryosuke Niwa
Comment 18
2018-08-01 20:38:12 PDT
Oh, you're right:
https://html.spec.whatwg.org/#integration-with-the-javascript-job-queue
But I think the definition of job there is slightly different from what we're doing here.
Yusuke Suzuki
Comment 19
2018-08-01 20:55:52 PDT
Committed
r234491
: <
https://trac.webkit.org/changeset/234491
>
Radar WebKit Bug Importer
Comment 20
2018-08-01 21:07:52 PDT
<
rdar://problem/42841210
>
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