From 50365a556b51da2455de051bfe4697872f49d8df Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 4 May 2014 15:32:07 +0200 Subject: [PATCH] Implement with_compartment to enter compartments from Rust code. --- rust.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rust.rs b/rust.rs index 204d90901..ecf756388 100644 --- a/rust.rs +++ b/rust.rs @@ -223,6 +223,15 @@ pub extern fn reportError(_cx: *JSContext, msg: *c_char, report: *JSErrorReport) } } +pub fn with_compartment(cx: *JSContext, object: *JSObject, cb: || -> R) -> R { + unsafe { + let call = JS_EnterCrossCompartmentCall(cx, object); + let result = cb(); + JS_LeaveCrossCompartmentCall(call); + result + } +} + // ___________________________________________________________________________ // compartment