mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Always pass InRealm to GlobalScope::from_context to avoid getting null global
This commit is contained in:
parent
795dab71ff
commit
403ffcf1eb
16 changed files with 79 additions and 61 deletions
|
@ -13,9 +13,9 @@ 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::realms::{enter_realm, InRealm};
|
||||
use crate::script_runtime::JSContext;
|
||||
use js::jsapi::Heap;
|
||||
use js::jsapi::JSAutoRealm;
|
||||
use js::jsapi::{AddRawValueRoot, IsCallable, JSObject};
|
||||
use js::jsapi::{EnterRealm, LeaveRealm, Realm, RemoveRawValueRoot};
|
||||
use js::jsval::{JSVal, ObjectValue, UndefinedValue};
|
||||
|
@ -270,11 +270,8 @@ impl Drop for CallSetup {
|
|||
unsafe {
|
||||
LeaveRealm(*self.cx, self.old_realm);
|
||||
if self.handling == ExceptionHandling::Report {
|
||||
let _ac = JSAutoRealm::new(
|
||||
*self.cx,
|
||||
self.exception_global.reflector().get_jsobject().get(),
|
||||
);
|
||||
report_pending_exception(*self.cx, true);
|
||||
let ar = enter_realm(&*self.exception_global);
|
||||
report_pending_exception(*self.cx, true, InRealm::Entered(&ar));
|
||||
}
|
||||
drop(self.incumbent_script.take());
|
||||
drop(self.entry_script.take().unwrap());
|
||||
|
|
|
@ -57,7 +57,7 @@ DOMInterfaces = {
|
|||
},
|
||||
|
||||
'Window': {
|
||||
'inRealms': ['Fetch'],
|
||||
'inRealms': ['Fetch', 'Opener'],
|
||||
},
|
||||
|
||||
'WorkerGlobalScope': {
|
||||
|
|
|
@ -14,6 +14,7 @@ use crate::dom::bindings::conversions::{
|
|||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::domexception::{DOMErrorName, DOMException};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::realms::InRealm;
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
#[cfg(feature = "js_backtrace")]
|
||||
use backtrace::Backtrace;
|
||||
|
@ -231,7 +232,7 @@ impl ErrorInfo {
|
|||
///
|
||||
/// The `dispatch_event` argument is temporary and non-standard; passing false
|
||||
/// prevents dispatching the `error` event.
|
||||
pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool) {
|
||||
pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool, realm: InRealm) {
|
||||
if !JS_IsExceptionPending(cx) {
|
||||
return;
|
||||
}
|
||||
|
@ -285,7 +286,7 @@ pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool)
|
|||
}
|
||||
|
||||
if dispatch_event {
|
||||
GlobalScope::from_context(cx).report_an_error(error_info, value.handle());
|
||||
GlobalScope::from_context(cx, realm).report_an_error(error_info, value.handle());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::dom::bindings::transferable::Transferable;
|
|||
use crate::dom::blob::Blob;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::messageport::MessagePort;
|
||||
use crate::realms::enter_realm;
|
||||
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
use js::glue::CopyJSStructuredCloneData;
|
||||
use js::glue::DeleteJSAutoStructuredCloneBuffer;
|
||||
|
@ -129,8 +129,9 @@ unsafe extern "C" fn read_callback(
|
|||
"tag should be higher than StructuredCloneTags::Min"
|
||||
);
|
||||
if tag == StructuredCloneTags::DomBlob as u32 {
|
||||
let in_realm_proof = AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx));
|
||||
return read_blob(
|
||||
&GlobalScope::from_context(cx),
|
||||
&GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof)),
|
||||
r,
|
||||
&mut *(closure as *mut StructuredDataHolder),
|
||||
);
|
||||
|
@ -145,8 +146,9 @@ unsafe extern "C" fn write_callback(
|
|||
closure: *mut raw::c_void,
|
||||
) -> bool {
|
||||
if let Ok(blob) = root_from_object::<Blob>(*obj, cx) {
|
||||
let in_realm_proof = AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx));
|
||||
return write_blob(
|
||||
&GlobalScope::from_context(cx),
|
||||
&GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof)),
|
||||
blob,
|
||||
w,
|
||||
&mut *(closure as *mut StructuredDataHolder),
|
||||
|
@ -166,7 +168,8 @@ unsafe extern "C" fn read_transfer_callback(
|
|||
) -> bool {
|
||||
if tag == StructuredCloneTags::MessagePort as u32 {
|
||||
let mut sc_holder = &mut *(closure as *mut StructuredDataHolder);
|
||||
let owner = GlobalScope::from_context(cx);
|
||||
let in_realm_proof = AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx));
|
||||
let owner = GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof));
|
||||
if let Ok(_) = <MessagePort as Transferable>::transfer_receive(
|
||||
&owner,
|
||||
&mut sc_holder,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue