@@ -57,6 +57,12 @@ function re_viewer_js() {
57
57
const end = `wasm_bindgen = Object.assign(__wbg_init, { initSync }, __exports);
58
58
59
59
})();` ;
60
+ if ( code . indexOf ( start ) === - 1 ) {
61
+ throw new Error ( "failed to run js build script: failed to patch re_viewer.js, could not find replace start marker" ) ;
62
+ }
63
+ if ( code . indexOf ( end ) === - 1 ) {
64
+ throw new Error ( "failed to run js build script: failed to patch re_viewer.js, could not find replace end marker" ) ;
65
+ }
60
66
code = code . replace ( start , "" ) . replace ( end , "" ) ;
61
67
62
68
code = `
@@ -66,10 +72,11 @@ ${code}
66
72
function deinit() {
67
73
__wbg_init.__wbindgen_wasm_module = null;
68
74
wasm = null;
75
+ cachedUint8ArrayMemory0 = null;
69
76
cachedFloat32ArrayMemory0 = null;
70
77
cachedInt32ArrayMemory0 = null;
71
78
cachedUint32ArrayMemory0 = null;
72
- cachedUint8ArrayMemory0 = null;
79
+ cachedDataViewMemory0 = null;
73
80
}
74
81
75
82
return Object.assign(__wbg_init, { initSync, deinit }, __exports);
@@ -80,19 +87,32 @@ return Object.assign(__wbg_init, { initSync, deinit }, __exports);
80
87
// Otherwise we end up with an exceptioon during closure destruction which prevents the references from all being
81
88
// cleaned up properly.
82
89
// TODO(jprochazk): Can we force these to run before we null `wasm` instead?
83
- const closure_dtors = `const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
84
- ? { register: () => {}, unregister: () => {} }
85
- : new FinalizationRegistry(state => {
86
- wasm.__wbindgen_export_4.get(state.dtor)(state.a, state.b)
87
- });` ;
90
+ const closure_dtors_start_marker = "const CLOSURE_DTORS" ;
91
+ const closure_dtors_end_marker = "});" ;
92
+
93
+ const closure_dtors_start = code . indexOf ( closure_dtors_start_marker ) ;
94
+ if ( closure_dtors_start === - 1 ) {
95
+ throw new Error ( "failed to run js build script: failed to patch re_viewer.js, could not find CLOSURE_DTORS start" ) ;
96
+ }
97
+ const closure_dtors_end = code . indexOf ( closure_dtors_end_marker , closure_dtors_start ) ;
98
+ if ( closure_dtors_end === - 1 ) {
99
+ throw new Error ( "failed to run js build script: failed to patch re_viewer.js, could not find CLOSURE_DTORS end" ) ;
100
+ }
101
+
102
+ let m = code . substring ( closure_dtors_start , closure_dtors_end ) . match ( / _ _ w b i n d g e n _ e x p o r t _ \d + / ) ;
103
+ if ( ! m ) {
104
+ throw new Error ( "failed to run js build script: failed to patch re_viewer.js, could not find __wbindgen_export within CLOSURE_DTORS" ) ;
105
+ }
106
+
107
+ let wbindgen_export = m [ 0 ] ;
88
108
89
109
const closure_dtors_patch = `const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
90
110
? { register: () => {}, unregister: () => {} }
91
111
: new FinalizationRegistry(state => {
92
- wasm?.__wbindgen_export_4 .get(state.dtor)(state.a, state.b)
112
+ wasm?.${ wbindgen_export } .get(state.dtor)(state.a, state.b)
93
113
});` ;
94
114
95
- code = code . replace ( closure_dtors , closure_dtors_patch ) ;
115
+ code = code . substring ( 0 , closure_dtors_start ) + closure_dtors_patch + code . slice ( closure_dtors_end + closure_dtors_end_marker . length ) ;
96
116
97
117
fs . writeFileSync ( path . join ( __dirname , "re_viewer.js" ) , code ) ;
98
118
}
0 commit comments