Update to new JS runtime creation APIs.

This commit is contained in:
Josh Matthews 2018-12-02 14:23:09 -05:00
parent b1a4913b3f
commit 644101e1e4
5 changed files with 17 additions and 22 deletions

View file

@ -63,6 +63,7 @@ indexmap = "1.0.2"
ipc-channel = "0.11"
itertools = "0.8"
jstraceable_derive = {path = "../jstraceable_derive"}
js = {package = "mozjs", version = "0.10.0"}
keyboard-types = "0.4.4"
lazy_static = "1"
libc = "0.2"
@ -114,9 +115,3 @@ webvr_traits = {path = "../webvr_traits"}
[target.'cfg(not(target_os = "ios"))'.dependencies]
mozangle = "0.1"
[target.'cfg(target_os = "android")'.dependencies]
js = {package = "mozjs", version = "0.9.5", features=["init_once"]}
[target.'cfg(not(target_os = "android"))'.dependencies]
js = {package = "mozjs", version = "0.9.5"}

View file

@ -2592,7 +2592,7 @@ class CGConstructorEnabled(CGAbstractMethod):
return CGList((CGGeneric(cond) for cond in conditions), " &&\n")
def CreateBindingJSObject(descriptor, parent=None):
def CreateBindingJSObject(descriptor):
assert not descriptor.isGlobal()
create = "let raw = Box::into_raw(object);\nlet _rt = RootedTraceable::new(&*raw);\n"
if descriptor.proxy:
@ -2601,12 +2601,11 @@ let handler = RegisterBindings::PROXY_HANDLERS[PrototypeList::Proxies::%s as usi
rooted!(in(cx) let private = PrivateValue(raw as *const libc::c_void));
let obj = NewProxyObject(cx, handler,
Handle::from_raw(UndefinedHandleValue),
proto.get(), %s.get(),
ptr::null_mut(), ptr::null_mut());
proto.get());
assert!(!obj.is_null());
SetProxyReservedSlot(obj, 0, &private.get());
rooted!(in(cx) let obj = obj);\
""" % (descriptor.name, parent)
""" % (descriptor.name)
else:
create += ("rooted!(in(cx) let obj = JS_NewObjectWithGivenProto(\n"
" cx, &Class.base as *const JSClass, proto.handle()));\n"
@ -2699,7 +2698,7 @@ class CGWrapMethod(CGAbstractMethod):
def definition_body(self):
unforgeable = CopyUnforgeablePropertiesToInstance(self.descriptor)
create = CreateBindingJSObject(self.descriptor, "scope")
create = CreateBindingJSObject(self.descriptor)
return CGGeneric("""\
let scope = scope.reflector().get_jsobject();
assert!(!scope.get().is_null());

View file

@ -42,6 +42,7 @@ use js::panic::wrap_panic;
use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult};
use js::rust::Handle;
use js::rust::IntoHandle;
use js::rust::JSEngine;
use js::rust::Runtime as RustRuntime;
use malloc_size_of::MallocSizeOfOps;
use msg::constellation_msg::PipelineId;
@ -56,6 +57,7 @@ use std::os;
use std::os::raw::c_void;
use std::panic::AssertUnwindSafe;
use std::ptr;
use std::sync::Arc;
use style::thread_state::{self, ThreadState};
use time::{now, Tm};
@ -322,10 +324,14 @@ impl Deref for Runtime {
}
}
lazy_static! {
static ref JS_ENGINE: Arc<JSEngine> = JSEngine::init().unwrap();
}
#[allow(unsafe_code)]
pub unsafe fn new_rt_and_cx() -> Runtime {
LiveDOMReferences::initialize();
let runtime = RustRuntime::new().unwrap();
let runtime = RustRuntime::new(JS_ENGINE.clone());
let cx = runtime.cx();
JS_AddExtraGCRootsTracer(cx, Some(trace_rust_roots), ptr::null_mut());