@@ -716,8 +716,10 @@ def generate_js(data_target, data_files, metadata):
716716    create_data  =  '''// canOwn this data in the filesystem, it is a slice into the heap that will never change 
717717          Module['FS_createDataFile'](this.name, null, byteArray, true, true, true); 
718718          Module['removeRunDependency'](`fp ${that.name}`);''' 
719-     ready_promise  =  ''' 
720-           loadDataResolve();''' 
719+ 
720+     finish_handler  =  create_preloaded  if  options .use_preload_plugins  else  create_data 
721+     if  options .export_es6 :
722+       finish_handler  +=  '\n loadDataResolve();' 
721723
722724    if  not  options .lz4 :
723725      # Data requests - for getting a block of data out of the big archive - have 
@@ -744,14 +746,14 @@ def generate_js(data_target, data_files, metadata):
744746        finish: async function(byteArray) { 
745747          var that = this; 
746748          %s 
747-           this.requests[this.name] = null;%s  
749+           this.requests[this.name] = null; 
748750        } 
749751      }; 
750752
751753      var files = metadata['files']; 
752754      for (var i = 0; i < files.length; ++i) { 
753755        new DataRequest(files[i]['start'], files[i]['end'], files[i]['audio'] || 0).open('GET', files[i]['filename']); 
754-       }\n '''  %  ( create_preloaded   if   options . use_preload_plugins   else   create_data ,  ready_promise   if   options . export_es6   else   '' ) 
756+       }\n '''  %  finish_handler 
755757
756758  if  options .has_embedded  and  not  options .obj_output :
757759    diagnostics .warn ('--obj-output is recommended when using --embed.  This outputs an object file for linking directly into your application is more efficient than JS encoding' )
@@ -1054,10 +1056,13 @@ def generate_js(data_target, data_files, metadata):
10541056
10551057    code  +=  ''' 
10561058      Module['preloadResults'] ??= {};\n ''' 
1057-     catch_case  =  ''' 
1058-           .catch((error) => { 
1059-             loadDataReject(error); 
1060-           })''' 
1059+ 
1060+   catch_handler  =  '' 
1061+   if  options .export_es6 :
1062+     catch_handler  +=  ''' 
1063+         .catch((error) => { 
1064+           loadDataReject(error); 
1065+         })''' 
10611066
10621067    if  options .use_preload_cache :
10631068      code  +=  ''' 
@@ -1087,7 +1092,7 @@ def generate_js(data_target, data_files, metadata):
10871092          await preloadFallback(e)%s; 
10881093        } 
10891094
1090-         Module['setStatus']?.('Downloading...');\n '''  %  ( catch_case   if   options . export_es6   else   '' ) 
1095+         Module['setStatus']?.('Downloading...');\n '''  %  catch_handler 
10911096    else :
10921097      # Not using preload cache, so we might as well start the xhr ASAP, 
10931098      # potentially before JS parsing of the main codebase if it's after us. 
@@ -1109,7 +1114,7 @@ def generate_js(data_target, data_files, metadata):
11091114              fetched = data; 
11101115            } 
11111116          })%s; 
1112-       }\n '''  %  ( catch_case   if   options . export_es6   else   '' ) 
1117+       }\n '''  %  catch_handler 
11131118
11141119      code  +=  ''' 
11151120      Module['preloadResults'][PACKAGE_NAME] = {fromCache: false}; 
@@ -1129,7 +1134,7 @@ def generate_js(data_target, data_files, metadata):
11291134      runWithFS(Module)%s; 
11301135    } else { 
11311136      (Module['preRun'] ??= []).push(runWithFS); // FS is not initialized yet, wait for it 
1132-     }\n '''  %  ( catch_case   if   options . export_es6   else   '' ) 
1137+     }\n '''  %  catch_handler 
11331138
11341139  if  options .separate_metadata :
11351140    node_support_code  =  '' 
0 commit comments