-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
Using jsvu and eshost we can test our BSON lib directly on v8, spidermonkey, and JavascriptCore (Safari). This could go a long way to ensuring web compatibility and enable perf testing on multiple javascript runtimes.
To make this possible we have to add some polyfilling to allow our lib to work in environments that have no Buffer present. And we would need a TextEncoder/Decoder polyfill.
The surface area of our API usage is:
- Buffer.copy (uses .set internally) – replaced with .set
- Buffer.alloc – replaced with Uint8Array constructor call (17mb, we might want remove)
- toString('utf8', start, end) – there's no easy replacement - requires TextDecoder
Karma has so many errors surrounding the node builtins and polyfils and there are outstanding issues that are years old and people still report issues with 20 days ago. There is very little documentation on this because of how odd it is. It's rare and non-performant to want to ship to the browser code that uses Node.js. https://github.com/rollup/plugins/issues/581#issuecomment-757376570
We have to implement:
- utf8 decoding ourselves
- TextDecoder polyfill - https://github.com/inexorabletash/text-encoding
- Target browsers that support textdecoder
- let users who bundle bring in the polyfil
- Bring in our own polyfill