Skip to content

Commit

Permalink
auto merge of #2573 : Manishearth/servo/union-return, r=Ms2ger
Browse files Browse the repository at this point in the history
Blocks #2559
  • Loading branch information
bors-servo committed Jun 7, 2014
2 parents 1184b50 + 7843b7b commit c787fde
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/components/script/dom/bindings/codegen/CodegenRust.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ def finish(self, scope):
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 "
Expand Down
17 changes: 14 additions & 3 deletions src/components/script/dom/testbinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {}

Expand Down Expand Up @@ -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 }
Expand All @@ -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) }
Expand All @@ -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) {}
Expand Down
12 changes: 8 additions & 4 deletions src/components/script/dom/webidls/TestBinding.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -106,6 +106,8 @@ interface TestBinding {
TestEnum receiveEnum();
Blob receiveInterface();
any receiveAny();
(HTMLElement or long) receiveUnion();
(Event or DOMString) receiveUnion2();

byte? receiveNullableByte();
boolean? receiveNullableBoolean();
Expand All @@ -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);
Expand Down

0 comments on commit c787fde

Please sign in to comment.