]> git.codecow.com Git - nano25519.git/commitdiff
Force V8 copy of small buffer from the heap at instantiation while buffer is zero...
authorChris Duncan <chris@codecow.com>
Sat, 17 Oct 2026 07:19:01 +0000 (00:19 -0700)
committerChris Duncan <chris@codecow.com>
Sat, 17 Oct 2026 07:19:01 +0000 (00:19 -0700)
src/lib/bytes.ts

index 567650adda97a887c2c0ea336aaca59ca7054668..5be3e6c013761c1c4a8ddefd7d22c532155d4f8f 100644 (file)
@@ -19,6 +19,7 @@ import { Nano25519RangeError, Nano25519TypeError, } from './errors'
 export type Bytes = Uint8Array<ArrayBuffer>
 export type Words = Uint32Array<ArrayBuffer>
 
+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`. */