Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WebIDL sequence arguments #9056

Merged
merged 4 commits into from Jan 12, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

codegen: Move conversion behaviour to a common function

  • Loading branch information
emilio committed Jan 12, 2016
commit 2f1eee599cd56a4533db731f8cdd81ecf939563a
@@ -775,20 +775,7 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,
raise TypeError("Can't handle SpiderMonkey interface arguments yet")

if type.isDOMString():
assert not isEnforceRange and not isClamp

treatAs = {
"Default": "StringificationBehavior::Default",
"EmptyString": "StringificationBehavior::Empty",
}
if treatNullAs not in treatAs:
raise TypeError("We don't support [TreatNullAs=%s]" % treatNullAs)
if type.nullable():
# Note: the actual behavior passed here doesn't matter for nullable
# strings.
nullBehavior = "StringificationBehavior::Default"
else:
nullBehavior = treatAs[treatNullAs]
nullBehavior = getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs)

conversionCode = (
"match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
@@ -1002,16 +989,7 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,
if not type.isPrimitive():
raise TypeError("Need conversion for argument type '%s'" % str(type))

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 = "()"
conversionBehavior = getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs)

if failureCode is None:
failureCode = 'return false'
@@ -1215,6 +1193,36 @@ def typeNeedsCx(type, retVal=False):
return type.isAny() or type.isObject()


# Returns a conversion behavior suitable for a type
def getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs):
if type.isSequence():
return getConversionConfigForType(type.unroll(), isEnforceRange, isClamp, treatNullAs)
if type.isDOMString():
assert not isEnforceRange and not isClamp

treatAs = {
"Default": "StringificationBehavior::Default",
"EmptyString": "StringificationBehavior::Empty",
}
if treatNullAs not in treatAs:
raise TypeError("We don't support [TreatNullAs=%s]" % treatNullAs)
if type.nullable():
# Note: the actual behavior passed here doesn't matter for nullable
# strings.
return "StringificationBehavior::Default"
else:
return treatAs[treatNullAs]
if type.isInteger():
if isEnforceRange:
return "ConversionBehavior::EnforceRange"
elif isClamp:
return "ConversionBehavior::Clamp"
else:
return "ConversionBehavior::Default"
assert not isEnforceRange and not isClamp
return "()"


# Returns a CGThing containing the type of the return value.
def getRetvalDeclarationForType(returnType, descriptorProvider):
if returnType is None or returnType.isVoid():
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.