mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
auto merge of #2558 : Ms2ger/servo/mod-unions, r=jdm
This will allow multiple unions to contain the same type.
This commit is contained in:
commit
d448e97c6a
4 changed files with 29 additions and 19 deletions
|
@ -555,7 +555,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
raise TypeError("Can't handle unions as members, we have a "
|
raise TypeError("Can't handle unions as members, we have a "
|
||||||
"holderType")
|
"holderType")
|
||||||
|
|
||||||
declType = CGGeneric(type.name)
|
declType = CGGeneric(type.name + "::" + type.name)
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
declType = CGWrapper(declType, pre="Option<", post=" >")
|
declType = CGWrapper(declType, pre="Option<", post=" >")
|
||||||
|
|
||||||
|
@ -1657,6 +1657,20 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
|
||||||
Returns a CGList containing CGUnionStructs for every union.
|
Returns a CGList containing CGUnionStructs for every union.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
'dom::bindings::utils::unwrap_jsmanaged',
|
||||||
|
'dom::bindings::codegen::PrototypeList',
|
||||||
|
'dom::bindings::conversions::FromJSValConvertible',
|
||||||
|
'dom::bindings::conversions::ToJSValConvertible',
|
||||||
|
'dom::bindings::conversions::Default',
|
||||||
|
'dom::bindings::error::throw_not_in_union',
|
||||||
|
'dom::bindings::js::JS',
|
||||||
|
'dom::types::*',
|
||||||
|
'js::jsapi::JSContext',
|
||||||
|
'js::jsval::JSVal',
|
||||||
|
'servo_util::str::DOMString',
|
||||||
|
]
|
||||||
|
|
||||||
# Now find all the things we'll need as arguments and return values because
|
# Now find all the things we'll need as arguments and return values because
|
||||||
# we need to wrap or unwrap them.
|
# we need to wrap or unwrap them.
|
||||||
unionStructs = dict()
|
unionStructs = dict()
|
||||||
|
@ -1668,7 +1682,12 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
|
||||||
name = str(t)
|
name = str(t)
|
||||||
if not name in unionStructs:
|
if not name in unionStructs:
|
||||||
provider = descriptor or config.getDescriptorProvider()
|
provider = descriptor or config.getDescriptorProvider()
|
||||||
unionStructs[name] = CGList([CGUnionStruct(t, provider), CGUnionConversionStruct(t, provider)])
|
unionStructs[name] = CGNamespace(name,
|
||||||
|
CGImports(CGList([
|
||||||
|
CGUnionStruct(t, provider),
|
||||||
|
CGUnionConversionStruct(t, provider)
|
||||||
|
]), [], imports),
|
||||||
|
public=True)
|
||||||
|
|
||||||
return CGList(SortedDictValues(unionStructs), "\n\n")
|
return CGList(SortedDictValues(unionStructs), "\n\n")
|
||||||
|
|
||||||
|
@ -4531,7 +4550,7 @@ class CGNativeMember(ClassMethod):
|
||||||
if type.isUnion():
|
if type.isUnion():
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
type = type.inner
|
type = type.inner
|
||||||
return str(type), False, True
|
return str(type) + "::" + str(type), False, True
|
||||||
|
|
||||||
if type.isGeckoInterface() and not type.isCallbackInterface():
|
if type.isGeckoInterface() and not type.isCallbackInterface():
|
||||||
iface = type.unroll().inner
|
iface = type.unroll().inner
|
||||||
|
@ -5315,20 +5334,6 @@ class GlobalGenRoots():
|
||||||
config.getCallbacks(),
|
config.getCallbacks(),
|
||||||
config)
|
config)
|
||||||
|
|
||||||
curr = CGImports(curr, [], [
|
|
||||||
'dom::bindings::utils::unwrap_jsmanaged',
|
|
||||||
'dom::bindings::codegen::PrototypeList',
|
|
||||||
'dom::bindings::conversions::FromJSValConvertible',
|
|
||||||
'dom::bindings::conversions::ToJSValConvertible',
|
|
||||||
'dom::bindings::conversions::Default',
|
|
||||||
'dom::bindings::error::throw_not_in_union',
|
|
||||||
'dom::bindings::js::JS',
|
|
||||||
'dom::types::*',
|
|
||||||
'js::jsapi::JSContext',
|
|
||||||
'js::jsval::JSVal',
|
|
||||||
'servo_util::str::DOMString',
|
|
||||||
])
|
|
||||||
|
|
||||||
# Add the auto-generated comment.
|
# Add the auto-generated comment.
|
||||||
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
|
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding;
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLSelectElementDerived;
|
use dom::bindings::codegen::InheritTypes::HTMLSelectElementDerived;
|
||||||
use dom::bindings::codegen::UnionTypes::{HTMLElementOrLong, HTMLOptionElementOrHTMLOptGroupElement};
|
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong::HTMLElementOrLong;
|
||||||
|
use dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement::HTMLOptionElementOrHTMLOptGroupElement;
|
||||||
use dom::bindings::js::{JSRef, Temporary};
|
use dom::bindings::js::{JSRef, Temporary};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::HTMLSelectElementTypeId;
|
use dom::element::HTMLSelectElementTypeId;
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||||
use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnum;
|
use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnum;
|
||||||
use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnumValues::_empty;
|
use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnumValues::_empty;
|
||||||
use dom::bindings::codegen::UnionTypes::{HTMLElementOrLong, EventOrString};
|
use dom::bindings::codegen::UnionTypes::BlobOrString::BlobOrString;
|
||||||
|
use dom::bindings::codegen::UnionTypes::EventOrString::EventOrString;
|
||||||
|
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong::HTMLElementOrLong;
|
||||||
use dom::bindings::str::ByteString;
|
use dom::bindings::str::ByteString;
|
||||||
use dom::bindings::utils::{Reflector, Reflectable};
|
use dom::bindings::utils::{Reflector, Reflectable};
|
||||||
use dom::blob::Blob;
|
use dom::blob::Blob;
|
||||||
|
@ -139,6 +141,7 @@ pub trait TestBindingMethods {
|
||||||
fn PassInterface(&self, _: &JSRef<Blob>) {}
|
fn PassInterface(&self, _: &JSRef<Blob>) {}
|
||||||
fn PassUnion(&self, _: HTMLElementOrLong) {}
|
fn PassUnion(&self, _: HTMLElementOrLong) {}
|
||||||
fn PassUnion2(&self, _: EventOrString) {}
|
fn PassUnion2(&self, _: EventOrString) {}
|
||||||
|
fn PassUnion3(&self, _: BlobOrString) {}
|
||||||
fn PassAny(&self, _: *mut JSContext, _: JSVal) {}
|
fn PassAny(&self, _: *mut JSContext, _: JSVal) {}
|
||||||
|
|
||||||
fn PassNullableBoolean(&self, _: Option<bool>) {}
|
fn PassNullableBoolean(&self, _: Option<bool>) {}
|
||||||
|
|
|
@ -138,6 +138,7 @@ interface TestBinding {
|
||||||
void passInterface(Blob arg);
|
void passInterface(Blob arg);
|
||||||
void passUnion((HTMLElement or long) arg);
|
void passUnion((HTMLElement or long) arg);
|
||||||
void passUnion2((Event or DOMString) data);
|
void passUnion2((Event or DOMString) data);
|
||||||
|
void passUnion3((Blob or DOMString) data);
|
||||||
void passAny(any arg);
|
void passAny(any arg);
|
||||||
|
|
||||||
void passNullableBoolean(boolean? arg);
|
void passNullableBoolean(boolean? arg);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue