aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Bishop <mbtyke@gmail.com>2013-10-11 14:52:28 -0400
committerJukka Jylänki <jujjyl@gmail.com>2014-04-29 14:57:58 +0300
commit7ff1046c01ba8b4586576a6c5f29cdf5ab878bc4 (patch)
tree7125e65bc20358b65c7c2bf2238452e4fad216f1
parent583efabba5f0da11fecdebbe1ff3d1c846bfbd1e (diff)
Wrapped the delegate calls in exception handlers so the exceptions
would be reported, but not bubble up and be caught by the callers of the FS methods since the callers will interpret those as problems with the FS code and report them as such (which is very confusing). Also removed the "willClose" call as I don't use it.
-rw-r--r--src/library_fs.js77
1 files changed, 54 insertions, 23 deletions
diff --git a/src/library_fs.js b/src/library_fs.js
index 6c083ed5..e0b73db8 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -719,8 +719,13 @@ mergeInto(LibraryManager.library, {
throw new FS.ErrnoError(err);
}
}
- if (FS.trackingDelegate['willMovePath'])
- FS.trackingDelegate['willMovePath'](old_path, new_path);
+ try {
+ if (FS.trackingDelegate['willMovePath']) {
+ FS.trackingDelegate['willMovePath'](old_path, new_path);
+ }
+ } catch(e) {
+ console.log("FS.trackingDelegate['willMovePath']('"+old_path+"', '"+new_path+"') threw an exception: " + e.message);
+ }
// remove the node from the lookup hash
FS.hashRemoveNode(old_node);
// do the underlying fs rename
@@ -732,8 +737,13 @@ mergeInto(LibraryManager.library, {
// add the node back to the hash (in case node_ops.rename
// changed its name)
FS.hashAddNode(old_node);
- if (FS.trackingDelegate['didMovePath'])
+ }
+ try {
+ if (FS.trackingDelegate['didMovePath']) {
FS.trackingDelegate['didMovePath'](old_path, new_path);
+ }
+ } catch(e) {
+ console.log("FS.trackingDelegate['didMovePath']('"+old_path+"', '"+new_path+"') threw an exception: " + e.message);
}
},
rmdir: function(path) {
@@ -751,13 +761,21 @@ mergeInto(LibraryManager.library, {
if (FS.isMountpoint(node)) {
throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
}
- if (FS.trackingDelegate['willDeletePath']) {
- FS.trackingDelegate['willDeletePath'](path);
+ try {
+ if (FS.trackingDelegate['willDeletePath']) {
+ FS.trackingDelegate['willDeletePath'](path);
+ }
+ } catch(e) {
+ console.log("FS.trackingDelegate['willDeletePath']('"+path+"') threw an exception: " + e.message);
}
parent.node_ops.rmdir(parent, name);
FS.destroyNode(node);
- if (FS.trackingDelegate['didDeletePath']) {
- FS.trackingDelegate['didDeletePath'](path);
+ try {
+ if (FS.trackingDelegate['didDeletePath']) {
+ FS.trackingDelegate['didDeletePath'](path);
+ }
+ } catch(e) {
+ console.log("FS.trackingDelegate['didDeletePath']('"+path+"') threw an exception: " + e.message);
}
},
readdir: function(path) {
@@ -785,13 +803,21 @@ mergeInto(LibraryManager.library, {
if (FS.isMountpoint(node)) {
throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
}
- if (FS.trackingDelegate['willDeletePath']) {
- FS.trackingDelegate['willDeletePath'](path);
+ try {
+ if (FS.trackingDelegate['willDeletePath']) {
+ FS.trackingDelegate['willDeletePath'](path);
+ }
+ } catch(e) {
+ console.log("FS.trackingDelegate['willDeletePath']('"+path+"') threw an exception: " + e.message);
}
parent.node_ops.unlink(parent, name);
FS.destroyNode(node);
- if (FS.trackingDelegate['didDeletePath']) {
- FS.trackingDelegate['didDeletePath'](path);
+ try {
+ if (FS.trackingDelegate['didDeletePath']) {
+ FS.trackingDelegate['didDeletePath'](path);
+ }
+ } catch(e) {
+ console.log("FS.trackingDelegate['didDeletePath']('"+path+"') threw an exception: " + e.message);
}
},
readlink: function(path) {
@@ -987,13 +1013,17 @@ mergeInto(LibraryManager.library, {
Module['printErr']('read file: ' + path);
}
}
- if (FS.trackingDelegate && FS.trackingDelegate['didOpenFile']) {
- var trackingFlags = 0;
- if ((flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_WRONLY') }}})
- trackingFlags |= FS.tracking.openFlags.READ;
- if ((flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_RDONLY') }}})
- trackingFlags |= FS.tracking.openFlags.WRITE;
- FS.trackingDelegate['didOpenFile'](path, trackingFlags);
+ try {
+ if (FS.trackingDelegate['didOpenFile']) {
+ var trackingFlags = 0;
+ if ((flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_WRONLY') }}})
+ trackingFlags |= FS.tracking.openFlags.READ;
+ if ((flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_RDONLY') }}})
+ trackingFlags |= FS.tracking.openFlags.WRITE;
+ FS.trackingDelegate['didOpenFile'](path, trackingFlags);
+ }
+ } catch(e) {
+ console.log("FS.trackingDelegate['didOpenFile']('"+path+"', flags) threw an exception: " + e.message);
}
return stream;
},
@@ -1006,9 +1036,6 @@ mergeInto(LibraryManager.library, {
throw e;
} finally {
FS.closeStream(stream.fd);
- if (FS.trackingDelegate && stream.path && FS.trackingDelegate['didCloseFile']) {
- FS.trackingDelegate['didCloseFile'](stream.path);
- }
}
},
llseek: function(stream, offset, whence) {
@@ -1067,8 +1094,12 @@ mergeInto(LibraryManager.library, {
}
var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
if (!seeking) stream.position += bytesWritten;
- if (FS.trackingDelegate && stream.path && FS.trackingDelegate['didWriteToFile']) {
- FS.trackingDelegate['didWriteToFile'](stream.path);
+ try {
+ if (stream.path && FS.trackingDelegate['didWriteToFile']) {
+ FS.trackingDelegate['didWriteToFile'](stream.path);
+ }
+ } catch(e) {
+ console.log("FS.trackingDelegate['didWriteToFile']('"+path+"') threw an exception: " + e.message);
}
return bytesWritten;
},