Skip to content

Commit f877382

Browse files
committed
patch
1 parent d131883 commit f877382

File tree

2 files changed

+147
-3
lines changed

2 files changed

+147
-3
lines changed

patch.js

+123-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,46 @@ const beforeMemoryJs = `export class Memory {
5555
}
5656
}`
5757

58+
const beforeMemoryJs2 = `export class Memory {
59+
60+
__destroy_into_raw() {
61+
const ptr = this.__wbg_ptr;
62+
this.__wbg_ptr = 0;
63+
MemoryFinalization.unregister(this);
64+
return ptr;
65+
}
66+
67+
free() {
68+
const ptr = this.__destroy_into_raw();
69+
wasm.__wbg_memory_free(ptr, 0);
70+
}
71+
/**
72+
* @param {Uint8Array} inner
73+
*/
74+
constructor(inner) {
75+
const ptr0 = passArray8ToWasm0(inner, wasm.__wbindgen_malloc);
76+
const len0 = WASM_VECTOR_LEN;
77+
const ret = wasm.memory_new(ptr0, len0);
78+
this.__wbg_ptr = ret >>> 0;
79+
MemoryFinalization.register(this, this.__wbg_ptr, this);
80+
return this;
81+
}
82+
/**
83+
* @returns {number}
84+
*/
85+
ptr() {
86+
const ret = wasm.memory_ptr(this.__wbg_ptr);
87+
return ret >>> 0;
88+
}
89+
/**
90+
* @returns {number}
91+
*/
92+
len() {
93+
const ret = wasm.memory_len(this.__wbg_ptr);
94+
return ret >>> 0;
95+
}
96+
}`
97+
5898
const afterMemoryJs = `export class Memory {
5999
60100
static __wrap(ptr) {
@@ -68,6 +108,8 @@ const afterMemoryJs = `export class Memory {
68108
__destroy_into_raw() {
69109
const ptr = this.__wbg_ptr;
70110
this.__wbg_ptr = 0;
111+
this.__wbg_ptr0 = 0;
112+
this.__wbg_len0 = 0;
71113
MemoryFinalization.unregister(this);
72114
return ptr;
73115
}
@@ -84,6 +126,8 @@ const afterMemoryJs = `export class Memory {
84126
const len0 = WASM_VECTOR_LEN;
85127
const ret = wasm.memory_new(ptr0, len0);
86128
this.__wbg_ptr = ret >>> 0;
129+
this.__wbg_ptr0 = ptr0 >>> 0;
130+
this.__wbg_len0 = len0 >>> 0;
87131
MemoryFinalization.register(this, this.__wbg_ptr, this);
88132
return this;
89133
}
@@ -102,10 +146,84 @@ const afterMemoryJs = `export class Memory {
102146
return ret >>> 0;
103147
}
104148
/**
149+
* @returns {number}
150+
*/
151+
get ptr0() {
152+
return this.__wbg_ptr0 ??= this.ptr();
153+
}
154+
/**
155+
* @returns {number}
156+
*/
157+
get len0() {
158+
return this.__wbg_len0 ??= this.len();
159+
}
160+
/**
161+
* @returns {Uint8Array}
162+
*/
163+
get bytes() {
164+
return getUint8ArrayMemory0().subarray(this.ptr0, this.ptr0 + this.len0);
165+
}
166+
}`
167+
168+
const afterMemoryJs2 = `export class Memory {
169+
170+
__destroy_into_raw() {
171+
const ptr = this.__wbg_ptr;
172+
this.__wbg_ptr = 0;
173+
this.__wbg_ptr0 = 0;
174+
this.__wbg_len0 = 0;
175+
MemoryFinalization.unregister(this);
176+
return ptr;
177+
}
178+
179+
free() {
180+
const ptr = this.__destroy_into_raw();
181+
wasm.__wbg_memory_free(ptr, 0);
182+
}
183+
/**
184+
* @param {Uint8Array} inner
185+
*/
186+
constructor(inner) {
187+
const ptr0 = passArray8ToWasm0(inner, wasm.__wbindgen_malloc);
188+
const len0 = WASM_VECTOR_LEN;
189+
const ret = wasm.memory_new(ptr0, len0);
190+
this.__wbg_ptr = ret >>> 0;
191+
this.__wbg_ptr0 = ptr0 >>> 0;
192+
this.__wbg_len0 = len0 >>> 0;
193+
MemoryFinalization.register(this, this.__wbg_ptr, this);
194+
return this;
195+
}
196+
/**
197+
* @returns {number}
198+
*/
199+
ptr() {
200+
const ret = wasm.memory_ptr(this.__wbg_ptr);
201+
return ret >>> 0;
202+
}
203+
/**
204+
* @returns {number}
205+
*/
206+
len() {
207+
const ret = wasm.memory_len(this.__wbg_ptr);
208+
return ret >>> 0;
209+
}
210+
/**
211+
* @returns {number}
212+
*/
213+
get ptr0() {
214+
return this.__wbg_ptr0 ??= this.ptr();
215+
}
216+
/**
217+
* @returns {number}
218+
*/
219+
get len0() {
220+
return this.__wbg_len0 ??= this.len();
221+
}
222+
/**
105223
* @returns {Uint8Array}
106224
*/
107225
get bytes() {
108-
return getUint8ArrayMemory0().subarray(this.ptr(), this.ptr() + this.len());
226+
return getUint8ArrayMemory0().subarray(this.ptr0, this.ptr0 + this.len0);
109227
}
110228
}`
111229

@@ -147,8 +265,12 @@ const afterMemoryTs = `export class Memory {
147265

148266
const glueJs = readFileSync(`./src/wasm/pkg/${name}.js`, "utf8")
149267
.replaceAll(beforeMemoryJs, afterMemoryJs)
268+
.replaceAll(beforeMemoryJs2, afterMemoryJs2)
150269
.replaceAll(`free()`, `[Symbol.dispose]()`)
151270
.replaceAll(`(typeof FinalizationRegistry === 'undefined')`, `true`)
271+
.replaceAll(`.register(this, this.__wbg_ptr, this)`, ``)
272+
.replaceAll(`.register(obj, obj.__wbg_ptr, obj)`, ``)
273+
.replaceAll(`.unregister(this)`, ``)
152274
.replaceAll(`module_or_path = new URL('${name}_bg.wasm', import.meta.url);`, `throw new Error();`)
153275

154276
const glueTs = readFileSync(`./src/wasm/pkg/${name}.d.ts`, "utf8")

src/wasm/pkg/memory_wasm.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export class Memory {
3737
__destroy_into_raw() {
3838
const ptr = this.__wbg_ptr;
3939
this.__wbg_ptr = 0;
40-
MemoryFinalization.unregister(this);
40+
this.__wbg_ptr0 = 0;
41+
this.__wbg_len0 = 0;
42+
MemoryFinalization;
4143
return ptr;
4244
}
4345

@@ -53,7 +55,9 @@ export class Memory {
5355
const len0 = WASM_VECTOR_LEN;
5456
const ret = wasm.memory_new(ptr0, len0);
5557
this.__wbg_ptr = ret >>> 0;
56-
MemoryFinalization.register(this, this.__wbg_ptr, this);
58+
this.__wbg_ptr0 = ptr0 >>> 0;
59+
this.__wbg_len0 = len0 >>> 0;
60+
MemoryFinalization;
5761
return this;
5862
}
5963
/**
@@ -70,6 +74,24 @@ export class Memory {
7074
const ret = wasm.memory_len(this.__wbg_ptr);
7175
return ret >>> 0;
7276
}
77+
/**
78+
* @returns {number}
79+
*/
80+
get ptr0() {
81+
return this.__wbg_ptr0 ??= this.ptr();
82+
}
83+
/**
84+
* @returns {number}
85+
*/
86+
get len0() {
87+
return this.__wbg_len0 ??= this.len();
88+
}
89+
/**
90+
* @returns {Uint8Array}
91+
*/
92+
get bytes() {
93+
return getUint8ArrayMemory0().subarray(this.ptr0, this.ptr0 + this.len0);
94+
}
7395
}
7496

7597
async function __wbg_load(module, imports) {

0 commit comments

Comments
 (0)