Skip to content

Conversation

gibson042
Copy link
Contributor

Includes #4545
Ref #4509

%TypedArray% static properties

  • %TypedArray%.from

    • throws a TypeError if the receiver constructs an immutable ArrayBuffer, after determining the length from source but before checking if the constructed ArrayBuffer is too short or (more testably) calling mapper
  • %TypedArray%.of

    • throws a TypeError if the receiver constructs an immutable ArrayBuffer, after determining the length from source but before checking if the constructed ArrayBuffer is too short or (more testably) coercing any value to bigint/number

@gibson042 gibson042 requested a review from a team as a code owner July 24, 2025 20:59
@gibson042 gibson042 force-pushed the 2025-07-immutable-arraybuffer-typedarray-static-functions branch from a8d03e1 to 22ff6f5 Compare July 24, 2025 21:01
With `sedi` being a portable `sed -i`, e.g. `sed -i '' "$@"` on BSD and
`sed -i "$@"` on Linux:
```sh
git grep -l 'testWith[A-Za-z]*TypedArrayConstructors[(].*, N.*' test/built-ins/ | \
  xargs sedi -E 's#(testWith[A-Za-z]*TypedArrayConstructors[(].*), N([^a-zA-Z].*)#\1\2#'
```
With `sedi` being a portable `sed -i`, e.g. `sed -i '' "$@"` on BSD and
`sed -i "$@"` on Linux:
```sh
git grep -l 'testBigIntTypedArray[.]js' | \
  xargs sedi 's#testBigIntTypedArray[.]js#testTypedArray.js#'
```
…uctors

With `sedi` being a portable `sed -i`, e.g. `sed -i '' "$@"` on BSD and
`sed -i "$@"` on Linux:
```sh
git grep -l 'testWith[A-Za-z]*TypedArrayConstructors[(]' test/built-ins/ | \
  while read f; do
    grep -qF detachArrayBuffer.js "$f" && continue
    grep -qF '.resize(' "$f" && continue
    taCtorAliases="$(sed -nE \
      's#testWith[A-Za-z]*TypedArrayConstructors[(] *(function[^(]*[(] *|[^a-zA-Z0-9_]*)([a-zA-Z0-9_]+).*#\2#p' \
      "$f")"
    sedi -E '
      s#(testWith[A-Za-z]*TypedArrayConstructors[(] *(function[^(]*[(] *|[(] *)[a-zA-Z0-9_]+)#\1, makeCtorArg#; t;
      s#(testWith[A-Za-z]*TypedArrayConstructors[(] *)([a-zA-Z0-9_]+)#\1(\2, makeCtorArg)#; t;
      '"$(printf '%s' "$taCtorAliases" | sed -E 's/(.*)/s#\\b\1[(]([0-9.]+n?|[[][^]]*[]])[)]#\1(makeCtorArg(\\1))#/')" \
      "$f"
  done

git diff --numstat -- test/built-ins/ | \
  awk '{ print $NF }' | \
  xargs grep -c '\bmakeCtorArg\b' | \
  sed -n 's/:1$//p' | \
  xargs sedi -E '
    /makeCtorArg/,$ { s#^[}][)]#}, null, ["passthrough"])#; }
    /makeCtorArg/ { s#, makeCtorArg##; s#[(]([a-zA-Z0-9_]+)[)] =>#\1 =>#; }
  '

git diff --numstat -- test/built-ins/ | \
  awk '{ print $NF }' | \
  xargs grep -l '\bdefineProperty\b' | \
  xargs sedi -E \
    '/testWith[A-Za-z]*TypedArrayConstructors[(]/,$s#^[}][)]#}, null, ["passthrough"])#'
```
…e contents

With `sedi` being a portable `sed -i`, e.g. `sed -i '' "$@"` on BSD and
`sed -i "$@"` on Linux:
```sh
git grep -l 'testWith[A-Za-z]*TypedArrayConstructors[(]' \
    test/built-ins/TypedArray/prototype/{copyWithin,fill,reverse,set,sort} | \
  xargs sedi -E \
    '/testWith[A-Za-z]*TypedArrayConstructors[(]/,$s#^[}][)]#}, null, null, ["immutable"])#'

git grep -l 'testWith[A-Za-z]*TypedArrayConstructors[(]' \
    test/built-ins/TypedArray/prototype | \
  grep -E 'set-value-during-|predicate-call-changes-value|values-are-not-cached' | \
  xargs sedi -E \
    '/testWith[A-Za-z]*TypedArrayConstructors[(]/,$s#^[}][)]#}, null, null, ["immutable"])#'
```
@ptomato ptomato force-pushed the 2025-07-immutable-arraybuffer-typedarray-static-functions branch from 22ff6f5 to 26717f7 Compare August 25, 2025 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants