Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compiled/bindings/generator.cpp

Issue 29431555: Issue 5216 - [emscripten] Use a more reliable way of retrieving mangled function name (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created May 6, 2017, 8:36 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
}
« no previous file with comments | « compile ('k') | compiled/bindings/library.h » ('j') | compiled/bindings/library.js » ('J')

Powered by Google App Engine
This is Rietveld