Skip to content

Commit e0bc809

Browse files
committed
address @sbc100 review
1 parent 529e4a2 commit e0bc809

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tools/file_packager.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,10 @@ def generate_js(data_target, data_files, metadata):
713713
create_data = '''// canOwn this data in the filesystem, it is a slide into the heap that will never change
714714
Module['FS_createDataFile'](this.name, null, byteArray, true, true, true);
715715
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 += '\nloadDataResolve();'
718720

719721
if not options.lz4:
720722
# 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):
741743
finish: function(byteArray) {
742744
var that = this;
743745
%s
744-
this.requests[this.name] = null;%s
746+
this.requests[this.name] = null;
745747
}
746748
};
747749
748750
var files = metadata['files'];
749751
for (var i = 0; i < files.length; ++i) {
750752
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
752754

753755
if options.has_embedded and not options.obj_output:
754756
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,10 +1053,13 @@ def generate_js(data_target, data_files, metadata):
10511053

10521054
code += '''
10531055
Module['preloadResults'] ??= {};\n'''
1054-
catch_case = '''
1055-
.catch((error) => {
1056-
loadDataReject(error);
1057-
})'''
1056+
1057+
catch_handler = ''
1058+
if options.export_es6:
1059+
catch_handler += '''
1060+
.catch((error) => {
1061+
loadDataReject(error);
1062+
})'''
10581063

10591064
if options.use_preload_cache:
10601065
code += '''
@@ -1084,7 +1089,7 @@ def generate_js(data_target, data_files, metadata):
10841089
await preloadFallback(e)%s;
10851090
}
10861091
1087-
Module['setStatus']?.('Downloading...');\n''' % (catch_case if options.export_es6 else '')
1092+
Module['setStatus']?.('Downloading...');\n''' % catch_handler
10881093
else:
10891094
# Not using preload cache, so we might as well start the xhr ASAP,
10901095
# 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):
11061111
fetched = data;
11071112
}
11081113
})%s;
1109-
}\n''' % (catch_case if options.export_es6 else '')
1114+
}\n''' % catch_handler
11101115

11111116
code += '''
11121117
Module['preloadResults'][PACKAGE_NAME] = {fromCache: false};
@@ -1126,7 +1131,7 @@ def generate_js(data_target, data_files, metadata):
11261131
runWithFS(Module)%s;
11271132
} else {
11281133
(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
11301135

11311136
if options.separate_metadata:
11321137
node_support_code = ''

0 commit comments

Comments
 (0)