[TS] Correct encodeUint64Array array view length
authorMatt Corallo <git@bluematt.me>
Thu, 6 Oct 2022 19:16:13 +0000 (19:16 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 6 Oct 2022 19:16:13 +0000 (19:16 +0000)
Otherwise the `set` call fails as the array view we've constructed
is only 1 element long.

typescript_strings.py

index 84dd9a1565f5d61860bc4edecdfb7fb59b9014a9..ee4e7094823a705a8b4bea446a0d7ee97cc6c4eb 100644 (file)
@@ -187,9 +187,9 @@ export function encodeUint32Array (inputArray: Uint32Array|Array<number>): numbe
 /* @internal */
 export function encodeUint64Array (inputArray: BigUint64Array|Array<bigint>): number {
        const cArrayPointer = wasm.TS_malloc((inputArray.length + 1) * 8);
-       const arrayMemoryView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, 1);
-       arrayMemoryView.set(inputArray, 1);
+       const arrayMemoryView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, inputArray.length + 1);
        arrayMemoryView[0] = BigInt(inputArray.length);
+       arrayMemoryView.set(inputArray, 1);
        return cArrayPointer;
 }