diff options
author | marmeladema <xademax@gmail.com> | 2019-07-20 14:00:37 +0100 |
---|---|---|
committer | marmeladema <xademax@gmail.com> | 2019-07-24 08:18:20 +0100 |
commit | dbcd8d7af232cd10c3a8ef751076cc7b9cd068a4 (patch) | |
tree | 2bdde950e75d6f6a7ab522f37fa779fe62bc0244 /components/script/script_runtime.rs | |
parent | 5d85f60f7df1316eca8f80714acb4ba519a1082d (diff) | |
download | servo-dbcd8d7af232cd10c3a8ef751076cc7b9cd068a4.tar.gz servo-dbcd8d7af232cd10c3a8ef751076cc7b9cd068a4.zip |
Add safe JSontext wrapper around unsafe RawJSContext
Diffstat (limited to 'components/script/script_runtime.rs')
-rw-r--r-- | components/script/script_runtime.rs | 19 |
1 files changed, 19 insertions, 0 deletions
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 + } +} |