Bug 1022607 - Only cache the response when the readyState is DONE. r=bent, a=lmandel
authorShian-Yow Wu <swu@mozilla.com>
Wed, 11 Jun 2014 11:37:47 +0800
changeset 208211 372fc43da087408a0a0b5a7c5a278c79e2139019
parent 208210 042efa0757405a246c93e904b274679287197bce
child 208212 5b8263f7b46c087a2dbedea8268a5702d8be0754
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent, lmandel
bugs1022607
milestone32.0a2
Bug 1022607 - Only cache the response when the readyState is DONE. r=bent, a=lmandel
content/base/test/file_bug1008126_worker.js
content/base/test/file_bug945152.jar
dom/workers/XMLHttpRequest.cpp
--- a/content/base/test/file_bug1008126_worker.js
+++ b/content/base/test/file_bug1008126_worker.js
@@ -1,15 +1,16 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 var gJar1 = "jar:http://example.org/tests/content/base/test/file_bug945152.jar!/data_1.txt";
 var gJar2 = "jar:http://example.org/tests/content/base/test/file_bug945152.jar!/data_2.txt";
+var gJar3 = "jar:http://example.org/tests/content/base/test/file_bug945152.jar!/data_big.txt";
 var gPaddingChar = ".";
 var gPaddingSize = 10000;
 var gPadding = "";
 for (var i = 0; i < gPaddingSize; i++) {
   gPadding += gPaddingChar;
 }
 var gData1 = "TEST_DATA_1:ABCDEFGHIJKLMNOPQRSTUVWXYZ" + gPadding;
 var gData2 = "TEST_DATA_2:1234567890" + gPadding;
@@ -50,24 +51,32 @@ self.onmessage = function onmessage(even
   }
 
   function test_chunked_arraybuffer() {
     ok(true, "Test chunked arraybuffer");
 
     var lastIndex = 0;
     xhr.onprogress = function(event) {
       if (xhr.response) {
-        var str = String.fromCharCode.apply(null, Uint8Array(xhr.response));
-        ok(str.length == gData1.length, "Data size is correct");
-        ok(str == gData1.substr(lastIndex, str.length), "Data chunk is correct");
+        var buf = new Uint8Array(xhr.response);
+        var allMatched = true;
+        // The content of data cycles from 0 to 9 (i.e. 01234567890123......).
+        for (var i = 0; i < buf.length; i++) {
+          if (String.fromCharCode(buf[i]) != lastIndex % 10) {
+            allMatched = false;
+            break;
+          }
+          lastIndex++;
+        }
+        ok(allMatched, "Data chunk is correct.  Loaded " +
+                        event.loaded + "/" + event.total + " bytes.");
       }
-      lastIndex += str.length;
     };
     xhr.onload = runTests;
-    xhr.open("GET", gJar1, true);
+    xhr.open("GET", gJar3, true);
     xhr.responseType = "moz-chunked-arraybuffer";
     xhr.send();
   }
 
   var readystatechangeCount = 0;
   var loadCount = 0;
   var loadendCount = 0;
 
index 23cc979b170d05cd1aee63c12cdd681c93e174bf..eb732980d90e75982e1764be71d9ea02bad76a0c
GIT binary patch
literal 92275
zc%1FrdsNSP9>?*|?^kU<-ItQ2$fXEB-Q)<#HC@oCpGz7)U4E+Rt|&8Bxh!^6PNIv;
z4zjIlE=lM}F_SS3Bexi|GD?bw*+NWP8P2h@``?~p&YtJvd%o}g-mlN+^F8PD-}m$J
z@=#MZ6hbBwh5@#ZLN=!yKO%%MkqDtLx`+t>$j}9<*f@E-D!@NFTH&K1B!hg6M8x_Z
z^j6sDlsy@(anodu&B9AxztFO*Uy_|uax`3faM`M-jj3aM>do8S-1?_CmzzK7W#7+q
z{+g^$OVb?{L$(E;muWrSdoA_o@Wd18^@9c*Oq(&L=VyK6?`~ZYW&Ky<W7VaNnTM~+
z?o}xQPM7B|-STS9ScS`jkq@#i93D6-r(S7YnVS^v>%H<H`SX&lk24MFz3Q5_WNL(6
z`KRml6-hl^2ORS6Vy#-!|C04zt~h61czkB3#Vg_U!8(<GDygTM5DJ+PTJ7r$jSNyH
z$V1{H!rw1(Q$|DVWfy~z(=7*QKOc9-VBp=NB>RE`Gh1CG1;x4Pmc|=wZ+}xXVcoR0
z`1tjs<r|wyHK#0YSypt@*re?9H0L`eW#8*JxoX&*|M|)`v!o}*t6uIn_{KcBB-?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{>!MCgF;OCA_rtdbN=-hnAckSu!XeC6)t0iK!gZ$(CmA3M@gt+&cudQu?wg3PC
z0PsKNGs)XWIdPoNIHj%AxbYJvPMYjG#m(KrbLzC|UZ2eH_EF57HG7V)8~^|S00000
z00000004mh10S9y+o-T`au7mTTD?6@)_I`C?t=p@k4rstOZpfJ8`q#i!-~?9q*Z2Z
z^4h>q)4;O&p+8zj$y;OQwRjh*zyB|9>{H3Fg9w?>P5N%4acza%Vwgk--vFtO==FAx
zfY9K#!*mg9J&Q8DYrf9#UX-9MB<gi)LUfi#WwsL0M<x!rZy$K$bk?L}VQFENC&mo>
z9smFU0000000000000000000000000d_>MgF;hD47`WdS<~pSj000000000000000
z00000000000001dY<gS<00000000000000000000000000002M?+cd!0000000000
z0000000000000000002+J2R~)##1VUu-Tp1P}8ICZ`l9<0000000000000000001d
zG!e#L9uldsnxPOfnJ^5neH5}e<@gaHgo#85ebGg{vuk-rjqr~QU7(7MlgFz9{G+24
zJ{m$Y$j3<hdy3LeCG}JjLLn1E>w}cK_8J-)q)L#7#6^VvhXBzTaD3OE?v7SMbi5x1
zsMLiB@{jXZ+REb+;{NLlHYzNf9NHT!e-q$1;@1GX-vpR<1hh{<H|e{H#<dl4i(&0w
z!8bsvBYJc;OF9F#ybA~j4SpA)*0U(Xdr^Y6kf_(Sue-B&d1(Bhqf4XxncLnf4esdw
E7XWHVBme*a
--- a/dom/workers/XMLHttpRequest.cpp
+++ b/dom/workers/XMLHttpRequest.cpp
@@ -1187,22 +1187,26 @@ EventRunnable::PreDispatch(JSContext* aC
                                   response.toObjectOrNull() : nullptr);
         if (obj && JS_IsArrayBufferObject(obj)) {
           // Use cached response if the arraybuffer has been transfered.
           if (mProxy->mArrayBufferResponseWasTransferred) {
             MOZ_ASSERT(JS_IsNeuteredArrayBufferObject(obj));
             mUseCachedArrayBufferResponse = true;
             doClone = false;
           } else {
+            MOZ_ASSERT(!JS_IsNeuteredArrayBufferObject(obj));
             JS::AutoValueArray<1> argv(aCx);
             argv[0].set(response);
             obj = JS_NewArrayObject(aCx, argv);
             if (obj) {
               transferable.setObject(*obj);
-              mProxy->mArrayBufferResponseWasTransferred = true;
+              // Only cache the response when the readyState is DONE.
+              if (xhr->ReadyState() == nsIXMLHttpRequest::DONE) {
+                mProxy->mArrayBufferResponseWasTransferred = true;
+              }
             } else {
               mResponseResult = NS_ERROR_OUT_OF_MEMORY;
               doClone = false;
             }
           }
         }
 
         if (doClone) {