Fix for bug 633934. r=bzbarsky
authorEmanuele Costa <emanuele.costa@gmail.com>
Mon, 04 Apr 2011 16:10:10 -0700
changeset 64669 5e74b6d598e762b661bbb1cb5841f590cdbea098
parent 64668 b6af6b28b7294e1be7855f004b62467857662209
child 64670 299615ca371a3e17c57e60411564df1db6db35d6
push id19384
push userbzbarsky@mozilla.com
push dateTue, 05 Apr 2011 16:22:12 +0000
treeherdermozilla-central@385684ad7eed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs633934, 410005
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Fix for bug 633934. r=bzbarsky Two files need to be patched: /dom/src/json/nsJSON.cpp /dom/src/json/test/unit/test_encode.js The first problem is a wrong nsnull initialization parameter in one of the nsJSONWriter constructor. The second problem is caused by related bug 410005 and only happens on windows and can be solved by calling the clone() method before calling filesize attribute on a file that has been created and later on modified by adding extra content. The BOM check set to true causes this behaviour // check BOMs // the clone() calls are there to work around -- bug 410005 var f = writeToFile({},"UTF-8", true).clone(); As discussed Linux is not affected. The overall 410005 seems to be related to a wrong logic in the mDirty and MakeDirty() flag in nsLocalFileWin.cpp implementation.
dom/src/json/nsJSON.cpp
dom/src/json/test/unit/test_encode.js
--- a/dom/src/json/nsJSON.cpp
+++ b/dom/src/json/nsJSON.cpp
@@ -292,17 +292,17 @@ nsJSON::EncodeInternal(nsJSONWriter *wri
 nsJSONWriter::nsJSONWriter() : mStream(nsnull),
                                mBuffer(nsnull),
                                mBufferCount(0),
                                mDidWrite(PR_FALSE),
                                mEncoder(nsnull)
 {
 }
 
-nsJSONWriter::nsJSONWriter(nsIOutputStream *aStream) : mStream(nsnull),
+nsJSONWriter::nsJSONWriter(nsIOutputStream *aStream) : mStream(aStream),
                                                        mBuffer(nsnull),
                                                        mBufferCount(0),
                                                        mDidWrite(PR_FALSE),
                                                        mEncoder(nsnull)
 {
 }
 
 nsJSONWriter::~nsJSONWriter()
--- a/dom/src/json/test/unit/test_encode.js
+++ b/dom/src/json/test/unit/test_encode.js
@@ -133,21 +133,22 @@ function testOutputStreams() {
 
       // all ascii with no BOMs, so this will work
       do_check_eq(utf16LEFile.fileSize / 2, utf8File.fileSize);
       do_check_eq(utf16LEFile.fileSize, utf16BEFile.fileSize);
     }
   }
 
   // check BOMs
-  var f = writeToFile({},"UTF-8", true);
+  // the clone() calls are there to work around -- bug 410005
+  var f = writeToFile({},"UTF-8", true).clone();
   do_check_eq(f.fileSize, 5);
-  var f = writeToFile({},"UTF-16LE", true);
+  var f = writeToFile({},"UTF-16LE", true).clone();
   do_check_eq(f.fileSize, 6);
-  var f = writeToFile({},"UTF-16BE", true);
+  var f = writeToFile({},"UTF-16BE", true).clone();
   do_check_eq(f.fileSize, 6);
   
   outputDir.remove(true);
 }
 
 function throwingToJSON() {
   var a = {
     "b": 1,
@@ -158,12 +159,11 @@ function throwingToJSON() {
     var y = nativeJSON.encode(a);
   } catch (ex) {}
 }
 
 function run_test() {
   testStringEncode();
   throwingToJSON();
   
-  // failing on windows -- bug 410005
-  // testOutputStreams();
+  testOutputStreams();
   
 }