mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Add proof that code is executed in compartment
This commit is contained in:
parent
54f54d194d
commit
7b293ee8cb
2 changed files with 34 additions and 0 deletions
33
components/script/compartments.rs
Normal file
33
components/script/compartments.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use crate::dom::globalscope::GlobalScope;
|
||||||
|
use js::jsapi::{GetCurrentRealmOrNull, JSAutoCompartment};
|
||||||
|
|
||||||
|
pub struct AlreadyInCompartment(());
|
||||||
|
|
||||||
|
impl AlreadyInCompartment {
|
||||||
|
#![allow(unsafe_code)]
|
||||||
|
pub fn assert(global: &GlobalScope) -> AlreadyInCompartment {
|
||||||
|
unsafe {
|
||||||
|
assert!(!GetCurrentRealmOrNull(global.get_cx()).is_null());
|
||||||
|
}
|
||||||
|
AlreadyInCompartment(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum InCompartment<'a> {
|
||||||
|
Already(&'a AlreadyInCompartment),
|
||||||
|
Entered(&'a JSAutoCompartment),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> InCompartment<'a> {
|
||||||
|
pub fn in_compartment(token: &AlreadyInCompartment) -> InCompartment {
|
||||||
|
InCompartment::Already(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn entered(token: &JSAutoCompartment) -> InCompartment {
|
||||||
|
InCompartment::Entered(token)
|
||||||
|
}
|
||||||
|
}
|
|
@ -57,6 +57,7 @@ mod devtools;
|
||||||
pub mod document_loader;
|
pub mod document_loader;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod dom;
|
mod dom;
|
||||||
|
mod compartments;
|
||||||
pub mod fetch;
|
pub mod fetch;
|
||||||
mod image_listener;
|
mod image_listener;
|
||||||
mod layout_image;
|
mod layout_image;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue