@@ -376,6 +376,17 @@ function ByteViewSnapshot(value, buffer, sharedBufferView) { |
376 | 376 | } |
377 | 377 | ByteViewSnapshot.prototype = ObjectFreeze({ __proto__: null }); |
378 | 378 |
|
| 379 | +// The snapshot of a non-empty view of a fixed-length, non-shared ArrayBuffer, |
| 380 | +// the common case. Such a view can only change by the buffer being detached, |
| 381 | +// which makes its byteLength 0, so its byteLength is all that needs to be |
| 382 | +// recorded. `buffer` is null to tell it from a ByteViewSnapshot. |
| 383 | +function FixedByteView(value, byteLength) { |
| 384 | + this.value = value; |
| 385 | + this.byteLength = byteLength; |
| 386 | + this.buffer = null; |
| 387 | +} |
| 388 | +FixedByteView.prototype = ObjectFreeze({ __proto__: null }); |
| 389 | + |
379 | 390 | function BatchEntry(views, byteLength) { |
380 | 391 | this.views = views; |
381 | 392 | this.byteLength = byteLength; |
@@ -399,12 +410,25 @@ PendingWrite.prototype = ObjectFreeze({ __proto__: null }); |
399 | 410 |
|
400 | 411 | function snapshotByteView(value) { |
401 | 412 | const buffer = TypedArrayPrototypeGetBuffer(value); |
402 | | - const sharedBufferView = isSharedArrayBuffer(buffer) ? |
403 | | - new Uint8Array(buffer) : undefined; |
404 | | - return new ByteViewSnapshot(value, buffer, sharedBufferView); |
| 413 | + if (isSharedArrayBuffer(buffer)) { |
| 414 | + return new ByteViewSnapshot(value, buffer, new Uint8Array(buffer)); |
| 415 | + } |
| 416 | + const byteLength = TypedArrayPrototypeGetByteLength(value); |
| 417 | + if (byteLength !== 0 && !ArrayBufferPrototypeGetResizable(buffer)) { |
| 418 | + return new FixedByteView(value, byteLength); |
| 419 | + } |
| 420 | + return new ByteViewSnapshot(value, buffer, undefined); |
405 | 421 | } |
406 | 422 |
|
407 | 423 | function validateByteView(snapshot) { |
| 424 | + if (snapshot.buffer === null) { |
| 425 | + const { value } = snapshot; |
| 426 | + if (TypedArrayPrototypeGetByteLength(value) !== snapshot.byteLength) { |
| 427 | + throw new ERR_INVALID_STATE.TypeError( |
| 428 | + 'Byte view was resized or detached after being accepted'); |
| 429 | + } |
| 430 | + return value; |
| 431 | + } |
408 | 432 | const { |
409 | 433 | value, |
410 | 434 | buffer, |
|