Skip to content

Instantly share code, notes, and snippets.

@kripken
Created February 10, 2016 02:50
Show Gist options
  • Save kripken/afdba9aa40e58c062eb8 to your computer and use it in GitHub Desktop.
Save kripken/afdba9aa40e58c062eb8 to your computer and use it in GitHub Desktop.
diff --git a/tests/test_core.py b/tests/test_core.py
index 0cf3327..c43e5ab 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -5574,6 +5574,31 @@ PORT: 3979
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_library_features(self):
+ open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(r'''
+ #include <stdio.h>
+ extern "C" {
+ extern int countey();
+ }
+ int main() {
+ printf("%d\n", countey());
+ printf("%d\n", countey());
+ printf("%d\n", countey());
+ printf("%d\n", countey());
+ printf("%d\n", countey());
+ return 0;
+ }
+ ''')
+ open(os.path.join(self.get_dir(), 'mylib.js'), 'w').write('''
+ mergeInto(LibraryManager.library, {
+ // code provided in a string is emitted directly; this lets us do a closure in a simple way
+ countey: '(function() { var counter = 0; return function() { return counter++ }; })()',
+ });
+ ''')
+
+ self.emcc_args += ['--js-library', os.path.join(self.get_dir(), 'mylib.js')]
+ self.do_run(open(os.path.join(self.get_dir(), 'main.cpp'), 'r').read(), '0\n1\n2\n3\n4\n')
+
def test_constglobalunion(self):
self.emcc_args += ['-s', 'EXPORT_ALL=1']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment