зеркало из https://github.com/mozilla/gecko-dev.git
Bug 808492 - Support double-closing DirectoryIterator in asynchronous mode. r=dteller
This commit is contained in:
Родитель
5fc188ade4
Коммит
4e247b0648
|
@ -145,6 +145,7 @@ if (this.Components) {
|
|||
*
|
||||
* @param {*} id A unique identifier, as used by |OpenFiles|.
|
||||
* @param {Function} f A function to call.
|
||||
* @param {boolean} ignoreAbsent If |true|, the error is ignored. Otherwise, the error causes an exception.
|
||||
* @return The return value of |f()|
|
||||
*
|
||||
* This function attempts to get the file matching |id|. If
|
||||
|
@ -160,10 +161,13 @@ if (this.Components) {
|
|||
};
|
||||
|
||||
let OpenedDirectoryIterators = new ResourceTracker();
|
||||
let withDir = function withDir(fd, f) {
|
||||
let withDir = function withDir(fd, f, ignoreAbsent) {
|
||||
let file = OpenedDirectoryIterators.get(fd);
|
||||
if (file == null) {
|
||||
throw new Error("Could not find Directory");
|
||||
if (!ignoreAbsent) {
|
||||
throw new Error("Could not find Directory");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!(file instanceof File.DirectoryIterator)) {
|
||||
throw new Error("file is not a directory iterator " + file.__proto__.toSource());
|
||||
|
@ -322,7 +326,7 @@ if (this.Components) {
|
|||
}
|
||||
throw x;
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
},
|
||||
DirectoryIterator_prototype_nextBatch: function nextBatch(dir, size) {
|
||||
return withDir(dir,
|
||||
|
@ -335,18 +339,18 @@ if (this.Components) {
|
|||
throw x;
|
||||
}
|
||||
return result.map(File.DirectoryIterator.Entry.toMsg);
|
||||
});
|
||||
}, false);
|
||||
},
|
||||
DirectoryIterator_prototype_close: function close(dir) {
|
||||
return withDir(dir,
|
||||
function do_close() {
|
||||
this.close();
|
||||
OpenedDirectoryIterators.remove(dir);
|
||||
});
|
||||
}, true);// ignore error to support double-closing |DirectoryIterator|
|
||||
}
|
||||
};
|
||||
} catch(ex) {
|
||||
dump("WORKER ERROR DURING SETUP " + ex + "\n");
|
||||
dump("WORKER ERROR DETAIL " + ex.stack + "\n");
|
||||
}
|
||||
})(this);
|
||||
})(this);
|
||||
|
|
|
@ -559,6 +559,12 @@ let test_iter = maketest("iter", function iter(test) {
|
|||
yield iterator.close();
|
||||
test.info("Closed iterator");
|
||||
|
||||
test.info("Double closing DirectoryIterator");
|
||||
iterator = new OS.File.DirectoryIterator(currentDir);
|
||||
yield iterator.close();
|
||||
yield iterator.close(); //double closing |DirectoryIterator|
|
||||
test.ok(true, "|DirectoryIterator| was closed twice successfully");
|
||||
|
||||
let allFiles2 = [];
|
||||
let i = 0;
|
||||
iterator = new OS.File.DirectoryIterator(currentDir);
|
||||
|
|
Загрузка…
Ссылка в новой задаче