aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2011-02-12 19:35:45 -0800
committerAlon Zakai <azakai@mozilla.com>2011-02-12 19:35:45 -0800
commitffb61d77cae700fe2f45c60e06715033ae9f653a (patch)
tree1ff4e3c091603dd2a38a9029976a586234a41dfd
parent96b74d5914bb6495f4e82cac12ce25c7aedf77a1 (diff)
emscripten_run_script API
-rw-r--r--src/include/emscripten.h8
-rw-r--r--src/library.js5
-rw-r--r--tests/runner.py12
3 files changed, 25 insertions, 0 deletions
diff --git a/src/include/emscripten.h b/src/include/emscripten.h
index 1974fc71..958bef98 100644
--- a/src/include/emscripten.h
+++ b/src/include/emscripten.h
@@ -9,6 +9,10 @@
// ES_SIZEOF
//
+// NOTE: As of now, ES_SIZEOF is not needed when using QUANTUM_SIZE
+// of 4. We will use the same offsets as C/C++ does in that case.
+// ES_SIZEOF is useful if QUANTUM_SIZE is 1.
+//
// A 'safe' sizeof operator. Sadly llvm-gcc calculates sizeof's
// and stores them hardcoded as raw values, unlike say offsets
// within a structure which it nicely details using getelementptr.
@@ -40,3 +44,7 @@
#define ES_SIZEOF(T) sizeof(T)
#endif
+// Interface to the underlying JS engine. This function will
+// eval() the given script.
+extern void emscripten_run_script(const char *script);
+
diff --git a/src/library.js b/src/library.js
index cc8fe45f..f79de6c8 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1147,6 +1147,11 @@ var Library = {
opendir: function(pname) {
return 0;
+ },
+
+ // ** emscripten.h **
+ _Z21emscripten_run_scriptPKc: function(ptr) {
+ eval(Pointer_stringify(ptr));
}
};
diff --git a/tests/runner.py b/tests/runner.py
index 2da9b9c9..d936f10d 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1131,6 +1131,18 @@ if 'benchmark' not in sys.argv:
'''
self.do_test(src, '*2,2,5,8,8***8,8,5,8,8***7,2,6,990,7,2*', [], lambda x: x.replace('\n', '*'))
+ def test_emscripten_api(self):
+ src = '''
+ #include <stdio.h>
+ #include "emscripten.h"
+
+ int main() {
+ emscripten_run_script("print('hello world' + '!')");
+ return 0;
+ }
+ '''
+ self.do_test(src, 'hello world!')
+
def test_tinyfuncstr(self):
src = '''
#include <stdio.h>