yoshihitoh / zstd-codec

Zstandard codec for Node.js and Web, powered by Emscripten
MIT License
183 stars 28 forks source link

Don't handle unhandledRejection/Exception when used in Node #216

Closed pimterry closed 2 years ago

pimterry commented 2 years ago

This PR fixes #214 (incorrectly closed automatically when #215 was merged).

By default, Emscripten automatically adds logic to handle exceptions & promise rejections that aren't handled, assuming that the code is being compiled as a standalone application, rather than a library.

When used as a library, as here, these should be disabled and error handling should be left to the downstream application.

This PR also updates Emscripten to 1.38.41, which brings a small set of extra changes in the bindings. That's required because this is the first version that makes the rejection behaviour configurable (see https://github.com/emscripten-core/emscripten/commit/389493499bf0fd803823ea820ea6b8cdb9945334)

pimterry commented 2 years ago

Amazing, thanks! Looking forward to the new release. :+1:

BTW, now I'm motivated to maintain this module again, so please let me know if you need any improvements or preferred features on this module.

Great! For context, I'm using this module in https://www.npmjs.com/package/http-encoding, with is used in Mockttp (a Node.js & browser HTTP proxy lib) and HTTP Toolkit (an Electron-powered HTTP debugging tool) for encoding & decoding intercepted HTTP traffic that uses Zstandard, so I'm running it in both Node and browsers.

Right now it works great, I don't really have any major suggestions for features to be honest. I'd definitely be interested in anything you can do to shrink the library, since it's a major contributor to my JS bundle size, but I do understand that that's very difficult.

yoshihitoh commented 2 years ago

Thank you for sharing the context!

I'm happy to know that you're using this module on your projects! I tried the great tool HTTP Toolkit, I think it's very convenient for web developers. 😊

so I'm running it in both Node and browsers.

Hmm, now I'm planning to separate this module into two, one for Node.js with a native extension, and another for web with WebAssembly (but be able to use it on Node.js too). I'll test them with your projects to know real-world use cases.

I'd definitely be interested in anything you can do to shrink the library, since it's a major contributor to my JS bundle size, but I do understand that that's very difficult.

Maybe the latest Emscripten will bring improvements on module size, so I'll try it next month :)