chore(deps): update mozjs

- 798c5b6: Bring `RustJSPrincipals` back
This commit is contained in:
yvt 2021-07-11 23:01:21 +09:00
parent fd177a9199
commit 40fbe6b722
4 changed files with 30 additions and 12 deletions

2
Cargo.lock generated
View file

@ -3808,7 +3808,7 @@ dependencies = [
[[package]] [[package]]
name = "mozjs" name = "mozjs"
version = "0.14.1" version = "0.14.1"
source = "git+https://github.com/servo/rust-mozjs#a8b688ad32a852172536443d77baa844f59a23fa" source = "git+https://github.com/servo/rust-mozjs#2e4c6a82c9f94210da7c452bb29de210fb658c1a"
dependencies = [ dependencies = [
"cc", "cc",
"lazy_static", "lazy_static",

View file

@ -9,7 +9,7 @@ use crate::dom::bindings::codegen::PrototypeList;
use crate::dom::bindings::constant::{define_constants, ConstantSpec}; use crate::dom::bindings::constant::{define_constants, ConstantSpec};
use crate::dom::bindings::conversions::{get_dom_class, DOM_OBJECT_SLOT}; use crate::dom::bindings::conversions::{get_dom_class, DOM_OBJECT_SLOT};
use crate::dom::bindings::guard::Guard; use crate::dom::bindings::guard::Guard;
use crate::dom::bindings::utils::{ProtoOrIfaceArray, DOM_PROTOTYPE_SLOT}; use crate::dom::bindings::utils::{ProtoOrIfaceArray, ServoJSPrincipal, DOM_PROTOTYPE_SLOT};
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::JSContext as SafeJSContext; use crate::script_runtime::JSContext as SafeJSContext;
use js::error::throw_type_error; use js::error::throw_type_error;
@ -149,14 +149,12 @@ pub unsafe fn create_global_object(
options.creationOptions_.streams_ = true; options.creationOptions_.streams_ = true;
select_compartment(cx, &mut options); select_compartment(cx, &mut options);
let origin = Box::new(origin.clone()); let principal = ServoJSPrincipal::new(origin);
let mut principal =
CreateRustJSPrincipal(Box::into_raw(origin) as *const ::libc::c_void, None, None);
rval.set(JS_NewGlobalObject( rval.set(JS_NewGlobalObject(
*cx, *cx,
class, class,
principal, principal.0,
OnNewGlobalHookOption::DontFireOnNewGlobalHook, OnNewGlobalHookOption::DontFireOnNewGlobalHook,
&*options, &*options,
)); ));

View file

@ -29,7 +29,10 @@ use js::glue::{
CreateCrossOriginWrapper, GetCrossCompartmentWrapper, GetOpaqueWrapper, GetSecurityWrapper, CreateCrossOriginWrapper, GetCrossCompartmentWrapper, GetOpaqueWrapper, GetSecurityWrapper,
JS_GetReservedSlot, WrapperNew, JS_GetReservedSlot, WrapperNew,
}; };
use js::glue::{CreateWrapperProxyHandler, GetPrincipalOrigin, UncheckedUnwrapObject}; use js::glue::{
CreateRustJSPrincipals, CreateWrapperProxyHandler, GetRustJSPrincipalsPrivate,
JSPrincipalsCallbacks, UncheckedUnwrapObject,
};
use js::glue::{UnwrapObjectDynamic, UnwrapObjectStatic, RUST_JSID_TO_INT, RUST_JSID_TO_STRING}; use js::glue::{UnwrapObjectDynamic, UnwrapObjectStatic, RUST_JSID_TO_INT, RUST_JSID_TO_STRING};
use js::glue::{ use js::glue::{
RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING, RUST_JSID_IS_VOID, RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING, RUST_JSID_IS_VOID,
@ -83,17 +86,32 @@ impl MallocSizeOf for WindowProxyHandler {
} }
//TODO make principal.rs //TODO make principal.rs
pub struct ServoJSPrincipal(*mut JSPrincipals); // TODO: RAII ref-counting
pub struct ServoJSPrincipal(pub *mut JSPrincipals);
impl ServoJSPrincipal { impl ServoJSPrincipal {
pub fn new(origin: &MutableOrigin) -> Self {
let private: Box<MutableOrigin> = Box::new(origin.clone());
Self(unsafe { CreateRustJSPrincipals(&PRINCIPALS_CALLBACKS, Box::into_raw(private) as _) })
}
pub unsafe fn origin(&self) -> MutableOrigin { pub unsafe fn origin(&self) -> MutableOrigin {
let origin = GetPrincipalOrigin(self.0) as *mut MutableOrigin; let origin = GetRustJSPrincipalsPrivate(self.0) as *mut MutableOrigin;
(*origin).clone() (*origin).clone()
} }
} }
pub unsafe fn destroy_servo_jsprincipal(principal: &mut ServoJSPrincipal) { pub unsafe extern "C" fn destroy_servo_jsprincipal(principals: *mut JSPrincipals) {
let origin = GetPrincipalOrigin(principal.0) as *mut Box<MutableOrigin>; (GetRustJSPrincipalsPrivate(principals) as *mut Box<MutableOrigin>).drop_in_place();
}
const PRINCIPALS_CALLBACKS: JSPrincipalsCallbacks = JSPrincipalsCallbacks {
write: None,
isSystemOrAddonPrincipal: Some(principals_is_system_or_addon_principal),
};
unsafe extern "C" fn principals_is_system_or_addon_principal(_: *mut JSPrincipals) -> bool {
false
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]

View file

@ -61,7 +61,7 @@ use js::jsapi::{
JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled, JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled,
}; };
use js::jsapi::{JSObject, PromiseRejectionHandlingState, SetPreserveWrapperCallbacks}; use js::jsapi::{JSObject, PromiseRejectionHandlingState, SetPreserveWrapperCallbacks};
use js::jsapi::{JSSecurityCallbacks, JS_SetSecurityCallbacks}; use js::jsapi::{JSSecurityCallbacks, JS_InitDestroyPrincipalsCallback, JS_SetSecurityCallbacks};
use js::jsapi::{SetJobQueue, SetProcessBuildIdOp, SetPromiseRejectionTrackerCallback}; use js::jsapi::{SetJobQueue, SetProcessBuildIdOp, SetPromiseRejectionTrackerCallback};
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use js::panic::wrap_panic; use js::panic::wrap_panic;
@ -475,6 +475,8 @@ unsafe fn new_rt_and_cx_with_parent(
JS_SetSecurityCallbacks(cx, &SECURITY_CALLBACKS); JS_SetSecurityCallbacks(cx, &SECURITY_CALLBACKS);
JS_InitDestroyPrincipalsCallback(cx, Some(utils::destroy_servo_jsprincipal));
// Needed for debug assertions about whether GC is running. // Needed for debug assertions about whether GC is running.
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
JS_SetGCCallback(cx, Some(debug_gc_callback), ptr::null_mut()); JS_SetGCCallback(cx, Some(debug_gc_callback), ptr::null_mut());