aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-11-30 13:54:56 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-07 14:23:21 -0800
commit60a3fd1bcd5c618047c3b1501bee6d56bc03b88d (patch)
tree929326449d15482bfca25281180aedb002c7c7bc
parent0ff46c223d1ea261c98b5d8bee8e69dba184ee13 (diff)
enclose asm.js to prevent Function code from seeing the global scope, for testing purposes
-rwxr-xr-xemscripten.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/emscripten.py b/emscripten.py
index df7895a1..184559e6 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -266,6 +266,9 @@ def emscript(infile, settings, outfile, libraries=[]):
def blockaddrsize(js):
return re.sub(r'{{{ BA_([\w\d_$]+)\|([\w\d_$]+) }}}', lambda m: str(blockaddrs[m.groups(0)[0]][m.groups(0)[1]]), js)
+ if settings.get('ASM_JS'):
+ outfile.write('(function() {\n'); # prevent new Function from seeing the global scope
+
#if DEBUG: outfile.write('// pre\n')
outfile.write(blockaddrsize(indexize(pre)))
pre = None
@@ -343,6 +346,9 @@ var asm = asmPre(%s, buffer); // pass through Function to prevent seeing outside
outfile.write(indexize(post))
if DEBUG: print >> sys.stderr, ' emscript: phase 3 took %s seconds' % (time.time() - t)
+ if settings.get('ASM_JS'):
+ outfile.write('})()\n');
+
outfile.close()