| Summary: | Built-in Promise API does not work with headless JSContexts | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | ide |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | benjamin, fpizlo, ggaren, sam, ysuzuki |
| Priority: | P2 | ||
| Version: | 528+ (Nightly build) | ||
| Hardware: | All | ||
| OS: | All | ||
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 => { /*...*/ })"];
|
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."