Bug 1014965 - NativeJSObject.optString does the wrong thing on "key":null, r=jchen, f=nalexander

This commit is contained in:
Mark Capella 2014-05-28 17:04:56 -04:00
parent 331f3d56a9
commit bdb3beec4c
3 changed files with 18 additions and 1 deletions

View File

@ -294,5 +294,20 @@ public class testEventDispatcher extends UITest
null, object.optStringArray("stringArray", null));
fAssertSame("optStringArray returns fallback value if nonexistent",
null, object.optStringArray("nonexistent_stringArray", null));
fAssertEquals("Native has(null) is false", false, object.has("null"));
fAssertEquals("Native has(emptyString) is true", true, object.has("emptyString"));
fAssertEquals("Native optBoolean returns fallback value if null",
true, object.optBoolean("null", true));
fAssertEquals("Native optInt returns fallback value if null",
42, object.optInt("null", 42));
fAssertEquals("Native optDouble returns fallback value if null",
-3.1415926535, object.optDouble("null", -3.1415926535));
fAssertEquals("Native optString returns fallback value if null",
"baz", object.optString("null", "baz"));
fAssertNotEquals("Native optString does not return fallback value if emptyString",
"baz", object.optString("emptyString", "baz"));
}
}

View File

@ -15,6 +15,8 @@ function send_test_message(type) {
intArray: [2, 3],
double: 0.5,
doubleArray: [1.5, 2.5],
null: null,
emptyString: "",
string: "foo",
stringArray: ["bar", "baz"],
}

View File

@ -668,7 +668,7 @@ GetProperty(JNIEnv* env, jobject instance, jstring name,
JS_GetUCProperty(cx, object, strName, strName.Length(), &val))) {
return typename Property::Type();
}
if (val.isUndefined()) {
if (val.isUndefined() || val.isNull()) {
if (option == FallbackOption::THROW) {
AndroidBridge::ThrowException(env,
"java/lang/IllegalArgumentException",