Bug 135866 - Built-in Promise API does not work with headless JSContexts
Summary: Built-in Promise API does not work with headless JSContexts
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-12 16:20 PDT by ide
Modified: 2017-07-11 03:41 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ide 2014-08-12 16:20:54 PDT
The built-in Promise implementation does not work with a JSContext that is not associated with a WebView/UIWebView/WKWebView and prints out the error, "Event loop not supported". For example, fulfilling a Promise calls "globalObject->queueMicrotask" which fails to invoke subscribed callbacks.

Sample code:

JSContext *context = [[JSContext alloc] init];
[context evaluateScript:@"Promise.resolve(42).then(function(result) { /*...*/ })"];
// Prints "ERROR: Event loop not supported."
Comment 1 ide 2017-07-11 03:41:56 PDT
This appears to have been fixed in iOS 10.0. The original sample code behaves as expected and also doesn't print an error message.

In iOS 10.3, async functions work too:
[_context evaluateScript:@"(async () => 42)().then(result => { /*...*/ })"];