You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It was closed as being an upstream issue. Not sure how its going to be fixed if upstream doesn't know about it, so I'm mirroring it here :)
Thankyou
--
In vanilla IE11, Edge, Chrome, Safari, FireFox, PhantomJS and Node the following code succeeds.
vararray=newUint8Array();
When executing the above line after importing the babel-polyfill, it throws 'TypeError: Wrong length!' in all browsers except Chrome.
The expected behavuour is that new Uint8Array() should not throw, as this is the existing behaviour in ALL user-agents tested.
This affects the usage of legacy libraries which initialise a default Uint8Array and then replace the array with larger arrays if the length of the array is smaller than required. Similar to how a vector might work in some other languages.
A code-change in the user code can be made to instead declare the array as :
vararray=newUint8Array(0);
But this is not applicable in to modules and other code bases which are imported.
The following mocha/karma test suite tests the behaviour, and reproduces the failures. If you comment the babel-polyfill line, the tests all pass.
Using babel-polyfill@6.23.0 and type-detect@4.0.0
import{assert}from'chai';importtypefrom'type-detect';import'babel-polyfill';describe('Uint8Array',function(){it('constructor with no arguments does not throw',function(){letarray;assert.doesNotThrow(function(){array=newUint8Array();});});it('type of default Uint8Array is Uint8Array',function(){letarray;assert.doesNotThrow(function(){array=newUint8Array();});assert.strictEqual(type(array),'Uint8Array');});it('length of default Uint8Array is 0',function(){letarray;letlength;assert.doesNotThrow(function(){array=newUint8Array();length=array.length;});assert.strictEqual(length,0);});});
Karma test run in IE, Edge, Chrome, Safari, Firefox, PhantomJS with babel-polyfill disabled: :
START:
Uint8Array
√ constructor with no arguments does not throw
√ type of default Uint8Array is Uint8Array
√ length of default Uint8Array is 0
Finished in 0.134 secs / 0.035 secs @ 17:35:57 GMT+1100 (AUS Eastern Daylight Time)
SUMMARY:
√ 18 tests completed
node mocha test with babel-polyfill disabled:
Uint8Array
√ constructor with no arguments does not throw
√ type of default Uint8Array is Uint8Array
√ length of default Uint8Array is 0
3 passing (652ms)
Karma in IE, Edge, Chrome, Safari, Firefox, PhantomJS with babel-polyfill enabled:
START:
Uint8Array
× constructor with no arguments does not throw
× type of default Uint8Array is Uint8Array
× length of default Uint8Array is 0
Finished in 0.178 secs / 0.104 secs @ 17:37:55 GMT+1100 (AUS Eastern Daylight Time)
SUMMARY:
√ 3 tests completed
× 15 tests failed
FAILED TESTS:
Uint8Array
× constructor with no arguments does not throw
PhantomJS 2.1.1 (Windows 8 0.0.0)
IE 11.0.0 (Windows 10 0.0.0)
Safari 10.0.3 (Mac OS X 10.11.6)
Edge 14.14393.0 (Windows 10 0.0.0)
Firefox 52.0.0 (Windows 10 0.0.0)
expected [Function] to not throw an error but 'TypeError: Wrong length!' was thrown
AssertionError@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:592:13
require<[26]</module.exports/Assertion.prototype.assert@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29
d9dc.browserify:3633:13
assertThrows@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:5092:5
require<[33]</module.exports/ctx[name]@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:7
619:18
require<[29]</module.exports/assert.doesNotThrow@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.br
owserify:6727:5
require<["C:\\Users\\dev\\Documents\\GitHub\\<redacted>\tests\\node\\unit\\testUint8Array.js"]</</<@C:/Users/dev/Ap
pData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:178231:3
× type of default Uint8Array is Uint8Array
PhantomJS 2.1.1 (Windows 8 0.0.0)
IE 11.0.0 (Windows 10 0.0.0)
Safari 10.0.3 (Mac OS X 10.11.6)
Edge 14.14393.0 (Windows 10 0.0.0)
Firefox 52.0.0 (Windows 10 0.0.0)
expected [Function] to not throw an error but 'TypeError: Wrong length!' was thrown
AssertionError@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:592:13
require<[26]</module.exports/Assertion.prototype.assert@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29
d9dc.browserify:3633:13
assertThrows@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:5092:5
require<[33]</module.exports/ctx[name]@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:7
619:18
require<[29]</module.exports/assert.doesNotThrow@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.br
owserify:6727:5
require<["C:\\Users\\dev\\Documents\\GitHub\\<redacted>\\tests\\node\\unit\\testUint8Array.js"]</</<@C:/Users/dev/Ap
pData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:178241:3
× length of default Uint8Array is 0
PhantomJS 2.1.1 (Windows 8 0.0.0)
IE 11.0.0 (Windows 10 0.0.0)
Safari 10.0.3 (Mac OS X 10.11.6)
Edge 14.14393.0 (Windows 10 0.0.0)
Firefox 52.0.0 (Windows 10 0.0.0)
expected [Function] to not throw an error but 'TypeError: Wrong length!' was thrown
AssertionError@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:592:13
require<[26]</module.exports/Assertion.prototype.assert@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29
d9dc.browserify:3633:13
assertThrows@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:5092:5
require<[33]</module.exports/ctx[name]@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:7
619:18
require<[29]</module.exports/assert.doesNotThrow@C:/Users/dev/AppData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.br
owserify:6727:5
require<["C:\\Users\\dev\\Documents\\GitHub\\<redacted>\\tests\\node\\unit\\testUint8Array.js"]</</<@C:/Users/dev/Ap
pData/Local/Temp/b66d671ed5a59eaa0a0fd7eafc29d9dc.browserify:178253:3
Note: the tests above passed in Chrome only.
node mocha test with babel-polyfill enabled:
Uint8Array
√ constructor with no arguments does not throw
√ type of default Uint8Array is Uint8Array
√ length of default Uint8Array is 0
3 passing (650ms)
The tests also pass in Node.
Thankyou
The text was updated successfully, but these errors were encountered:
22.2.1.1 %TypedArray% ( )
This description applies only if the %TypedArray% function is called with no arguments.
If NewTarget is undefined, throw a TypeError exception.
Return AllocateTypedArray(NewTarget, 0).
I posted a bug report with tests to the babel-polyfil tracker:
babel/babel#5565
It was closed as being an upstream issue. Not sure how its going to be fixed if
upstream
doesn't know about it, so I'm mirroring it here :)Thankyou
--
In vanilla IE11, Edge, Chrome, Safari, FireFox, PhantomJS and Node the following code succeeds.
When executing the above line after importing the babel-polyfill, it throws 'TypeError: Wrong length!' in all browsers except Chrome.
The expected behavuour is that
new Uint8Array()
should not throw, as this is the existing behaviour in ALL user-agents tested.This affects the usage of legacy libraries which initialise a default Uint8Array and then replace the array with larger arrays if the length of the array is smaller than required. Similar to how a vector might work in some other languages.
A code-change in the user code can be made to instead declare the array as :
But this is not applicable in to modules and other code bases which are imported.
The following mocha/karma test suite tests the behaviour, and reproduces the failures. If you comment the babel-polyfill line, the tests all pass.
Using babel-polyfill@6.23.0 and type-detect@4.0.0
Karma test run in IE, Edge, Chrome, Safari, Firefox, PhantomJS with babel-polyfill disabled: :
node mocha test with babel-polyfill disabled:
Karma in IE, Edge, Chrome, Safari, Firefox, PhantomJS with babel-polyfill enabled:
Note: the tests above passed in Chrome only.
node mocha test with babel-polyfill enabled:
The tests also pass in Node.
Thankyou
The text was updated successfully, but these errors were encountered: