Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | var Ci = Components.interfaces; |
michael@0 | 2 | var Cc = Components.classes; |
michael@0 | 3 | |
michael@0 | 4 | var nativeJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON); |
michael@0 | 5 | |
michael@0 | 6 | function run_test() |
michael@0 | 7 | { |
michael@0 | 8 | function read_file(path) |
michael@0 | 9 | { |
michael@0 | 10 | try |
michael@0 | 11 | { |
michael@0 | 12 | var f = do_get_file(path); |
michael@0 | 13 | var istream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream); |
michael@0 | 14 | istream.init(f, -1, -1, false); |
michael@0 | 15 | return nativeJSON.decodeFromStream(istream, istream.available()); |
michael@0 | 16 | } |
michael@0 | 17 | finally |
michael@0 | 18 | { |
michael@0 | 19 | istream.close(); |
michael@0 | 20 | } |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | var x = read_file("decodeFromStream-01.json"); |
michael@0 | 24 | do_check_eq(x["JSON Test Pattern pass3"]["The outermost value"], "must be an object or array."); |
michael@0 | 25 | do_check_eq(x["JSON Test Pattern pass3"]["In this test"], "It is an object."); |
michael@0 | 26 | |
michael@0 | 27 | x = read_file("decodeFromStream-small.json"); |
michael@0 | 28 | do_check_eq(x.toSource(), "({})", "empty object parsed"); |
michael@0 | 29 | } |