From 88cacfb0098e20be70c27bfde6b74cd3290f1fe4 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Mon, 22 Jul 2019 22:14:11 +0100 Subject: Modify *::get_cx methods to return a safe JSContext instead of a raw one --- components/script/script_thread.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'components/script/script_thread.rs') diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 0ceed35db57..81ef7d9493c 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -70,7 +70,7 @@ use crate::dom::worklet::WorkletThreadPool; use crate::dom::workletglobalscope::WorkletGlobalScopeInit; use crate::fetch::FetchCanceller; use crate::microtask::{Microtask, MicrotaskQueue}; -use crate::script_runtime::{get_reports, new_rt_and_cx, Runtime, ScriptPort}; +use crate::script_runtime::{get_reports, new_rt_and_cx, JSContext, Runtime, ScriptPort}; use crate::script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; use crate::serviceworkerjob::{Job, JobQueue}; use crate::task_manager::TaskManager; @@ -102,7 +102,7 @@ use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::router::ROUTER; use js::glue::GetWindowProxyClass; -use js::jsapi::{JSContext, JS_SetWrapObjectCallbacks}; +use js::jsapi::JS_SetWrapObjectCallbacks; use js::jsapi::{JSTracer, SetWindowProxyClass}; use js::jsval::UndefinedValue; use js::rust::ParentRuntime; @@ -915,7 +915,7 @@ impl ScriptThread { let script_thread = &*script_thread; script_thread .microtask_queue - .enqueue(task, script_thread.get_cx()); + .enqueue(task, *script_thread.get_cx()); } } }); @@ -1317,8 +1317,9 @@ impl ScriptThread { } } - pub fn get_cx(&self) -> *mut JSContext { - self.js_runtime.cx() + #[allow(unsafe_code)] + pub fn get_cx(&self) -> JSContext { + unsafe { JSContext::from_ptr(self.js_runtime.cx()) } } /// Starts the script thread. After calling this method, the script thread will loop receiving @@ -2349,7 +2350,7 @@ impl ScriptThread { let path_seg = format!("url({})", urls); let mut reports = vec![]; - reports.extend(get_reports(self.get_cx(), path_seg)); + reports.extend(get_reports(*self.get_cx(), path_seg)); reports_chan.send(reports); } @@ -3540,13 +3541,13 @@ impl ScriptThread { // Script source is ready to be evaluated (11.) let _ac = enter_realm(global_scope); - rooted!(in(global_scope.get_cx()) let mut jsval = UndefinedValue()); + rooted!(in(*global_scope.get_cx()) let mut jsval = UndefinedValue()); global_scope.evaluate_js_on_global_with_result(&script_source, jsval.handle_mut()); load_data.js_eval_result = if jsval.get().is_string() { unsafe { let strval = DOMString::from_jsval( - global_scope.get_cx(), + *global_scope.get_cx(), jsval.handle(), StringificationBehavior::Empty, ); @@ -3776,7 +3777,7 @@ impl ScriptThread { let script_thread = &*root.get().unwrap(); script_thread .microtask_queue - .enqueue(job, script_thread.get_cx()); + .enqueue(job, *script_thread.get_cx()); }); } @@ -3791,7 +3792,7 @@ impl ScriptThread { unsafe { self.microtask_queue.checkpoint( - self.get_cx(), + *self.get_cx(), |id| self.documents.borrow().find_global(id), globals, ) -- cgit v1.2.3