anonyco / FastestSmallestTextEncoderDecoder

The fastest smallest Javascript polyfill for encodeInto of TextEncoder, encode of TextEncoder, and decode of TextDecoder for UTF-8 only.
https://anonyco.github.io/FastestSmallestTextEncoderDecoder/gh-pages/
Creative Commons Zero v1.0 Universal
145 stars 33 forks source link

Does not work in Node #8

Closed AsaAyers closed 4 years ago

AsaAyers commented 4 years ago

I used nvm to verify it works on 0.10 and 0.12, but then breaks on node 4 or higher. https://nodejs.org/en/download/releases/

asa:~/repos$ cat test.js 

var tmp = require('fastestsmallesttextencoderdecoder')

console.log(
  tmp.decode(tmp.encode("Hello"))
)
asa:~/repos$ nvm install 0.12; nvm use 0.12; node --version; node test.js
Downloading and installing node v0.12.18...
Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz...
########################################################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v0.12.18 (npm v2.15.11)
Now using node v0.12.18 (npm v2.15.11)
v0.12.18
Hello
asa:~/repos$ nvm install 4; nvm use 4; node --version; node test.js
v4.9.1 is already installed.
Now using node v4.9.1 (npm v2.15.11)
Now using node v4.9.1 (npm v2.15.11)
v4.9.1
/home/asa/repos/node_modules/fastestsmallesttextencoderdecoder/NodeJS/EncoderAndDecoderNodeJS.min.js:2
A);for(var a=b.length|0,c=new (h?k:e)(a),d=0;d<a;d=d+1|0)c[d]=b.charCodeAt(d)|0;return c},q=function(){},A=function(b){var a=b.charCodeAt(0)|0;if(55296<=a&&56319>=a){var c=b.charCodeAt(1)|0;if(c===c&&56320<=c&&57343>=c){if(a=(a-55296<<10)+c-56320+65536|0,65535<a)return g(240|a>>>18,128|a>>>12&63,128|a>>>6&63,128|a&63)}else return g(239,191,189)}return 127>=a?b:2047>=a?g(192|a>>>6,128|a&63):g(224|a>>>12,128|a>>>6&63,128|a&63)},r=function(b){b=b&&b.buffer||b;var a=m.call(b);if(a!==z&&a!==y)throw Error("Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");

Error: Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'
asa:~/repos$ nvm install 13; nvm use 13; node --version; node test.js
v13.5.0 is already installed.
Now using node v13.5.0 (npm v6.13.4)
Now using node v13.5.0 (npm v6.13.4)
v13.5.0
/home/asa/repos/node_modules/fastestsmallesttextencoderdecoder/NodeJS/EncoderAndDecoderNodeJS.min.js:2
A);for(var a=b.length|0,c=new (h?k:e)(a),d=0;d<a;d=d+1|0)c[d]=b.charCodeAt(d)|0;return c},q=function(){},A=function(b){var a=b.charCodeAt(0)|0;if(55296<=a&&56319>=a){var c=b.charCodeAt(1)|0;if(c===c&&56320<=c&&57343>=c){if(a=(a-55296<<10)+c-56320+65536|0,65535<a)return g(240|a>>>18,128|a>>>12&63,128|a>>>6&63,128|a&63)}else return g(239,191,189)}return 127>=a?b:2047>=a?g(192|a>>>6,128|a&63):g(224|a>>>12,128|a>>>6&63,128|a&63)},r=function(b){b=b&&b.buffer||b;var a=m.call(b);if(a!==z&&a!==y)throw Error("Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");

Error: Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'
anonyco commented 4 years ago

Thank you so much for bringing this issue to my attention. I shall begin looking into this problem immediately.

~ Happy Coding!

anonyco commented 4 years ago

I have resolved the problem with commit https://github.com/anonyco/FastestSmallestTextEncoderDecoder/commit/8e889b66ad18b50d524688ac22e05364f40f52b6. It appears to work just as well with version v0.12.18 as with v10.18.0 of NodeJS. Thank you so much for bringing this issue to my attention. I should have conducted further testing in npm when I was creating this project.

~ Happy Coding!