mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Implemented Houdini worklets.
This commit is contained in:
parent
abb2985ffe
commit
af8436c9be
34 changed files with 1209 additions and 17 deletions
|
@ -23,12 +23,17 @@
|
|||
//! as JS roots.
|
||||
|
||||
use core::nonzero::NonZero;
|
||||
use dom::bindings::conversions::ToJSValConvertible;
|
||||
use dom::bindings::error::Error;
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::reflector::{DomObject, Reflector};
|
||||
use dom::bindings::trace::trace_reflector;
|
||||
use dom::promise::Promise;
|
||||
use js::jsapi::JSAutoCompartment;
|
||||
use js::jsapi::JSTracer;
|
||||
use libc;
|
||||
use script_thread::Runnable;
|
||||
use script_thread::ScriptThread;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use std::collections::hash_map::HashMap;
|
||||
|
@ -115,6 +120,40 @@ impl TrustedPromise {
|
|||
promise
|
||||
})
|
||||
}
|
||||
|
||||
/// A runnable which will reject the promise.
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn reject_runnable(self, error: Error) -> impl Runnable + Send {
|
||||
struct RejectPromise(TrustedPromise, Error);
|
||||
impl Runnable for RejectPromise {
|
||||
fn main_thread_handler(self: Box<Self>, script_thread: &ScriptThread) {
|
||||
let this = *self;
|
||||
let cx = script_thread.get_cx();
|
||||
let promise = this.0.root();
|
||||
let _ac = JSAutoCompartment::new(cx, promise.reflector().get_jsobject().get());
|
||||
promise.reject_error(cx, this.1);
|
||||
}
|
||||
}
|
||||
RejectPromise(self, error)
|
||||
}
|
||||
|
||||
/// A runnable which will resolve the promise.
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn resolve_runnable<T>(self, value: T) -> impl Runnable + Send where
|
||||
T: ToJSValConvertible + Send
|
||||
{
|
||||
struct ResolvePromise<T>(TrustedPromise, T);
|
||||
impl<T: ToJSValConvertible> Runnable for ResolvePromise<T> {
|
||||
fn main_thread_handler(self: Box<Self>, script_thread: &ScriptThread) {
|
||||
let this = *self;
|
||||
let cx = script_thread.get_cx();
|
||||
let promise = this.0.root();
|
||||
let _ac = JSAutoCompartment::new(cx, promise.reflector().get_jsobject().get());
|
||||
promise.resolve_native(cx, &this.1);
|
||||
}
|
||||
}
|
||||
ResolvePromise(self, value)
|
||||
}
|
||||
}
|
||||
|
||||
/// A safe wrapper around a raw pointer to a DOM object that can be
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue