mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Use safe JSContext in compartments
This commit is contained in:
parent
ce3778afcc
commit
b18fa8b8a7
2 changed files with 5 additions and 4 deletions
|
@ -4,7 +4,8 @@
|
||||||
|
|
||||||
use crate::dom::bindings::reflector::DomObject;
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use js::jsapi::{GetCurrentRealmOrNull, JSAutoRealm, JSContext};
|
use crate::script_runtime::JSContext;
|
||||||
|
use js::jsapi::{GetCurrentRealmOrNull, JSAutoRealm};
|
||||||
|
|
||||||
pub struct AlreadyInCompartment(());
|
pub struct AlreadyInCompartment(());
|
||||||
|
|
||||||
|
@ -17,9 +18,9 @@ impl AlreadyInCompartment {
|
||||||
AlreadyInCompartment(())
|
AlreadyInCompartment(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn assert_for_cx(cx: *mut JSContext) -> AlreadyInCompartment {
|
pub fn assert_for_cx(cx: JSContext) -> AlreadyInCompartment {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(!GetCurrentRealmOrNull(cx).is_null());
|
assert!(!GetCurrentRealmOrNull(*cx).is_null());
|
||||||
}
|
}
|
||||||
AlreadyInCompartment(())
|
AlreadyInCompartment(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3335,7 +3335,7 @@ class CGCallGenerator(CGThing):
|
||||||
if "cx" not in argsPre and needsCx:
|
if "cx" not in argsPre and needsCx:
|
||||||
args.prepend(CGGeneric("cx"))
|
args.prepend(CGGeneric("cx"))
|
||||||
if nativeMethodName in descriptor.inCompartmentMethods:
|
if nativeMethodName in descriptor.inCompartmentMethods:
|
||||||
args.append(CGGeneric("InCompartment::in_compartment(&AlreadyInCompartment::assert_for_cx(*cx))"))
|
args.append(CGGeneric("InCompartment::in_compartment(&AlreadyInCompartment::assert_for_cx(cx))"))
|
||||||
|
|
||||||
# Build up our actual call
|
# Build up our actual call
|
||||||
self.cgRoot = CGList([], "\n")
|
self.cgRoot = CGList([], "\n")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue