Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/stub-modules/io.js

Issue 29984592: Issue 6959 - Use async/await in test/stub-modules/io.js (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Jan. 17, 2019, 9:23 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/stub-modules/io.js
===================================================================
--- a/test/stub-modules/io.js
+++ b/test/stub-modules/io.js
@@ -25,74 +25,62 @@
},
_setModifiedTime(fileName, lastModified)
{
if (data.has(fileName))
data.get(fileName).lastModified = lastModified;
},
// Public API
- writeToFile(fileName, generator)
+ async writeToFile(fileName, generator)
{
- return Promise.resolve().then(() =>
- {
- data.set(fileName, {
- lastModified: Date.now(),
- contents: Array.from(generator)
- });
- });
- },
- readFromFile(fileName, listener)
- {
- return Promise.resolve().then(() =>
- {
- if (!data.has(fileName))
- throw new Error("File doesn't exist");
-
- let lines = data.get(fileName).contents;
- for (let line of lines)
- listener(line);
+ data.set(fileName, {
+ lastModified: Date.now(),
+ contents: Array.from(generator)
});
},
- copyFile(fromName, toName)
+ async readFromFile(fileName, listener)
{
- return Promise.resolve().then(() =>
- {
- if (!data.has(fromName))
- throw new Error("File doesn't exist");
- if (fromName == toName)
- throw new Error("Cannot copy file to itself");
+ if (!data.has(fileName))
+ throw new Error("File doesn't exist");
+
+ let lines = data.get(fileName).contents;
+ for (let line of lines)
+ listener(line);
+ },
+ async copyFile(fromName, toName)
+ {
+ if (!data.has(fromName))
+ throw new Error("File doesn't exist");
+
+ if (fromName == toName)
+ throw new Error("Cannot copy file to itself");
- data.set(toName, data.get(fromName));
- });
+ data.set(toName, data.get(fromName));
},
- renameFile(fromName, toName)
+ async renameFile(fromName, toName)
+ {
+ await this.copyFile(fromName, toName);
+ await this.removeFile(fromName);
Manish Jethani 2019/01/17 09:29:55 Note that to be exactly like the previous version
+ },
+ async removeFile(fileName)
{
- return this.copyFile(fromName, toName).then(() => this.removeFile(fromName));
+ if (!data.has(fileName))
+ throw new Error("File doesn't exist");
+
+ data.delete(fileName);
},
- removeFile(fileName)
+ async statFile(fileName)
{
- return Promise.resolve().then(() =>
+ if (data.has(fileName))
{
- if (!data.has(fileName))
- throw new Error("File doesn't exist");
+ return {
+ exists: true,
+ lastModified: data.get(fileName).lastModified
+ };
+ }
- data.delete(fileName);
- });
- },
- statFile(fileName)
- {
- return Promise.resolve().then(() =>
- {
- if (data.has(fileName))
- {
- return {
- exists: true,
- lastModified: data.get(fileName).lastModified
- };
- }
- return {
- exists: false,
- lastModified: 0
- };
- });
+ return {
+ exists: false,
+ lastModified: 0
+ };
}
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld