From: Chris Duncan Date: Sat, 17 Oct 2026 07:19:01 +0000 (-0700) Subject: Force V8 copy of small buffer from the heap at instantiation while buffer is zero... X-Git-Tag: v2.0.0~1^2~4 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=a1ed6f589ef07fb4fb74177d2be94efdb5dace9d;p=nano25519.git Force V8 copy of small buffer from the heap at instantiation while buffer is zero-initialized. --- diff --git a/src/lib/bytes.ts b/src/lib/bytes.ts index 567650a..5be3e6c 100644 --- a/src/lib/bytes.ts +++ b/src/lib/bytes.ts @@ -19,6 +19,7 @@ import { Nano25519RangeError, Nano25519TypeError, } from './errors' export type Bytes = Uint8Array export type Words = Uint32Array +const Buffer = ArrayBuffer const Bytes = Uint8Array const Words = Uint32Array const TypedArray = Object.getPrototypeOf(Bytes.prototype) @@ -40,7 +41,7 @@ const getTag = getter(TypedArray, Symbol.toStringTag) /** Reads internal slot `[[ViewedArrayBuffer]]`. */ const getBuffer = getter(TypedArray, 'buffer') /** Throws if passed `SharedArrayBuffer`, distinguishing it from `ArrayBuffer`. */ -const getBufferByteLength = getter(ArrayBuffer.prototype, 'byteLength') +const getBufferByteLength = getter(Buffer.prototype, 'byteLength') /** Reads internal slot `[[ByteLength]]`. */ const getByteLength = getter(TypedArray, 'byteLength') /** Reads internal slot `[[ByteOffset]]`. */ @@ -61,7 +62,8 @@ export function allocate (byteLength: number): Bytes { if (typeof length !== 'number') { throw new Nano25519TypeError('Invalid byte length') } - return new Bytes(length) + const buffer = new Buffer(length) + return new Bytes(buffer) } /** Captured version of `Uint8Array.prototype.byteLength`. */