Skip to content

Instantly share code, notes, and snippets.

@jorendorff
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorendorff/8724830 to your computer and use it in GitHub Desktop.
Save jorendorff/8724830 to your computer and use it in GitHub Desktop.
/*
* Sketch of the API surface we would need to expose
* in order to shift the Promise implementation from dom to js/src.
*/
namespace JS {
/*
* Microtask API.
*
* SpiderMonkey does not have its own event queue implementation. If an
* embedding supports Promises, it must provide an event queue
* implementation by calling SetEnqueueMicrotaskCallback. Promise objects
* will then use that callback to put Microtask pointers into the queue,
* and the embedding is responsibile for calling RunMicrotask on each of
* those pointers eventually.
*/
struct Microtask;
/*
* The embedding provides a callback for registering a microtask.
*/
typedef bool (*EnqueueMicrotaskCallback)(JSContext *cx, Microtask *utask);
JS_PUBLIC_API(bool)
SetEnqueueMicrotaskCallback(JSRuntime *rt, EnqueueMicrotaskCallback cb);
/*
* Execute a microtask. The event loop calls this. Call it only once per
* Microtask; on success or failure the microtask object is freed.
*/
JS_PUBLIC_API(bool)
RunMicrotask(JSContext *cx, Microtask *utask);
/*
* Drop a microtask without running it.
*/
JS_PUBLIC_API(bool)
DestroyMicrotask(JSContext *cx, Microtask *utask);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment