diff options
-rwxr-xr-x | tests/runner.py | 6 | ||||
-rwxr-xr-x | tools/bindings_generator.py | 21 |
2 files changed, 13 insertions, 14 deletions
diff --git a/tests/runner.py b/tests/runner.py index 3dd42c85..7005718c 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -8637,7 +8637,7 @@ def process(filename): Module.Child2.prototype.runVirtualFunc(c2); c2.virtualFunc2(); -''' + ('' if Settings.ASM_JS else ''' +''' + (''' // extend the class from JS var c3 = new Module.Child2; Module.customizeVTable(c3, [{ @@ -8667,6 +8667,8 @@ def process(filename): src.close() ''' + Settings.RESERVED_FUNCTION_POINTERS = 20 + self.do_run(src, '''* 84 c1 @@ -8697,7 +8699,7 @@ Child2:9 *static* *virtualf* *virtualf* -*virtualf2*''' + ('' if Settings.ASM_JS else ''' +*virtualf2*''' + (''' Parent:9 Child2:9 *js virtualf replacement* diff --git a/tools/bindings_generator.py b/tools/bindings_generator.py index d610ab54..5bf0996e 100755 --- a/tools/bindings_generator.py +++ b/tools/bindings_generator.py @@ -468,7 +468,6 @@ Module['getClass'] = getClass; function customizeVTable(object, replacementPairs) { // Does not handle multiple inheritance - // Does not work with asm.js // Find out vtable size var vTable = getValue(object.ptr, 'void*'); @@ -478,23 +477,22 @@ function customizeVTable(object, replacementPairs) { size++; } - // Prepare replacement lookup table and add replacements to FUNCTION_TABLE + // Prepare replacement lookup table and add replacements. // There is actually no good way to do this! So we do the following hack: // We create a fake vtable with canary functions, to detect which actual // function is being called var vTable2 = _malloc(size*Runtime.QUANTUM_SIZE); setValue(object.ptr, vTable2, 'void*'); var canaryValue; - var functions = FUNCTION_TABLE.length; + var tempFuncs = []; for (var i = 0; i < size; i++) { - var index = FUNCTION_TABLE.length; (function(j) { - FUNCTION_TABLE.push(function() { + var index = Runtime.addFunction(function() { canaryValue = j; }); + setValue(vTable2 + Runtime.QUANTUM_SIZE*i, index, 'void*'); + tempFuncs.push(index); })(i); - FUNCTION_TABLE.push(0); - setValue(vTable2 + Runtime.QUANTUM_SIZE*i, index, 'void*'); } var args = [{ptr: 0}]; replacementPairs.forEach(function(pair) { @@ -509,16 +507,15 @@ function customizeVTable(object, replacementPairs) { } pair.originalIndex = getValue(vTable + canaryValue*Runtime.QUANTUM_SIZE, 'void*'); }); - FUNCTION_TABLE = FUNCTION_TABLE.slice(0, functions); + for (var i = 0; i < size; i++) { + Runtime.removeFunction(tempFuncs[i]); + } // Do the replacements var replacements = {}; replacementPairs.forEach(function(pair) { - var replacementIndex = FUNCTION_TABLE.length; - FUNCTION_TABLE.push(pair['replacement']); - FUNCTION_TABLE.push(0); - replacements[pair.originalIndex] = replacementIndex; + replacements[pair.originalIndex] = Runtime.addFunction(pair['replacement']); }); // Copy and modify vtable |