diff options
author | CYBAI <cyb.ai.815@gmail.com> | 2020-01-24 12:43:49 +0900 |
---|---|---|
committer | CYBAI <cyb.ai.815@gmail.com> | 2020-02-16 09:55:10 +0900 |
commit | 403ffcf1eb5c659626f70dec72f76aaf7782986d (patch) | |
tree | df2f2e06ed557fcaac17862791a6c1db1f8a7b57 /components/script/dom/globalscope.rs | |
parent | 795dab71fffe98434308732e4cb8ee682f28e465 (diff) | |
download | servo-403ffcf1eb5c659626f70dec72f76aaf7782986d.tar.gz servo-403ffcf1eb5c659626f70dec72f76aaf7782986d.zip |
Always pass InRealm to GlobalScope::from_context to avoid getting null global
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r-- | components/script/dom/globalscope.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index a773ac3c7c7..ea8dba9beb2 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -38,7 +38,7 @@ use crate::dom::window::Window; use crate::dom::workerglobalscope::WorkerGlobalScope; use crate::dom::workletglobalscope::WorkletGlobalScope; use crate::microtask::{Microtask, MicrotaskQueue, UserMicrotask}; -use crate::realms::enter_realm; +use crate::realms::{enter_realm, InRealm}; use crate::script_module::ModuleTree; use crate::script_runtime::{CommonScriptMsg, JSContext as SafeJSContext, ScriptChan, ScriptPort}; use crate::script_thread::{MainThreadScriptChan, ScriptThread}; @@ -61,10 +61,10 @@ use dom_struct::dom_struct; use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::router::ROUTER; use js::glue::{IsWrapper, UnwrapObjectDynamic}; +use js::jsapi::JSContext; use js::jsapi::JSObject; use js::jsapi::{CurrentGlobalOrNull, GetNonCCWObjectGlobal}; use js::jsapi::{HandleObject, Heap}; -use js::jsapi::{JSAutoRealm, JSContext}; use js::jsval::{JSVal, UndefinedValue}; use js::panic::maybe_resume_unwind; use js::rust::wrappers::EvaluateUtf8; @@ -1449,8 +1449,9 @@ impl GlobalScope { /// Returns the global scope for the given JSContext #[allow(unsafe_code)] - pub unsafe fn from_context(cx: *mut JSContext) -> DomRoot<Self> { + pub unsafe fn from_context(cx: *mut JSContext, _realm: InRealm) -> DomRoot<Self> { let global = CurrentGlobalOrNull(cx); + assert!(!global.is_null()); global_scope_from_global(global, cx) } @@ -1846,10 +1847,10 @@ impl GlobalScope { self.time_profiler_chan().clone(), || { let cx = self.get_cx(); - let globalhandle = self.reflector().get_jsobject(); let filename = CString::new(filename).unwrap(); - let _ac = JSAutoRealm::new(*cx, globalhandle.get()); + let ar = enter_realm(&*self); + let _aes = AutoEntryScript::new(self); let options = CompileOptionsWrapper::new(*cx, filename.as_ptr(), line_number); @@ -1866,7 +1867,7 @@ impl GlobalScope { if !result { debug!("error evaluating Dom string"); - unsafe { report_pending_exception(*cx, true) }; + unsafe { report_pending_exception(*cx, true, InRealm::Entered(&ar)) }; } maybe_resume_unwind(); |