WebKit Bugzilla
Attachment 346612 Details for
Bug 188247
: Implement self.queueMicrotask in Workers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188247-20180806140055.patch (text/plain), 10.00 KB, created by
Yusuke Suzuki
on 2018-08-05 22:00:56 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2018-08-05 22:00:56 PDT
Size:
10.00 KB
patch
obsolete
>Subversion Revision: 234586 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 35b4a0bee7cbfc70b72a03107b6fe4225ea06ee0..9f779c086e25704160a3e26d3d183a20cfbf290f 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,21 @@ >+2018-08-05 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ Implement self.queueMicrotask in Workers >+ https://bugs.webkit.org/show_bug.cgi?id=188247 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch adds support for self.queueMicrotask to workers. >+ >+ Tests: http/wpt/workers/queue-microtask.any.html >+ http/wpt/workers/queue-microtask.any.worker.html >+ >+ * bindings/js/JSWorkerGlobalScopeCustom.cpp: >+ (WebCore::JSWorkerGlobalScope::queueMicrotask): >+ * page/DOMWindow.idl: >+ Move queueMicrotask declaration to WindowOrWorkerGlobalScope.idl. >+ * page/WindowOrWorkerGlobalScope.idl: >+ > 2018-08-05 Yusuke Suzuki <utatane.tea@gmail.com> > > Add support for microtasks in workers >diff --git a/Source/WebCore/bindings/js/JSWorkerGlobalScopeCustom.cpp b/Source/WebCore/bindings/js/JSWorkerGlobalScopeCustom.cpp >index 56b37c6ca045f20a8a1d3442341ac1a7db83734a..0b7345ac11b3a4ae6b6dd17f296224d0dcb2572d 100644 >--- a/Source/WebCore/bindings/js/JSWorkerGlobalScopeCustom.cpp >+++ b/Source/WebCore/bindings/js/JSWorkerGlobalScopeCustom.cpp >@@ -27,6 +27,7 @@ > #include "JSWorkerGlobalScope.h" > > #include "WorkerGlobalScope.h" >+#include <JavaScriptCore/JSMicrotask.h> > > > namespace WebCore { >@@ -47,4 +48,21 @@ void JSWorkerGlobalScope::visitAdditionalChildren(SlotVisitor& visitor) > wrapped().visitJSEventListeners(visitor); > } > >+JSValue JSWorkerGlobalScope::queueMicrotask(ExecState& state) >+{ >+ VM& vm = state.vm(); >+ auto scope = DECLARE_THROW_SCOPE(vm); >+ >+ if (UNLIKELY(state.argumentCount() < 1)) >+ return throwException(&state, scope, createNotEnoughArgumentsError(&state)); >+ >+ JSValue functionValue = state.uncheckedArgument(0); >+ if (UNLIKELY(!functionValue.isFunction(vm))) >+ return JSValue::decode(throwArgumentMustBeFunctionError(state, scope, 0, "callback", "WorkerGlobalScope", "queueMicrotask")); >+ >+ scope.release(); >+ Base::queueMicrotask(JSC::createJSMicrotask(vm, functionValue)); >+ return jsUndefined(); >+} >+ > } // namespace WebCore >diff --git a/Source/WebCore/page/DOMWindow.idl b/Source/WebCore/page/DOMWindow.idl >index ff4d9575290b7643c7b99705d745ba9f2bbdba35..14c392d343ec6025da155d75509c31a84c0a68d7 100644 >--- a/Source/WebCore/page/DOMWindow.idl >+++ b/Source/WebCore/page/DOMWindow.idl >@@ -89,8 +89,6 @@ typedef USVString CSSOMString; > DOMString? prompt(optional DOMString message = "", optional DOMString defaultValue = ""); > void print(); > >- [Custom] void queueMicrotask(VoidCallback callback); >- > long requestAnimationFrame(RequestAnimationFrameCallback callback); // FIXME: Should return an unsigned long. > void cancelAnimationFrame(long handle); // FIXME: handle should be an unsigned long. > >diff --git a/Source/WebCore/page/WindowOrWorkerGlobalScope.idl b/Source/WebCore/page/WindowOrWorkerGlobalScope.idl >index a24f42617a481ca5098e133810c71203ad8ccce0..74db0b1307bade41296256ada5e0656d111e644f 100644 >--- a/Source/WebCore/page/WindowOrWorkerGlobalScope.idl >+++ b/Source/WebCore/page/WindowOrWorkerGlobalScope.idl >@@ -46,6 +46,8 @@ typedef (CanvasImageSource or Blob or ImageData) ImageBitmapSource; > [CallWith=ScriptState, MayThrowException] long setInterval(ScheduledAction handler, optional long timeout = 0, any... arguments); > void clearInterval(optional long handle = 0); > >+ [Custom] void queueMicrotask(VoidCallback callback); >+ > // Base64 utility methods. > [MayThrowException] DOMString atob(DOMString string); > [MayThrowException] DOMString btoa(DOMString string); >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 09f09c225aa06887f41ba8943a992a3c147c0e40..8751ed68a184bc619124eea7ec0f9b18060ce226 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,20 @@ >+2018-08-05 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ Implement self.queueMicrotask in Workers >+ https://bugs.webkit.org/show_bug.cgi?id=188247 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * http/wpt/workers/queue-microtask.any-expected.txt: Added. >+ * http/wpt/workers/queue-microtask.any.html: Added. >+ * http/wpt/workers/queue-microtask.any.js: Added. >+ (promise_test): >+ (promise_test.): >+ (queueMicrotask.promise_test): >+ (test): >+ * http/wpt/workers/queue-microtask.any.worker-expected.txt: Added. >+ * http/wpt/workers/queue-microtask.any.worker.html: Added. >+ > 2018-08-05 Yusuke Suzuki <utatane.tea@gmail.com> > > Add support for microtasks in workers >diff --git a/LayoutTests/http/wpt/workers/queue-microtask.any-expected.txt b/LayoutTests/http/wpt/workers/queue-microtask.any-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..38dcddebc132e76c4a6fdc672b5de26435887036 >--- /dev/null >+++ b/LayoutTests/http/wpt/workers/queue-microtask.any-expected.txt >@@ -0,0 +1,6 @@ >+ >+PASS Queued microtasks should be drained before executing macrotasks >+PASS queueMicrotask's callback has zero arguments and self as |this| >+PASS queueMicrotask and Promise uses the same Microtask queue >+PASS queueMicrotask should reject non-function arguments >+ >diff --git a/LayoutTests/http/wpt/workers/queue-microtask.any.html b/LayoutTests/http/wpt/workers/queue-microtask.any.html >new file mode 100644 >index 0000000000000000000000000000000000000000..2382913528e693b3a5d56c660a45060980b548c3 >--- /dev/null >+++ b/LayoutTests/http/wpt/workers/queue-microtask.any.html >@@ -0,0 +1 @@ >+<!-- This file is required for WebKit test infrastructure to run the templated test --> >\ No newline at end of file >diff --git a/LayoutTests/http/wpt/workers/queue-microtask.any.js b/LayoutTests/http/wpt/workers/queue-microtask.any.js >new file mode 100644 >index 0000000000000000000000000000000000000000..07327c0b94353d22dd9a422055d4b664c717ff55 >--- /dev/null >+++ b/LayoutTests/http/wpt/workers/queue-microtask.any.js >@@ -0,0 +1,93 @@ >+promise_test(() => { >+ var counter = 0; >+ self.queueMicrotask(() => { >+ assert_equals(counter++, 1); >+ self.queueMicrotask(() => { >+ assert_equals(counter++, 2); >+ }); >+ }); >+ var promise = new Promise((resolve, reject) => { >+ setTimeout(() => { >+ assert_equals(counter++, 3); >+ resolve(); >+ }, 0); >+ }); >+ assert_equals(counter++, 0); >+ return promise; >+}, `Queued microtasks should be drained before executing macrotasks`); >+ >+promise_test(() => { >+ return new Promise((resolve, reject) => { >+ self.queueMicrotask(function () { >+ try { >+ assert_equals(arguments.length, 0); >+ assert_equals(this, self); >+ self.queueMicrotask(function () { >+ try { >+ assert_equals(this, self); >+ self.queueMicrotask(function () { >+ 'use strict'; >+ try { >+ assert_equals(this, undefined); >+ resolve(); >+ } catch (e) { >+ reject(e); >+ } >+ }); >+ } catch (e) { >+ reject(e); >+ } >+ }); >+ } catch (e) { >+ reject(e); >+ } >+ }); >+ }); >+}, `queueMicrotask's callback has zero arguments and self as |this|`); >+ >+promise_test(() => { >+ return new Promise((resolve ,reject) => { >+ var counter = 0; >+ Promise.resolve().then(() => { >+ assert_equals(counter++, 1); >+ self.queueMicrotask(() => { >+ assert_equals(counter++, 3); >+ resolve(); >+ }); >+ }); >+ self.queueMicrotask(() => { >+ assert_equals(counter++, 2); >+ }); >+ assert_equals(counter++, 0); >+ }); >+}, `queueMicrotask and Promise uses the same Microtask queue`); >+ >+test(() => { >+ assert_throws(new TypeError, () => { >+ self.queueMicrotask(); >+ }); >+ assert_throws(new TypeError, () => { >+ self.queueMicrotask(null); >+ }); >+ assert_throws(new TypeError, () => { >+ self.queueMicrotask(undefined); >+ }); >+ assert_throws(new TypeError, () => { >+ self.queueMicrotask(42); >+ }); >+ assert_throws(new TypeError, () => { >+ self.queueMicrotask("42"); >+ }); >+ assert_throws(new TypeError, () => { >+ self.queueMicrotask(true); >+ }); >+ assert_throws(new TypeError, () => { >+ self.queueMicrotask(Symbol("42")); >+ }); >+ assert_throws(new TypeError, () => { >+ self.queueMicrotask({}); >+ }); >+ assert_throws(new TypeError, () => { >+ self.queueMicrotask({ handleEvent() { } }); >+ }); >+}, `queueMicrotask should reject non-function arguments`); >diff --git a/LayoutTests/http/wpt/workers/queue-microtask.any.worker-expected.txt b/LayoutTests/http/wpt/workers/queue-microtask.any.worker-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..38dcddebc132e76c4a6fdc672b5de26435887036 >--- /dev/null >+++ b/LayoutTests/http/wpt/workers/queue-microtask.any.worker-expected.txt >@@ -0,0 +1,6 @@ >+ >+PASS Queued microtasks should be drained before executing macrotasks >+PASS queueMicrotask's callback has zero arguments and self as |this| >+PASS queueMicrotask and Promise uses the same Microtask queue >+PASS queueMicrotask should reject non-function arguments >+ >diff --git a/LayoutTests/http/wpt/workers/queue-microtask.any.worker.html b/LayoutTests/http/wpt/workers/queue-microtask.any.worker.html >new file mode 100644 >index 0000000000000000000000000000000000000000..2382913528e693b3a5d56c660a45060980b548c3 >--- /dev/null >+++ b/LayoutTests/http/wpt/workers/queue-microtask.any.worker.html >@@ -0,0 +1 @@ >+<!-- This file is required for WebKit test infrastructure to run the templated test --> >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
rniwa
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188247
: 346612