diff options
author | marmeladema <xademax@gmail.com> | 2019-07-21 16:05:04 +0100 |
---|---|---|
committer | marmeladema <xademax@gmail.com> | 2019-07-24 08:18:22 +0100 |
commit | 2fb3f1f98327ee1de698dfed83124350f58ff52a (patch) | |
tree | eff85118b3849cc1ef9854f0e3757ad2b34fa16c /components/script/dom/bindings | |
parent | 6e4caf11537cb8db83405afe461b74470f3a7e5a (diff) | |
download | servo-2fb3f1f98327ee1de698dfed83124350f58ff52a.tar.gz servo-2fb3f1f98327ee1de698dfed83124350f58ff52a.zip |
Callbacks now uses safe JSContext instead of raw JSContext
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/callback.rs | 11 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 8 |
2 files changed, 10 insertions, 9 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) } |