mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Add Clamp and EnforceRange support for webidl arguments.
This commit is contained in:
parent
0888e1acac
commit
7f152b665d
5 changed files with 153 additions and 57 deletions
|
@ -832,7 +832,9 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
if treatNullAs not in treatAs:
|
||||
raise TypeError("We don't support [TreatNullAs=%s]" % treatNullAs)
|
||||
if type.nullable():
|
||||
nullBehavior = "()"
|
||||
# Note: the actual behavior passed here doesn't matter for nullable
|
||||
# strings.
|
||||
nullBehavior = "StringificationBehavior::Default"
|
||||
else:
|
||||
nullBehavior = treatAs[treatNullAs]
|
||||
|
||||
|
@ -1046,7 +1048,16 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
if not type.isPrimitive():
|
||||
raise TypeError("Need conversion for argument type '%s'" % str(type))
|
||||
|
||||
assert not isEnforceRange and not isClamp
|
||||
if type.isInteger():
|
||||
if isEnforceRange:
|
||||
conversionBehavior = "ConversionBehavior::EnforceRange"
|
||||
elif isClamp:
|
||||
conversionBehavior = "ConversionBehavior::Clamp"
|
||||
else:
|
||||
conversionBehavior = "ConversionBehavior::Default"
|
||||
else:
|
||||
assert not isEnforceRange and not isClamp
|
||||
conversionBehavior = "()"
|
||||
|
||||
if failureCode is None:
|
||||
failureCode = 'return 0'
|
||||
|
@ -1055,12 +1066,11 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
if type.nullable():
|
||||
declType = CGWrapper(declType, pre="Option<", post=">")
|
||||
|
||||
# XXXjdm support conversionBehavior here
|
||||
template = (
|
||||
"match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
|
||||
"match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
|
||||
" Ok(v) => v,\n"
|
||||
" Err(_) => { %s }\n"
|
||||
"}" % exceptionCode)
|
||||
"}" % (conversionBehavior, exceptionCode))
|
||||
|
||||
if defaultValue is not None:
|
||||
if isinstance(defaultValue, IDLNullValue):
|
||||
|
@ -2002,6 +2012,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
|
|||
'dom::bindings::codegen::PrototypeList',
|
||||
'dom::bindings::conversions::FromJSValConvertible',
|
||||
'dom::bindings::conversions::ToJSValConvertible',
|
||||
'dom::bindings::conversions::ConversionBehavior',
|
||||
'dom::bindings::conversions::native_from_handlevalue',
|
||||
'dom::bindings::conversions::StringificationBehavior',
|
||||
'dom::bindings::error::throw_not_in_union',
|
||||
|
@ -5209,7 +5220,7 @@ class CGBindingRoot(CGThing):
|
|||
'dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction}',
|
||||
'dom::bindings::callback::{CallSetup,ExceptionHandling}',
|
||||
'dom::bindings::callback::wrap_call_this_object',
|
||||
'dom::bindings::conversions::{FromJSValConvertible, ToJSValConvertible}',
|
||||
'dom::bindings::conversions::{FromJSValConvertible, ToJSValConvertible, ConversionBehavior}',
|
||||
'dom::bindings::conversions::{native_from_reflector, native_from_handlevalue, native_from_handleobject}',
|
||||
'dom::bindings::conversions::DOM_OBJECT_SLOT',
|
||||
'dom::bindings::conversions::IDLInterface',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue