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/document.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/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index d7e77ef9243..85639964710 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -102,6 +102,7 @@ use crate::dom::wheelevent::WheelEvent; use crate::dom::window::{ReflowReason, Window}; use crate::dom::windowproxy::WindowProxy; use crate::fetch::FetchCanceller; +use crate::script_runtime::JSContext; use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; use crate::script_thread::{MainThreadScriptMsg, ScriptThread}; use crate::stylesheet_set::StylesheetSetRef; @@ -117,7 +118,7 @@ use euclid::default::Point2D; use html5ever::{LocalName, Namespace, QualName}; use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{JSContext, JSObject, JSRuntime}; +use js::jsapi::{JSObject, JSRuntime}; use keyboard_types::{Key, KeyState, Modifiers}; use metrics::{ InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory, @@ -4218,11 +4219,7 @@ impl DocumentMethods for Document { #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter - unsafe fn NamedGetter( - &self, - _cx: *mut JSContext, - name: DOMString, - ) -> Option<NonNull<JSObject>> { + fn NamedGetter(&self, _cx: JSContext, name: DOMString) -> Option<NonNull<JSObject>> { #[derive(JSTraceable, MallocSizeOf)] struct NamedElementFilter { name: Atom, @@ -4270,7 +4267,7 @@ impl DocumentMethods for Document { } let name = Atom::from(name); let root = self.upcast::<Node>(); - { + unsafe { // Step 1. let mut elements = root .traverse_preorder(ShadowIncluding::No) @@ -4291,9 +4288,11 @@ impl DocumentMethods for Document { // Step 4. let filter = NamedElementFilter { name: name }; let collection = HTMLCollection::create(self.window(), root, Box::new(filter)); - Some(NonNull::new_unchecked( - collection.reflector().get_jsobject().get(), - )) + unsafe { + Some(NonNull::new_unchecked( + collection.reflector().get_jsobject().get(), + )) + } } // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names |