diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-07-24 11:54:47 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-24 11:54:47 -0400 |
commit | 9b14bbdc98ea078a4f868abee1b7c7244161f46d (patch) | |
tree | c3061b4cc48e42c8fa247d43cdd0f263e70be0df /components/script/dom/permissions.rs | |
parent | 410c8e5085b45d5d0628159cecc3df05f82ac87d (diff) | |
parent | 88cacfb0098e20be70c27bfde6b74cd3290f1fe4 (diff) | |
download | servo-9b14bbdc98ea078a4f868abee1b7c7244161f46d.tar.gz servo-9b14bbdc98ea078a4f868abee1b7c7244161f46d.zip |
Auto merge of #23816 - marmeladema:issue-20377, r=jdm
Wrapping unsafe raw JSContext pointers in a safe struct. Part 1.
Wrapping unsafe raw JSContext pointers in a safe struct. Issue #20377.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] create a struct JSContext(*mut jsapi::JSContext) type
- [x] implement Deref for this new type so it's easy to obtain the inner context pointer
- [x] add an unsafe from_ptr static method that returns a new instance of the type
- [x] start by changing various Argument uses in CodegenRust.py for python classes that inherit from CGAbstractMethod
- [x] convert the python code that interacts with CGClass (CGCallback, CGCallbackFunction, CGCallbackFunctionImpl, CGCallbackInterface) and any rust code that interacts with it
- [x] update CGDictionary and any rust code that interacts with it
- [x] make the code generator declare trait methods that accept the new type instead of *mut JSContext (CGInterfaceTrait)
- [x] modify GlobalScope::get_cx to return a SafeJSContext
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23816)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/permissions.rs')
-rw-r--r-- | components/script/dom/permissions.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/components/script/dom/permissions.rs b/components/script/dom/permissions.rs index 5c6d7b0aed0..419115d1240 100644 --- a/components/script/dom/permissions.rs +++ b/components/script/dom/permissions.rs @@ -17,6 +17,7 @@ use crate::dom::bluetoothpermissionresult::BluetoothPermissionResult; use crate::dom::globalscope::GlobalScope; use crate::dom::permissionstatus::PermissionStatus; use crate::dom::promise::Promise; +use crate::script_runtime::JSContext as SafeJSContext; use dom_struct::dom_struct; use js::conversions::ConversionResult; use js::jsapi::{JSContext, JSObject}; @@ -199,22 +200,19 @@ impl Permissions { } impl PermissionsMethods for Permissions { - #[allow(unsafe_code)] // https://w3c.github.io/permissions/#dom-permissions-query - unsafe fn Query(&self, cx: *mut JSContext, permissionDesc: *mut JSObject) -> Rc<Promise> { - self.manipulate(Operation::Query, cx, permissionDesc, None) + fn Query(&self, cx: SafeJSContext, permissionDesc: *mut JSObject) -> Rc<Promise> { + self.manipulate(Operation::Query, *cx, permissionDesc, None) } - #[allow(unsafe_code)] // https://w3c.github.io/permissions/#dom-permissions-request - unsafe fn Request(&self, cx: *mut JSContext, permissionDesc: *mut JSObject) -> Rc<Promise> { - self.manipulate(Operation::Request, cx, permissionDesc, None) + fn Request(&self, cx: SafeJSContext, permissionDesc: *mut JSObject) -> Rc<Promise> { + self.manipulate(Operation::Request, *cx, permissionDesc, None) } - #[allow(unsafe_code)] // https://w3c.github.io/permissions/#dom-permissions-revoke - unsafe fn Revoke(&self, cx: *mut JSContext, permissionDesc: *mut JSObject) -> Rc<Promise> { - self.manipulate(Operation::Revoke, cx, permissionDesc, None) + fn Revoke(&self, cx: SafeJSContext, permissionDesc: *mut JSObject) -> Rc<Promise> { + self.manipulate(Operation::Revoke, *cx, permissionDesc, None) } } @@ -232,7 +230,7 @@ impl PermissionAlgorithm for Permissions { .handle_mut() .set(ObjectValue(permission_descriptor_obj)); unsafe { - match PermissionDescriptor::new(cx, property.handle()) { + match PermissionDescriptor::new(SafeJSContext::from_ptr(cx), property.handle()) { Ok(ConversionResult::Success(descriptor)) => Ok(descriptor), Ok(ConversionResult::Failure(error)) => Err(Error::Type(error.into_owned())), Err(_) => Err(Error::JSFailed), |