Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Normative: throw whenever creating TA from OOB TA #72

Merged
merged 3 commits into from
Dec 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -758,12 +758,20 @@ <h1>InitializeTypedArrayFromTypedArray ( _O_, _srcArray_ )</h1>
1. Let _bufferConstructor_ be ? SpeciesConstructor(_srcData_, %ArrayBuffer%).
1. Else,
1. Let _bufferConstructor_ be %ArrayBuffer%.
1. <ins>Let _data_ be ? AllocateArrayBuffer(_bufferConstructor_, _byteLength_).</ins>
1. <ins>Let _getSrcBufferByteLength_ be MakeIdempotentArrayBufferByteLengthGetter(~SeqCst~).</ins>
1. <ins>If IsIntegerIndexedObjectOutOfBounds(_srcArray_, _getSrcBufferByteLength_) is *true*, throw a *TypeError* exception.</ins>
1. <ins>Set _elementLength_ to IntegerIndexedObjectLength(_srcArray_, _getSrcBufferByteLength_).</ins>
1. <ins>Set _byteLength_ to _elementSize_ &times; _elementLength_.</ins>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new byteLength might be greater than the old byteLength. byteLength should only be updated if the buffer was shrunk. Alternatively, you could assign the new byte length to a newByteLength, and pass min(newByteLength, _byteLength) to CopyDataBlockBytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Persisting the variable _byteLength_ might be confusing in what is becoming a somewhat complicated algorithm (readers might not recognize that despite its authoritative name, its value is not the byte length). There's also _elementLength_ to consider, which maybe ought to be complimented with a corresponding _newElementLength_ (more for coherence than a direct need).

I think we can use the new buffer's [[ArrayBufferByteLength]] slot to get the prior value of _byteLength_ without having to communicate "newness" or "oldness" through variable names. I've pushed up a commit to demonstrate what I have in mind. Does that seem appropriate to you?

Copy link
Collaborator

@syg syg Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use [[ArrayBufferByteLength]] for growable SharedArrayBuffers, which stores its byte length in a separate shared block. That's why the idempotent getter exists.

I retract my comment, I missed the operative keyword "new". Using the new buffer's [[ArrayBufferByteLength]]. That works for me.

1. If _elementType_ is the same as _srcType_, then
1. Let _data_ be ? CloneArrayBuffer(_srcData_, _srcByteOffset_, _byteLength_, _bufferConstructor_).
1. <del>Let _data_ be ? CloneArrayBuffer(_srcData_, _srcByteOffset_, _byteLength_, _bufferConstructor_).</del>
1. <ins>Let _srcBlock_ be _srcData_.[[ArrayBufferData]].</ins>
1. <ins>Let _targetBlock_ be _data_.[[ArrayBufferData]].</ins>
1. <ins>Let _count_ be min(_byteLength_, _data_.[[ArrayBufferByteLength]]).</ins>
1. <ins>Perform CopyDataBlockBytes(_targetBlock_, 0, _srcBlock_, _srcByteOffset_, _count_).</ins>
1. Else,
1. Let _data_ be ? AllocateArrayBuffer(_bufferConstructor_, _byteLength_).
1. <del>Let _data_ be ? AllocateArrayBuffer(_bufferConstructor_, _byteLength_).</del>
1. <del>If IsDetachedBuffer(_srcData_) is *true*, throw a *TypeError* exception.</del>
1. <ins>If IsIntegerIndexedObjectOutOfBounds(_srcArray_, _getSrcBufferByteLength_) is *true*, throw a *TypeError* exception.</ins>
1. If _srcArray_.[[ContentType]] &ne; _O_.[[ContentType]], throw a *TypeError* exception.
1. Let _srcByteIndex_ be _srcByteOffset_.
1. Let _targetByteIndex_ be 0.
Expand Down