Index: compiled/bindings/generator.cpp |
=================================================================== |
--- a/compiled/bindings/generator.cpp |
+++ b/compiled/bindings/generator.cpp |
@@ -12,19 +12,18 @@ |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
#include <cstdio> |
-#include <emscripten.h> |
- |
#include "generator.h" |
+#include "library.h" |
namespace |
{ |
std::vector<bindings_internal::ClassInfo> classes; |
std::vector<bindings_internal::NamespaceInfo> namespaces; |
void printProperties(const bindings_internal::PropertyList& properties) |
{ |
@@ -136,87 +135,24 @@ namespace bindings_internal |
signature += 'd'; |
break; |
default: |
throw std::runtime_error("Unexpected function argument type"); |
} |
args.push_back(type); |
} |
- get_function_name(function, signature.c_str()); |
+ GetFunctionName(name, function, signature.c_str()); |
} |
bool FunctionInfo::empty() const |
{ |
return name[0] == '\0'; |
} |
- void FunctionInfo::get_function_name(void* ptr, const char* signature) |
- { |
- // This is a hack, C++ won't let us get the mangled function name. |
- // JavaScript is more dynamic so we pass the pointer to our function |
- // there. With that and the function signature we can call the function - |
- // with a full stack so that we will cause it to abort. Sometimes the |
- // function we are calling will also be missing from the build. The result |
- // is the same: abort() is called which in turn calls stackTrace(). By |
- // replacing stackTrace() we get access to the call stack and search it |
- // for the name of our function. |
- |
- EM_ASM_ARGS({ |
- var signature = AsciiToString($2); |
- var args = []; |
- for (var i = 1; i < signature.length; i++) |
- args.push(0); |
- |
- var oldPrint = Module.print; |
- var oldPrintErr = Module.printErr; |
- var oldStackTrace = stackTrace; |
- var sp = Runtime.stackSave(); |
- Module.print = function(){}; |
- Module.printErr = function(){}; |
- stackTrace = function() |
- { |
- var stack = []; |
- for (var f = arguments.callee.caller; f; f = f.caller) |
- { |
- if (f.name) |
- { |
- if (f.name.indexOf("dynCall") == 0) |
- break; |
- else |
- stack.push(f.name); |
- } |
- } |
- |
- result = stack[stack.length - 1]; |
- if (result && result.indexOf("__wrapper") >= 0) |
- result = stack[stack.length - 2]; |
- throw result; |
- }; |
- |
- Runtime.stackRestore(STACK_MAX); |
- |
- try |
- { |
- Runtime.dynCall(signature, HEAP32[$1 >> 2], args); |
- } |
- catch(e) |
- { |
- Module.stringToAscii(e, $0); |
- } |
- finally |
- { |
- Runtime.stackRestore(sp); |
- Module.print = oldPrint; |
- Module.printErr = oldPrintErr; |
- stackTrace = oldStackTrace; |
- } |
- }, name, ptr, signature); |
- } |
- |
ClassInfo* find_class(TYPEID classID) |
{ |
for (auto& classInfo : classes) |
if (classInfo.id == classID) |
return &classInfo; |
return nullptr; |
} |