diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-11-07 22:35:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-07 22:35:43 -0500 |
commit | df9065afb6e1716044855a310d1e24f05221721d (patch) | |
tree | 17309749516f1f4e9c7fba4a67da05e1dfb46b9d /components/script/dom/bindings | |
parent | fc7b88019538de63fdd4d24ed720ad7198602fd8 (diff) | |
parent | cf46a9a6dc1b57874a6f4722660b1a57b737b02e (diff) | |
download | servo-df9065afb6e1716044855a310d1e24f05221721d.tar.gz servo-df9065afb6e1716044855a310d1e24f05221721d.zip |
Auto merge of #24636 - saschanaz:windowproxy, r=nox,jdm
Use MessageEventSource on MessageEvent IDL
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #22617
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___
<!-- 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. -->
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 4 | ||||
-rw-r--r-- | components/script/dom/bindings/conversions.rs | 22 |
2 files changed, 25 insertions, 1 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 77c3c776c3e..e660471364e 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -836,6 +836,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, descriptorType = descriptor.nativeType elif isArgument: descriptorType = descriptor.argumentType + elif descriptor.interface.identifier.name == "WindowProxy": + conversionFunction = "windowproxy_from_handlevalue" if failureCode is None: substitutions = { @@ -2409,6 +2411,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config): 'crate::dom::bindings::conversions::ConversionBehavior', 'crate::dom::bindings::conversions::StringificationBehavior', 'crate::dom::bindings::conversions::root_from_handlevalue', + 'crate::dom::bindings::conversions::windowproxy_from_handlevalue', 'std::ptr::NonNull', 'crate::dom::bindings::record::Record', 'crate::dom::bindings::num::Finite', @@ -2419,6 +2422,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config): 'crate::dom::bindings::trace::RootedTraceableBox', 'crate::dom::bindings::utils::find_enum_value', 'crate::dom::types::*', + 'crate::dom::windowproxy::WindowProxy', 'crate::script_runtime::JSContext as SafeJSContext', 'js::error::throw_type_error', 'js::rust::HandleValue', diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index c84adf64dbb..863c84c0512 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -45,6 +45,7 @@ use crate::dom::htmlcollection::HTMLCollection; use crate::dom::htmlformcontrolscollection::HTMLFormControlsCollection; use crate::dom::htmloptionscollection::HTMLOptionsCollection; use crate::dom::nodelist::NodeList; +use crate::dom::windowproxy::WindowProxy; use js::conversions::latin1_to_string; pub use js::conversions::ConversionBehavior; pub use js::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible}; @@ -55,10 +56,10 @@ use js::glue::{IsWrapper, UnwrapObjectDynamic}; use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT}; use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING}; use js::jsapi::{Heap, JSContext, JSObject, JSString}; +use js::jsapi::{IsWindowProxy, JS_NewStringCopyN, JS_StringHasLatin1Chars}; use js::jsapi::{ JS_GetLatin1StringCharsAndLength, JS_GetTwoByteStringCharsAndLength, JS_IsExceptionPending, }; -use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars}; use js::jsval::{ObjectValue, StringValue, UndefinedValue}; use js::rust::wrappers::{JS_GetProperty, JS_HasProperty, JS_IsArrayObject}; use js::rust::{get_object_class, is_dom_class, is_dom_object, maybe_wrap_value, ToString}; @@ -634,3 +635,22 @@ where Err(()) => Err(Error::JSFailed), } } + +/// Get a `DomRoot<T>` for a WindowProxy accessible from a `HandleValue`. +/// Caller is responsible for throwing a JS exception if needed in case of error. +pub unsafe fn windowproxy_from_handlevalue( + v: HandleValue, + _cx: *mut JSContext, +) -> Result<DomRoot<WindowProxy>, ()> { + if !v.get().is_object() { + return Err(()); + } + let object = v.get().to_object(); + if !IsWindowProxy(object) { + return Err(()); + } + let mut value = UndefinedValue(); + GetProxyReservedSlot(object, 0, &mut value); + let ptr = value.to_private() as *const WindowProxy; + Ok(DomRoot::from_ref(&*ptr)) +} |