Bug 765704 - Don't throw when setting XHR.responseType to an invalid value; r=bz

This commit is contained in:
Ms2ger 2012-06-21 09:11:07 +02:00
parent 206ad00f97
commit def1cc5c96
6 changed files with 39 additions and 9 deletions

View File

@ -450,9 +450,8 @@ FindEnumStringIndex(JSContext* cx, JS::Value v, const EnumEntry* values, bool* o
}
}
// XXX we don't know whether we're on the main thread, so play it safe
*ok = Throw<false>(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
return 0;
*ok = true;
return -1;
}
inline nsWrapperCache*

View File

@ -1342,7 +1342,8 @@ ${target} = tmp.forget();""").substitute(self.substitution)
def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
isDefinitelyObject=False,
isMember=False,
isOptional=False):
isOptional=False,
invalidEnumValueFatal=True):
"""
Get a template for converting a JS value to a native object based on the
given type and descriptor. If failureCode is given, then we're actually
@ -1717,12 +1718,17 @@ for (uint32_t i = 0; i < length; ++i) {
return (
"{\n"
" bool ok;\n"
" ${declName} = static_cast<%(enumtype)s>(FindEnumStringIndex(cx, ${val}, %(values)s, &ok));\n"
" int index = FindEnumStringIndex(cx, ${val}, %(values)s, &ok);\n"
" if (!ok) {\n"
" return false;\n"
" }\n"
" if (index < 0) {\n"
" return %(failureCode)s;\n"
" }\n"
" ${declName} = static_cast<%(enumtype)s>(index);\n"
"}" % { "enumtype" : enum,
"values" : enum + "Values::strings" },
"values" : enum + "Values::strings",
"failureCode" : "Throw<false>(cx, NS_ERROR_XPC_BAD_CONVERT_JS)" if invalidEnumValueFatal else "true" },
CGGeneric(enum), None, isOptional)
if type.isCallback():
@ -1920,7 +1926,8 @@ class CGArgumentConverter(CGThing):
argument list, and the argv and argc strings and generates code to
unwrap the argument to the right native type.
"""
def __init__(self, argument, index, argv, argc, descriptorProvider):
def __init__(self, argument, index, argv, argc, descriptorProvider,
invalidEnumValueFatal=True):
CGThing.__init__(self)
self.argument = argument
# XXXbz should optional jsval args get JSVAL_VOID? What about
@ -1953,12 +1960,14 @@ class CGArgumentConverter(CGThing):
self.argcAndIndex = replacer
else:
self.argcAndIndex = None
self.invalidEnumValueFatal = invalidEnumValueFatal
def define(self):
return instantiateJSToNativeConversionTemplate(
getJSToNativeConversionTemplate(self.argument.type,
self.descriptorProvider,
isOptional=(self.argcAndIndex is not None)),
isOptional=(self.argcAndIndex is not None),
invalidEnumValueFatal=self.invalidEnumValueFatal),
self.replacementVariables,
self.argcAndIndex).define()
@ -2359,7 +2368,8 @@ class CGPerSignatureCall(CGThing):
else:
cgThings = []
cgThings.extend([CGArgumentConverter(arguments[i], i, self.getArgv(),
self.getArgc(), self.descriptor) for
self.getArgc(), self.descriptor,
invalidEnumValueFatal=not setter) for
i in range(argConversionStartsAt, self.argCount)])
cgThings.append(CGCallGenerator(

View File

@ -57,6 +57,7 @@ $(CPPSRCS): ../%Binding.cpp: $(bindinggen_dependencies) \
$(MAKE) -C .. $*Binding.cpp
_TEST_FILES = \
test_enums.html \
test_interfaceToString.html \
test_lookupGetter.html \
test_InstanceOf.html \

View File

@ -279,6 +279,9 @@ public:
void PassEnum(TestEnum, ErrorResult&);
void PassOptionalEnum(const Optional<TestEnum>&, ErrorResult&);
TestEnum ReceiveEnum(ErrorResult&);
TestEnum GetEnumAttribute(ErrorResult&);
TestEnum GetReadonlyEnumAttribute(ErrorResult&);
void SetEnumAttribute(TestEnum, ErrorResult&);
// Callback types
void PassCallback(JSContext*, JSObject*, ErrorResult&);

View File

@ -212,6 +212,8 @@ interface TestInterface {
// void passOptionalNullableEnum(optional TestEnum? arg);
// void passOptionalNullableEnumWithDefaultValue(optional TestEnum? arg = null);
TestEnum receiveEnum();
attribute TestEnum enumAttribute;
readonly attribute TestEnum readonlyEnumAttribute;
// Callback types
void passCallback(TestCallback arg);

View File

@ -0,0 +1,15 @@
<!doctype html>
<meta charset=utf-8>
<title>Enums</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
test(function() {
var xhr = new XMLHttpRequest();
xhr.open("get", "foo")
assert_equals(xhr.responseType, "");
xhr.responseType = "foo";
assert_equals(xhr.responseType, "");
}, "Assigning an invalid value to an enum attribute should not throw.");
</script>