projects
/
ldk-java
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
890e35a
)
[TS] Handle nullable arrays and objects in more cases
author
Matt Corallo
<git@bluematt.me>
Fri, 28 Oct 2022 18:32:32 +0000
(18:32 +0000)
committer
Matt Corallo
<git@bluematt.me>
Fri, 28 Oct 2022 18:34:07 +0000
(18:34 +0000)
typescript_strings.py
patch
|
blob
|
history
diff --git
a/typescript_strings.py
b/typescript_strings.py
index 6be8cecc05f004b298878739310ad1608e65a11d..aeb2a4ae8e68b5ac7214eec3a0c5273e844cfb14 100644
(file)
--- a/
typescript_strings.py
+++ b/
typescript_strings.py
@@
-167,7
+167,8
@@
export function WitnessVersionArrToBytes(inputArray: Array<WitnessVersion>): Uin
/* @internal */
/* @internal */
-export function encodeUint8Array (inputArray: Uint8Array): number {
+export function encodeUint8Array (inputArray: Uint8Array|null): number {
+ if (inputArray == null) return 0;
const cArrayPointer = wasm.TS_malloc(inputArray.length + 8);
const arrayLengthView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, 1);
arrayLengthView[0] = BigInt(inputArray.length);
const cArrayPointer = wasm.TS_malloc(inputArray.length + 8);
const arrayLengthView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, 1);
arrayLengthView[0] = BigInt(inputArray.length);
@@
-176,7
+177,8
@@
export function encodeUint8Array (inputArray: Uint8Array): number {
return cArrayPointer;
}
/* @internal */
return cArrayPointer;
}
/* @internal */
-export function encodeUint32Array (inputArray: Uint32Array|Array<number>): number {
+export function encodeUint32Array (inputArray: Uint32Array|Array<number>|null): number {
+ if (inputArray == null) return 0;
const cArrayPointer = wasm.TS_malloc((inputArray.length + 2) * 4);
const arrayLengthView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, 1);
arrayLengthView[0] = BigInt(inputArray.length);
const cArrayPointer = wasm.TS_malloc((inputArray.length + 2) * 4);
const arrayLengthView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, 1);
arrayLengthView[0] = BigInt(inputArray.length);
@@
-185,7
+187,8
@@
export function encodeUint32Array (inputArray: Uint32Array|Array<number>): numbe
return cArrayPointer;
}
/* @internal */
return cArrayPointer;
}
/* @internal */
-export function encodeUint64Array (inputArray: BigUint64Array|Array<bigint>): number {
+export function encodeUint64Array (inputArray: BigUint64Array|Array<bigint>|null): number {
+ if (inputArray == null) return 0;
const cArrayPointer = wasm.TS_malloc((inputArray.length + 1) * 8);
const arrayMemoryView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, inputArray.length + 1);
arrayMemoryView[0] = BigInt(inputArray.length);
const cArrayPointer = wasm.TS_malloc((inputArray.length + 1) * 8);
const arrayMemoryView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, inputArray.length + 1);
arrayMemoryView[0] = BigInt(inputArray.length);
@@
-194,8
+197,8
@@
export function encodeUint64Array (inputArray: BigUint64Array|Array<bigint>): nu
}
/* @internal */
}
/* @internal */
-export function check_arr_len(arr: Uint8Array, len: number): Uint8Array {
- if (arr.length != len) { throw new Error("Expected array of length " + len + " got " + arr.length); }
+export function check_arr_len(arr: Uint8Array
|null
, len: number): Uint8Array {
+ if (arr
!== null && arr
.length != len) { throw new Error("Expected array of length " + len + " got " + arr.length); }
return arr;
}
return arr;
}
@@
-347,8
+350,8
@@
export class CommonBase {
// In Java, protected means "any subclass can access fields on any other subclass'"
// In TypeScript, protected means "any subclass can access parent fields on instances of itself"
// To work around this, we add accessors for other instances' protected fields here.
// In Java, protected means "any subclass can access fields on any other subclass'"
// In TypeScript, protected means "any subclass can access parent fields on instances of itself"
// To work around this, we add accessors for other instances' protected fields here.
- protected static add_ref_from(holder: CommonBase
, referent: object
) {
- if (holder !== null) { holder.ptrs_to.push(referent); }
+ protected static add_ref_from(holder: CommonBase
|null, referent: object|null
) {
+ if (holder !== null
&& referent !== null
) { holder.ptrs_to.push(referent); }
}
protected static get_ptr_of(o: CommonBase) {
return o.ptr;
}
protected static get_ptr_of(o: CommonBase) {
return o.ptr;