diff options
author | marmeladema <xademax@gmail.com> | 2019-07-22 01:09:24 +0100 |
---|---|---|
committer | marmeladema <xademax@gmail.com> | 2019-07-24 08:24:50 +0100 |
commit | 2c5d0a6ebc39ad263e2bbe623e357a11b4cec5aa (patch) | |
tree | c1c93f26ab047bb010d1781511a750a302cc5636 /components/script/dom/window.rs | |
parent | 808fa65aef163879b82baddc4af0a5445f806c81 (diff) | |
download | servo-2c5d0a6ebc39ad263e2bbe623e357a11b4cec5aa.tar.gz servo-2c5d0a6ebc39ad263e2bbe623e357a11b4cec5aa.zip |
Convert CGTraitInterface to use safe JSContext instead of raw JSContext
Diffstat (limited to 'components/script/dom/window.rs')
-rw-r--r-- | components/script/dom/window.rs | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 6df91312931..c97a3fd08fb 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -615,26 +615,28 @@ impl WindowMethods for Window { #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-opener - unsafe fn Opener(&self, cx: *mut JSContext) -> JSVal { - self.window_proxy().opener(cx) + fn Opener(&self, cx: SafeJSContext) -> JSVal { + unsafe { self.window_proxy().opener(*cx) } } #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-opener - unsafe fn SetOpener(&self, cx: *mut JSContext, value: HandleValue) { + fn SetOpener(&self, cx: SafeJSContext, value: HandleValue) { // Step 1. if value.is_null() { return self.window_proxy().disown(); } // Step 2. let obj = self.reflector().get_jsobject(); - assert!(JS_DefineProperty( - cx, - obj, - "opener\0".as_ptr() as *const libc::c_char, - value, - JSPROP_ENUMERATE as u32 - )); + unsafe { + assert!(JS_DefineProperty( + *cx, + obj, + "opener\0".as_ptr() as *const libc::c_char, + value, + JSPROP_ENUMERATE as u32 + )); + } } // https://html.spec.whatwg.org/multipage/#dom-window-closed @@ -739,11 +741,10 @@ impl WindowMethods for Window { self.navigator.or_init(|| Navigator::new(self)) } - #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout - unsafe fn SetTimeout( + fn SetTimeout( &self, - _cx: *mut JSContext, + _cx: SafeJSContext, callback: Rc<Function>, timeout: i32, args: Vec<HandleValue>, @@ -756,11 +757,10 @@ impl WindowMethods for Window { ) } - #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout - unsafe fn SetTimeout_( + fn SetTimeout_( &self, - _cx: *mut JSContext, + _cx: SafeJSContext, callback: DOMString, timeout: i32, args: Vec<HandleValue>, @@ -779,11 +779,10 @@ impl WindowMethods for Window { .clear_timeout_or_interval(handle); } - #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval - unsafe fn SetInterval( + fn SetInterval( &self, - _cx: *mut JSContext, + _cx: SafeJSContext, callback: Rc<Function>, timeout: i32, args: Vec<HandleValue>, @@ -796,11 +795,10 @@ impl WindowMethods for Window { ) } - #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval - unsafe fn SetInterval_( + fn SetInterval_( &self, - _cx: *mut JSContext, + _cx: SafeJSContext, callback: DOMString, timeout: i32, args: Vec<HandleValue>, @@ -903,11 +901,10 @@ impl WindowMethods for Window { doc.cancel_animation_frame(ident); } - #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-window-postmessage - unsafe fn PostMessage( + fn PostMessage( &self, - cx: *mut JSContext, + cx: SafeJSContext, message: HandleValue, origin: DOMString, ) -> ErrorResult { @@ -926,7 +923,7 @@ impl WindowMethods for Window { // Step 1-2, 6-8. // TODO(#12717): Should implement the `transfer` argument. - let data = StructuredCloneData::write(cx, message)?; + let data = StructuredCloneData::write(*cx, message)?; // Step 9. self.post_message(origin, &*source.window_proxy(), data); @@ -961,8 +958,8 @@ impl WindowMethods for Window { } #[allow(unsafe_code)] - unsafe fn WebdriverCallback(&self, cx: *mut JSContext, val: HandleValue) { - let rv = jsval_to_webdriver(cx, val); + fn WebdriverCallback(&self, cx: SafeJSContext, val: HandleValue) { + let rv = unsafe { jsval_to_webdriver(*cx, val) }; let opt_chan = self.webdriver_script_chan.borrow_mut().take(); if let Some(chan) = opt_chan { chan.send(rv).unwrap(); |