@@ -111,53 +111,12 @@ class CompiledApp {
111111
112112 <<JS_STRING_POLYFILL_METHODS>>
113113
114- const loadModuleFromBytes = async (bytes) => {
115- const module = await WebAssembly.compile(bytes, this.builtins);
116- return await WebAssembly.instantiate(module, {
117- ...baseImports,
118- ...additionalImports,
119- "wasm:js-string": jsStringPolyfill,
120- "module0": dartInstance.exports,
121- });
122- }
123-
124- const loadModule = async (loader, loaderArgument) => {
125- const source = await Promise.resolve(loader(loaderArgument));
126- const module = await ((source instanceof Response)
127- ? WebAssembly.compileStreaming(source, this.builtins)
128- : WebAssembly.compile(source, this.builtins));
129- return await WebAssembly.instantiate(module, {
130- ...baseImports,
131- ...additionalImports,
132- <<JS_POLYFILL_IMPORT>>
133- "module0": dartInstance.exports,
134- });
135- }
136-
137- const deferredLibraryHelper = {
138- "loadModule": async (moduleName) => {
139- if (!loadDeferredWasm) {
140- throw "No implementation of loadDeferredWasm provided.";
141- }
142- return await loadModule(loadDeferredWasm, moduleName);
143- },
144- "loadDynamicModuleFromUri": async (uri) => {
145- if (!loadDynamicModule) {
146- throw "No implementation of loadDynamicModule provided.";
147- }
148- const loadedModule = await loadModule(loadDynamicModule, uri);
149- return loadedModule.exports.$invokeEntryPoint;
150- },
151- "loadDynamicModuleFromBytes": async (bytes) => {
152- const loadedModule = await loadModuleFromBytes(loadDynamicModule, uri);
153- return loadedModule.exports.$invokeEntryPoint;
154- },
155- };
114+ <<DEFERRED_LIBRARY_HELPER_METHODS>>
156115
157116 dartInstance = await WebAssembly.instantiate(this.module, {
158117 ...baseImports,
159118 ...additionalImports,
160- "deferredLibraryHelper": deferredLibraryHelper,
119+ <<MODULE_LOADING_IMPORT>>
161120 <<JS_POLYFILL_IMPORT>>
162121 });
163122
@@ -223,6 +182,51 @@ const jsStringPolyfill = {
223182 };
224183''' ;
225184
185+ final moduleLoadingHelperTemplate = Template (r'''
186+ const loadModuleFromBytes = async (bytes) => {
187+ const module = await WebAssembly.compile(bytes, this.builtins);
188+ return await WebAssembly.instantiate(module, {
189+ ...baseImports,
190+ ...additionalImports,
191+ <<JS_POLYFILL_IMPORT>>
192+ "module0": dartInstance.exports,
193+ });
194+ }
195+
196+ const loadModule = async (loader, loaderArgument) => {
197+ const source = await Promise.resolve(loader(loaderArgument));
198+ const module = await ((source instanceof Response)
199+ ? WebAssembly.compileStreaming(source, this.builtins)
200+ : WebAssembly.compile(source, this.builtins));
201+ return await WebAssembly.instantiate(module, {
202+ ...baseImports,
203+ ...additionalImports,
204+ <<JS_POLYFILL_IMPORT>>
205+ "module0": dartInstance.exports,
206+ });
207+ }
208+
209+ const moduleLoadingHelper = {
210+ "loadModule": async (moduleName) => {
211+ if (!loadDeferredWasm) {
212+ throw "No implementation of loadDeferredWasm provided.";
213+ }
214+ return await loadModule(loadDeferredWasm, moduleName);
215+ },
216+ "loadDynamicModuleFromUri": async (uri) => {
217+ if (!loadDynamicModule) {
218+ throw "No implementation of loadDynamicModule provided.";
219+ }
220+ const loadedModule = await loadModule(loadDynamicModule, uri);
221+ return loadedModule.exports.$invokeEntryPoint;
222+ },
223+ "loadDynamicModuleFromBytes": async (bytes) => {
224+ const loadedModule = await loadModuleFromBytes(loadDynamicModule, uri);
225+ return loadedModule.exports.$invokeEntryPoint;
226+ },
227+ };
228+ ''' );
229+
226230class Template {
227231 static final _templateVariableRegExp = RegExp (r'<<(?<varname>[A-Z_]+)>>' );
228232 final List <_TemplatePart > _parts = [];
0 commit comments