aboutsummaryrefslogtreecommitdiff
path: root/emscripten.py
diff options
context:
space:
mode:
Diffstat (limited to 'emscripten.py')
-rwxr-xr-xemscripten.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/emscripten.py b/emscripten.py
index 649b3c0b..f4bfed82 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -305,7 +305,7 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
i = 2
if settings['ASM_JS']: i += 2*settings['RESERVED_FUNCTION_POINTERS']
for indexed in indexed_functions:
- #print >> sys.stderr, 'indaxx', indexed, i
+ #print >> sys.stderr, 'function indexing', indexed, i
forwarded_json['Functions']['indexedFunctions'][indexed] = i # make sure not to modify this python object later - we use it in indexize
i += 2
forwarded_json['Functions']['nextIndex'] = i
@@ -389,7 +389,7 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
newline = '\n' in item
return (bad if item.replace('\n', '') == '0' else item) + ('\n' if newline else '')
body = ','.join(map(fix_item, body))
- return ('function %s(%s) { %s abort(%d); %s }' % (bad, params, coercions, i, ret), raw[:start+1] + body + raw[end:])
+ return ('function %s(%s) { %s %s(%d); %s }' % (bad, params, coercions, 'abort' if not settings['ASSERTIONS'] else 'nullFunc', i, ret), raw[:start+1] + body + raw[end:])
infos = [make_table(sig, raw) for sig, raw in last_forwarded_json['Functions']['tables'].iteritems()]
function_tables_defs = '\n'.join([info[0] for info in infos]) + '\n// EMSCRIPTEN_END_FUNCS\n' + '\n'.join([info[1] for info in infos])
@@ -398,10 +398,15 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
fundamentals = ['Math', 'Int8Array', 'Int16Array', 'Int32Array', 'Uint8Array', 'Uint16Array', 'Uint32Array', 'Float32Array', 'Float64Array']
math_envs = ['Math.min'] # TODO: move min to maths
asm_setup += '\n'.join(['var %s = %s;' % (f.replace('.', '_'), f) for f in math_envs])
+
basic_funcs = ['abort', 'assert', 'asmPrintInt', 'asmPrintFloat', 'copyTempDouble', 'copyTempFloat'] + [m.replace('.', '_') for m in math_envs]
if settings['RESERVED_FUNCTION_POINTERS'] > 0: basic_funcs.append('jsCall')
if settings['SAFE_HEAP']: basic_funcs += ['SAFE_HEAP_LOAD', 'SAFE_HEAP_STORE', 'SAFE_HEAP_CLEAR']
if settings['CHECK_HEAP_ALIGN']: basic_funcs += ['CHECK_ALIGN_2', 'CHECK_ALIGN_4', 'CHECK_ALIGN_8']
+ if settings['ASSERTIONS']:
+ basic_funcs += ['nullFunc']
+ asm_setup += 'function nullFunc(x) { Module["printErr"]("Invalid function pointer called. Perhaps a miscast function pointer (check compilation warnings) or bad vtable lookup (maybe due to derefing a bad pointer, like NULL)?"); abort(x) }\n'
+
basic_vars = ['STACKTOP', 'STACK_MAX', 'tempDoublePtr', 'ABORT']
basic_float_vars = ['NaN', 'Infinity']
@@ -442,11 +447,13 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
''' % (sig, i, args, arg_coercions, jsret))
args = ','.join(['a' + str(i) for i in range(1, len(sig))])
args = 'index' + (',' if args else '') + args
+ # C++ exceptions are numbers, and longjmp is a string 'longjmp'
asm_setup += '''
function invoke_%s(%s) {
try {
%sModule.dynCall_%s(%s);
} catch(e) {
+ if (typeof e !== 'number' && e !== 'longjmp') throw e;
asm.setThrew(1, 0);
}
}
@@ -522,7 +529,7 @@ var asm = (function(global, env, buffer) {
var ret = 0;
ret = STACKTOP;
STACKTOP = (STACKTOP + size)|0;
- STACKTOP = ((STACKTOP + 3)>>2)<<2;
+''' + ('STACKTOP = ((STACKTOP + 3)>>2)<<2;' if settings['TARGET_X86'] else 'STACKTOP = ((STACKTOP + 7)>>3)<<3;') + '''
return ret|0;
}
function stackSave() {