From a4beaf4454ea5ecb08f6008cf67b6fab71fa2ff2 Mon Sep 17 00:00:00 2001 From: Aaron Mandle Date: Wed, 3 Sep 2014 16:26:03 -0700 Subject: [PATCH 01/11] add the ability to fetch memory initializers from a cdn --- src/postamble.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/postamble.js b/src/postamble.js index 3486bc9dc4b03..20f624af24c2e 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -2,7 +2,9 @@ // === Auto-generated postamble setup entry stuff === if (memoryInitializer) { - if (Module['memoryInitializerPrefixURL']) { + if (typeof Module['locateFilePackage']) === 'function') { + memoryInitializer = Module['locateFilePackage'](memoryInitializer); + } else if (Module['memoryInitializerPrefixURL']) { memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer; } if (ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL) { From bdfa7bc9631d5a153001dc69b7ae79295d3e31f1 Mon Sep 17 00:00:00 2001 From: Aaron Mandle Date: Wed, 10 Sep 2014 15:40:32 -0700 Subject: [PATCH 02/11] locateFilePackage -> locateFile --- src/postamble.js | 4 ++-- tools/file_packager.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/postamble.js b/src/postamble.js index 20f624af24c2e..fc743a12546f2 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -2,8 +2,8 @@ // === Auto-generated postamble setup entry stuff === if (memoryInitializer) { - if (typeof Module['locateFilePackage']) === 'function') { - memoryInitializer = Module['locateFilePackage'](memoryInitializer); + if (typeof Module['locateFile']) === 'function') { + memoryInitializer = Module['locateFile'](memoryInitializer); } else if (Module['memoryInitializerPrefixURL']) { memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer; } diff --git a/tools/file_packager.py b/tools/file_packager.py index 0c26f18a471ac..bbe92a667435e 100644 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -486,8 +486,8 @@ def was_seen(name): } var PACKAGE_NAME = '%s'; var REMOTE_PACKAGE_BASE = '%s'; - var REMOTE_PACKAGE_NAME = typeof Module['locateFilePackage'] === 'function' ? - Module['locateFilePackage'](REMOTE_PACKAGE_BASE) : + var REMOTE_PACKAGE_NAME = typeof Module['locateFile'] === 'function' ? + Module['locateFile'](REMOTE_PACKAGE_BASE) : ((Module['filePackagePrefixURL'] || '') + REMOTE_PACKAGE_BASE); var REMOTE_PACKAGE_SIZE = %d; var PACKAGE_UUID = '%s'; From eceb7b373c3363e03bcd369d75c55d3e4ac22338 Mon Sep 17 00:00:00 2001 From: Aaron Mandle Date: Fri, 12 Sep 2014 12:19:36 -0700 Subject: [PATCH 03/11] updating AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 08c16ced4a134..5117ad1919672 100644 --- a/AUTHORS +++ b/AUTHORS @@ -156,4 +156,5 @@ a license to everyone to use it as detailed in LICENSE.) * Boris Tsarev * Mark Logan (copyright owned by Artillery Games, Inc.) * Коренберг Марк +* Aaron Mandle From 67fe60fdf4e2160607d61d50e7772e7edaade52a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 12 Sep 2014 13:24:50 -0700 Subject: [PATCH 04/11] print out failing js engine in test runner --- tests/runner.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/runner.py b/tests/runner.py index ce7959367da59..b84a1ff796367 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -466,10 +466,13 @@ def do_run(self, src, expected_output, args=[], output_nicerizer=None, output_pr js_engines = filter(lambda engine: engine not in self.banned_js_engines, js_engines) if len(js_engines) == 0: return self.skip('No JS engine present to run this test with. Check %s and the paths therein.' % EM_CONFIG) for engine in js_engines: - #print engine js_output = self.run_generated_code(engine, filename + '.o.js', args, output_nicerizer=output_nicerizer, assert_returncode=assert_returncode) - self.assertContained(expected_output, js_output.replace('\r\n', '\n')) - self.assertNotContained('ERROR', js_output) + try: + self.assertContained(expected_output, js_output.replace('\r\n', '\n')) + self.assertNotContained('ERROR', js_output) + except Exception, e: + print '(test did not pass in JS engine: %s)' % engine + raise e #shutil.rmtree(dirname) # TODO: leave no trace in memory. But for now nice for debugging From 2c11df12f97e4e3412b0f4aa92cb83c60158df8e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 12 Sep 2014 13:30:04 -0700 Subject: [PATCH 05/11] fix test_posixtime for v8, which lacks monotonic time, and add testing for that path --- .../{test_posixtime.in => test_posixtime.c} | 0 tests/core/test_posixtime_no_monotonic.out | 17 +++++++++++++++++ tests/test_core.py | 11 ++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) rename tests/core/{test_posixtime.in => test_posixtime.c} (100%) create mode 100644 tests/core/test_posixtime_no_monotonic.out diff --git a/tests/core/test_posixtime.in b/tests/core/test_posixtime.c similarity index 100% rename from tests/core/test_posixtime.in rename to tests/core/test_posixtime.c diff --git a/tests/core/test_posixtime_no_monotonic.out b/tests/core/test_posixtime_no_monotonic.out new file mode 100644 index 0000000000000..52a47a143b79d --- /dev/null +++ b/tests/core/test_posixtime_no_monotonic.out @@ -0,0 +1,17 @@ +Tests for clockid_t=0 +----------------- +clock_getres resolution OK +clock_gettime OK +clock_settime failed with EPERM (OK) + +Tests for clockid_t=1 +----------------- +clock_getres failed +clock_gettime failed +clock_settime failed with EINVAL (OK) + +Tests for clockid_t=42 +----------------- +clock_gettime failed with EINVAL (OK) +clock_getres failed with EINVAL (OK) +clock_settime failed with EINVAL (OK) diff --git a/tests/test_core.py b/tests/test_core.py index ad43c3e2f3b07..142811bacb915 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -4634,14 +4634,19 @@ def test_unistd_misc(self): def test_posixtime(self): test_path = path_from_root('tests', 'core', 'test_posixtime') - src, output = (test_path + s for s in ('.in', '.out')) - + src, output = (test_path + s for s in ('.c', '.out')) + self.banned_js_engines = [V8_ENGINE] # v8 lacks monotonic time self.do_run_from_file(src, output) + if V8_ENGINE in JS_ENGINES: + self.banned_js_engines = filter(lambda engine: engine != V8_ENGINE, JS_ENGINES) + self.do_run_from_file(src, test_path + '_no_monotonic.out') + else: + print '(no v8, skipping no-monotonic case)' + def test_uname(self): test_path = path_from_root('tests', 'core', 'test_uname') src, output = (test_path + s for s in ('.in', '.out')) - self.do_run_from_file(src, output) def test_env(self): From 7d273f137fa8728284dbfd2bdb6fc3cf22502243 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 12 Sep 2014 17:10:08 -0700 Subject: [PATCH 06/11] restore mode of files in IDBFS --- src/library_idbfs.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/library_idbfs.js b/src/library_idbfs.js index 0ce13db85025f..277cf68971287 100644 --- a/src/library_idbfs.js +++ b/src/library_idbfs.js @@ -157,6 +157,7 @@ mergeInto(LibraryManager.library, { return callback(new Error('node type not supported')); } + FS.chmod(path, entry.mode); FS.utime(path, entry.timestamp, entry.timestamp); } catch (e) { return callback(e); From 848c7ed95f78a07d608d9762b8af094154732bc7 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 12 Sep 2014 17:28:06 -0700 Subject: [PATCH 07/11] tolerate NULL tm_zone in strftime --- src/library.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/library.js b/src/library.js index e7e2e3e4a4d99..e3e2446d88881 100644 --- a/src/library.js +++ b/src/library.js @@ -5273,6 +5273,8 @@ LibraryManager.library = { // size_t strftime(char *restrict s, size_t maxsize, const char *restrict format, const struct tm *restrict timeptr); // http://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html + var tm_zone = {{{ makeGetValue('tm', C_STRUCTS.tm.tm_zone, 'i32') }}}; + var date = { tm_sec: {{{ makeGetValue('tm', C_STRUCTS.tm.tm_sec, 'i32') }}}, tm_min: {{{ makeGetValue('tm', C_STRUCTS.tm.tm_min, 'i32') }}}, @@ -5284,7 +5286,7 @@ LibraryManager.library = { tm_yday: {{{ makeGetValue('tm', C_STRUCTS.tm.tm_yday, 'i32') }}}, tm_isdst: {{{ makeGetValue('tm', C_STRUCTS.tm.tm_isdst, 'i32') }}}, tm_gmtoff: {{{ makeGetValue('tm', C_STRUCTS.tm.tm_gmtoff, 'i32') }}}, - tm_zone: Pointer_stringify( {{{ makeGetValue('tm', C_STRUCTS.tm.tm_zone, 'i32') }}} ) + tm_zone: tm_zone ? Pointer_stringify(tm_zone) : '' }; var pattern = Pointer_stringify(format); From 42b1ab3625b85bb0e47ecf32c0d9f5ba1150c3ae Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 13 Sep 2014 11:55:25 -0700 Subject: [PATCH 08/11] document Module.locateFile --- site/source/docs/api_reference/module.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/site/source/docs/api_reference/module.rst b/site/source/docs/api_reference/module.rst index 1605474807ad6..29bffc0fac6dd 100644 --- a/site/source/docs/api_reference/module.rst +++ b/site/source/docs/api_reference/module.rst @@ -85,11 +85,14 @@ The following ``Module`` attributes affect code execution. This is the "prefix" URL for a preloaded data file that is hosted separately from its JavaScript and HTML files (it includes the full path up to, but not including, the data file). See :ref:`packaging-files-data-file-location` for more information. +.. js:attribute:: Module.locateFile + + If set, this method will be called when the runtime needs to load either a file generated by the file packager (this is a generalization of ``Module.filePackagePrefixURL``), or the ``.mem`` memory init file. In both cases the function receives the URL, and should return the actual URL. This lets you host file packages or the ``.mem`` file on a different location than the current directory (which is the default expectation), for example if you want to host them on a CDN. .. js:attribute:: Module.logReadFiles If set, :js:attr:`Module.printErr` will log when any file is read. - + Other methods ============= @@ -99,4 +102,4 @@ Other methods This method should be called to destroy C++ objects created in JavaScript using :ref:`WebIDL bindings `. If this method is not called, an object may be garbage collected, but its destructor will not be called. :param obj: The JavaScript-wrapped C++ object to be destroyed. - \ No newline at end of file + From 5a5eb43bc48761fa04ba3c8ef99cc3bd25edad93 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 13 Sep 2014 12:18:11 -0700 Subject: [PATCH 09/11] add test for locateFile --- tests/test_browser.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_browser.py b/tests/test_browser.py index 26405336ada60..29953bfaadea6 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -1992,3 +1992,34 @@ def test_wget(self): with open(os.path.join(self.get_dir(), 'test.txt'), 'w') as f: f.write('emscripten') self.btest(path_from_root('tests', 'test_wget.c'), expected='1', args=['-s', 'ASYNCIFY=1']) + + def test_locate_file(self): + self.clear() + open('src.cpp', 'w').write(self.with_report_result(r''' + #include + #include + #include + int main() { + FILE *f = fopen("data.txt", "r"); + assert(f && "could not open file"); + char buf[100]; + int num = fread(buf, 1, 20, f); + assert(num == 20 && "could not read 20 bytes"); + buf[20] = 0; + fclose(f); + int result = !strcmp("load me right before", buf); + printf("|%s| : %d\n", buf, result); + REPORT_RESULT(); + return 0; + } + ''')) + open('data.txt', 'w').write('load me right before...') + open('pre.js', 'w').write('Module.locateFile = function(x) { return "sub/" + x };') + Popen([PYTHON, FILE_PACKAGER, 'test.data', '--preload', 'data.txt'], stdout=open('data.js', 'w')).communicate() + # put pre.js first, then the file packager data, so locateFile is there for the file loading code + Popen([PYTHON, EMCC, 'src.cpp', '-O2', '-g', '--pre-js', 'pre.js', '--pre-js', 'data.js', '-o', 'page.html']).communicate() + os.mkdir('sub') + shutil.move('page.html.mem', os.path.join('sub', 'page.html.mem')) + shutil.move('test.data', os.path.join('sub', 'test.data')) + self.run_browser('page.html', None, '/report_result?1') + From 7046162aa8abcf6c366f0b62c0f5d0af4bde75e2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 15 Sep 2014 13:12:43 -0700 Subject: [PATCH 10/11] run webrtc test on a less-likely-to-be-used port --- tests/sockets/p2p/broker/p2p-broker.js | 4 ++-- tests/test_sockets.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/sockets/p2p/broker/p2p-broker.js b/tests/sockets/p2p/broker/p2p-broker.js index 028eb25ba6c10..ec37db987a694 100644 --- a/tests/sockets/p2p/broker/p2p-broker.js +++ b/tests/sockets/p2p/broker/p2p-broker.js @@ -4,7 +4,7 @@ var https = require('https'); var SSL_KEY = 'ssl/ssl.key'; var SSL_CERT = 'ssl/ssl-unified.crt'; -var PORT = 8080; +var PORT = 8182; var sslSupported = false; if(fs.existsSync(SSL_KEY) && fs.existsSync(SSL_CERT) && fs.statSync(SSL_KEY).isFile() && fs.statSync(SSL_CERT).isFile()) { @@ -28,7 +28,7 @@ if(sslSupported) { console.info('ssl mode enabled'); } else { app = require('http').createServer(handler); - port = 8080; + port = 8182; console.info('ssl mode disabled'); } console.info('listening on port', port); diff --git a/tests/test_sockets.py b/tests/test_sockets.py index 7e248e22b2fc3..dad89a369c5b0 100644 --- a/tests/test_sockets.py +++ b/tests/test_sockets.py @@ -378,7 +378,7 @@ def test_webrtc(self): open(os.path.join(self.get_dir(), 'host_pre.js'), 'w').write(''' var Module = { webrtc: { - broker: 'http://localhost:8080', + broker: 'http://localhost:8182', session: undefined, onpeer: function(peer, route) { window.open('http://localhost:8888/peer.html?' + route); @@ -402,7 +402,7 @@ def test_webrtc(self): open(os.path.join(self.get_dir(), 'peer_pre.js'), 'w').write(''' var Module = { webrtc: { - broker: 'http://localhost:8080', + broker: 'http://localhost:8182', session: window.location.toString().split('?')[1], onpeer: function(peer, route) { peer.connect(Module['webrtc']['session']); From db0b614969450eacc33668bca7ee3c5d61726854 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 15 Sep 2014 15:29:37 -0700 Subject: [PATCH 11/11] 1.24.0 --- emscripten-version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emscripten-version.txt b/emscripten-version.txt index 5416318ab2a57..7ae54502c613c 100644 --- a/emscripten-version.txt +++ b/emscripten-version.txt @@ -1,2 +1,2 @@ -1.23.5 +1.24.0