mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
codegen: Throw on an invalid enum value when appropiate
This commit is contained in:
parent
093f5c01e4
commit
e50d4b7624
5 changed files with 56 additions and 10 deletions
|
@ -662,12 +662,17 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
'%s' % (firstCap(sourceDescription), exceptionCode))),
|
||||
post="\n")
|
||||
|
||||
def onFailureInvalidEnumValue(failureCode):
|
||||
return CGGeneric(
|
||||
failureCode or
|
||||
('throw_type_error(cx, "%s is not a valid enum value."); %s'
|
||||
% (firstCap(sourceDescription), exceptionCode)))
|
||||
|
||||
def onFailureNotCallable(failureCode):
|
||||
return CGWrapper(
|
||||
CGGeneric(
|
||||
failureCode or
|
||||
('throw_type_error(cx, \"%s is not callable.\");\n'
|
||||
'%s' % (firstCap(sourceDescription), exceptionCode))))
|
||||
return CGGeneric(
|
||||
failureCode or
|
||||
('throw_type_error(cx, \"%s is not callable.\");\n'
|
||||
'%s' % (firstCap(sourceDescription), exceptionCode)))
|
||||
|
||||
# A helper function for handling null default values. Checks that the
|
||||
# default value, if it exists, is null.
|
||||
|
@ -868,7 +873,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
"yet")
|
||||
enum = type.inner.identifier.name
|
||||
if invalidEnumValueFatal:
|
||||
handleInvalidEnumValueCode = exceptionCode
|
||||
handleInvalidEnumValueCode = onFailureInvalidEnumValue(failureCode).define()
|
||||
else:
|
||||
handleInvalidEnumValueCode = "return true;"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue