@@ -713,8 +713,10 @@ def generate_js(data_target, data_files, metadata):
713
713
create_data = '''// canOwn this data in the filesystem, it is a slide into the heap that will never change
714
714
Module['FS_createDataFile'](this.name, null, byteArray, true, true, true);
715
715
Module['removeRunDependency'](`fp ${that.name}`);'''
716
- ready_promise = '''
717
- loadDataResolve();'''
716
+
717
+ finish_handler = create_preloaded if options .use_preload_plugins else create_data
718
+ if options .export_es6 :
719
+ finish_handler += '\n loadDataResolve();'
718
720
719
721
if not options .lz4 :
720
722
# Data requests - for getting a block of data out of the big archive - have
@@ -741,14 +743,14 @@ def generate_js(data_target, data_files, metadata):
741
743
finish: function(byteArray) {
742
744
var that = this;
743
745
%s
744
- this.requests[this.name] = null;%s
746
+ this.requests[this.name] = null;
745
747
}
746
748
};
747
749
748
750
var files = metadata['files'];
749
751
for (var i = 0; i < files.length; ++i) {
750
752
new DataRequest(files[i]['start'], files[i]['end'], files[i]['audio'] || 0).open('GET', files[i]['filename']);
751
- }\n ''' % ( create_preloaded if options . use_preload_plugins else create_data , ready_promise if options . export_es6 else '' )
753
+ }\n ''' % finish_handler
752
754
753
755
if options .has_embedded and not options .obj_output :
754
756
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' )
@@ -1051,7 +1053,10 @@ def generate_js(data_target, data_files, metadata):
1051
1053
1052
1054
code += '''
1053
1055
Module['preloadResults'] ??= {};\n '''
1054
- catch_case = '''
1056
+
1057
+ catch_handler = ''
1058
+ if options .export_es6 :
1059
+ catch_handler = '''
1055
1060
.catch((error) => {
1056
1061
loadDataReject(error);
1057
1062
})'''
@@ -1084,7 +1089,7 @@ def generate_js(data_target, data_files, metadata):
1084
1089
await preloadFallback(e)%s;
1085
1090
}
1086
1091
1087
- Module['setStatus']?.('Downloading...');\n ''' % ( catch_case if options . export_es6 else '' )
1092
+ Module['setStatus']?.('Downloading...');\n ''' % catch_handler
1088
1093
else :
1089
1094
# Not using preload cache, so we might as well start the xhr ASAP,
1090
1095
# potentially before JS parsing of the main codebase if it's after us.
@@ -1106,7 +1111,7 @@ def generate_js(data_target, data_files, metadata):
1106
1111
fetched = data;
1107
1112
}
1108
1113
})%s;
1109
- }\n ''' % ( catch_case if options . export_es6 else '' )
1114
+ }\n ''' % catch_handler
1110
1115
1111
1116
code += '''
1112
1117
Module['preloadResults'][PACKAGE_NAME] = {fromCache: false};
@@ -1126,7 +1131,7 @@ def generate_js(data_target, data_files, metadata):
1126
1131
runWithFS(Module)%s;
1127
1132
} else {
1128
1133
(Module['preRun'] ??= []).push(runWithFS); // FS is not initialized yet, wait for it
1129
- }\n ''' % ( catch_case if options . export_es6 else '' )
1134
+ }\n ''' % catch_handler
1130
1135
1131
1136
if options .separate_metadata :
1132
1137
node_support_code = ''
0 commit comments