4 ms·
One thing which makes me sad is the lack of structure of the Javascript API. Everything is now built using Javascript and the JS VM is not following any UNIX pr
by realusername 12y ago
One thing which makes me sad is the lack of structure of the Javascript API.
Everything is now built using Javascript and the JS VM is not following any UNIX principles in its implementation. I would really like to have a UNIX-like JS API.
A small example: let's say that you want to redirect the error output to the standard output.
Since everything is a file descriptor on UNIX, you can just call dup2(2) and this won't have any repercussion on other parts of the program. You can also redirect any error to a file just by using this on a file descriptor you got from open (2).
But in Javascript, everything is different, you have to redeclare console.error and hope that this won't break anything if some library is doing exactly the same thing as you somewhere.
This is also the same problem with XMLHttpRequest and various javascript APIs. (including the File and Blob API to read files on the browser).
- Bahamut 12y agoWhat you are talking about aren't JavaScript APIs, but browser APIs.
- reubenmorais 12y ago>Since everything is a file descriptor on UNIX, you can just call dup2(2) and this won't have any repercussion on other parts of the program. You chose an unfortunate example. From the dup2 documentation: The object referenced by the descriptor does not distinguish between fildes and fildes2 in any way. Thus if fildes2 and fildes are duplicate references to an open file, read(2), write(2) and lseek(2) calls all move a single pointer into the file, and append mode, non-blocking I/O and asynchronous I/O options are shared between the references. If a separate pointer into the file is desired, a different object reference to the file must be obtained by issuing an additional open(2) call. The close-on-exec flag on the new file descriptor is unset.
- evmar 12y agoAnd on top of that, you have to worry about CLOEXEC if your process can fork, so you need to consider using dup3.
- tlrobinson 12y agoIt sounds like you want something like Node.js Streams? People have written Stream adapters for XMLHttpRequest and such. There's also this: https://github.com/whatwg/streams https://github.com/whatwg/streams