Closed Bug 1014965 Opened 12 years ago Closed 12 years ago

NativeJSObject.optString does the wrong thing on "key":null

Categories

(Firefox for Android Graveyard :: General, defect)

All
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 32

People

(Reporter: nalexander, Assigned: capella)

Details

Attachments

(1 file, 3 obsolete files)

Per http://stackoverflow.com/a/23377941, JSONObject.optString on "key":null returns "null". NativeJSObject.optString throws an IllegalArgumentException (which is caught and *ignored* in the event handling, which is awful but not this bug). Like Android, we need to be bug-compatible, even though it sucks.
While we're at it, NativeJSObject doesn't implement isNull, making it impossible to work-around.
Implement isNull() for NativeJSObject, add tests ...
Attachment #8428724 - Flags: review?(nalexander)
Comment on attachment 8428724 [details] [diff] [review] bug1014965.diff Implement isNull() Review of attachment 8428724 [details] [diff] [review]: ----------------------------------------------------------------- This looks good to me, but I'm going to redirect to jchen. ::: mobile/android/base/tests/testEventDispatcher.java @@ +294,5 @@ > null, object.optStringArray("stringArray", null)); > fAssertSame("optStringArray returns fallback value if nonexistent", > null, object.optStringArray("nonexistent_stringArray", null)); > + > + fAssertEquals("Native (undefined) is null", true, object.isNull("isNullTest0")); Can we include a" has" test for these first two (or all four) to make it really clear how the first two act?
Attachment #8428724 - Flags: review?(nchen)
Attachment #8428724 - Flags: review?(nalexander)
Attachment #8428724 - Flags: feedback+
Sure :)
Attachment #8428761 - Flags: review?(nchen)
Attachment #8428724 - Flags: review?(nchen)
Attachment #8428724 - Attachment is obsolete: true
Assignee: nobody → markcapella
Status: NEW → ASSIGNED
Comment on attachment 8428761 [details] [diff] [review] bug1014965.diff Implement isNull() Review of attachment 8428761 [details] [diff] [review]: ----------------------------------------------------------------- Instead of adding isNull, can we treat null as undefined in GetProperty? See https://mail.mozilla.org/pipermail/mobile-firefox-dev/2014-May/000683.html
Attachment #8428761 - Flags: review?(nchen)
Attached patch bug1014965.diff (obsolete) — Splinter Review
mmmm .... that seems to make sense :-)
Attachment #8428761 - Attachment is obsolete: true
Attachment #8429371 - Flags: review?(nchen)
Comment on attachment 8429371 [details] [diff] [review] bug1014965.diff Review of attachment 8429371 [details] [diff] [review]: ----------------------------------------------------------------- LGTM. Thanks! ::: mobile/android/base/tests/testEventDispatcher.java @@ +311,5 @@ > + > + fAssertEquals("Native optDouble returns fallback value if undefined", > + -3.1415926535, object.optDouble("undefined", -3.1415926535)); > + fAssertEquals("Native optDouble returns fallback value if null", > + -3.1415926535, object.optDouble("null", -3.1415926535)); I tend to use numbers that have exact floating point representation (e.g. 0.5, 1.75, etc.) to avoid possible subtle bugs, but it's not a big deal. @@ +318,5 @@ > + "chromodynamics", object.optString("undefined", "chromodynamics")); > + fAssertEquals("Native optString returns fallback value if null", > + "chromodynamics", object.optString("null", "chromodynamics")); > + fAssertNotSame("Native optString does not return fallback value if emptyString", > + "chromodynamics", object.optString("emptyString", "chromodynamics")); fAssertNotEquals. And let's stick with "foo" and "bar" :)
Attachment #8429371 - Flags: review?(nchen) → review+
Attached patch bug1014965.diffSplinter Review
Re-requesting review ... I had to remove the test for the "undefined" var as the push-to-try failed, pointing out that it won't pass the |message.toBundle();| portion of the test.
Attachment #8429371 - Attachment is obsolete: true
Attachment #8430198 - Flags: review?(nchen)
Comment on attachment 8430198 [details] [diff] [review] bug1014965.diff Review of attachment 8430198 [details] [diff] [review]: ----------------------------------------------------------------- LGTM!
Attachment #8430198 - Flags: review?(nchen) → review+
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 32
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: