Restricted JS Execution Contexts

From MozillaWiki
Jump to: navigation, search

Various Web platform features have a need for script to run in "restricted contexts", where some features accessible to regular main-thread page JS are not available.

Audio Workers

Web Audio wants an "audio worker" --- processing audio samples on a real-time audio thread. Hopefully small snippets of code doing small amounts of work on each callback (e.g. processing 128 audio samples).

Vertex Shaders

For CSS Filter-ish use-cases, we want to be able to generate meshes by applying a JS function to vertices of a grid, mapping 2D points to 2D points.

UI Workers

When the compositor is rendering a frame, it might want to call into a "UI worker" to apply Web-author generated effects that can't be implemented efficiently/smoothly on the main thread, e.g. computing new transform offsets for the rendering of particular elements.

CSS Style Callbacks

To extend the CSS style system, we want to provide callbacks that run during style computation to parse values and generate computed style values.

CSS Layout Callbacks

To extend CSS layout, we want to provide callbacks that run during layout, to layout the contents of container elements.

CSS Painting Callbacks

To extend CSS painting, we want to provide callbacks that run during painting, to paint the contents of elements.

APIWork per callbackRetain state between callbacks?Isolated worlds per pageImpose time limitSend/receive messagesOther Web platform APIs neededNeed to prevent access to other APIs
Audio workersVery littleYesdozensYesYesMinimalNo
Vertex shadersVery littleNoflexibleMaybeNoMinimalMaybe
UI workersLittleYesFewYesYesCanvas, maybe othersNo
CSS style extensionsVery littleNolotsNoNoMinimalYes
CSS layout extensionsLots (e.g. constraint solving)Yes (caching)potentially lotsNoNoMinimalYes
CSS painting extensionsPotentially a lotprobably notdozensNoNoCanvasYes