GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: snapshot common stream/iter byte views in fewer fields · nodejs/node@6a29174

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams/iter
    • utils.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/iter/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/utils.js
+27-3Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,17 @@ function ByteViewSnapshot(value, buffer, sharedBufferView) {
376376
}
377377
ByteViewSnapshot.prototype = ObjectFreeze({ __proto__: null });
378378

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+
379390
function BatchEntry(views, byteLength) {
380391
this.views = views;
381392
this.byteLength = byteLength;
@@ -399,12 +410,25 @@ PendingWrite.prototype = ObjectFreeze({ __proto__: null });
399410

400411
function snapshotByteView(value) {
401412
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);
405421
}
406422

407423
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+
}
408432
const {
409433
value,
410434
buffer,

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.