Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
lib,src: use built-in array buffer detach
  • Loading branch information
anonrig committed Oct 12, 2023
commit ba7744e3983247f0506517f28e15e1f9fc9aca1f
12 changes: 0 additions & 12 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const {
ArrayBufferPrototypeGetByteLength,
ArrayFrom,
ArrayIsArray,
ArrayPrototypePush,
Expand Down Expand Up @@ -54,7 +53,6 @@ const {
} = require('internal/errors');
const { signals } = internalBinding('constants').os;
const {
isArrayBufferDetached: _isArrayBufferDetached,
guessHandleType: _guessHandleType,
privateSymbols: {
arrow_message_private_symbol,
Expand Down Expand Up @@ -776,15 +774,6 @@ function SideEffectFreeRegExpPrototypeSymbolSplit(regex, string, limit = undefin
return getCrossRelmRegex(regex)[SymbolSplit](string, limit);
}


function isArrayBufferDetached(value) {
if (ArrayBufferPrototypeGetByteLength(value) === 0) {
return _isArrayBufferDetached(value);
}

return false;
}

/**
* Helper function to lazy-load an initialize-once value.
* @template T Return value of initializer
Expand Down Expand Up @@ -888,7 +877,6 @@ module.exports = {
getSystemErrorMap,
getSystemErrorName,
guessHandleType,
isArrayBufferDetached,
isError,
isInsideNodeModules,
join,
Expand Down
8 changes: 3 additions & 5 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
isArrayBufferDetached,
kEmptyObject,
kEnumerableProperty,
SideEffectFreeRegExpPrototypeSymbolReplace,
Expand Down Expand Up @@ -103,7 +102,6 @@ const {
extractHighWaterMark,
extractSizeAlgorithm,
lazyTransfer,
isViewedArrayBufferDetached,
isBrandCheck,
resetQueue,
setPromiseHandled,
Expand Down Expand Up @@ -712,7 +710,7 @@ class ReadableStreamBYOBRequest {
const viewBuffer = ArrayBufferViewGetBuffer(view);
const viewBufferByteLength = ArrayBufferPrototypeGetByteLength(viewBuffer);

if (isArrayBufferDetached(viewBuffer)) {
if (viewBuffer.detached) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is a mutable property, so it must be a primordial

Suggested change
if (viewBuffer.detached) {
if (ArrayBufferPrototypeDetached(viewBuffer)) {

throw new ERR_INVALID_STATE.TypeError('Viewed ArrayBuffer is detached');
}

Expand All @@ -739,7 +737,7 @@ class ReadableStreamBYOBRequest {

validateBuffer(view, 'view');

if (isViewedArrayBufferDetached(view)) {
if (ArrayBufferViewGetBuffer(view).detached) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (ArrayBufferViewGetBuffer(view).detached) {
if (ArrayBufferPrototypeDetached(ArrayBufferViewGetBuffer(view)) {

throw new ERR_INVALID_STATE.TypeError('Viewed ArrayBuffer is detached');
}

Expand Down Expand Up @@ -2772,7 +2770,7 @@ function readableByteStreamControllerEnqueue(controller, chunk) {
if (pendingPullIntos.length) {
const firstPendingPullInto = pendingPullIntos[0];

if (isArrayBufferDetached(firstPendingPullInto.buffer)) {
if (firstPendingPullInto.buffer.detached) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (firstPendingPullInto.buffer.detached) {
if (ArrayBufferPrototypeDetached(firstPendingPullInto.buffer)) {

throw new ERR_INVALID_STATE.TypeError(
'Destination ArrayBuffer is detached',
);
Expand Down
9 changes: 0 additions & 9 deletions lib/internal/webstreams/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const {
} = internalBinding('util');

const assert = require('internal/assert');
const { isArrayBufferDetached } = require('internal/util');

const {
validateFunction,
Expand Down Expand Up @@ -132,13 +131,6 @@ function transferArrayBuffer(buffer) {
return res;
}

function isViewedArrayBufferDetached(view) {
return (
ArrayBufferViewGetByteLength(view) === 0 &&
isArrayBufferDetached(ArrayBufferViewGetBuffer(view))
);
}

function dequeueValue(controller) {
assert(controller[kState].queue !== undefined);
assert(controller[kState].queueTotalSize !== undefined);
Expand Down Expand Up @@ -284,7 +276,6 @@ module.exports = {
lazyTransfer,
isBrandCheck,
isPromisePending,
isViewedArrayBufferDetached,
peekQueueValue,
resetQueue,
setPromiseHandled,
Expand Down
12 changes: 0 additions & 12 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,6 @@ static void GetCallerLocation(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(Array::New(args.GetIsolate(), ret, arraysize(ret)));
}

static void IsArrayBufferDetached(const FunctionCallbackInfo<Value>& args) {
if (args[0]->IsArrayBuffer()) {
auto buffer = args[0].As<v8::ArrayBuffer>();
args.GetReturnValue().Set(buffer->WasDetached());
return;
}
args.GetReturnValue().Set(false);
}

static void PreviewEntries(const FunctionCallbackInfo<Value>& args) {
if (!args[0]->IsObject())
return;
Expand Down Expand Up @@ -278,7 +269,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(GetPromiseDetails);
registry->Register(GetProxyDetails);
registry->Register(GetCallerLocation);
registry->Register(IsArrayBufferDetached);
registry->Register(PreviewEntries);
registry->Register(GetOwnNonIndexProperties);
registry->Register(GetConstructorName);
Expand Down Expand Up @@ -377,8 +367,6 @@ void Initialize(Local<Object> target,
SetMethodNoSideEffect(context, target, "getProxyDetails", GetProxyDetails);
SetMethodNoSideEffect(
context, target, "getCallerLocation", GetCallerLocation);
SetMethodNoSideEffect(
context, target, "isArrayBufferDetached", IsArrayBufferDetached);
SetMethodNoSideEffect(context, target, "previewEntries", PreviewEntries);
SetMethodNoSideEffect(
context, target, "getOwnNonIndexProperties", GetOwnNonIndexProperties);
Expand Down