@@ -716,8 +716,10 @@ def generate_js(data_target, data_files, metadata):
716
716
create_data = '''// canOwn this data in the filesystem, it is a slice into the heap that will never change
717
717
Module['FS_createDataFile'](this.name, null, byteArray, true, true, true);
718
718
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();'
721
723
722
724
if not options .lz4 :
723
725
# 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):
744
746
finish: async function(byteArray) {
745
747
var that = this;
746
748
%s
747
- this.requests[this.name] = null;%s
749
+ this.requests[this.name] = null;
748
750
}
749
751
};
750
752
751
753
var files = metadata['files'];
752
754
for (var i = 0; i < files.length; ++i) {
753
755
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
755
757
756
758
if options .has_embedded and not options .obj_output :
757
759
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):
1054
1056
1055
1057
code += '''
1056
1058
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
+ })'''
1061
1066
1062
1067
if options .use_preload_cache :
1063
1068
code += '''
@@ -1087,7 +1092,7 @@ def generate_js(data_target, data_files, metadata):
1087
1092
await preloadFallback(e)%s;
1088
1093
}
1089
1094
1090
- Module['setStatus']?.('Downloading...');\n ''' % ( catch_case if options . export_es6 else '' )
1095
+ Module['setStatus']?.('Downloading...');\n ''' % catch_handler
1091
1096
else :
1092
1097
# Not using preload cache, so we might as well start the xhr ASAP,
1093
1098
# 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):
1109
1114
fetched = data;
1110
1115
}
1111
1116
})%s;
1112
- }\n ''' % ( catch_case if options . export_es6 else '' )
1117
+ }\n ''' % catch_handler
1113
1118
1114
1119
code += '''
1115
1120
Module['preloadResults'][PACKAGE_NAME] = {fromCache: false};
@@ -1129,7 +1134,7 @@ def generate_js(data_target, data_files, metadata):
1129
1134
runWithFS(Module)%s;
1130
1135
} else {
1131
1136
(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
1133
1138
1134
1139
if options .separate_metadata :
1135
1140
node_support_code = ''
0 commit comments