From ee46c7ae16d1f1272b5beaad943941945f820d7f Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Tue, 27 Jun 2023 16:16:02 -0700 Subject: [PATCH] Move detach check after argument coercion in resize Closes #116 --- docs/index.html | 4 ++-- spec.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/index.html b/docs/index.html index 5c0700a..f6fd7b6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -12,7 +12,7 @@

Stage 3 Draft / February 2, 2023

+

Stage 3 Draft / June 27, 2023

Resizable ArrayBuffer and growable SharedArrayBuffer

We extend the ArrayBuffer and SharedArrayBuffer constructors to take an additional maximum byte length, which would construct dynamically resizable and growable array buffers, respectively.

@@ -127,7 +127,7 @@

1.3.4 ArrayBuffer.prototype.slice ( start

1.3.5 ArrayBuffer.prototype.resize ( newLength )

The following steps are taken:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
  5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
  6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]], throw a RangeError exception.
  7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
  8. If hostHandled is handled, return undefined.
  9. Let oldBlock be O.[[ArrayBufferData]].
  10. Let newBlock be ? CreateByteDataBlock(newByteLength).
  11. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
  12. Perform CopyDataBlockBytes(newBlock, 0, oldBlock, 0, copyLength).
  13. NOTE: Neither creation of the new Data Block nor copying from the old Data Block are observable. Implementations reserve the right to implement this method as in-place growth or shrinkage.
  14. Set O.[[ArrayBufferData]] to newBlock.
  15. Set O.[[ArrayBufferByteLength]] to newLength.
  16. Return undefined.
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. Let newByteLength be ? ToIntegerOrInfinity(newLength).
  5. If IsDetachedBuffer(O) is true, throw a TypeError exception.
  6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]], throw a RangeError exception.
  7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
  8. If hostHandled is handled, return undefined.
  9. Let oldBlock be O.[[ArrayBufferData]].
  10. Let newBlock be ? CreateByteDataBlock(newByteLength).
  11. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
  12. Perform CopyDataBlockBytes(newBlock, 0, oldBlock, 0, copyLength).
  13. NOTE: Neither creation of the new Data Block nor copying from the old Data Block are observable. Implementations reserve the right to implement this method as in-place growth or shrinkage.
  14. Set O.[[ArrayBufferData]] to newBlock.
  15. Set O.[[ArrayBufferByteLength]] to newLength.
  16. Return undefined.
diff --git a/spec.html b/spec.html index 80779d9..b4ce530 100644 --- a/spec.html +++ b/spec.html @@ -273,8 +273,8 @@

ArrayBuffer.prototype.resize ( _newLength_ )

1. Let _O_ be the *this* value. 1. Perform ? RequireInternalSlot(_O_, [[ArrayBufferMaxByteLength]]). 1. If IsSharedArrayBuffer(_O_) is *true*, throw a *TypeError* exception. - 1. If IsDetachedBuffer(_O_) is *true*, throw a *TypeError* exception. 1. Let _newByteLength_ be ? ToIntegerOrInfinity(_newLength_). + 1. If IsDetachedBuffer(_O_) is *true*, throw a *TypeError* exception. 1. If _newByteLength_ < 0 or _newByteLength_ > _O_.[[ArrayBufferMaxByteLength]], throw a *RangeError* exception. 1. Let _hostHandled_ be ? HostResizeArrayBuffer(_O_, _newByteLength_). 1. If _hostHandled_ is ~handled~, return *undefined*.