Rewrite jsval_to_str and introduce jsval_to_domstring.

This commit is contained in:
Ms2ger 2013-11-08 12:04:08 +01:00
parent 255864a843
commit 793d87f07d
2 changed files with 58 additions and 44 deletions

View file

@ -443,7 +443,6 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
invalidEnumValueFatal=True,
defaultValue=None,
treatNullAs="Default",
treatUndefinedAs="Default",
isEnforceRange=False,
isClamp=False,
exceptionCode=None,
@ -1058,37 +1057,31 @@ for (uint32_t i = 0; i < length; ++i) {
assert not isEnforceRange and not isClamp
treatAs = {
"Default": "eStringify",
"EmptyString": "eEmpty",
"Null": "eNull"
"Default": "Default",
"EmptyString": "Empty",
}
if type.nullable():
# For nullable strings null becomes a null string.
treatNullAs = "Null"
# For nullable strings undefined becomes a null string unless
# specified otherwise.
if treatUndefinedAs == "Default":
treatUndefinedAs = "Null"
if treatNullAs not in treatAs:
raise TypeError("We don't support [TreatNullAs=%s]" % treatNullAs)
nullBehavior = treatAs[treatNullAs]
if treatUndefinedAs == "Missing":
raise TypeError("We don't support [TreatUndefinedAs=Missing]")
undefinedBehavior = treatAs[treatUndefinedAs]
def getConversionCode(varName, isOptional=False):
#XXXjdm support nullBehavior and undefinedBehavior
#conversionCode = (
# "if (!ConvertJSValueToString(cx, ${val}, ${valPtr}, %s, %s, %s)) {\n"
# " return false;\n"
# "}" % (nullBehavior, undefinedBehavior, varName))
strval = "Some(strval.unwrap())"
strval = "strval"
if not type.nullable():
# XXX #1207 Actually pass non-nullable strings to callees.
strval = "Some(%s)" % strval
if isOptional:
strval = "Some(%s)" % strval
if type.nullable():
call = "jsval_to_domstring(cx, ${val})"
else:
call = "jsval_to_str(cx, ${val}, %s)" % nullBehavior
conversionCode = (
"let strval = jsval_to_str(cx, ${val});\n"
"let strval = %s;\n"
"if strval.is_err() {\n"
" return 0;\n"
"}\n"
"%s = %s;" % (varName, strval))
"let strval = strval.unwrap();\n"
"%s = %s;" % (call, varName, strval))
if defaultValue is None:
return conversionCode
@ -1456,7 +1449,6 @@ class CGArgumentConverter(CGThing):
invalidEnumValueFatal=self.invalidEnumValueFatal,
defaultValue=self.argument.defaultValue,
treatNullAs=self.argument.treatNullAs,
treatUndefinedAs=self.argument.treatUndefinedAs,
isEnforceRange=self.argument.enforceRange,
isClamp=self.argument.clamp),
self.replacementVariables,
@ -3189,7 +3181,6 @@ class FakeArgument():
self.variadic = False
self.defaultValue = None
self.treatNullAs = interfaceMember.treatNullAs
self.treatUndefinedAs = interfaceMember.treatUndefinedAs
self.enforceRange = False
self.clamp = False
@ -4089,8 +4080,7 @@ class CGProxySpecialOperation(CGPerSignatureCall):
# arguments[0] is the index or name of the item that we're setting.
argument = arguments[1]
template = getJSToNativeConversionTemplate(argument.type, descriptor,
treatNullAs=argument.treatNullAs,
treatUndefinedAs=argument.treatUndefinedAs)
treatNullAs=argument.treatNullAs)
templateValues = {
"declName": argument.identifier.name,
"holderName": argument.identifier.name + "_holder",
@ -5692,7 +5682,7 @@ class CGCallbackInterface(CGCallback):
class FakeMember():
def __init__(self):
self.treatUndefinedAs = self.treatNullAs = "Default"
self.treatNullAs = "Default"
def isStatic(self):
return False
def isAttr(self):