aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChad Austin <chad@chadaustin.me>2014-04-24 00:34:18 -0700
committerChad Austin <chad@chadaustin.me>2014-04-24 00:34:18 -0700
commitc7b472ab5ac60c67cae8ab95d0363fd328dd4571 (patch)
treec4b07c789e7d08eee4c0ebc4609db15072039425 /src
parent2ad793ffc9402a09c393a5cc0f6916dc5cb9f7da (diff)
have asm.js embind go through dynCall
Diffstat (limited to 'src')
-rw-r--r--src/embind/embind.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 124892e3..058bd5c1 100644
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -1,4 +1,4 @@
-/*global Module, asm*/
+/*global Module*/
/*global _malloc, _free, _memcpy*/
/*global FUNCTION_TABLE, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64*/
/*global readLatin1String*/
@@ -707,9 +707,21 @@ function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cp
function requireFunction(signature, rawFunction) {
signature = readLatin1String(signature);
var fp;
+ // asm.js does not define FUNCTION_TABLE
if (typeof FUNCTION_TABLE === "undefined") {
- // asm.js style
- fp = asm['FUNCTION_TABLE_' + signature][rawFunction];
+ // asm.js does not give direct access to the function tables,
+ // and thus we must go through the dynCall interface which allows
+ // calling into a signature's function table by pointer value.
+ //
+ // https://github.com/dherman/asm.js/issues/83
+ //
+ // This has three main penalties:
+ // - dynCall is another function call in the path from JavaScript to C++.
+ // - JITs may not predict through the function table indirection at runtime.
+ // - Function.prototype.bind generally benchmarks poorly relative to
+ // function objects, but using 'arguments' would confound JITs and
+ // possibly allocate.
+ fp = Module['dynCall_' + signature].bind(undefined, rawFunction);
} else {
fp = FUNCTION_TABLE[rawFunction];
}