@@ -468,7 +468,7 @@ impl<'a> Context<'a> {
468
468
OutputMode :: Web => {
469
469
self . imports_post . push_str ( "let wasm;\n " ) ;
470
470
init = self . gen_init ( needs_manual_start, Some ( & mut imports) ) ?;
471
- footer. push_str ( "export { initSync }\n " ) ;
471
+ footer. push_str ( "export { initSync, initWithoutStart }\n " ) ;
472
472
footer. push_str ( "export default init;" ) ;
473
473
}
474
474
}
@@ -607,6 +607,7 @@ impl<'a> Context<'a> {
607
607
// Also in (at least) the NoModules, the `init()` method is renamed to `wasm_bindgen()`.
608
608
let setup_function_declaration;
609
609
let mut sync_init_function = String :: new ( ) ;
610
+ let mut without_start_init_function = String :: new ( ) ;
610
611
let declare_or_export;
611
612
if self . config . mode . no_modules ( ) {
612
613
declare_or_export = "declare" ;
@@ -632,6 +633,23 @@ impl<'a> Context<'a> {
632
633
memory_param = memory_param
633
634
) ) ;
634
635
636
+ without_start_init_function. push_str ( & format ! (
637
+ "\
638
+ /**\n \
639
+ * If `module_or_path` is {{RequestInfo}} or {{URL}}, makes a request and\n \
640
+ * for everything else, calls `WebAssembly.instantiate` directly.\n \
641
+ *\n \
642
+ * @param {{InitInput | Promise<InitInput>}} module_or_path\n \
643
+ {}\
644
+ *\n \
645
+ * @returns {{Promise<InitOutput>}}\n \
646
+ */\n \
647
+ export function initWithoutStart \
648
+ (module_or_path{}: InitInput | Promise<InitInput>{}): Promise<InitOutput>;\n \n \
649
+ ",
650
+ memory_doc, arg_optional, memory_param,
651
+ ) ) ;
652
+
635
653
setup_function_declaration = "export default function init" ;
636
654
}
637
655
Ok ( format ! (
@@ -644,7 +662,8 @@ impl<'a> Context<'a> {
644
662
{sync_init_function}\
645
663
/**\n \
646
664
* If `module_or_path` is {{RequestInfo}} or {{URL}}, makes a request and\n \
647
- * for everything else, calls `WebAssembly.instantiate` directly.\n \
665
+ * for everything else, calls `WebAssembly.instantiate` directly and runs\n \
666
+ * the start function.\n \
648
667
*\n \
649
668
* @param {{InitInput | Promise<InitInput>}} module_or_path\n \
650
669
{}\
@@ -831,11 +850,13 @@ impl<'a> Context<'a> {
831
850
{init_memory}
832
851
}}
833
852
834
- function finalizeInit(instance, module) {{
853
+ function finalizeInit(instance, module, start ) {{
835
854
wasm = instance.exports;
836
855
init.__wbindgen_wasm_module = module;
837
856
{init_memviews}
838
- {start}
857
+ if (start == true) {{
858
+ {start}
859
+ }}
839
860
return wasm;
840
861
}}
841
862
@@ -850,10 +871,10 @@ impl<'a> Context<'a> {
850
871
851
872
const instance = new WebAssembly.Instance(module, imports);
852
873
853
- return finalizeInit(instance, module);
874
+ return finalizeInit(instance, module, true );
854
875
}}
855
876
856
- async function init (input{init_memory_arg}) {{
877
+ async function initInternal (input{init_memory_arg}, start ) {{
857
878
{default_module_path}
858
879
const imports = getImports();
859
880
@@ -865,7 +886,15 @@ impl<'a> Context<'a> {
865
886
866
887
const {{ instance, module }} = await load(await input, imports);
867
888
868
- return finalizeInit(instance, module);
889
+ return finalizeInit(instance, module, start);
890
+ }}
891
+
892
+ async function initWithoutStart(input{init_memory_arg}) {{
893
+ return initInternal(input{init_memory_arg}, false);
894
+ }}
895
+
896
+ async function init(input{init_memory_arg}) {{
897
+ return initInternal(input{init_memory_arg}, true);
869
898
}}
870
899
" ,
871
900
init_memory_arg = init_memory_arg,
0 commit comments