Auto merge of #22353 - jdm:runtime-parent, r=nox

Update rust-mozjs

These changes adjust our uses of the rust-mozjs APIs to accommodate the changes in https://github.com/servo/rust-mozjs/pull/450.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #22342.
- [x] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22353)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-01-17 15:57:30 -05:00 committed by GitHub
commit fb95f9df9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 65 additions and 35 deletions

8
Cargo.lock generated
View file

@ -2308,7 +2308,7 @@ dependencies = [
"hyper 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper_serde 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.21.0",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2532,7 +2532,7 @@ dependencies = [
[[package]]
name = "mozjs"
version = "0.9.5"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3295,7 +3295,7 @@ dependencies = [
"mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"mozangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",
"num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -5064,7 +5064,7 @@ dependencies = [
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
"checksum mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9de3eca27871df31c33b807f834b94ef7d000956f57aa25c5aed9c5f0aae8f6f"
"checksum mozangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "45a8a18a41cfab0fde25cc2f43ea89064d211a0fbb33225b8ff93ab20406e0e7"
"checksum mozjs 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d1db0edead699324dd1768f74054a5a759de36a8ce92b15e8b179ec2549d19e"
"checksum mozjs 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c7eea7a83e5f237500eb7d66c8ca9c6dc97e3dc4f129eae2dc63fa17fb87f9a"
"checksum mozjs_sys 0.61.6 (registry+https://github.com/rust-lang/crates.io-index)" = "610d0fce234d68723526bfdc57091f6f4fe5ed661a343125014cd61823711cb5"
"checksum msdos_time 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aad9dfe950c057b1bfe9c1f2aa51583a8468ef2a5baba2ebbe06d775efeb7729"
"checksum muldiv 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "451a9a05d2a32c566c897835e0ea95cf79ed2fdfe957924045a1721a36c9980f"

View file

@ -33,6 +33,7 @@ hashglobe = { path = "../hashglobe" }
hyper = { version = "0.12", optional = true }
hyper_serde = { version = "0.9", optional = true }
keyboard-types = {version = "0.4.3", optional = true}
mozjs = { version = "0.10.0", optional = true}
selectors = { path = "../selectors" }
serde = { version = "1.0.27", optional = true }
serde_bytes = { version = "0.10", optional = true }
@ -46,9 +47,3 @@ url = { version = "1.2", optional = true }
webrender_api = { git = "https://github.com/servo/webrender", features = ["ipc"], optional = true }
xml5ever = { version = "0.12", optional = true }
void = "1.0.2"
[target.'cfg(target_os = "android")'.dependencies]
mozjs = { version = "0.9.5", optional = true, features=["init_once"]}
[target.'cfg(not(target_os = "android"))'.dependencies]
mozjs = { version = "0.9.5", optional = true}

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

@ -23,7 +23,7 @@ use crate::dom::messageevent::MessageEvent;
use crate::dom::worker::{TrustedWorkerAddress, Worker};
use crate::dom::workerglobalscope::WorkerGlobalScope;
use crate::script_runtime::ScriptThreadEventCategory::WorkerEvent;
use crate::script_runtime::{new_rt_and_cx, CommonScriptMsg, Runtime, ScriptChan, ScriptPort};
use crate::script_runtime::{new_child_runtime, CommonScriptMsg, Runtime, ScriptChan, ScriptPort};
use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
use crate::task_source::TaskSourceName;
use crossbeam_channel::{unbounded, Receiver, Sender};
@ -272,11 +272,9 @@ impl DedicatedWorkerGlobalScope {
let serialized_worker_url = worker_url.to_string();
let name = format!("WebWorker for {}", serialized_worker_url);
let top_level_browsing_context_id = TopLevelBrowsingContextId::installed();
let origin = GlobalScope::current()
.expect("No current global object")
.origin()
.immutable()
.clone();
let current_global = GlobalScope::current().expect("No current global object");
let origin = current_global.origin().immutable().clone();
let parent = current_global.runtime_handle();
thread::Builder::new()
.name(name)
@ -327,7 +325,7 @@ impl DedicatedWorkerGlobalScope {
let url = metadata.final_url;
let source = String::from_utf8_lossy(&bytes);
let runtime = unsafe { new_rt_and_cx() };
let runtime = unsafe { new_child_runtime(parent) };
let (devtools_mpsc_chan, devtools_mpsc_port) = unbounded();
ROUTER.route_ipc_receiver_to_crossbeam_sender(

View file

@ -47,7 +47,7 @@ use js::jsapi::{HandleObject, Heap};
use js::jsapi::{JSAutoCompartment, JSContext};
use js::panic::maybe_resume_unwind;
use js::rust::wrappers::Evaluate2;
use js::rust::{get_object_class, CompileOptionsWrapper, Runtime};
use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime};
use js::rust::{HandleValue, MutableHandleValue};
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
use msg::constellation_msg::PipelineId;
@ -711,6 +711,16 @@ impl GlobalScope {
unreachable!();
}
pub fn runtime_handle(&self) -> ParentRuntime {
if self.is::<Window>() {
ScriptThread::runtime_handle()
} else if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
worker.runtime_handle()
} else {
unreachable!()
}
}
/// Returns the ["current"] global object.
///
/// ["current"]: https://html.spec.whatwg.org/multipage/#current

View file

@ -292,7 +292,7 @@ impl ServiceWorkerGlobalScope {
},
};
let runtime = unsafe { new_rt_and_cx() };
let runtime = new_rt_and_cx();
let (devtools_mpsc_chan, devtools_mpsc_port) = unbounded();
ROUTER

View file

@ -39,7 +39,7 @@ use ipc_channel::ipc::IpcSender;
use js::jsapi::{JSAutoCompartment, JSContext};
use js::jsval::UndefinedValue;
use js::panic::maybe_resume_unwind;
use js::rust::HandleValue;
use js::rust::{HandleValue, ParentRuntime};
use msg::constellation_msg::PipelineId;
use net_traits::request::{CredentialsMode, Destination, RequestInit as NetRequestInit};
use net_traits::{load_whole_resource, IpcSend};
@ -135,6 +135,10 @@ impl WorkerGlobalScope {
}
}
pub fn runtime_handle(&self) -> ParentRuntime {
self.runtime.prepare_for_new_child()
}
pub fn from_devtools_sender(&self) -> Option<IpcSender<DevtoolScriptControlMsg>> {
self.from_devtools_sender.clone()
}

View file

@ -470,7 +470,7 @@ impl WorkletThread {
global_init: init.global_init,
global_scopes: HashMap::new(),
control_buffer: None,
runtime: unsafe { new_rt_and_cx() },
runtime: new_rt_and_cx(),
should_gc: false,
gc_threshold: MIN_GC_THRESHOLD,
});

View file

@ -42,6 +42,8 @@ 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::ParentRuntime;
use js::rust::Runtime as RustRuntime;
use malloc_size_of::MallocSizeOfOps;
use msg::constellation_msg::PipelineId;
@ -56,6 +58,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 +325,28 @@ 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 {
pub unsafe fn new_child_runtime(parent: ParentRuntime) -> Runtime {
new_rt_and_cx_with_parent(Some(parent))
}
#[allow(unsafe_code)]
pub fn new_rt_and_cx() -> Runtime {
unsafe { new_rt_and_cx_with_parent(None) }
}
#[allow(unsafe_code)]
unsafe fn new_rt_and_cx_with_parent(parent: Option<ParentRuntime>) -> Runtime {
LiveDOMReferences::initialize();
let runtime = RustRuntime::new().unwrap();
let runtime = if let Some(parent) = parent {
RustRuntime::create_with_parent(parent)
} else {
RustRuntime::new(JS_ENGINE.clone())
};
let cx = runtime.cx();
JS_AddExtraGCRootsTracer(cx, Some(trace_rust_roots), ptr::null_mut());

View file

@ -100,6 +100,7 @@ use js::glue::GetWindowProxyClass;
use js::jsapi::{JSAutoCompartment, JSContext, JS_SetWrapObjectCallbacks};
use js::jsapi::{JSTracer, SetWindowProxyClass};
use js::jsval::UndefinedValue;
use js::rust::ParentRuntime;
use metrics::{PaintTimeMetrics, MAX_TASK_NS};
use mime::{self, Mime};
use msg::constellation_msg::{
@ -726,6 +727,13 @@ impl ScriptThreadFactory for ScriptThread {
}
impl ScriptThread {
pub fn runtime_handle() -> ParentRuntime {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
script_thread.js_runtime.prepare_for_new_child()
})
}
pub unsafe fn note_newly_transitioning_nodes(nodes: Vec<UntrustedNodeAddress>) {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = &*root.get().unwrap();
@ -1010,7 +1018,7 @@ impl ScriptThread {
port: Receiver<MainThreadScriptMsg>,
chan: Sender<MainThreadScriptMsg>,
) -> ScriptThread {
let runtime = unsafe { new_rt_and_cx() };
let runtime = new_rt_and_cx();
let cx = runtime.cx();
unsafe {