aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler.js1
-rw-r--r--src/jsifier.js6
-rw-r--r--src/settings.js4
3 files changed, 10 insertions, 1 deletions
diff --git a/src/compiler.js b/src/compiler.js
index e5e8a755..4fe68e88 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -42,6 +42,7 @@ if (SAFE_HEAP >= 2) {
}
EXPORTED_FUNCTIONS = set(EXPORTED_FUNCTIONS);
+EXPORTED_GLOBALS = set(EXPORTED_GLOBALS);
// Settings sanity checks
diff --git a/src/jsifier.js b/src/jsifier.js
index 2344b21f..71797daa 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -178,9 +178,13 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
}
constant = makePointer(constant, null, 'ALLOC_STATIC', item.type);
+ var js = item.ident + '=' + constant + ';';
+ if (item.ident in EXPORTED_GLOBALS) {
+ js += '\nModule["' + item.ident + '"] = ' + item.ident + ';';
+ }
return ret.concat({
intertype: 'GlobalVariable',
- JS: item.ident + '=' + constant + ';',
+ JS: js,
});
}
}
diff --git a/src/settings.js b/src/settings.js
index f2dd9065..f3ed4d06 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -101,6 +101,10 @@ AUTO_OPTIMIZE = 0; // When run with the CHECK_* options, will not fail on errors
EXPORTED_FUNCTIONS = ['_main']; // Functions that are explicitly exported, so they are guaranteed to
// be accessible outside of the generated code.
+EXPORTED_GLOBALS = []; // Global non-function variables that are explicitly
+ // exported, so they are guaranteed to be
+ // accessible outside of the generated code.
+
SHOW_LABELS = 0; // Show labels in the generated code
// Compiler debugging options