From dbcd8d7af232cd10c3a8ef751076cc7b9cd068a4 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sat, 20 Jul 2019 14:00:37 +0100 Subject: Add safe JSontext wrapper around unsafe RawJSContext --- components/script/script_runtime.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 6a16a79cba7..76691c5de79 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -748,3 +748,22 @@ unsafe fn set_gc_zeal_options(cx: *mut RawJSContext) { #[allow(unsafe_code)] #[cfg(not(feature = "debugmozjs"))] unsafe fn set_gc_zeal_options(_: *mut RawJSContext) {} + +#[derive(Clone, Copy)] +pub struct JSContext(*mut RawJSContext); + +#[allow(unsafe_code)] +impl JSContext { + pub unsafe fn from_ptr(raw_js_context: *mut RawJSContext) -> Self { + JSContext(raw_js_context) + } +} + +#[allow(unsafe_code)] +impl Deref for JSContext { + type Target = *mut RawJSContext; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} -- cgit v1.2.3