This commit is contained in:
Chad Austin 2013-03-20 17:51:15 -07:00 коммит произвёл Jukka Jylänki
Родитель 41b65f63c4
Коммит bfcc6330b2
2 изменённых файлов: 34 добавлений и 30 удалений

Просмотреть файл

@ -3,10 +3,10 @@
/*global FUNCTION_TABLE, HEAP32, HEAPU8*/
/*global Pointer_stringify*/
/*global __emval_register, _emval_handle_array, __emval_decref*/
/*global ___typeName:false*/
var InternalError = Module.InternalError = extendError(Error, 'InternalError');
var BindingError = Module.BindingError = extendError(Error, 'BindingError');
var UnboundTypeError = Module.UnboundTypeError = extendError(BindingError, 'UnboundTypeError');
function throwInternalError(value) {
throw new InternalError(value);
@ -124,11 +124,8 @@ function whenDependentTypesAreResolved(dependentTypes, onComplete) {
}
}
function typeName(rawType) {
var bt = ___typeName(rawType);
var rv = Pointer_stringify(bt);
_free(bt);
return rv;
function getTypeName(type) {
return Module._embind_getTypeName(type);
}
function heap32VectorToArray(count, firstElement) {
@ -142,7 +139,7 @@ function heap32VectorToArray(count, firstElement) {
function requireRegisteredType(rawType, humanName) {
var impl = registeredTypes[rawType];
if (undefined === impl) {
throwBindingError(humanName + " has unknown type " + typeName(rawType));
throwBindingError(humanName + " has unknown type " + getTypeName(rawType));
}
return impl;
}
@ -279,8 +276,17 @@ function __embind_register_function(name, argCount, rawArgTypesAddr, rawInvoker,
var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
name = Pointer_stringify(name);
rawInvoker = FUNCTION_TABLE[rawInvoker];
var invoker = function() {
throw new UnboundTypeError('Cannot call ' + name + ' due to unbound types: UnboundFoo');
}
exposePublicSymbol(name, function() {
return invoker.apply(this, arguments);
});
whenDependentTypesAreResolved(argTypes, function(argTypes) {
exposePublicSymbol(name, makeInvoker(name, argCount, argTypes, rawInvoker, fn));
invoker = makeInvoker(name, argCount, argTypes, rawInvoker, fn);
});
}

Просмотреть файл

@ -1,5 +1,4 @@
#include <emscripten/bind.h>
#include <../lib/libcxxabi/src/private_typeinfo.h>
#include <../lib/libcxxabi/include/cxxabi.h>
#include <list>
#include <vector>
@ -9,29 +8,26 @@
using namespace emscripten;
static std::string _embind_getTypeName(intptr_t ti_raw) {
auto ti = reinterpret_cast<const std::type_info*>(ti_raw);
int stat;
char* demangled = abi::__cxa_demangle(ti->name(), NULL, NULL, &stat);
switch (stat) {
case -1:
return "<allocation failure>";
case -2:
return "<invalid C++ symbol>";
case -3:
return "<invalid argument>";
}
std::string rv(demangled);
free(demangled);
return rv;
}
namespace emscripten {
namespace internal {
extern "C" {
const char* EMSCRIPTEN_KEEPALIVE __typeName(const std::type_info* ti) {
size_t nameLen = std::min(strlen(ti->name()), 1024U);
char* name = (char *)malloc(nameLen+1);
int stat;
__cxxabiv1::__cxa_demangle(ti->name(), name, &nameLen, &stat);
if (stat != 0) {
strncpy(name, ti->name(), nameLen);
name[nameLen] = '\0';
}
return name;
}
size_t EMSCRIPTEN_KEEPALIVE __peek32(size_t p) {
return *reinterpret_cast<size_t*>(p);
}
}
JSInterface* create_js_interface(EM_VAL e) {
return new JSInterface(e);
}
@ -60,4 +56,6 @@ EMSCRIPTEN_BINDINGS(native_and_builtin_types) {
_embind_register_cstring(TypeID<std::string>::get(), "std::string");
_embind_register_emval(TypeID<val>::get(), "emscripten::val");
function("_embind_getTypeName", &_embind_getTypeName);
}