mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1297756
part 1. Improve the exception thrown when an invalid default value (right type but wrong value) is used for a union. r=mystor
This commit is contained in:
parent
389ae20f08
commit
1e5fa72546
@ -3309,6 +3309,11 @@ def matchIntegerValueToType(value):
|
||||
|
||||
return None
|
||||
|
||||
class NoCoercionFoundError(WebIDLError):
|
||||
"""
|
||||
A class we use to indicate generic coercion failures because none of the
|
||||
types worked out in IDLValue.coerceToType.
|
||||
"""
|
||||
|
||||
class IDLValue(IDLObject):
|
||||
def __init__(self, location, type, value):
|
||||
@ -3336,8 +3341,18 @@ class IDLValue(IDLObject):
|
||||
# use the value's type when it is a default value of a
|
||||
# union, and the union cares about the exact float type.
|
||||
return IDLValue(self.location, subtype, coercedValue.value)
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
# Make sure to propagate out WebIDLErrors that are not the
|
||||
# generic "hey, we could not coerce to this type at all"
|
||||
# exception, because those are specific "coercion failed for
|
||||
# reason X" exceptions. Note that we want to swallow
|
||||
# non-WebIDLErrors here, because those can just happen if
|
||||
# "type" is not something that can have a default value at
|
||||
# all.
|
||||
if (isinstance(e, WebIDLError) and
|
||||
not isinstance(e, NoCoercionFoundError)):
|
||||
raise e
|
||||
|
||||
# If the type allows null, rerun this matching on the inner type, except
|
||||
# nullable enums. We handle those specially, because we want our
|
||||
# default string values to stay strings even when assigned to a nullable
|
||||
@ -3399,8 +3414,8 @@ class IDLValue(IDLObject):
|
||||
|
||||
return IDLValue(self.location, type, self.value)
|
||||
|
||||
raise WebIDLError("Cannot coerce type %s to type %s." %
|
||||
(self.type, type), [location])
|
||||
raise NoCoercionFoundError("Cannot coerce type %s to type %s." %
|
||||
(self.type, type), [location])
|
||||
|
||||
def _getDependentObjects(self):
|
||||
return set()
|
||||
|
Loading…
Reference in New Issue
Block a user