MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / make_invoke

Function make_invoke

tools/js_manipulation.py:128–152  ·  view source on GitHub ↗
(sig)

Source from the content-addressed store, hash-verified

126
127
128def make_invoke(sig):
129 legal_sig = legalize_sig(sig) # TODO: do this in extcall, jscall?
130 args = ['index'] + ['a' + str(i) for i in range(1, len(legal_sig))]
131 ret = 'return ' if sig[0] != 'v' else ''
132 # For function that needs to return a genuine i64 (i.e. if legal_sig[0] is 'j')
133 # we need to return an actual BigInt, even in the exceptional case because
134 # wasm won't implicitly convert undefined to 0 in this case.
135 exceptional_ret = '\n return 0n;' if legal_sig[0] == 'j' else ''
136 body = '%s%s;' % (ret, make_dynCall(sig, args))
137 # Create a try-catch guard that rethrows the Emscripten EH exception.
138 maybe_rethrow = 'if (!(e instanceof EmscriptenEH)) throw e;'
139
140 ret = '''\
141function invoke_%s(%s) {
142 var sp = stackSave();
143 try {
144 %s
145 } catch(e) {
146 stackRestore(sp);
147 %s
148 _setThrew(1, 0);%s
149 }
150}''' % (sig, ','.join(args), body, maybe_rethrow, exceptional_ret)
151
152 return ret
153
154
155def make_wasm64_wrapper(sig):

Callers

nothing calls this directly

Calls 4

legalize_sigFunction · 0.85
make_dynCallFunction · 0.85
rangeFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected