| Index: lib/adblockplus_compat.js |
| =================================================================== |
| --- a/lib/adblockplus_compat.js |
| +++ b/lib/adblockplus_compat.js |
| @@ -171,42 +171,50 @@ require.scopes.io = |
| }, |
| writeToFile: function(file, encode, data, callback, timeLineID) |
| { |
| this._getFileEntry(file, true, function(fs, fileEntry) |
| { |
| fileEntry.createWriter(function(writer) |
| { |
| - writer.onwriteend = function() |
| + var executeWriteOperation = function(op, nextOperation) |
| { |
| - if (writer.error) |
| - callback(writer.error); |
| - else |
| - callback(null); |
| - }; |
| + writer.onwriteend = function() |
| + { |
| + if (writer.error) |
| + callback(writer.error); |
| + else |
| + nextOperation(); |
| + }.bind(this); |
|
Felix Dahlke
2012/10/12 08:16:21
Why bind this? Doesn't seem to be used.
|
| - var blob; |
| - try |
| + op(); |
| + }.bind(this); |
|
Felix Dahlke
2012/10/12 08:16:21
Again, why bind this?
|
| + |
| + executeWriteOperation(writer.truncate.bind(writer, 0), function() |
| { |
| - blob = new Blob([data.join("\n") + "\n"], {type: "text/plain"}); |
| - } |
| - catch (e) |
| - { |
| - if (!(e instanceof TypeError)) |
| - throw e; |
| + var blob; |
| + try |
| + { |
| + blob = new Blob([data.join(this.lineBreak) + this.lineBreak], {type: "text/plain"}); |
| + } |
| + catch (e) |
| + { |
| + if (!(e instanceof TypeError)) |
| + throw e; |
| - // Blob wasn't a constructor before Chrome 20 |
| - var builder = new (window.BlobBuilder || window.WebKitBlobBuilder); |
| - builder.append(data.join("\n") + "\n"); |
| - blob = builder.getBlob("text/plain"); |
| - } |
| - writer.write(blob); |
| - }, callback); |
| - }, callback); |
| + // Blob wasn't a constructor before Chrome 20 |
| + var builder = new (window.BlobBuilder || window.WebKitBlobBuilder); |
| + builder.append(data.join(this.lineBreak) + this.lineBreak); |
| + blob = builder.getBlob("text/plain"); |
| + } |
| + executeWriteOperation(writer.write.bind(writer, blob), callback.bind(null, null)); |
| + }.bind(this)); |
| + }.bind(this), callback); |
| + }.bind(this), callback); |
| }, |
| copyFile: function(fromFile, toFile, callback) |
| { |
| // Simply combine read and write operations |
| var data = []; |
| this.readFromFile(fromFile, false, { |
| process: function(line) |