diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-11-05 17:52:22 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-11-05 17:52:22 -0800 |
commit | c0f26e65da33a6437a04d1adba19966f98fd79cb (patch) | |
tree | 7da5b925b27a3a45f22d3de42aafcf2a6962e922 /src/library_fs.js | |
parent | 21997d53d6cf2269cf215689e9673a1fe8ab719f (diff) |
use __proto__ when available for new streams, otherwise do a full copy; fixes #1759, #1760
Diffstat (limited to 'src/library_fs.js')
-rw-r--r-- | src/library_fs.js | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/library_fs.js b/src/library_fs.js index 16512385..5412185f 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -361,9 +361,10 @@ mergeInto(LibraryManager.library, { // SOCKFS is completed. createStream: function(stream, fd_start, fd_end) { if (!FS.FSStream) { - FS.FSStream = {}; + FS.FSStream = function(){}; + FS.FSStream.prototype = {}; // compatibility - Object.defineProperties(FS.FSStream, { + Object.defineProperties(FS.FSStream.prototype, { object: { get: function() { return this.node; }, set: function(val) { this.node = val; } @@ -379,7 +380,16 @@ mergeInto(LibraryManager.library, { } }); } - stream.prototype = FS.FSStream; + if (stream.__proto__) { + // reuse the object + stream.__proto__ = FS.FSStream.prototype; + } else { + var newStream = new FS.FSStream(); + for (var p in stream) { + newStream[p] = stream[p]; + } + stream = newStream; + } var fd = FS.nextfd(fd_start, fd_end); stream.fd = fd; FS.streams[fd] = stream; |