mirror of
https://github.com/servo/servo.git
synced 2025-07-24 07:40:27 +01:00
parent
b26c7bd7ea
commit
4ad1a8ddcc
3 changed files with 42 additions and 21 deletions
|
@ -1221,7 +1221,7 @@ def getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs):
|
||||||
return "StringificationBehavior::Default"
|
return "StringificationBehavior::Default"
|
||||||
else:
|
else:
|
||||||
return treatAs[treatNullAs]
|
return treatAs[treatNullAs]
|
||||||
if type.isInteger():
|
if type.isPrimitive() and type.isInteger():
|
||||||
if isEnforceRange:
|
if isEnforceRange:
|
||||||
return "ConversionBehavior::EnforceRange"
|
return "ConversionBehavior::EnforceRange"
|
||||||
elif isClamp:
|
elif isClamp:
|
||||||
|
@ -3571,8 +3571,8 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
|
||||||
# for getJSToNativeConversionInfo.
|
# for getJSToNativeConversionInfo.
|
||||||
# Also, for dictionaries we would need to handle conversion of
|
# Also, for dictionaries we would need to handle conversion of
|
||||||
# null/undefined to the dictionary correctly.
|
# null/undefined to the dictionary correctly.
|
||||||
if type.isDictionary() or type.isSequence():
|
if type.isDictionary():
|
||||||
raise TypeError("Can't handle dictionaries or sequences in unions")
|
raise TypeError("Can't handle dictionaries in unions")
|
||||||
|
|
||||||
if type.isGeckoInterface():
|
if type.isGeckoInterface():
|
||||||
name = type.inner.identifier.name
|
name = type.inner.identifier.name
|
||||||
|
@ -3580,7 +3580,11 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
|
||||||
elif type.isEnum():
|
elif type.isEnum():
|
||||||
name = type.inner.identifier.name
|
name = type.inner.identifier.name
|
||||||
typeName = name
|
typeName = name
|
||||||
elif type.isArray() or type.isSequence():
|
elif type.isSequence():
|
||||||
|
name = type.name
|
||||||
|
inner = getUnionTypeTemplateVars(type.unroll(), descriptorProvider)
|
||||||
|
typeName = "Vec<" + inner["typeName"] + ">"
|
||||||
|
elif type.isArray():
|
||||||
name = str(type)
|
name = str(type)
|
||||||
# XXXjdm dunno about typeName here
|
# XXXjdm dunno about typeName here
|
||||||
typeName = "/*" + type.name + "*/"
|
typeName = "/*" + type.name + "*/"
|
||||||
|
@ -3664,22 +3668,22 @@ class CGUnionConversionStruct(CGThing):
|
||||||
names = []
|
names = []
|
||||||
conversions = []
|
conversions = []
|
||||||
|
|
||||||
|
def get_name(memberType):
|
||||||
|
if self.type.isGeckoInterface():
|
||||||
|
return memberType.inner.identifier.name
|
||||||
|
|
||||||
|
return memberType.name
|
||||||
|
|
||||||
|
def get_match(name):
|
||||||
|
return (
|
||||||
|
"match %s::TryConvertTo%s(cx, value) {\n"
|
||||||
|
" Err(_) => return Err(()),\n"
|
||||||
|
" Ok(Some(value)) => return Ok(%s::e%s(value)),\n"
|
||||||
|
" Ok(None) => (),\n"
|
||||||
|
"}\n") % (self.type, name, self.type, name)
|
||||||
|
|
||||||
interfaceMemberTypes = filter(lambda t: t.isNonCallbackInterface(), memberTypes)
|
interfaceMemberTypes = filter(lambda t: t.isNonCallbackInterface(), memberTypes)
|
||||||
if len(interfaceMemberTypes) > 0:
|
if len(interfaceMemberTypes) > 0:
|
||||||
def get_name(memberType):
|
|
||||||
if self.type.isGeckoInterface():
|
|
||||||
return memberType.inner.identifier.name
|
|
||||||
|
|
||||||
return memberType.name
|
|
||||||
|
|
||||||
def get_match(name):
|
|
||||||
return (
|
|
||||||
"match %s::TryConvertTo%s(cx, value) {\n"
|
|
||||||
" Err(_) => return Err(()),\n"
|
|
||||||
" Ok(Some(value)) => return Ok(%s::e%s(value)),\n"
|
|
||||||
" Ok(None) => (),\n"
|
|
||||||
"}\n") % (self.type, name, self.type, name)
|
|
||||||
|
|
||||||
typeNames = [get_name(memberType) for memberType in interfaceMemberTypes]
|
typeNames = [get_name(memberType) for memberType in interfaceMemberTypes]
|
||||||
interfaceObject = CGList(CGGeneric(get_match(typeName)) for typeName in typeNames)
|
interfaceObject = CGList(CGGeneric(get_match(typeName)) for typeName in typeNames)
|
||||||
names.extend(typeNames)
|
names.extend(typeNames)
|
||||||
|
@ -3689,7 +3693,9 @@ class CGUnionConversionStruct(CGThing):
|
||||||
arrayObjectMemberTypes = filter(lambda t: t.isArray() or t.isSequence(), memberTypes)
|
arrayObjectMemberTypes = filter(lambda t: t.isArray() or t.isSequence(), memberTypes)
|
||||||
if len(arrayObjectMemberTypes) > 0:
|
if len(arrayObjectMemberTypes) > 0:
|
||||||
assert len(arrayObjectMemberTypes) == 1
|
assert len(arrayObjectMemberTypes) == 1
|
||||||
raise TypeError("Can't handle arrays or sequences in unions.")
|
typeName = arrayObjectMemberTypes[0].name
|
||||||
|
arrayObject = CGGeneric(get_match(typeName))
|
||||||
|
names.append(typeName)
|
||||||
else:
|
else:
|
||||||
arrayObject = None
|
arrayObject = None
|
||||||
|
|
||||||
|
@ -3727,8 +3733,12 @@ class CGUnionConversionStruct(CGThing):
|
||||||
|
|
||||||
hasObjectTypes = interfaceObject or arrayObject or dateObject or nonPlatformObject or object
|
hasObjectTypes = interfaceObject or arrayObject or dateObject or nonPlatformObject or object
|
||||||
if hasObjectTypes:
|
if hasObjectTypes:
|
||||||
assert interfaceObject
|
assert interfaceObject or arrayObject
|
||||||
templateBody = CGList([interfaceObject], "\n")
|
templateBody = CGList([], "\n")
|
||||||
|
if interfaceObject:
|
||||||
|
templateBody.append(interfaceObject)
|
||||||
|
if arrayObject:
|
||||||
|
templateBody.append(arrayObject)
|
||||||
conversions.append(CGIfWrapper("value.get().is_object()", templateBody))
|
conversions.append(CGIfWrapper("value.get().is_object()", templateBody))
|
||||||
|
|
||||||
otherMemberTypes = [
|
otherMemberTypes = [
|
||||||
|
|
|
@ -9,6 +9,7 @@ use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||||
use dom::bindings::codegen::Bindings::TestBindingBinding::{self, TestBindingMethods, TestEnum};
|
use dom::bindings::codegen::Bindings::TestBindingBinding::{self, TestBindingMethods, TestEnum};
|
||||||
use dom::bindings::codegen::UnionTypes::{BlobOrString, EventOrString};
|
use dom::bindings::codegen::UnionTypes::{BlobOrString, EventOrString};
|
||||||
use dom::bindings::codegen::UnionTypes::{EventOrUSVString, HTMLElementOrLong};
|
use dom::bindings::codegen::UnionTypes::{EventOrUSVString, HTMLElementOrLong};
|
||||||
|
use dom::bindings::codegen::UnionTypes::{StringOrLongSequence, StringOrStringSequence};
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -188,6 +189,8 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn ReceiveObject(&self, _: *mut JSContext) -> *mut JSObject { panic!() }
|
fn ReceiveObject(&self, _: *mut JSContext) -> *mut JSObject { panic!() }
|
||||||
fn ReceiveUnion(&self) -> HTMLElementOrLong { HTMLElementOrLong::eLong(0) }
|
fn ReceiveUnion(&self) -> HTMLElementOrLong { HTMLElementOrLong::eLong(0) }
|
||||||
fn ReceiveUnion2(&self) -> EventOrString { EventOrString::eString(DOMString::new()) }
|
fn ReceiveUnion2(&self) -> EventOrString { EventOrString::eString(DOMString::new()) }
|
||||||
|
fn ReceiveUnion3(&self) -> StringOrLongSequence { StringOrLongSequence::eLongSequence(vec![]) }
|
||||||
|
fn ReceiveUnion4(&self) -> StringOrStringSequence { StringOrStringSequence::eStringSequence(vec![]) }
|
||||||
fn ReceiveSequence(&self) -> Vec<i32> { vec![1] }
|
fn ReceiveSequence(&self) -> Vec<i32> { vec![1] }
|
||||||
|
|
||||||
fn ReceiveNullableBoolean(&self) -> Option<bool> { Some(false) }
|
fn ReceiveNullableBoolean(&self) -> Option<bool> { Some(false) }
|
||||||
|
@ -217,6 +220,9 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn ReceiveNullableUnion2(&self) -> Option<EventOrString> {
|
fn ReceiveNullableUnion2(&self) -> Option<EventOrString> {
|
||||||
Some(EventOrString::eString(DOMString::new()))
|
Some(EventOrString::eString(DOMString::new()))
|
||||||
}
|
}
|
||||||
|
fn ReceiveNullableUnion3(&self) -> Option<StringOrLongSequence> {
|
||||||
|
Some(StringOrLongSequence::eString(DOMString::new()))
|
||||||
|
}
|
||||||
fn ReceiveNullableSequence(&self) -> Option<Vec<i32>> { Some(vec![1]) }
|
fn ReceiveNullableSequence(&self) -> Option<Vec<i32>> { Some(vec![1]) }
|
||||||
|
|
||||||
fn PassBoolean(&self, _: bool) {}
|
fn PassBoolean(&self, _: bool) {}
|
||||||
|
@ -240,6 +246,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn PassUnion(&self, _: HTMLElementOrLong) {}
|
fn PassUnion(&self, _: HTMLElementOrLong) {}
|
||||||
fn PassUnion2(&self, _: EventOrString) {}
|
fn PassUnion2(&self, _: EventOrString) {}
|
||||||
fn PassUnion3(&self, _: BlobOrString) {}
|
fn PassUnion3(&self, _: BlobOrString) {}
|
||||||
|
fn PassUnion4(&self, _: StringOrStringSequence) {}
|
||||||
fn PassAny(&self, _: *mut JSContext, _: HandleValue) {}
|
fn PassAny(&self, _: *mut JSContext, _: HandleValue) {}
|
||||||
fn PassObject(&self, _: *mut JSContext, _: *mut JSObject) {}
|
fn PassObject(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||||
fn PassCallbackFunction(&self, _: Rc<Function>) {}
|
fn PassCallbackFunction(&self, _: Rc<Function>) {}
|
||||||
|
|
|
@ -149,6 +149,8 @@ interface TestBinding {
|
||||||
object receiveObject();
|
object receiveObject();
|
||||||
(HTMLElement or long) receiveUnion();
|
(HTMLElement or long) receiveUnion();
|
||||||
(Event or DOMString) receiveUnion2();
|
(Event or DOMString) receiveUnion2();
|
||||||
|
(DOMString or sequence<long>) receiveUnion3();
|
||||||
|
(DOMString or sequence<DOMString>) receiveUnion4();
|
||||||
sequence<long> receiveSequence();
|
sequence<long> receiveSequence();
|
||||||
|
|
||||||
byte? receiveNullableByte();
|
byte? receiveNullableByte();
|
||||||
|
@ -172,6 +174,7 @@ interface TestBinding {
|
||||||
object? receiveNullableObject();
|
object? receiveNullableObject();
|
||||||
(HTMLElement or long)? receiveNullableUnion();
|
(HTMLElement or long)? receiveNullableUnion();
|
||||||
(Event or DOMString)? receiveNullableUnion2();
|
(Event or DOMString)? receiveNullableUnion2();
|
||||||
|
(DOMString or sequence<long>)? receiveNullableUnion3();
|
||||||
sequence<long>? receiveNullableSequence();
|
sequence<long>? receiveNullableSequence();
|
||||||
|
|
||||||
void passBoolean(boolean arg);
|
void passBoolean(boolean arg);
|
||||||
|
@ -195,6 +198,7 @@ interface TestBinding {
|
||||||
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 passUnion3((Blob or DOMString) data);
|
||||||
|
void passUnion4((DOMString or sequence<DOMString>) seq);
|
||||||
void passAny(any arg);
|
void passAny(any arg);
|
||||||
void passObject(object arg);
|
void passObject(object arg);
|
||||||
void passCallbackFunction(Function fun);
|
void passCallbackFunction(Function fun);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue