servo: Merge #7439 - Prefer JSTrue/JSFalse to 1/0 (from frewsxcv:jsfalse-jstrue); r=jdm

Source-Repo: https://github.com/servo/servo
Source-Revision: 67cbda4be35a63222553ca806d475581030bea4e
This commit is contained in:
Corey Farwell 2015-08-28 22:15:21 -06:00
parent 87fd899fef
commit 2d6351b526

View File

@ -339,7 +339,7 @@ class CGMethodCall(CGThing):
code = ( code = (
"if argc < %d {\n" "if argc < %d {\n"
" throw_type_error(cx, \"Not enough arguments to %s.\");\n" " throw_type_error(cx, \"Not enough arguments to %s.\");\n"
" return 0;\n" " return JSFalse;\n"
"}" % (requiredArgs, methodName)) "}" % (requiredArgs, methodName))
self.cgRoot.prepend( self.cgRoot.prepend(
CGWrapper(CGGeneric(code), pre="\n", post="\n")) CGWrapper(CGGeneric(code), pre="\n", post="\n"))
@ -512,11 +512,11 @@ class CGMethodCall(CGThing):
CGSwitch("argcount", CGSwitch("argcount",
argCountCases, argCountCases,
CGGeneric("throw_type_error(cx, \"Not enough arguments to %s.\");\n" CGGeneric("throw_type_error(cx, \"Not enough arguments to %s.\");\n"
"return 0;" % methodName))) "return JSFalse;" % methodName)))
# XXXjdm Avoid unreachable statement warnings # XXXjdm Avoid unreachable statement warnings
# overloadCGThings.append( # overloadCGThings.append(
# CGGeneric('panic!("We have an always-returning default case");\n' # CGGeneric('panic!("We have an always-returning default case");\n'
# 'return 0;')) # 'return JSFalse;'))
self.cgRoot = CGWrapper(CGList(overloadCGThings, "\n"), self.cgRoot = CGWrapper(CGList(overloadCGThings, "\n"),
pre="\n") pre="\n")
@ -888,7 +888,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if invalidEnumValueFatal: if invalidEnumValueFatal:
handleInvalidEnumValueCode = exceptionCode handleInvalidEnumValueCode = exceptionCode
else: else:
handleInvalidEnumValueCode = "return 1;" handleInvalidEnumValueCode = "return JSTrue;"
template = ( template = (
"match find_enum_string_index(cx, ${val}, %(values)s) {\n" "match find_enum_string_index(cx, ${val}, %(values)s) {\n"
@ -1012,7 +1012,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
declType = CGGeneric(typeName) declType = CGGeneric(typeName)
template = ("match %s::new(cx, ${val}) {\n" template = ("match %s::new(cx, ${val}) {\n"
" Ok(dictionary) => dictionary,\n" " Ok(dictionary) => dictionary,\n"
" Err(_) => return 0,\n" " Err(_) => return JSFalse,\n"
"}" % typeName) "}" % typeName)
return handleOptional(template, declType, handleDefaultNull("%s::empty(cx)" % typeName)) return handleOptional(template, declType, handleDefaultNull("%s::empty(cx)" % typeName))
@ -1037,7 +1037,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
conversionBehavior = "()" conversionBehavior = "()"
if failureCode is None: if failureCode is None:
failureCode = 'return 0' failureCode = 'return JSFalse'
declType = CGGeneric(builtinNames[type.tag()]) declType = CGGeneric(builtinNames[type.tag()])
if type.nullable(): if type.nullable():
@ -1216,7 +1216,7 @@ class CGArgumentConverter(CGThing):
return self.converter.define() return self.converter.define()
def wrapForType(jsvalRef, result='result', successCode='return 1;', pre=''): def wrapForType(jsvalRef, result='result', successCode='return JSTrue;', pre=''):
""" """
Reflect a Rust value into JS. Reflect a Rust value into JS.
@ -2778,7 +2778,7 @@ class CGSetterCall(CGPerSignatureCall):
def wrap_return_value(self): def wrap_return_value(self):
# We have no return value # We have no return value
return "\nreturn 1;" return "\nreturn JSTrue;"
def getArgc(self): def getArgc(self):
return "1" return "1"
@ -2950,7 +2950,7 @@ class CGStaticSetter(CGAbstractStaticBindingMethod):
"let args = CallArgs::from_vp(vp, argc);\n" "let args = CallArgs::from_vp(vp, argc);\n"
"if (argc == 0) {\n" "if (argc == 0) {\n"
" throw_type_error(cx, \"Not enough arguments to %s setter.\");\n" " throw_type_error(cx, \"Not enough arguments to %s setter.\");\n"
" return 0;\n" " return JSFalse;\n"
"}" % self.attr.identifier.name) "}" % self.attr.identifier.name)
call = CGSetterCall(["global.r()"], self.attr.type, nativeName, self.descriptor, call = CGSetterCall(["global.r()"], self.attr.type, nativeName, self.descriptor,
self.attr) self.attr)