diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/bindings/callback.rs | 11 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 8 | ||||
-rw-r--r-- | components/script/dom/customelementregistry.rs | 6 | ||||
-rw-r--r-- | components/script/dom/eventtarget.rs | 18 | ||||
-rw-r--r-- | components/script/script_runtime.rs | 2 |
5 files changed, 27 insertions, 18 deletions
diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index fd33be86546..77f6880e35a 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -13,6 +13,7 @@ use crate::dom::bindings::settings_stack::{AutoEntryScript, AutoIncumbentScript} use crate::dom::bindings::utils::AsCCharPtrPtr; use crate::dom::globalscope::GlobalScope; use crate::dom::window::Window; +use crate::script_runtime::JSContext as SafeJSContext; use js::jsapi::Heap; use js::jsapi::JSAutoRealm; use js::jsapi::{AddRawValueRoot, IsCallable, JSContext, JSObject}; @@ -112,7 +113,7 @@ impl PartialEq for CallbackObject { /// callback interface types. pub trait CallbackContainer { /// Create a new CallbackContainer object for the given `JSObject`. - unsafe fn new(cx: *mut JSContext, callback: *mut JSObject) -> Rc<Self>; + unsafe fn new(cx: SafeJSContext, callback: *mut JSObject) -> Rc<Self>; /// Returns the underlying `CallbackObject`. fn callback_holder(&self) -> &CallbackObject; /// Returns the underlying `JSObject`. @@ -151,8 +152,8 @@ impl CallbackFunction { /// Initialize the callback function with a value. /// Should be called once this object is done moving. - pub unsafe fn init(&mut self, cx: *mut JSContext, callback: *mut JSObject) { - self.object.init(cx, callback); + pub unsafe fn init(&mut self, cx: SafeJSContext, callback: *mut JSObject) { + self.object.init(*cx, callback); } } @@ -178,8 +179,8 @@ impl CallbackInterface { /// Initialize the callback function with a value. /// Should be called once this object is done moving. - pub unsafe fn init(&mut self, cx: *mut JSContext, callback: *mut JSObject) { - self.object.init(cx, callback); + pub unsafe fn init(&mut self, cx: SafeJSContext, callback: *mut JSObject) { + self.object.init(*cx, callback); } /// Returns the property with the given `name`, if it is a callable object, diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index d4c606183ca..71b7a279b7a 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -836,7 +836,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, if descriptor.interface.isCallback(): name = descriptor.nativeType declType = CGWrapper(CGGeneric(name), pre="Rc<", post=">") - template = "%s::new(cx, ${val}.get().to_object())" % name + template = "%s::new(SafeJSContext::from_ptr(cx), ${val}.get().to_object())" % name if type.nullable(): declType = CGWrapper(declType, pre="Option<", post=">") template = wrapObjectTemplate("Some(%s)" % template, "None", @@ -2364,7 +2364,7 @@ class CGGeneric(CGThing): class CGCallbackTempRoot(CGGeneric): def __init__(self, name): - CGGeneric.__init__(self, "%s::new(cx, ${val}.get().to_object())" % name) + CGGeneric.__init__(self, "%s::new(SafeJSContext::from_ptr(cx), ${val}.get().to_object())" % name) def getAllTypes(descriptors, dictionaries, callbacks, typedefs): @@ -6795,7 +6795,7 @@ class CGCallback(CGClass): def getConstructors(self): return [ClassConstructor( - [Argument("*mut JSContext", "aCx"), Argument("*mut JSObject", "aCallback")], + [Argument("SafeJSContext", "aCx"), Argument("*mut JSObject", "aCallback")], bodyInHeader=True, visibility="pub", explicit=False, @@ -6891,7 +6891,7 @@ class CGCallbackFunctionImpl(CGGeneric): def __init__(self, callback): impl = string.Template("""\ impl CallbackContainer for ${type} { - unsafe fn new(cx: *mut JSContext, callback: *mut JSObject) -> Rc<${type}> { + unsafe fn new(cx: SafeJSContext, callback: *mut JSObject) -> Rc<${type}> { ${type}::new(cx, callback) } diff --git a/components/script/dom/customelementregistry.rs b/components/script/dom/customelementregistry.rs index 913397cf780..e2355445db8 100644 --- a/components/script/dom/customelementregistry.rs +++ b/components/script/dom/customelementregistry.rs @@ -31,6 +31,7 @@ use crate::dom::node::{document_from_node, window_from_node, Node, ShadowIncludi use crate::dom::promise::Promise; use crate::dom::window::Window; use crate::microtask::Microtask; +use crate::script_runtime::JSContext as SafeJSContext; use crate::script_thread::ScriptThread; use dom_struct::dom_struct; use html5ever::{LocalName, Namespace, Prefix}; @@ -238,7 +239,10 @@ unsafe fn get_callback( if !callback.is_object() || !IsCallable(callback.to_object()) { return Err(Error::Type("Lifecycle callback is not callable".to_owned())); } - Ok(Some(Function::new(cx, callback.to_object()))) + Ok(Some(Function::new( + SafeJSContext::from_ptr(cx), + callback.to_object(), + ))) } else { Ok(None) } diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 02cd36bdd69..0a1d9a137ba 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -33,6 +33,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::node::document_from_node; use crate::dom::virtualmethods::VirtualMethods; use crate::dom::window::Window; +use crate::script_runtime::JSContext; use dom_struct::dom_struct; use fnv::FnvHasher; use js::jsapi::{JSAutoRealm, JSFunction, JS_GetFunctionObject, SourceText}; @@ -543,16 +544,16 @@ impl EventTarget { // Step 1.14 if is_error { Some(CommonEventHandler::ErrorEventHandler(unsafe { - OnErrorEventHandlerNonNull::new(cx, funobj) + OnErrorEventHandlerNonNull::new(JSContext::from_ptr(cx), funobj) })) } else { if ty == &atom!("beforeunload") { Some(CommonEventHandler::BeforeUnloadEventHandler(unsafe { - OnBeforeUnloadEventHandlerNonNull::new(cx, funobj) + OnBeforeUnloadEventHandlerNonNull::new(JSContext::from_ptr(cx), funobj) })) } else { Some(CommonEventHandler::EventHandler(unsafe { - EventHandlerNonNull::new(cx, funobj) + EventHandlerNonNull::new(JSContext::from_ptr(cx), funobj) })) } } @@ -567,7 +568,7 @@ impl EventTarget { let event_listener = listener.map(|listener| { InlineEventListener::Compiled(CommonEventHandler::EventHandler(unsafe { - EventHandlerNonNull::new(cx, listener.callback()) + EventHandlerNonNull::new(JSContext::from_ptr(cx), listener.callback()) })) }); self.set_inline_event_listener(Atom::from(ty), event_listener); @@ -582,7 +583,7 @@ impl EventTarget { let event_listener = listener.map(|listener| { InlineEventListener::Compiled(CommonEventHandler::ErrorEventHandler(unsafe { - OnErrorEventHandlerNonNull::new(cx, listener.callback()) + OnErrorEventHandlerNonNull::new(JSContext::from_ptr(cx), listener.callback()) })) }); self.set_inline_event_listener(Atom::from(ty), event_listener); @@ -600,7 +601,7 @@ impl EventTarget { let event_listener = listener.map(|listener| { InlineEventListener::Compiled(CommonEventHandler::BeforeUnloadEventHandler(unsafe { - OnBeforeUnloadEventHandlerNonNull::new(cx, listener.callback()) + OnBeforeUnloadEventHandlerNonNull::new(JSContext::from_ptr(cx), listener.callback()) })) }); self.set_inline_event_listener(Atom::from(ty), event_listener); @@ -612,7 +613,10 @@ impl EventTarget { let listener = self.get_inline_event_listener(&Atom::from(ty)); unsafe { listener.map(|listener| { - CallbackContainer::new(cx, listener.parent().callback_holder().get()) + CallbackContainer::new( + JSContext::from_ptr(cx), + listener.parent().callback_holder().get(), + ) }) } } diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 76691c5de79..4c7953de443 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -179,7 +179,7 @@ unsafe extern "C" fn enqueue_promise_job( let pipeline = global.pipeline_id(); microtask_queue.enqueue( Microtask::Promise(EnqueuedPromiseCallback { - callback: PromiseJobCallback::new(cx, job.get()), + callback: PromiseJobCallback::new(JSContext::from_ptr(cx), job.get()), pipeline, }), cx, |