aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--components/script/dom/bindings/interface.rs8
-rw-r--r--components/script/dom/bindings/utils.rs28
-rw-r--r--components/script/script_runtime.rs4
4 files changed, 30 insertions, 12 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5545a73432e..cba7f618714 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3808,7 +3808,7 @@ dependencies = [
[[package]]
name = "mozjs"
version = "0.14.1"
-source = "git+https://github.com/servo/rust-mozjs#a8b688ad32a852172536443d77baa844f59a23fa"
+source = "git+https://github.com/servo/rust-mozjs#2e4c6a82c9f94210da7c452bb29de210fb658c1a"
dependencies = [
"cc",
"lazy_static",
diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs
index 5d8036dd5c8..d9fba2c5b8d 100644
--- a/components/script/dom/bindings/interface.rs
+++ b/components/script/dom/bindings/interface.rs
@@ -9,7 +9,7 @@ use crate::dom::bindings::codegen::PrototypeList;
use crate::dom::bindings::constant::{define_constants, ConstantSpec};
use crate::dom::bindings::conversions::{get_dom_class, DOM_OBJECT_SLOT};
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::script_runtime::JSContext as SafeJSContext;
use js::error::throw_type_error;
@@ -149,14 +149,12 @@ pub unsafe fn create_global_object(
options.creationOptions_.streams_ = true;
select_compartment(cx, &mut options);
- let origin = Box::new(origin.clone());
- let mut principal =
- CreateRustJSPrincipal(Box::into_raw(origin) as *const ::libc::c_void, None, None);
+ let principal = ServoJSPrincipal::new(origin);
rval.set(JS_NewGlobalObject(
*cx,
class,
- principal,
+ principal.0,
OnNewGlobalHookOption::DontFireOnNewGlobalHook,
&*options,
));
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index e5804779d3b..f8bb6ec1a91 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -29,7 +29,10 @@ use js::glue::{
CreateCrossOriginWrapper, GetCrossCompartmentWrapper, GetOpaqueWrapper, GetSecurityWrapper,
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::{
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
-pub struct ServoJSPrincipal(*mut JSPrincipals);
+// TODO: RAII ref-counting
+pub struct ServoJSPrincipal(pub *mut JSPrincipals);
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 {
- let origin = GetPrincipalOrigin(self.0) as *mut MutableOrigin;
+ let origin = GetRustJSPrincipalsPrivate(self.0) as *mut MutableOrigin;
(*origin).clone()
}
}
-pub unsafe fn destroy_servo_jsprincipal(principal: &mut ServoJSPrincipal) {
- let origin = GetPrincipalOrigin(principal.0) as *mut Box<MutableOrigin>;
+pub unsafe extern "C" fn destroy_servo_jsprincipal(principals: *mut JSPrincipals) {
+ (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)]
diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs
index 151db669405..50d516280fc 100644
--- a/components/script/script_runtime.rs
+++ b/components/script/script_runtime.rs
@@ -61,7 +61,7 @@ use js::jsapi::{
JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled,
};
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::jsval::UndefinedValue;
use js::panic::wrap_panic;
@@ -475,6 +475,8 @@ unsafe fn new_rt_and_cx_with_parent(
JS_SetSecurityCallbacks(cx, &SECURITY_CALLBACKS);
+ JS_InitDestroyPrincipalsCallback(cx, Some(utils::destroy_servo_jsprincipal));
+
// Needed for debug assertions about whether GC is running.
if cfg!(debug_assertions) {
JS_SetGCCallback(cx, Some(debug_gc_callback), ptr::null_mut());