fune/servo/components/script/dom/testworklet.rs
Alan Jeffrey 33d16ecbe0 servo: Merge #16814 - Implement Houdini worklets (from asajeffrey:script-worklets); r=jdm
<!-- Please describe your changes on the following line: -->

This PR implements the current draft Houdini Worklets specification (https://drafts.css-houdini.org/worklets/).

The implementation is intended to provide a responsive environment for worklet execution, and in particular to ensure that the primary worklet executor does not garbage collect, and does not block loading module code. The implementation does this by providing a thread pool, and performing GC and module loading in a backup thread, not in the primary thread.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #16206
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: ac99a48aeaa184d3acdb39d249636a140c4b7393

--HG--
rename : servo/components/script/dom/webidls/Function.webidl => servo/components/script/dom/webidls/VoidFunction.webidl
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : d4069e68d5b007ec258bf5821d6386a3ec63c490
2017-05-17 16:20:42 -05:00

61 lines
2.1 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// check-tidy: no specs after this line
use dom::bindings::codegen::Bindings::TestWorkletBinding::TestWorkletMethods;
use dom::bindings::codegen::Bindings::TestWorkletBinding::Wrap;
use dom::bindings::codegen::Bindings::WorkletBinding::WorkletBinding::WorkletMethods;
use dom::bindings::codegen::Bindings::WorkletBinding::WorkletOptions;
use dom::bindings::error::Fallible;
use dom::bindings::js::JS;
use dom::bindings::js::Root;
use dom::bindings::reflector::Reflector;
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::bindings::str::USVString;
use dom::promise::Promise;
use dom::window::Window;
use dom::worklet::Worklet;
use dom::workletglobalscope::WorkletGlobalScopeType;
use dom_struct::dom_struct;
use script_thread::ScriptThread;
use std::rc::Rc;
#[dom_struct]
pub struct TestWorklet {
reflector: Reflector,
worklet: JS<Worklet>,
}
impl TestWorklet {
fn new_inherited(worklet: &Worklet) -> TestWorklet {
TestWorklet {
reflector: Reflector::new(),
worklet: JS::from_ref(worklet),
}
}
fn new(window: &Window) -> Root<TestWorklet> {
let worklet = Worklet::new(window, WorkletGlobalScopeType::Test);
reflect_dom_object(box TestWorklet::new_inherited(&*worklet), window, Wrap)
}
pub fn Constructor(window: &Window) -> Fallible<Root<TestWorklet>> {
Ok(TestWorklet::new(window))
}
}
impl TestWorkletMethods for TestWorklet {
#[allow(unrooted_must_root)]
fn AddModule(&self, moduleURL: USVString, options: &WorkletOptions) -> Rc<Promise> {
self.worklet.AddModule(moduleURL, options)
}
fn Lookup(&self, key: DOMString) -> Option<DOMString> {
let id = self.worklet.worklet_id();
let pool = ScriptThread::worklet_thread_pool();
pool.test_worklet_lookup(id, String::from(key)).map(DOMString::from)
}
}