Skip to content

Commit

Permalink
[file_packager] Add missing support_node check when using preload c…
Browse files Browse the repository at this point in the history
…ache (#23059)

Fixes an error "isNode is not defined" error when using the preload cache
and building with -sENVIRONMENT=web.
  • Loading branch information
dashodanger authored Jan 15, 2025
1 parent d0df369 commit 9aa4df6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 8 additions & 1 deletion test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,17 @@ def test_preload_caching(self, extra_size):
self.skipTest('chrome bug')
create_file('somefile.txt', '''load me right before running the code please''' + ('_' * extra_size))
print('size:', os.path.getsize('somefile.txt'))
self.compile_btest('main.c', ['--use-preload-cache', '--js-library', 'test.js', '--preload-file', 'somefile.txt', '-o', 'page.html', '-sALLOW_MEMORY_GROWTH'], reporting=Reporting.JS_ONLY)
args = ['--use-preload-cache', '--js-library', 'test.js', '--preload-file', 'somefile.txt', '-o', 'page.html', '-sALLOW_MEMORY_GROWTH']
self.compile_btest('main.c', args, reporting=Reporting.JS_ONLY)
self.run_browser('page.html', '/report_result?exit:0')
self.run_browser('page.html', '/report_result?exit:1')

# test with ENVIRONMENT=web, to check for problems with node.js support
# (see #23059)
self.clear_indexed_db()
self.compile_btest('main.c', args + ['-sENVIRONMENT=web'], reporting=Reporting.JS_ONLY)
self.run_browser('page.html', '/report_result?exit:0')

def test_preload_caching_indexeddb_name(self):
self.set_setting('EXIT_RUNTIME')
create_file('somefile.txt', '''load me right before running the code please''')
Expand Down
11 changes: 7 additions & 4 deletions tools/file_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,13 @@ def generate_js(data_target, data_files, metadata):
var DB_VERSION = 1;
var METADATA_STORE_NAME = 'METADATA';
var PACKAGE_STORE_NAME = 'PACKAGES';
function openDatabase(callback, errback) {
if (isNode) {
return errback();
}
function openDatabase(callback, errback) {'''
if options.support_node:
code += '''
if (isNode) {
return errback();
}'''
code += '''
var indexedDB;
if (typeof window === 'object') {
indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
Expand Down

0 comments on commit 9aa4df6

Please sign in to comment.