Implemented paint worklets invoking worklet scripts.

This commit is contained in:
Alan Jeffrey 2017-06-05 13:49:27 -05:00
parent 9a13cf6bda
commit 3db4761767
20 changed files with 575 additions and 19 deletions

View file

@ -32,6 +32,7 @@
//! | sequences | `Vec<T>` |
//! | union types | `T` |
use dom::bindings::error::{Error, Fallible};
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::num::Finite;
@ -48,15 +49,15 @@ use js::glue::{GetProxyPrivate, IsWrapper};
use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT};
use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING, UnwrapObject};
use js::jsapi::{HandleId, HandleObject, HandleValue, JSContext, JSObject, JSString};
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetReservedSlot};
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_IsArrayObject};
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetProperty, JS_GetReservedSlot};
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_IsArrayObject, JS_IsExceptionPending};
use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars, MutableHandleValue};
use js::jsval::{ObjectValue, StringValue};
use js::jsval::{ObjectValue, StringValue, UndefinedValue};
use js::rust::{ToString, get_object_class, is_dom_class, is_dom_object, maybe_wrap_value};
use libc;
use num_traits::Float;
use servo_config::opts;
use std::{char, ptr, slice};
use std::{char, ffi, ptr, slice};
/// A trait to check whether a given `JSObject` implements an IDL interface.
pub trait IDLInterface {
@ -481,3 +482,45 @@ pub unsafe fn is_array_like(cx: *mut JSContext, value: HandleValue) -> bool {
assert!(JS_IsArrayObject(cx, value, &mut result));
result
}
/// Get a property from a JS object.
pub unsafe fn get_property_jsval(cx: *mut JSContext,
object: HandleObject,
name: &str,
rval: MutableHandleValue)
-> Fallible<()>
{
rval.set(UndefinedValue());
let cname = match ffi::CString::new(name) {
Ok(cname) => cname,
Err(_) => return Ok(()),
};
JS_GetProperty(cx, object, cname.as_ptr(), rval);
if JS_IsExceptionPending(cx) {
return Err(Error::JSFailed);
}
Ok(())
}
/// Get a property from a JS object, and convert it to a Rust value.
pub unsafe fn get_property<T>(cx: *mut JSContext,
object: HandleObject,
name: &str,
option: T::Config)
-> Fallible<Option<T>> where
T: FromJSValConvertible
{
debug!("Getting property {}.", name);
rooted!(in(cx) let mut result = UndefinedValue());
get_property_jsval(cx, object, name, result.handle_mut())?;
if result.is_undefined() {
debug!("No property {}.", name);
return Ok(None);
}
debug!("Converting property {}.", name);
match T::from_jsval(cx, result.handle(), option) {
Ok(ConversionResult::Success(value)) => Ok(Some(value)),
Ok(ConversionResult::Failure(_)) => Ok(None),
Err(()) => Err(Error::JSFailed),
}
}