| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 request.overrideMimeType("text/plain" + (decode ? "? charset=utf-8" : "")) ; | 82 request.overrideMimeType("text/plain" + (decode ? "? charset=utf-8" : "")) ; |
| 83 | 83 |
| 84 let onProgress = function(event) | 84 let onProgress = function(event) |
| 85 { | 85 { |
| 86 if (timeLineID) | 86 if (timeLineID) |
| 87 { | 87 { |
| 88 TimeLine.asyncStart(timeLineID); | 88 TimeLine.asyncStart(timeLineID); |
| 89 } | 89 } |
| 90 | 90 |
| 91 let data = event.target.response; | 91 let data = event.target.response; |
| 92 let index = (processing ? -1 : Math.max(data.lastIndexOf("\n"), data.las tIndexOf("\r"))); | 92 let index = (processing ? -1 : Math.max(data.lastIndexOf("\n"), data.las tIndexOf("\r"))); |
|
Felix Dahlke
2014/03/14 16:10:45
This doesn't really seem reentrant to me. What if
Wladimir Palant
2014/03/14 18:04:51
JavaScript is a single-threaded language, reentran
Felix Dahlke
2014/03/14 21:32:49
Ah, thought this was actually proper multithreadin
| |
| 93 if (index >= 0) | 93 if (index >= 0) |
| 94 { | 94 { |
| 95 // Protect against reentrance in case the listener processes events. | 95 // Protect against reentrance in case the listener processes events. |
|
Felix Dahlke
2014/03/14 16:10:45
"processes multiple events" I suppose?
Wladimir Palant
2014/03/14 18:04:51
No, "processes events" = "spins the event loop"
| |
| 96 processing = true; | 96 processing = true; |
| 97 try | 97 try |
| 98 { | 98 { |
| 99 let oldBuffer = buffer; | 99 let oldBuffer = buffer; |
| 100 buffer = data.substr(index + 1); | 100 buffer = data.substr(index + 1); |
|
Felix Dahlke
2014/03/14 16:10:45
Is reference assignment atomic in Gecko? Otherwise
Wladimir Palant
2014/03/14 18:04:51
As I said, the only place where we might get reent
| |
| 101 data = data.substr(0, index + 1); | 101 data = data.substr(0, index + 1); |
| 102 let lines = data.split(/[\r\n]+/); | 102 let lines = data.split(/[\r\n]+/); |
| 103 lines.pop(); | 103 lines.pop(); |
| 104 lines[0] = oldBuffer + lines[0]; | 104 lines[0] = oldBuffer + lines[0]; |
| 105 for (let i = 0; i < lines.length; i++) | 105 for (let i = 0; i < lines.length; i++) |
| 106 listener.process(lines[i]); | 106 listener.process(lines[i]); |
| 107 } | 107 } |
| 108 finally | 108 finally |
| 109 { | 109 { |
| 110 processing = false; | 110 processing = false; |
| 111 let e = { | 111 let e = { |
| 112 target: {response: buffer} | 112 target: {response: buffer} |
| 113 }; | 113 }; |
| 114 buffer = ""; | 114 buffer = ""; |
| 115 onProgress(e); | 115 onProgress(e); |
| 116 | 116 |
| 117 if (loadEvent) | 117 if (loadEvent) |
| 118 { | 118 { |
| 119 let event = loadEvent; | |
| 119 loadEvent = null; | 120 loadEvent = null; |
| 120 onLoad(loadEvent); | 121 onLoad(event); |
|
Felix Dahlke
2014/03/14 16:10:45
onLoad(null) doesn't seem to be what's desired her
Wladimir Palant
2014/03/14 18:04:51
True, we need to save the original event before nu
| |
| 121 } | 122 } |
| 122 | 123 |
| 123 if (errorEvent) | 124 if (errorEvent) |
| 124 { | 125 { |
| 126 let event = errorEvent; | |
| 125 errorEvent = null; | 127 errorEvent = null; |
| 126 onError(errorEvent); | 128 onError(event); |
| 127 } | 129 } |
| 128 } | 130 } |
| 129 } | 131 } |
| 130 else | 132 else |
| 131 buffer += data; | 133 buffer += data; |
| 132 | 134 |
| 133 if (timeLineID) | 135 if (timeLineID) |
| 134 { | 136 { |
| 135 TimeLine.asyncEnd(timeLineID); | 137 TimeLine.asyncEnd(timeLineID); |
| 136 } | 138 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 isFile: exists && file.isFile(), | 379 isFile: exists && file.isFile(), |
| 378 lastModified: exists ? file.lastModifiedTime : 0 | 380 lastModified: exists ? file.lastModifiedTime : 0 |
| 379 }); | 381 }); |
| 380 } | 382 } |
| 381 catch(e) | 383 catch(e) |
| 382 { | 384 { |
| 383 callback(e); | 385 callback(e); |
| 384 } | 386 } |
| 385 } | 387 } |
| 386 } | 388 } |
| LEFT | RIGHT |