mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Allow union types to be used as return values
This commit is contained in:
parent
1184b500e5
commit
7843b7b317
4 changed files with 28 additions and 8 deletions
|
@ -1002,6 +1002,11 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
|
|||
if returnType.nullable():
|
||||
result = CGWrapper(result, pre="Option<", post=">")
|
||||
return result
|
||||
if returnType.isUnion():
|
||||
result = CGGeneric('%s::%s' % (returnType.unroll().name, returnType.unroll().name))
|
||||
if returnType.nullable():
|
||||
result = CGWrapper(result, pre="Option<", post=">")
|
||||
return result
|
||||
if returnType.isAny():
|
||||
return CGGeneric("JSVal")
|
||||
if returnType.isObject() or returnType.isSpiderMonkeyInterface():
|
||||
|
|
|
@ -2133,7 +2133,7 @@ class IDLAttribute(IDLInterfaceMember):
|
|||
raise WebIDLError("An attribute cannot be of a sequence type",
|
||||
[self.location])
|
||||
if self.type.isUnion():
|
||||
for f in self.type.flatMemberTypes:
|
||||
for f in self.type.unroll().flatMemberTypes:
|
||||
if f.isDictionary():
|
||||
raise WebIDLError("An attribute cannot be of a union "
|
||||
"type if one of its member types (or "
|
||||
|
|
|
@ -6,8 +6,8 @@ use dom::bindings::js::{JS, JSRef, Temporary};
|
|||
use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnum;
|
||||
use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnumValues::_empty;
|
||||
use dom::bindings::codegen::UnionTypes::BlobOrString::BlobOrString;
|
||||
use dom::bindings::codegen::UnionTypes::EventOrString::EventOrString;
|
||||
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong::HTMLElementOrLong;
|
||||
use dom::bindings::codegen::UnionTypes::EventOrString::{EventOrString, eString};
|
||||
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong::{HTMLElementOrLong, eLong};
|
||||
use dom::bindings::str::ByteString;
|
||||
use dom::bindings::utils::{Reflector, Reflectable};
|
||||
use dom::blob::Blob;
|
||||
|
@ -56,6 +56,10 @@ pub trait TestBindingMethods {
|
|||
fn SetEnumAttribute(&self, _: TestEnum) {}
|
||||
fn InterfaceAttribute(&self) -> Temporary<Blob>;
|
||||
fn SetInterfaceAttribute(&self, _: &JSRef<Blob>) {}
|
||||
fn UnionAttribute(&self) -> HTMLElementOrLong { eLong(0) }
|
||||
fn SetUnionAttribute(&self, _: HTMLElementOrLong) {}
|
||||
fn Union2Attribute(&self) -> EventOrString { eString("".to_string()) }
|
||||
fn SetUnion2Attribute(&self, _: EventOrString) {}
|
||||
fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||
fn SetAnyAttribute(&self, _: *mut JSContext, _: JSVal) {}
|
||||
|
||||
|
@ -88,7 +92,10 @@ pub trait TestBindingMethods {
|
|||
fn GetEnumAttributeNullable(&self) -> Option<TestEnum> { Some(_empty) }
|
||||
fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>>;
|
||||
fn SetInterfaceAttributeNullable(&self, _: Option<JSRef<Blob>>) {}
|
||||
|
||||
fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> { Some(eLong(0)) }
|
||||
fn SetUnionAttributeNullable(&self, _: Option<HTMLElementOrLong>) {}
|
||||
fn GetUnion2AttributeNullable(&self) -> Option<EventOrString> { Some(eString("".to_string())) }
|
||||
fn SetUnion2AttributeNullable(&self, _: Option<EventOrString>) {}
|
||||
fn ReceiveVoid(&self) -> () {}
|
||||
fn ReceiveBoolean(&self) -> bool { false }
|
||||
fn ReceiveByte(&self) -> i8 { 0 }
|
||||
|
@ -106,6 +113,8 @@ pub trait TestBindingMethods {
|
|||
fn ReceiveEnum(&self) -> TestEnum { _empty }
|
||||
fn ReceiveInterface(&self) -> Temporary<Blob>;
|
||||
fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||
fn ReceiveUnion(&self) -> HTMLElementOrLong { eLong(0) }
|
||||
fn ReceiveUnion2(&self) -> EventOrString { eString("".to_string()) }
|
||||
|
||||
fn ReceiveNullableBoolean(&self) -> Option<bool> { Some(false) }
|
||||
fn ReceiveNullableByte(&self) -> Option<i8> { Some(0) }
|
||||
|
@ -123,6 +132,8 @@ pub trait TestBindingMethods {
|
|||
fn ReceiveNullableEnum(&self) -> Option<TestEnum> { Some(_empty) }
|
||||
fn ReceiveNullableInterface(&self) -> Option<Temporary<Blob>>;
|
||||
fn ReceiveNullableAny(&self, _: *mut JSContext) -> Option<JSVal> { Some(NullValue()) }
|
||||
fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> { Some(eLong(0)) }
|
||||
fn ReceiveNullableUnion2(&self) -> Option<EventOrString> { Some(eString("".to_string())) }
|
||||
|
||||
fn PassBoolean(&self, _: bool) {}
|
||||
fn PassByte(&self, _: i8) {}
|
||||
|
|
|
@ -69,8 +69,8 @@ interface TestBinding {
|
|||
attribute ByteString byteStringAttribute;
|
||||
attribute TestEnum enumAttribute;
|
||||
attribute Blob interfaceAttribute;
|
||||
// attribute (HTMLElement or long) unionAttribute;
|
||||
// attribute (Event or DOMString) union2Attribute;
|
||||
attribute (HTMLElement or long) unionAttribute;
|
||||
attribute (Event or DOMString) union2Attribute;
|
||||
attribute any anyAttribute;
|
||||
|
||||
attribute boolean? booleanAttributeNullable;
|
||||
|
@ -88,8 +88,8 @@ interface TestBinding {
|
|||
attribute ByteString? byteStringAttributeNullable;
|
||||
readonly attribute TestEnum? enumAttributeNullable;
|
||||
attribute Blob? interfaceAttributeNullable;
|
||||
// attribute (HTMLElement or long)? unionAttributeNullable;
|
||||
// attribute (Event or DOMString)? union2AttributeNullable;
|
||||
attribute (HTMLElement or long)? unionAttributeNullable;
|
||||
attribute (Event or DOMString)? union2AttributeNullable;
|
||||
|
||||
void receiveVoid();
|
||||
boolean receiveBoolean();
|
||||
|
@ -106,6 +106,8 @@ interface TestBinding {
|
|||
TestEnum receiveEnum();
|
||||
Blob receiveInterface();
|
||||
any receiveAny();
|
||||
(HTMLElement or long) receiveUnion();
|
||||
(Event or DOMString) receiveUnion2();
|
||||
|
||||
byte? receiveNullableByte();
|
||||
boolean? receiveNullableBoolean();
|
||||
|
@ -120,6 +122,8 @@ interface TestBinding {
|
|||
ByteString? receiveNullableByteString();
|
||||
TestEnum? receiveNullableEnum();
|
||||
Blob? receiveNullableInterface();
|
||||
(HTMLElement or long)? receiveNullableUnion();
|
||||
(Event or DOMString)? receiveNullableUnion2();
|
||||
|
||||
void passBoolean(boolean arg);
|
||||
void passByte(byte arg);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue