From 6e4caf11537cb8db83405afe461b74470f3a7e5a Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sun, 21 Jul 2019 01:25:29 +0100 Subject: [PATCH] DefineDOMInterfaceMethod now takes a SafeJSContext instead of a JSContext as first argument. --- components/script/build.rs | 2 +- components/script/dom/bindings/codegen/CodegenRust.py | 10 +++++----- components/script/dom/bindings/utils.rs | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/components/script/build.rs b/components/script/build.rs index 794e2fe3283..1b8ed578387 100644 --- a/components/script/build.rs +++ b/components/script/build.rs @@ -47,7 +47,7 @@ fn main() { let mut phf = File::create(&phf).unwrap(); write!( &mut phf, - "pub static MAP: phf::Map<&'static [u8], unsafe fn(*mut JSContext, HandleObject)> = " + "pub static MAP: phf::Map<&'static [u8], unsafe fn(JSContext, HandleObject)> = " ) .unwrap(); map.build(&mut phf).unwrap(); diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index e656a7ab3ce..d4c606183ca 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -3268,7 +3268,7 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod): def __init__(self, descriptor): assert descriptor.interface.hasInterfaceObject() args = [ - Argument('*mut JSContext', 'cx'), + Argument('SafeJSContext', 'cx'), Argument('HandleObject', 'global'), ] CGAbstractMethod.__init__(self, descriptor, 'DefineDOMInterface', @@ -3285,12 +3285,12 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod): return CGGeneric("""\ assert!(!global.get().is_null()); -if !ConstructorEnabled(SafeJSContext::from_ptr(cx), global) { +if !ConstructorEnabled(cx, global) { return; } -rooted!(in(cx) let mut proto = ptr::null_mut::()); -%s(SafeJSContext::from_ptr(cx), global, proto.handle_mut()); +rooted!(in(*cx) let mut proto = ptr::null_mut::()); +%s(cx, global, proto.handle_mut()); assert!(!proto.is_null());""" % (function,)) @@ -7312,7 +7312,7 @@ class GlobalGenRoots(): def InterfaceObjectMap(config): mods = [ "crate::dom::bindings::codegen", - "js::jsapi::JSContext", + "crate::script_runtime::JSContext", "js::rust::HandleObject", "phf", ] diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 54ff2a35eab..7146e1533b7 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -13,6 +13,7 @@ use crate::dom::bindings::inheritance::TopTypeId; use crate::dom::bindings::str::DOMString; use crate::dom::bindings::trace::trace_object; use crate::dom::windowproxy; +use crate::script_runtime::JSContext as SafeJSContext; use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper}; use js::glue::{GetCrossCompartmentWrapper, JS_GetReservedSlot, WrapperNew}; use js::glue::{UnwrapObjectDynamic, RUST_JSID_TO_INT, RUST_JSID_TO_STRING}; @@ -353,7 +354,7 @@ pub unsafe extern "C" fn enumerate_global( return false; } for init_fun in InterfaceObjectMap::MAP.values() { - init_fun(cx, Handle::from_raw(obj)); + init_fun(SafeJSContext::from_ptr(cx), Handle::from_raw(obj)); } true } @@ -388,7 +389,7 @@ pub unsafe extern "C" fn resolve_global( let bytes = slice::from_raw_parts(ptr, length as usize); if let Some(init_fun) = InterfaceObjectMap::MAP.get(bytes) { - init_fun(cx, Handle::from_raw(obj)); + init_fun(SafeJSContext::from_ptr(cx), Handle::from_raw(obj)); *rval = true; } else { *rval = false;