codegen: Throw on an invalid enum value when appropiate

This commit is contained in:
Emilio Cobos Álvarez 2016-05-13 10:11:30 +02:00
parent 093f5c01e4
commit e50d4b7624
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
5 changed files with 56 additions and 10 deletions

View file

@ -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;"