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
{{ message }}
Repository navigation
TypedArray species creation skips the content type check #1770
A TypeError is thrown, because the species constructor creates a Number-typed array from a BigInt-typed one.
JavaScriptCore (321440):
$ jsc -e 'class A extends BigInt64Array { static [Symbol.species] = Uint8Array; } new A().slice();'
Exception: TypeError: Content types of source and created typed arrays are different
slice, filter, map and subarray create their result with TypedArraySpeciesCreate, whose last step is "If result.[[ContentType]] is not exemplar.[[ContentType]], throw a TypeError exception." BigInt64Array has content type bigint and Uint8Array has number, so all four must throw. The check does not depend on the length, so an empty source is enough.
As in #1690, a non-empty source hides the missing check, because the element copy fails instead: new A(1).slice() throws TypeError: cannot convert BigInt to number. PR #1694 added the check to the TypedArray constructor only; species creation needs the same test.
JavaScriptCore throws on all four and SpiderMonkey on slice and subarray. V8 15.6.20 behaves like QuickJS-ng here, so it is not a useful reference for this case.
Activity
check content type in typedarray species creation (quickjs-ng#1770)