aboutsummaryrefslogtreecommitdiff
path: root/src/js/node/fs.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/node/fs.js')
-rw-r--r--src/js/node/fs.js21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/js/node/fs.js b/src/js/node/fs.js
index 8340c7375..df500342e 100644
--- a/src/js/node/fs.js
+++ b/src/js/node/fs.js
@@ -126,14 +126,27 @@ var access = function access(...args) {
copyFile = function copyFile(...args) {
const callback = args[args.length - 1];
if (typeof callback !== "function") {
- // TODO: set code
- throw new TypeError("Callback must be a function");
+ const err = new TypeError("Callback must be a function");
+ err.code = "ERR_INVALID_ARG_TYPE";
+ throw err;
}
fs.copyFile(...args).then(result => callback(null, result), callback);
},
- exists = function exists(...args) {
- callbackify(fs.exists, args);
+ exists = function exists(path, callback) {
+ if (typeof callback !== "function") {
+ const err = new TypeError("Callback must be a function");
+ err.code = "ERR_INVALID_ARG_TYPE";
+ throw err;
+ }
+ try {
+ fs.exists.apply(fs, [path]).then(
+ existed => callback(existed),
+ _ => callback(false),
+ );
+ } catch (e) {
+ callback(false);
+ }
},
chown = function chown(...args) {
callbackify(fs.chown, args);