diff --git a/src/jsifier.js b/src/jsifier.js index 7522d471bf783..a0597907cc345 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -55,9 +55,8 @@ function JSify(data, functionsOnly) { if (mainPass) { // Add additional necessary items for the main pass. We can now do this since types are parsed (types can be used through // generateStructInfo in library.js) - //B.start('jsifier-libload'); + LibraryManager.load(); - //B.stop('jsifier-libload'); var libFuncsToInclude; if (INCLUDE_FULL_LIBRARY) { @@ -68,10 +67,6 @@ function JSify(data, functionsOnly) { libFuncsToInclude.push(key); } } - // mark implemented functions as already added (so if memcpy is in the forced full JS library, but also done in C, we just need the C) - for (var added in IMPLEMENTED_FUNCTIONS) { - addedLibraryItems[added.substr(1)] = true; - } } else { libFuncsToInclude = DEFAULT_LIBRARY_FUNCS_TO_INCLUDE; } @@ -134,6 +129,13 @@ function JSify(data, functionsOnly) { var finalName = '_' + ident; } + // if the function was implemented in compiled code, we just need to export it so we can reach it from JS + if (finalName in IMPLEMENTED_FUNCTIONS) { + EXPORTED_FUNCTIONS[finalName] = 1; + // stop here: we don't need to add anything from our js libraries, not even deps, compiled code is on it + return ''; + } + // Don't replace implemented functions with library ones (which can happen when we add dependencies). // Note: We don't return the dependencies here. Be careful not to end up where this matters if (finalName in Functions.implementedFunctions) return ''; diff --git a/tests/test_core.py b/tests/test_core.py index 99439fe649b2f..b4d8bed343700 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -4741,6 +4741,38 @@ def test_unicode_js_library(self): self.emcc_args += ['--js-library', path_from_root('tests', 'unicode_library.js')] self.do_run(open(os.path.join(self.get_dir(), 'main.cpp'), 'r').read(), u'Unicode snowman \u2603 says hello!') + def test_js_lib_dep_memset(self): + open('lib.js', 'w').write(r''' +mergeInto(LibraryManager.library, { + depper__deps: ['memset'], + depper: function(ptr) { + _memset(ptr, 'd'.charCodeAt(0), 10); + }, +}); +''') + src = r''' +#include +#include + +extern "C" { +extern void depper(char*); +} + +int main(int argc, char** argv) { + char buffer[11]; + buffer[10] = '\0'; + // call by a pointer, to force linking of memset, no llvm intrinsic here + volatile auto ptr = memset; + (*ptr)(buffer, 'a', 10); + depper(buffer); + puts(buffer); +} +''' + self.emcc_args += ['--js-library', 'lib.js'] + self.do_run(src, 'dddddddddd') + Settings.INCLUDE_FULL_LIBRARY = 1 + self.do_run(src, 'dddddddddd') + def test_funcptr_import_type(self): self.emcc_args += ['--js-library', path_from_root('tests', 'core', 'test_funcptr_import_type.js'), '-std=c++11'] self.do_run_in_out_file_test('tests', 'core', 'test_funcptr_import_type')