diff options
author | Chad Austin <chad@imvu.com> | 2013-03-14 01:18:18 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:25:57 +0300 |
commit | 7d783d874a38b63515e8e3cc4c0c8ec15e428175 (patch) | |
tree | f3747150dc080b13c0ad707962e578a2b8e6a694 | |
parent | fb92020f00a7ae5b43927927b1ec571afc161bf1 (diff) |
Use typeid name for interface wrappers too. (Also introduce more uses of makeLegalFunctionName)
-rwxr-xr-x | src/embind/embind.js | 17 | ||||
-rwxr-xr-x | system/include/emscripten/bind.h | 3 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index 2f30750f..8810727d 100755 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -680,6 +680,7 @@ function __embind_register_class( rawDestructor = FUNCTION_TABLE[rawDestructor]; upcast = FUNCTION_TABLE[upcast]; downcast = FUNCTION_TABLE[downcast]; + var legalFunctionName = makeLegalFunctionName(name); whenDependentTypesAreResolved(baseClassRawType ? [baseClassRawType] : [], function(base) { base = base[0]; @@ -696,7 +697,7 @@ function __embind_register_class( basePrototype = ClassHandle.prototype; } - var Handle = createNamedFunction(name, function(registeredPointer, ptr) { + var Handle = createNamedFunction(legalFunctionName, function(registeredPointer, ptr) { Object.defineProperty(this, '$$', { value: { registeredPointer: registeredPointer, @@ -781,7 +782,7 @@ function __embind_register_class( true, false)); - type.constructor = createNamedFunction(name, function() { + type.constructor = createNamedFunction(legalFunctionName, function() { if (Object.getPrototypeOf(this) !== Handle.prototype) { throw new BindingError("Use 'new' to construct " + name); } @@ -794,7 +795,7 @@ function __embind_register_class( type.constructor.prototype = type.Handle.prototype; type.constructor.type = type; - exposePublicSymbol(name, type.constructor); + exposePublicSymbol(legalFunctionName, type.constructor); }); } @@ -955,8 +956,16 @@ function __embind_register_class_property( }); } +var char_0 = '0'.charCodeAt(0); +var char_9 = '9'.charCodeAt(0); function makeLegalFunctionName(name) { - return '_' + name.replace(/[^a-zA-Z0-9_]/g, '$'); + var rv = name.replace(/[^a-zA-Z0-9_]/g, '$'); + var f = rv.charCodeAt(0); + if (f >= char_0 && f <= char_9) { + return '_' + rv; + } else { + return rv; + } } function __embind_register_smart_ptr( diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 10d0d926..e5865971 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -780,8 +780,7 @@ namespace emscripten { class_& allow_subclass() { using namespace internal; - // TODO: unique or anonymous name - class_<WrapperType, base<ClassType>>("WrapperType") + class_<WrapperType, base<ClassType>>(typeid(WrapperType).name()) .template constructor<val>() ; |