aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/window.rs
diff options
context:
space:
mode:
authorKagami Sascha Rosylight <saschanaz@outlook.com>2019-07-25 10:09:33 +0900
committerGitHub <noreply@github.com>2019-07-25 10:09:33 +0900
commitcaf7a2488eda6218ccf8dc8d81f090531b4c77e8 (patch)
tree2712b566869664297ab33495612bfbbea52365dd /components/script/dom/window.rs
parent16b4e3446bc466c87327fac3402736d3636a5f73 (diff)
parent82f649751c045730419f9d1704305717c4f346ec (diff)
downloadservo-caf7a2488eda6218ccf8dc8d81f090531b4c77e8.tar.gz
servo-caf7a2488eda6218ccf8dc8d81f090531b4c77e8.zip
Merge branch 'master' into tojson
Diffstat (limited to 'components/script/dom/window.rs')
-rw-r--r--components/script/dom/window.rs72
1 files changed, 32 insertions, 40 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 4d1ea5e80d4..ccbd08e1ef7 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -57,7 +57,7 @@ use crate::fetch;
use crate::layout_image::fetch_image_for_layout;
use crate::microtask::MicrotaskQueue;
use crate::script_runtime::{
- CommonScriptMsg, Runtime, ScriptChan, ScriptPort, ScriptThreadEventCategory,
+ CommonScriptMsg, JSContext, Runtime, ScriptChan, ScriptPort, ScriptThreadEventCategory,
};
use crate::script_thread::{ImageCacheMsg, MainThreadScriptChan, MainThreadScriptMsg};
use crate::script_thread::{ScriptThread, SendableMainThreadScriptChan};
@@ -79,7 +79,6 @@ use euclid::{Point2D, Rect, Scale, Size2D, Vector2D};
use ipc_channel::ipc::{channel, IpcSender};
use ipc_channel::router::ROUTER;
use js::jsapi::JSAutoRealm;
-use js::jsapi::JSContext;
use js::jsapi::JSPROP_ENUMERATE;
use js::jsapi::{GCReason, JS_GC};
use js::jsval::JSVal;
@@ -371,8 +370,9 @@ impl Window {
self.globalscope.origin()
}
- pub fn get_cx(&self) -> *mut JSContext {
- self.js_runtime.borrow().as_ref().unwrap().cx()
+ #[allow(unsafe_code)]
+ pub fn get_cx(&self) -> JSContext {
+ unsafe { JSContext::from_ptr(self.js_runtime.borrow().as_ref().unwrap().cx()) }
}
pub fn main_thread_script_chan(&self) -> &Sender<MainThreadScriptMsg> {
@@ -614,26 +614,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: JSContext) -> 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: JSContext, 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
@@ -738,11 +740,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: JSContext,
callback: Rc<Function>,
timeout: i32,
args: Vec<HandleValue>,
@@ -755,11 +756,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: JSContext,
callback: DOMString,
timeout: i32,
args: Vec<HandleValue>,
@@ -778,11 +778,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: JSContext,
callback: Rc<Function>,
timeout: i32,
args: Vec<HandleValue>,
@@ -795,11 +794,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: JSContext,
callback: DOMString,
timeout: i32,
args: Vec<HandleValue>,
@@ -902,14 +900,8 @@ impl WindowMethods for Window {
doc.cancel_animation_frame(ident);
}
- #[allow(unsafe_code)]
// https://html.spec.whatwg.org/multipage/#dom-window-postmessage
- unsafe fn PostMessage(
- &self,
- cx: *mut JSContext,
- message: HandleValue,
- origin: DOMString,
- ) -> ErrorResult {
+ fn PostMessage(&self, cx: JSContext, message: HandleValue, origin: DOMString) -> ErrorResult {
let source_global = GlobalScope::incumbent().expect("no incumbent global??");
let source = source_global.as_window();
@@ -925,7 +917,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);
@@ -950,7 +942,7 @@ impl WindowMethods for Window {
#[allow(unsafe_code)]
fn Gc(&self) {
unsafe {
- JS_GC(self.get_cx(), GCReason::API);
+ JS_GC(*self.get_cx(), GCReason::API);
}
}
@@ -960,8 +952,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: JSContext, 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();
@@ -2179,7 +2171,7 @@ impl Window {
player_context,
});
- unsafe { WindowBinding::Wrap(runtime.cx(), win) }
+ unsafe { WindowBinding::Wrap(JSContext::from_ptr(runtime.cx()), win) }
}
pub fn pipeline_id(&self) -> Option<PipelineId> {
@@ -2281,8 +2273,8 @@ impl Window {
// Steps 7.2.-7.5.
let cx = this.get_cx();
let obj = this.reflector().get_jsobject();
- let _ac = JSAutoRealm::new(cx, obj.get());
- rooted!(in(cx) let mut message_clone = UndefinedValue());
+ let _ac = JSAutoRealm::new(*cx, obj.get());
+ rooted!(in(*cx) let mut message_clone = UndefinedValue());
serialize_with_transfer_result.read(
this.upcast(),
message_clone.handle_mut(),