mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Auto merge of #22084 - KiChjang:idl-default-empty-array, r=jdm
Handle default empty sequence values Fixes #22077. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22084) <!-- Reviewable:end -->
This commit is contained in:
commit
200cc8aa6b
3 changed files with 22 additions and 15 deletions
|
@ -17,6 +17,7 @@ import functools
|
||||||
from WebIDL import (
|
from WebIDL import (
|
||||||
BuiltinTypes,
|
BuiltinTypes,
|
||||||
IDLBuiltinType,
|
IDLBuiltinType,
|
||||||
|
IDLEmptySequenceValue,
|
||||||
IDLInterfaceMember,
|
IDLInterfaceMember,
|
||||||
IDLNullableType,
|
IDLNullableType,
|
||||||
IDLNullValue,
|
IDLNullValue,
|
||||||
|
@ -673,17 +674,19 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
('throw_type_error(cx, \"%s is not callable.\");\n'
|
('throw_type_error(cx, \"%s is not callable.\");\n'
|
||||||
'%s' % (firstCap(sourceDescription), exceptionCode)))
|
'%s' % (firstCap(sourceDescription), exceptionCode)))
|
||||||
|
|
||||||
# A helper function for handling null default values. Checks that the
|
# A helper function for handling default values.
|
||||||
# default value, if it exists, is null.
|
def handleDefault(nullValue):
|
||||||
def handleDefaultNull(nullValue):
|
|
||||||
if defaultValue is None:
|
if defaultValue is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not isinstance(defaultValue, IDLNullValue):
|
if isinstance(defaultValue, IDLNullValue):
|
||||||
raise TypeError("Can't handle non-null default value here")
|
assert type.nullable() or type.isDictionary()
|
||||||
|
return nullValue
|
||||||
|
elif isinstance(defaultValue, IDLEmptySequenceValue):
|
||||||
|
assert type.isSequence()
|
||||||
|
return "Vec::new()"
|
||||||
|
|
||||||
assert type.nullable() or type.isDictionary()
|
raise TypeError("Can't handle non-null or non-empty sequence default value here")
|
||||||
return nullValue
|
|
||||||
|
|
||||||
# A helper function for wrapping up the template body for
|
# A helper function for wrapping up the template body for
|
||||||
# possibly-nullable objecty stuff
|
# possibly-nullable objecty stuff
|
||||||
|
@ -726,7 +729,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
" _ => { %s },\n"
|
" _ => { %s },\n"
|
||||||
"}" % (config, indent(failOrPropagate, 8), exceptionCode))
|
"}" % (config, indent(failOrPropagate, 8), exceptionCode))
|
||||||
|
|
||||||
return handleOptional(templateBody, declType, handleDefaultNull("None"))
|
return handleOptional(templateBody, declType, handleDefault("None"))
|
||||||
|
|
||||||
if type.isUnion():
|
if type.isUnion():
|
||||||
declType = CGGeneric(union_native_type(type))
|
declType = CGGeneric(union_native_type(type))
|
||||||
|
@ -758,7 +761,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
else:
|
else:
|
||||||
default = None
|
default = None
|
||||||
else:
|
else:
|
||||||
default = handleDefaultNull("None")
|
default = handleDefault("None")
|
||||||
|
|
||||||
return handleOptional(templateBody, declType, default)
|
return handleOptional(templateBody, declType, default)
|
||||||
|
|
||||||
|
@ -810,7 +813,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
declType = CGGeneric("&Promise")
|
declType = CGGeneric("&Promise")
|
||||||
else:
|
else:
|
||||||
declType = CGGeneric("Rc<Promise>")
|
declType = CGGeneric("Rc<Promise>")
|
||||||
return handleOptional(templateBody, declType, handleDefaultNull("None"))
|
return handleOptional(templateBody, declType, handleDefault("None"))
|
||||||
|
|
||||||
if type.isGeckoInterface():
|
if type.isGeckoInterface():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
@ -828,7 +831,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
isDefinitelyObject, type,
|
isDefinitelyObject, type,
|
||||||
failureCode)
|
failureCode)
|
||||||
|
|
||||||
return handleOptional(template, declType, handleDefaultNull("None"))
|
return handleOptional(template, declType, handleDefault("None"))
|
||||||
|
|
||||||
conversionFunction = "root_from_handlevalue"
|
conversionFunction = "root_from_handlevalue"
|
||||||
descriptorType = descriptor.returnType
|
descriptorType = descriptor.returnType
|
||||||
|
@ -875,7 +878,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
templateBody = wrapObjectTemplate(templateBody, "None",
|
templateBody = wrapObjectTemplate(templateBody, "None",
|
||||||
isDefinitelyObject, type, failureCode)
|
isDefinitelyObject, type, failureCode)
|
||||||
|
|
||||||
return handleOptional(templateBody, declType, handleDefaultNull("None"))
|
return handleOptional(templateBody, declType, handleDefault("None"))
|
||||||
|
|
||||||
if is_typed_array(type):
|
if is_typed_array(type):
|
||||||
if failureCode is None:
|
if failureCode is None:
|
||||||
|
@ -918,7 +921,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
templateBody = wrapObjectTemplate(templateBody, "None",
|
templateBody = wrapObjectTemplate(templateBody, "None",
|
||||||
isDefinitelyObject, type, failureCode)
|
isDefinitelyObject, type, failureCode)
|
||||||
|
|
||||||
return handleOptional(templateBody, declType, handleDefaultNull("None"))
|
return handleOptional(templateBody, declType, handleDefault("None"))
|
||||||
|
|
||||||
elif type.isSpiderMonkeyInterface():
|
elif type.isSpiderMonkeyInterface():
|
||||||
raise TypeError("Can't handle SpiderMonkey interface arguments other than typed arrays yet")
|
raise TypeError("Can't handle SpiderMonkey interface arguments other than typed arrays yet")
|
||||||
|
@ -1145,7 +1148,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
isDefinitelyObject, type, failureCode)
|
isDefinitelyObject, type, failureCode)
|
||||||
|
|
||||||
return handleOptional(templateBody, declType,
|
return handleOptional(templateBody, declType,
|
||||||
handleDefaultNull(default))
|
handleDefault(default))
|
||||||
|
|
||||||
if type.isDictionary():
|
if type.isDictionary():
|
||||||
# There are no nullable dictionaries
|
# There are no nullable dictionaries
|
||||||
|
@ -1167,7 +1170,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
" _ => { %s },\n"
|
" _ => { %s },\n"
|
||||||
"}" % (indent(failOrPropagate, 8), exceptionCode))
|
"}" % (indent(failOrPropagate, 8), exceptionCode))
|
||||||
|
|
||||||
return handleOptional(template, declType, handleDefaultNull(empty))
|
return handleOptional(template, declType, handleDefault(empty))
|
||||||
|
|
||||||
if type.isVoid():
|
if type.isVoid():
|
||||||
# This one only happens for return values, and its easy: Just
|
# This one only happens for return values, and its easy: Just
|
||||||
|
|
|
@ -554,6 +554,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
dict: RootedTraceableBox::new(TestDictionaryDefaults {
|
dict: RootedTraceableBox::new(TestDictionaryDefaults {
|
||||||
UnrestrictedDoubleValue: 0.0,
|
UnrestrictedDoubleValue: 0.0,
|
||||||
anyValue: RootedTraceableBox::new(Heap::default()),
|
anyValue: RootedTraceableBox::new(Heap::default()),
|
||||||
|
arrayValue: Vec::new(),
|
||||||
booleanValue: false,
|
booleanValue: false,
|
||||||
bytestringValue: ByteString::new(vec![]),
|
bytestringValue: ByteString::new(vec![]),
|
||||||
byteValue: 0,
|
byteValue: 0,
|
||||||
|
@ -790,6 +791,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn PassOptionalUsvstringWithDefault(&self, _: USVString) {}
|
fn PassOptionalUsvstringWithDefault(&self, _: USVString) {}
|
||||||
fn PassOptionalBytestringWithDefault(&self, _: ByteString) {}
|
fn PassOptionalBytestringWithDefault(&self, _: ByteString) {}
|
||||||
fn PassOptionalEnumWithDefault(&self, _: TestEnum) {}
|
fn PassOptionalEnumWithDefault(&self, _: TestEnum) {}
|
||||||
|
fn PassOptionalSequenceWithDefault(&self, _: Vec<i32>) {}
|
||||||
|
|
||||||
fn PassOptionalNullableBooleanWithDefault(&self, _: Option<bool>) {}
|
fn PassOptionalNullableBooleanWithDefault(&self, _: Option<bool>) {}
|
||||||
fn PassOptionalNullableByteWithDefault(&self, _: Option<i8>) {}
|
fn PassOptionalNullableByteWithDefault(&self, _: Option<i8>) {}
|
||||||
|
|
|
@ -64,6 +64,7 @@ dictionary TestDictionaryDefaults {
|
||||||
USVString usvstringValue = "foo";
|
USVString usvstringValue = "foo";
|
||||||
TestEnum enumValue = "bar";
|
TestEnum enumValue = "bar";
|
||||||
any anyValue = null;
|
any anyValue = null;
|
||||||
|
sequence<object> arrayValue = [];
|
||||||
|
|
||||||
boolean? nullableBooleanValue = false;
|
boolean? nullableBooleanValue = false;
|
||||||
byte? nullableByteValue = 7;
|
byte? nullableByteValue = 7;
|
||||||
|
@ -380,6 +381,7 @@ interface TestBinding {
|
||||||
void passOptionalStringWithDefault(optional DOMString arg = "x");
|
void passOptionalStringWithDefault(optional DOMString arg = "x");
|
||||||
void passOptionalUsvstringWithDefault(optional USVString arg = "x");
|
void passOptionalUsvstringWithDefault(optional USVString arg = "x");
|
||||||
void passOptionalEnumWithDefault(optional TestEnum arg = "foo");
|
void passOptionalEnumWithDefault(optional TestEnum arg = "foo");
|
||||||
|
void passOptionalSequenceWithDefault(optional sequence<long> seq = []);
|
||||||
// void passOptionalUnionWithDefault(optional (HTMLElement or long) arg = 9);
|
// void passOptionalUnionWithDefault(optional (HTMLElement or long) arg = 9);
|
||||||
// void passOptionalUnion2WithDefault(optional(Event or DOMString)? data = "foo");
|
// void passOptionalUnion2WithDefault(optional(Event or DOMString)? data = "foo");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue