Bug 146828 - Integrate automatic microtask draining into JSC framework and re-enable Promise
Summary: Integrate automatic microtask draining into JSC framework and re-enable Promise
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-10 01:53 PDT by Yusuke Suzuki
Modified: 2015-07-17 16:20 PDT (History)
4 users (show)

See Also:


Attachments
Patch (18.23 KB, patch)
2015-07-13 05:44 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (18.27 KB, patch)
2015-07-13 07:53 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (18.27 KB, patch)
2015-07-13 08:01 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (18.25 KB, patch)
2015-07-13 08:11 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (18.55 KB, patch)
2015-07-14 10:17 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (18.55 KB, patch)
2015-07-14 10:31 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (18.48 KB, patch)
2015-07-16 09:06 PDT, Yusuke Suzuki
sam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2015-07-10 01:53:59 PDT
https://lists.webkit.org/pipermail/webkit-dev/2015-July/027531.html

Add default microtask system to JSC framework and draining the tasks when apilock depth becomes 0.
Comment 1 Yusuke Suzuki 2015-07-13 05:44:22 PDT
Created attachment 256694 [details]
Patch
Comment 2 Saam Barati 2015-07-13 07:10:39 PDT
Comment on attachment 256694 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256694&action=review

Looks good to me.

> Source/JavaScriptCore/API/tests/testapi.c:1862
> +            JSStringRef undefined = JSStringCreateWithUTF8CString("function");

This should be renamed to "function" or something like that.
Comment 3 Saam Barati 2015-07-13 07:24:02 PDT
Comment on attachment 256694 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256694&action=review

> Source/JavaScriptCore/jsc.cpp:1404
> +        globalObject->vm().drainMicrotasks();

Will this handle the nested queuing of microtasks?
Comment 4 Yusuke Suzuki 2015-07-13 07:47:18 PDT
Comment on attachment 256694 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256694&action=review

I'll update the patch to pass the build in OSX (adding export macro to the specific method).

>> Source/JavaScriptCore/jsc.cpp:1404
>> +        globalObject->vm().drainMicrotasks();
> 
> Will this handle the nested queuing of microtasks?

Yes. In drainMicrotasks, we consumes the microtasks like the following,

    while (!m_microtaskQueue.isEmpty())
        m_microtaskQueue.takeFirst()->run();

During the microtask execution, the new microtask may be enqueued.
In that case, the queue becomes non empty and we'll drain it in the next loop iteration.
I added the test for this case in js/promise-nested-microtasks :)
Comment 5 Yusuke Suzuki 2015-07-13 07:53:23 PDT
Created attachment 256697 [details]
Patch
Comment 6 Yusuke Suzuki 2015-07-13 08:01:05 PDT
Created attachment 256699 [details]
Patch
Comment 7 Yusuke Suzuki 2015-07-13 08:11:37 PDT
Created attachment 256700 [details]
Patch
Comment 8 Yusuke Suzuki 2015-07-13 08:13:09 PDT
Currently I'm checking GTK port environment.
I'll check it in OSX to pass the build.
Comment 9 Yusuke Suzuki 2015-07-14 02:46:37 PDT
OK, could you take a look?
Comment 10 Saam Barati 2015-07-14 09:23:54 PDT
Comment on attachment 256700 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256700&action=review

Looks good to me. I'd r+ if I could.

> Source/JavaScriptCore/API/tests/testapi.c:1862
> +            JSStringRef undefined = JSStringCreateWithUTF8CString("function");

Name this variable "function" or something similar

> LayoutTests/js/script-tests/promise-nested-microtasks.js:26
> +debug('The promise is not fulfilled now.');

Maybe call this:
"The promise is not fulfilled until after this function call executes"
Comment 11 Yusuke Suzuki 2015-07-14 10:13:35 PDT
Comment on attachment 256700 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256700&action=review

Thanks!

>> Source/JavaScriptCore/API/tests/testapi.c:1862
>> +            JSStringRef undefined = JSStringCreateWithUTF8CString("function");
> 
> Name this variable "function" or something similar

Oops! Thanks, nice catch.
I'll fix it :D

>> LayoutTests/js/script-tests/promise-nested-microtasks.js:26
>> +debug('The promise is not fulfilled now.');
> 
> Maybe call this:
> "The promise is not fulfilled until after this function call executes"

Looks nice. Fixed.
Comment 12 Yusuke Suzuki 2015-07-14 10:17:55 PDT
Created attachment 256775 [details]
Patch
Comment 13 Yusuke Suzuki 2015-07-14 10:31:32 PDT
Created attachment 256777 [details]
Patch
Comment 14 Yusuke Suzuki 2015-07-16 09:06:19 PDT
Created attachment 256902 [details]
Patch
Comment 15 Yusuke Suzuki 2015-07-16 09:07:19 PDT
Hi, could anyone take a look?
Comment 16 Sam Weinig 2015-07-17 15:33:02 PDT
Comment on attachment 256902 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256902&action=review

> Source/JavaScriptCore/runtime/VM.h:615
> +    WTF::Deque<std::unique_ptr<QueuedTask>> m_microtaskQueue;

I don't think the WTF is needed here.
Comment 17 Yusuke Suzuki 2015-07-17 15:41:14 PDT
Comment on attachment 256902 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256902&action=review

Thank you for your review!

>> Source/JavaScriptCore/runtime/VM.h:615
>> +    WTF::Deque<std::unique_ptr<QueuedTask>> m_microtaskQueue;
> 
> I don't think the WTF is needed here.

Dropped `WTF::`.
Comment 18 Yusuke Suzuki 2015-07-17 15:41:58 PDT
Committed r186966: <http://trac.webkit.org/changeset/186966>
Comment 19 Yusuke Suzuki 2015-07-17 15:58:16 PDT
I'm now creating the follow up patch.
Comment 20 Yusuke Suzuki 2015-07-17 16:20:06 PDT
Committed r186970: <http://trac.webkit.org/changeset/186970>