Add an inCompartments config for bindings

This commit is contained in:
Bastien Orivel 2019-05-24 22:24:41 +02:00
parent 2181872973
commit 7dbff6efb7
7 changed files with 37 additions and 10 deletions

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::globalscope::GlobalScope;
use js::jsapi::{GetCurrentRealmOrNull, JSAutoRealm};
use js::jsapi::{GetCurrentRealmOrNull, JSAutoRealm, JSContext};
pub struct AlreadyInCompartment(());
@ -15,6 +15,13 @@ impl AlreadyInCompartment {
}
AlreadyInCompartment(())
}
pub fn assert_for_cx(cx: *mut JSContext) -> AlreadyInCompartment {
unsafe {
assert!(!GetCurrentRealmOrNull(cx).is_null());
}
AlreadyInCompartment(())
}
}
#[derive(Clone, Copy)]