-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Editorial: Make better use of ValidateTypedArray #3634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gibson042
wants to merge
3
commits into
tc39:main
Choose a base branch
from
gibson042:3629-use-validatetypedarray
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41197,8 +41197,7 @@ <h1>%ArrayIteratorPrototype%.next ( )</h1> | |
1. Let _index_ be _O_.[[ArrayLikeNextIndex]]. | ||
1. Let _kind_ be _O_.[[ArrayLikeIterationKind]]. | ||
1. If _array_ has a [[TypedArrayName]] internal slot, then | ||
1. Let _taRecord_ be MakeTypedArrayWithBufferWitnessRecord(_array_, ~seq-cst~). | ||
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception. | ||
1. Let _taRecord_ be ? ValidateTypedArray(_array_, ~seq-cst~). | ||
1. Let _len_ be TypedArrayLength(_taRecord_). | ||
1. Else, | ||
1. Let _len_ be ? LengthOfArrayLike(_array_). | ||
|
@@ -41732,8 +41731,7 @@ <h1>%TypedArray%.prototype.copyWithin ( _target_, _start_ [ , _end_ ] )</h1> | |
1. If _count_ > 0, then | ||
1. NOTE: The copying must be performed in a manner that preserves the bit-level encoding of the source data. | ||
1. Let _buffer_ be _O_.[[ViewedArrayBuffer]]. | ||
1. Set _taRecord_ to MakeTypedArrayWithBufferWitnessRecord(_O_, ~seq-cst~). | ||
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception. | ||
1. Set _taRecord_ to ? ValidateTypedArray(_O_, ~seq-cst~). | ||
1. Set _len_ to TypedArrayLength(_taRecord_). | ||
1. Let _elementSize_ be TypedArrayElementSize(_O_). | ||
1. Let _byteOffset_ be _O_.[[ByteOffset]]. | ||
|
@@ -41809,8 +41807,7 @@ <h1>%TypedArray%.prototype.fill ( _value_ [ , _start_ [ , _end_ ] ] )</h1> | |
1. If _relativeEnd_ = -∞, let _endIndex_ be 0. | ||
1. Else if _relativeEnd_ < 0, let _endIndex_ be max(_len_ + _relativeEnd_, 0). | ||
1. Else, let _endIndex_ be min(_relativeEnd_, _len_). | ||
1. Set _taRecord_ to MakeTypedArrayWithBufferWitnessRecord(_O_, ~seq-cst~). | ||
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception. | ||
1. Set _taRecord_ to ? ValidateTypedArray(_O_, ~seq-cst~). | ||
1. Set _len_ to TypedArrayLength(_taRecord_). | ||
1. Set _endIndex_ to min(_endIndex_, _len_). | ||
1. Let _k_ be _startIndex_. | ||
|
@@ -42194,8 +42191,7 @@ <h1> | |
<dd>It sets multiple values in _target_, starting at index _targetOffset_, reading the values from _source_.</dd> | ||
</dl> | ||
<emu-alg> | ||
1. Let _targetRecord_ be MakeTypedArrayWithBufferWitnessRecord(_target_, ~seq-cst~). | ||
1. If IsTypedArrayOutOfBounds(_targetRecord_) is *true*, throw a *TypeError* exception. | ||
1. Let _targetRecord_ be ? ValidateTypedArray(_target_, ~seq-cst~). | ||
1. Let _targetLength_ be TypedArrayLength(_targetRecord_). | ||
1. Let _src_ be ? ToObject(_source_). | ||
1. Let _srcLength_ be ? LengthOfArrayLike(_src_). | ||
|
@@ -42226,12 +42222,10 @@ <h1> | |
</dl> | ||
<emu-alg> | ||
1. Let _targetBuffer_ be _target_.[[ViewedArrayBuffer]]. | ||
1. Let _targetRecord_ be MakeTypedArrayWithBufferWitnessRecord(_target_, ~seq-cst~). | ||
1. If IsTypedArrayOutOfBounds(_targetRecord_) is *true*, throw a *TypeError* exception. | ||
1. Let _targetRecord_ be ? ValidateTypedArray(_target_, ~seq-cst~). | ||
1. Let _targetLength_ be TypedArrayLength(_targetRecord_). | ||
1. Let _srcBuffer_ be _source_.[[ViewedArrayBuffer]]. | ||
1. Let _srcRecord_ be MakeTypedArrayWithBufferWitnessRecord(_source_, ~seq-cst~). | ||
1. If IsTypedArrayOutOfBounds(_srcRecord_) is *true*, throw a *TypeError* exception. | ||
1. Let _srcRecord_ be ? ValidateTypedArray(_source_, ~seq-cst~). | ||
1. Let _srcLength_ be TypedArrayLength(_srcRecord_). | ||
1. Let _targetType_ be TypedArrayElementType(_target_). | ||
1. Let _targetElementSize_ be TypedArrayElementSize(_target_). | ||
|
@@ -42288,8 +42282,7 @@ <h1>%TypedArray%.prototype.slice ( _start_, _end_ )</h1> | |
1. Let _countBytes_ be max(_endIndex_ - _startIndex_, 0). | ||
1. Let _A_ be ? TypedArraySpeciesCreate(_O_, « 𝔽(_countBytes_) »). | ||
1. If _countBytes_ > 0, then | ||
1. Set _taRecord_ to MakeTypedArrayWithBufferWitnessRecord(_O_, ~seq-cst~). | ||
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception. | ||
1. Set _taRecord_ to ? ValidateTypedArray(_O_, ~seq-cst~). | ||
1. Set _endIndex_ to min(_endIndex_, TypedArrayLength(_taRecord_)). | ||
1. Set _countBytes_ to max(_endIndex_ - _startIndex_, 0). | ||
1. Let _srcType_ be TypedArrayElementType(_O_). | ||
|
@@ -42745,8 +42738,7 @@ <h1> | |
1. Let _srcType_ be TypedArrayElementType(_srcArray_). | ||
1. Let _srcElementSize_ be TypedArrayElementSize(_srcArray_). | ||
1. Let _srcByteOffset_ be _srcArray_.[[ByteOffset]]. | ||
1. Let _srcRecord_ be MakeTypedArrayWithBufferWitnessRecord(_srcArray_, ~seq-cst~). | ||
1. If IsTypedArrayOutOfBounds(_srcRecord_) is *true*, throw a *TypeError* exception. | ||
1. Let _srcRecord_ be ? ValidateTypedArray(_srcArray_, ~seq-cst~). | ||
1. Let _elementLength_ be TypedArrayLength(_srcRecord_). | ||
1. Let _byteLength_ be _elementSize_ × _elementLength_. | ||
1. If _elementType_ is _srcType_, then | ||
|
@@ -44503,7 +44495,7 @@ <h1> | |
</dl> | ||
<emu-alg> | ||
1. If IsUnclampedIntegerElementType(_type_) is *true*, return *true*. | ||
1. If IsBigIntElementType(_type_) is *true* and _order_ is neither ~init~ nor ~unordered~, return *true*. | ||
1. If IsBigIntElementType(_type_) is *true* and _order_ is ~seq-cst~, return *true*. | ||
1. Return *false*. | ||
</emu-alg> | ||
</emu-clause> | ||
|
@@ -45897,13 +45889,12 @@ <h1> | |
<dl class="header"> | ||
</dl> | ||
<emu-alg> | ||
1. Let _taRecord_ be ? ValidateTypedArray(_typedArray_, ~unordered~). | ||
1. NOTE: Bounds checking is not a synchronizing operation when _typedArray_'s backing buffer is a growable SharedArrayBuffer. | ||
1. Let _taRecord_ be ? ValidateTypedArray(_typedArray_, ~unordered~). | ||
1. If _waitable_ is *true*, then | ||
1. If _typedArray_.[[TypedArrayName]] is neither *"Int32Array"* nor *"BigInt64Array"*, throw a *TypeError* exception. | ||
1. Else, | ||
1. Let _type_ be TypedArrayElementType(_typedArray_). | ||
1. If IsUnclampedIntegerElementType(_type_) is *false* and IsBigIntElementType(_type_) is *false*, throw a *TypeError* exception. | ||
1. Let _type_ be TypedArrayElementType(_typedArray_). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the |
||
1. If IsNoTearConfiguration(_type_, ~seq-cst~) is *false*, throw a *TypeError* exception. | ||
1. Return _taRecord_. | ||
</emu-alg> | ||
</emu-clause> | ||
|
@@ -45956,9 +45947,8 @@ <h1> | |
<dd>This operation revalidates the index within the backing buffer for atomic operations after all argument coercions are performed in Atomics methods, as argument coercions can have arbitrary side effects, which could cause the buffer to become out of bounds. This operation does not throw when _typedArray_'s backing buffer is a SharedArrayBuffer.</dd> | ||
</dl> | ||
<emu-alg> | ||
1. Let _taRecord_ be MakeTypedArrayWithBufferWitnessRecord(_typedArray_, ~unordered~). | ||
1. NOTE: Bounds checking is not a synchronizing operation when _typedArray_'s backing buffer is a growable SharedArrayBuffer. | ||
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception. | ||
1. Let _taRecord_ be ? ValidateTypedArray(_typedArray_, ~unordered~). | ||
1. Assert: _byteIndexInBuffer_ ≥ _typedArray_.[[ByteOffset]]. | ||
1. If _byteIndexInBuffer_ ≥ _taRecord_.[[CachedBufferByteLength]], throw a *RangeError* exception. | ||
1. Return ~unused~. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems worse to me. Every existing use of ValidateTypedArray is passed an object which is not yet known to be a TA.
I'd be OK with introducing a new AO for this - GetInBoundsTALengthWitness or something, maybe - and then using it ValidateTypedArray and in callsites such as this. But I really don't like re-using ValidateTypedArray for this.