GeezerVison is showing github.com — lib,src: use built-in array buffer detach, transfer · nodejs/node@b59c8b8
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/util.js -12Lines changed: 0 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | 3 | const { | 4 | | - ArrayBufferPrototypeGetByteLength, | 5 | 4 | ArrayFrom, | 6 | 5 | ArrayIsArray, | 7 | 6 | ArrayPrototypePush, | @@ -57,7 +56,6 @@ const { | 57 | 56 | } = require('internal/errors'); | 58 | 57 | const { signals } = internalBinding('constants').os; | 59 | 58 | const { | 60 | | - isArrayBufferDetached: _isArrayBufferDetached, | 61 | 59 | guessHandleType: _guessHandleType, | 62 | 60 | privateSymbols: { | 63 | 61 | arrow_message_private_symbol, | @@ -798,15 +796,6 @@ function SideEffectFreeRegExpPrototypeSymbolSplit(regex, string, limit = undefin | 798 | 796 | return getCrossRelmRegex(regex)[SymbolSplit](string, limit); | 799 | 797 | } | 800 | 798 |
| 801 | | - | 802 | | -function isArrayBufferDetached(value) { | 803 | | - if (ArrayBufferPrototypeGetByteLength(value) === 0) { | 804 | | - return _isArrayBufferDetached(value); | 805 | | - } | 806 | | - | 807 | | - return false; | 808 | | -} | 809 | | - | 810 | 799 | /** | 811 | 800 | * Helper function to lazy-load an initialize-once value. | 812 | 801 | * @template T Return value of initializer | @@ -917,7 +906,6 @@ module.exports = { | 917 | 906 | getSystemErrorMap, | 918 | 907 | getSystemErrorName, | 919 | 908 | guessHandleType, | 920 | | - isArrayBufferDetached, | 921 | 909 | isError, | 922 | 910 | isInsideNodeModules, | 923 | 911 | isMacOS, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/webstreams/readablestream.js +11-12Lines changed: 11 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | const { | 4 | 4 | ArrayBuffer, | 5 | 5 | ArrayBufferPrototypeGetByteLength, | | 6 | + ArrayBufferPrototypeGetDetached, | 6 | 7 | ArrayBufferPrototypeSlice, | | 8 | + ArrayBufferPrototypeTransfer, | 7 | 9 | ArrayPrototypePush, | 8 | 10 | ArrayPrototypeShift, | 9 | 11 | DataView, | @@ -49,7 +51,6 @@ const { | 49 | 51 | const { | 50 | 52 | createDeferredPromise, | 51 | 53 | customInspectSymbol: kInspect, | 52 | | - isArrayBufferDetached, | 53 | 54 | kEmptyObject, | 54 | 55 | kEnumerableProperty, | 55 | 56 | SideEffectFreeRegExpPrototypeSymbolReplace, | @@ -103,11 +104,9 @@ const { | 103 | 104 | extractHighWaterMark, | 104 | 105 | extractSizeAlgorithm, | 105 | 106 | lazyTransfer, | 106 | | - isViewedArrayBufferDetached, | 107 | 107 | isBrandCheck, | 108 | 108 | resetQueue, | 109 | 109 | setPromiseHandled, | 110 | | - transferArrayBuffer, | 111 | 110 | nonOpCancel, | 112 | 111 | nonOpPull, | 113 | 112 | nonOpStart, | @@ -698,7 +697,7 @@ class ReadableStreamBYOBRequest { | 698 | 697 | const viewBuffer = ArrayBufferViewGetBuffer(view); | 699 | 698 | const viewBufferByteLength = ArrayBufferPrototypeGetByteLength(viewBuffer); | 700 | 699 |
| 701 | | - if (isArrayBufferDetached(viewBuffer)) { | | 700 | + if (ArrayBufferPrototypeGetDetached(viewBuffer)) { | 702 | 701 | throw new ERR_INVALID_STATE.TypeError('Viewed ArrayBuffer is detached'); | 703 | 702 | } | 704 | 703 |
| @@ -725,7 +724,7 @@ class ReadableStreamBYOBRequest { | 725 | 724 |
| 726 | 725 | validateBuffer(view, 'view'); | 727 | 726 |
| 728 | | - if (isViewedArrayBufferDetached(view)) { | | 727 | + if (ArrayBufferPrototypeGetDetached(view.buffer)) { | 729 | 728 | throw new ERR_INVALID_STATE.TypeError('Viewed ArrayBuffer is detached'); | 730 | 729 | } | 731 | 730 |
| @@ -1981,7 +1980,7 @@ function readableByteStreamControllerConvertPullIntoDescriptor(desc) { | 1981 | 1980 | if (bytesFilled > byteLength) | 1982 | 1981 | throw new ERR_INVALID_STATE.RangeError('The buffer size is invalid'); | 1983 | 1982 | assert(!(bytesFilled % elementSize)); | 1984 | | - const transferredBuffer = transferArrayBuffer(buffer); | | 1983 | + const transferredBuffer = ArrayBufferPrototypeTransfer(buffer); | 1985 | 1984 |
| 1986 | 1985 | if (ctor === Buffer) { | 1987 | 1986 | return Buffer.from(transferredBuffer, byteOffset, bytesFilled / elementSize); | @@ -2650,7 +2649,7 @@ function readableByteStreamControllerPullInto( | 2650 | 2649 |
| 2651 | 2650 | let transferredBuffer; | 2652 | 2651 | try { | 2653 | | - transferredBuffer = transferArrayBuffer(buffer); | | 2652 | + transferredBuffer = ArrayBufferPrototypeTransfer(buffer); | 2654 | 2653 | } catch (error) { | 2655 | 2654 | readIntoRequest[kError](error); | 2656 | 2655 | return; | @@ -2743,7 +2742,7 @@ function readableByteStreamControllerRespond(controller, bytesWritten) { | 2743 | 2742 | throw new ERR_INVALID_ARG_VALUE.RangeError('bytesWritten', bytesWritten); | 2744 | 2743 | } | 2745 | 2744 |
| 2746 | | - desc.buffer = transferArrayBuffer(desc.buffer); | | 2745 | + desc.buffer = ArrayBufferPrototypeTransfer(desc.buffer); | 2747 | 2746 |
| 2748 | 2747 | readableByteStreamControllerRespondInternal(controller, bytesWritten); | 2749 | 2748 | } | @@ -2793,20 +2792,20 @@ function readableByteStreamControllerEnqueue(controller, chunk) { | 2793 | 2792 | if (closeRequested || stream[kState].state !== 'readable') | 2794 | 2793 | return; | 2795 | 2794 |
| 2796 | | - const transferredBuffer = transferArrayBuffer(buffer); | | 2795 | + const transferredBuffer = ArrayBufferPrototypeTransfer(buffer); | 2797 | 2796 |
| 2798 | 2797 | if (pendingPullIntos.length) { | 2799 | 2798 | const firstPendingPullInto = pendingPullIntos[0]; | 2800 | 2799 |
| 2801 | | - if (isArrayBufferDetached(firstPendingPullInto.buffer)) { | | 2800 | + if (ArrayBufferPrototypeGetDetached(firstPendingPullInto.buffer)) { | 2802 | 2801 | throw new ERR_INVALID_STATE.TypeError( | 2803 | 2802 | 'Destination ArrayBuffer is detached', | 2804 | 2803 | ); | 2805 | 2804 | } | 2806 | 2805 |
| 2807 | 2806 | readableByteStreamControllerInvalidateBYOBRequest(controller); | 2808 | 2807 |
| 2809 | | - firstPendingPullInto.buffer = transferArrayBuffer( | | 2808 | + firstPendingPullInto.buffer = ArrayBufferPrototypeTransfer( | 2810 | 2809 | firstPendingPullInto.buffer, | 2811 | 2810 | ); | 2812 | 2811 |
| @@ -3104,7 +3103,7 @@ function readableByteStreamControllerRespondWithNewView(controller, view) { | 3104 | 3103 | if (bufferByteLength !== viewBufferByteLength) | 3105 | 3104 | throw new ERR_INVALID_ARG_VALUE.RangeError('view', view); | 3106 | 3105 |
| 3107 | | - desc.buffer = transferArrayBuffer(viewBuffer); | | 3106 | + desc.buffer = ArrayBufferPrototypeTransfer(viewBuffer); | 3108 | 3107 |
| 3109 | 3108 | readableByteStreamControllerRespondInternal(controller, viewByteLength); | 3110 | 3109 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/webstreams/util.js -21Lines changed: 0 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,13 +21,11 @@ const { | 21 | 21 | ERR_ARG_NOT_ITERABLE, | 22 | 22 | ERR_INVALID_ARG_VALUE, | 23 | 23 | ERR_INVALID_STATE, | 24 | | - ERR_OPERATION_FAILED, | 25 | 24 | }, | 26 | 25 | } = require('internal/errors'); | 27 | 26 |
| 28 | 27 | const { | 29 | 28 | copyArrayBuffer, | 30 | | - detachArrayBuffer, | 31 | 29 | } = internalBinding('buffer'); | 32 | 30 |
| 33 | 31 | const { | @@ -42,7 +40,6 @@ const { | 42 | 40 | } = internalBinding('util'); | 43 | 41 |
| 44 | 42 | const assert = require('internal/assert'); | 45 | | -const { isArrayBufferDetached } = require('internal/util'); | 46 | 43 |
| 47 | 44 | const { | 48 | 45 | validateFunction, | @@ -118,22 +115,6 @@ function isBrandCheck(brand) { | 118 | 115 | }; | 119 | 116 | } | 120 | 117 |
| 121 | | -function transferArrayBuffer(buffer) { | 122 | | - const res = detachArrayBuffer(buffer); | 123 | | - if (res === undefined) { | 124 | | - throw new ERR_OPERATION_FAILED.TypeError( | 125 | | - 'The ArrayBuffer could not be transferred'); | 126 | | - } | 127 | | - return res; | 128 | | -} | 129 | | - | 130 | | -function isViewedArrayBufferDetached(view) { | 131 | | - return ( | 132 | | - ArrayBufferViewGetByteLength(view) === 0 && | 133 | | - isArrayBufferDetached(ArrayBufferViewGetBuffer(view)) | 134 | | - ); | 135 | | -} | 136 | | - | 137 | 118 | function dequeueValue(controller) { | 138 | 119 | assert(controller[kState].queue !== undefined); | 139 | 120 | assert(controller[kState].queueTotalSize !== undefined); | @@ -291,11 +272,9 @@ module.exports = { | 291 | 272 | invokePromiseCallback, | 292 | 273 | isBrandCheck, | 293 | 274 | isPromisePending, | 294 | | - isViewedArrayBufferDetached, | 295 | 275 | peekQueueValue, | 296 | 276 | resetQueue, | 297 | 277 | setPromiseHandled, | 298 | | - transferArrayBuffer, | 299 | 278 | nonOpCancel, | 300 | 279 | nonOpFlush, | 301 | 280 | nonOpPull, | |
Collapse file Copy file name to clipboardExpand all lines: src/node_util.cc -12Lines changed: 0 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -162,15 +162,6 @@ static void GetCallerLocation(const FunctionCallbackInfo<Value>& args) { | 162 | 162 | args.GetReturnValue().Set(Array::New(args.GetIsolate(), ret, arraysize(ret))); | 163 | 163 | } | 164 | 164 |
| 165 | | -static void IsArrayBufferDetached(const FunctionCallbackInfo<Value>& args) { | 166 | | - if (args[0]->IsArrayBuffer()) { | 167 | | - auto buffer = args[0].As<v8::ArrayBuffer>(); | 168 | | - args.GetReturnValue().Set(buffer->WasDetached()); | 169 | | - return; | 170 | | - } | 171 | | - args.GetReturnValue().Set(false); | 172 | | -} | 173 | | - | 174 | 165 | static void PreviewEntries(const FunctionCallbackInfo<Value>& args) { | 175 | 166 | if (!args[0]->IsObject()) | 176 | 167 | return; | @@ -306,7 +297,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | 306 | 297 | registry->Register(GetPromiseDetails); | 307 | 298 | registry->Register(GetProxyDetails); | 308 | 299 | registry->Register(GetCallerLocation); | 309 | | - registry->Register(IsArrayBufferDetached); | 310 | 300 | registry->Register(PreviewEntries); | 311 | 301 | registry->Register(GetCallSite); | 312 | 302 | registry->Register(GetOwnNonIndexProperties); | @@ -406,8 +396,6 @@ void Initialize(Local<Object> target, | 406 | 396 | SetMethodNoSideEffect(context, target, "getProxyDetails", GetProxyDetails); | 407 | 397 | SetMethodNoSideEffect( | 408 | 398 | context, target, "getCallerLocation", GetCallerLocation); | 409 | | - SetMethodNoSideEffect( | 410 | | - context, target, "isArrayBufferDetached", IsArrayBufferDetached); | 411 | 399 | SetMethodNoSideEffect(context, target, "previewEntries", PreviewEntries); | 412 | 400 | SetMethodNoSideEffect( | 413 | 401 | context, target, "getOwnNonIndexProperties", GetOwnNonIndexProperties); | |
Collapse file Copy file name to clipboardExpand all lines: typings/primordials.d.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -150,7 +150,9 @@ declare namespace primordials { | 150 | 150 | export import ArrayBuffer = globalThis.ArrayBuffer; | 151 | 151 | export const ArrayBufferPrototype: typeof ArrayBuffer.prototype | 152 | 152 | export const ArrayBufferIsView: typeof ArrayBuffer.isView | | 153 | + export const ArrayBufferPrototypeGetDetached: UncurryThis<typeof ArrayBuffer.prototype.detached> | 153 | 154 | export const ArrayBufferPrototypeSlice: UncurryThis<typeof ArrayBuffer.prototype.slice> | | 155 | + export const ArrayBufferPrototypeTransfer: UncurryThis<typeof ArrayBuffer.prototype.transfer> | 154 | 156 | export const AsyncIteratorPrototype: AsyncIterable<any>; | 155 | 157 | export import BigInt = globalThis.BigInt; | 156 | 158 | export const BigIntPrototype: typeof BigInt.prototype | |
|