aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/Cargo.toml2
-rw-r--r--components/script/dom/bindings/reflector.rs3
-rw-r--r--components/script/dom/bindings/trace.rs14
-rw-r--r--components/script/dom/customelementregistry.rs3
-rw-r--r--components/script/timers.rs9
5 files changed, 25 insertions, 6 deletions
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml
index 4730eeeb18a..c9edde464ee 100644
--- a/components/script/Cargo.toml
+++ b/components/script/Cargo.toml
@@ -62,7 +62,7 @@ metrics = {path = "../metrics"}
mitochondria = "1.1.2"
mime = "0.2.1"
mime_guess = "1.8.0"
-mozjs = { version = "0.3", features = ["promises"]}
+mozjs = { version = "0.4", features = ["promises"]}
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
num-traits = "0.1.32"
diff --git a/components/script/dom/bindings/reflector.rs b/components/script/dom/bindings/reflector.rs
index 0fef0a30678..97d88cb4357 100644
--- a/components/script/dom/bindings/reflector.rs
+++ b/components/script/dom/bindings/reflector.rs
@@ -46,7 +46,8 @@ impl Reflector {
/// Get the reflector.
#[inline]
pub fn get_jsobject(&self) -> HandleObject {
- self.object.handle()
+ // We're rooted, so it's safe to hand out a handle to object in Heap
+ unsafe { self.object.handle() }
}
/// Initialize the reflector. (May be called only once.)
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index 423b053cbbf..be38b14a540 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -59,9 +59,9 @@ use hyper::mime::Mime;
use hyper::status::StatusCode;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use js::glue::{CallObjectTracer, CallValueTracer};
-use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind};
+use js::jsapi::{GCTraceKindToAscii, Heap, Handle, JSObject, JSTracer, TraceKind};
use js::jsval::JSVal;
-use js::rust::Runtime;
+use js::rust::{GCMethods, Runtime};
use js::typedarray::TypedArray;
use js::typedarray::TypedArrayElement;
use metrics::{InteractiveMetrics, InteractiveWindow};
@@ -788,6 +788,16 @@ impl<T: JSTraceable + 'static> RootedTraceableBox<T> {
}
}
+impl<T> RootedTraceableBox<Heap<T>>
+ where
+ Heap<T>: JSTraceable + 'static,
+ T: GCMethods + Copy,
+{
+ pub fn handle(&self) -> Handle<T> {
+ unsafe { (*self.ptr).handle() }
+ }
+}
+
impl<T: JSTraceable + Default> Default for RootedTraceableBox<T> {
fn default() -> RootedTraceableBox<T> {
RootedTraceableBox::new(T::default())
diff --git a/components/script/dom/customelementregistry.rs b/components/script/dom/customelementregistry.rs
index a208f99def6..123b0bef2cb 100644
--- a/components/script/dom/customelementregistry.rs
+++ b/components/script/dom/customelementregistry.rs
@@ -604,7 +604,8 @@ impl CustomElementReaction {
match *self {
CustomElementReaction::Upgrade(ref definition) => upgrade_element(definition.clone(), element),
CustomElementReaction::Callback(ref callback, ref arguments) => {
- let arguments = arguments.iter().map(|arg| arg.handle()).collect();
+ // We're rooted, so it's safe to hand out a handle to objects in Heap
+ let arguments = arguments.iter().map(|arg| unsafe { arg.handle() }).collect();
let _ = callback.Call_(&*element, arguments, ExceptionHandling::Report);
}
}
diff --git a/components/script/timers.rs b/components/script/timers.rs
index 4bc4bf37fff..a5e7020095f 100644
--- a/components/script/timers.rs
+++ b/components/script/timers.rs
@@ -500,7 +500,7 @@ impl JsTimerTask {
code_str, rval.handle_mut());
},
InternalTimerCallback::FunctionTimerCallback(ref function, ref arguments) => {
- let arguments = arguments.iter().map(|arg| arg.handle()).collect();
+ let arguments = self.collect_heap_args(arguments);
let _ = function.Call_(this, arguments, Report);
},
};
@@ -516,4 +516,11 @@ impl JsTimerTask {
timers.initialize_and_schedule(&this.global(), self);
}
}
+
+ // Returning Handles directly from Heap values is inherently unsafe, but here it's
+ // always done via rooted JsTimers, which is safe.
+ #[allow(unsafe_code)]
+ fn collect_heap_args(&self, args: &[Heap<JSVal>]) -> Vec<HandleValue> {
+ args.iter().map(|arg| unsafe { arg.handle() }).collect()
+ }
}