diff options
author | Bill Welden <bwelden@imvu.com> | 2013-01-28 15:21:59 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:23:43 +0300 |
commit | c42eb7377eb547237d670238d7062c86e9b08673 (patch) | |
tree | af2b2f4b22e55b9483680be8239cb62e0a108c00 | |
parent | 40ad51a5c81881ae0ddb5c36f19e7d362107ccc6 (diff) |
Removed explicit cast capability from bindings.
-rwxr-xr-x | src/embind/embind.js | 95 | ||||
-rwxr-xr-x | system/include/emscripten/bind.h | 63 |
2 files changed, 0 insertions, 158 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index d8a4a440..75450735 100755 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -5,7 +5,6 @@ /*global Pointer_stringify, writeStringToMemory*/ /*global __emval_register, _emval_handle_array, __emval_decref*/ /*global ___getDynamicPointerType: false*/ -/*global ___dynamicPointerCast: false*/ /*global ___typeName:false*/ /*global ___staticPointerCast: false*/ @@ -971,100 +970,6 @@ function __embind_register_class_method( }); } -// todo: cast methods should require binding of their target types -function __embind_register_raw_cast_method( - rawClassType, - isPolymorphic, - methodName, - rawReturnType, - rawInvoker -) { - requestDeferredRegistration(function() { - var classType = requireRegisteredType(rawClassType, 'class'); - methodName = Pointer_stringify(methodName); - var humanName = classType.name + '.' + methodName; - var returnType = requireRegisteredType(rawReturnType, 'method ' + humanName + ' return value'); - rawInvoker = FUNCTION_TABLE[rawInvoker]; - classType.Handle.prototype[methodName] = function() { - if (!this.ptr) { - throw new BindingError('cannot call emscripten binding method ' + humanName + ' on deleted object'); - } - if (arguments.length !== 0) { - throw new BindingError('emscripten binding method ' + humanName + ' called with arguments, none expected'); - } - if (isPolymorphic) { - // todo: this is all only to validate the cast -- cache the result - var runtimeType = ___getDynamicPointerType(this.ptr); - var derivation = Module.__getDerivationPath(rawReturnType, runtimeType); // downcast is valid - var size = derivation.size(); - derivation.delete(); - if (size === 0) { - derivation = Module.__getDerivationPath(runtimeType, rawReturnType); // upcast is valid - size = derivation.size(); - derivation.delete(); - if (size === 0) { - throw new CastError("Pointer conversion is not available"); - } - } - } - var args = new Array(1); - args[0] = this.ptr; - var ptr = rawInvoker.apply(null, args); - var rv = returnType.fromWireType(ptr); - rv.count = this.count; - this.count.value ++; - return rv; - }; - }); -} - -// todo: cast methods should not be passed from the smart ptr to the contained object!! -function __embind_register_smart_cast_method( - rawPointerType, - rawReturnType, - returnPointeeType, - isPolymorphic, - methodName, - rawInvoker -) { - requestDeferredRegistration(function() { - var pointerType = requireRegisteredType(rawPointerType, 'smart pointer class'); - methodName = Pointer_stringify(methodName); - var humanName = pointerType.name + '.' + methodName; - var returnType = requireRegisteredType(rawReturnType, 'method ' + humanName + ' return value'); - rawInvoker = FUNCTION_TABLE[rawInvoker]; - pointerType.Handle.prototype[methodName] = function() { - if (!this.ptr) { - throw new BindingError('cannot call emscripten binding method ' + humanName + ' on deleted object'); - } - if (arguments.length !== 0) { - throw new BindingError('emscripten binding method ' + humanName + ' called with arguments, none expected'); - } - if (isPolymorphic) { - // todo: just validating the cast -- cache the result - var runtimeType = ___getDynamicPointerType(this.ptr); - var derivation = Module.__getDerivationPath(returnPointeeType, runtimeType); // downcast is valid - var size = derivation.size(); - derivation.delete(); - if (size === 0) { - derivation = Module.__getDerivationPath(runtimeType, returnPointeeType); // upcast is valid - size = derivation.size(); - derivation.delete(); - if (size === 0) { - throw new CastError("Pointer conversion is not available"); - } - } - } - var args = new Array(2); - var ptr = _malloc(8); - args[0] = ptr; - args[1] = this.smartPointer; - rawInvoker.apply(null,args); - return returnType.fromWireType(ptr); - }; - }); -} - function __embind_register_class_classmethod( rawClassType, methodName, diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index ce9053f2..70a5b60c 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -124,21 +124,6 @@ namespace emscripten { size_t memberFunctionSize, void* memberFunction); - void _embind_register_raw_cast_method( - TYPEID classType, - bool isPolymorphic, - const char* methodName, - TYPEID returnType, - GenericFunction invoker); - - void _embind_register_smart_cast_method( - TYPEID pointerType, - TYPEID returnType, - TYPEID returnPointeeType, - bool isPolymorphic, - const char* methodName, - GenericFunction invoker); - void _embind_register_class_field( TYPEID classType, const char* fieldName, @@ -274,28 +259,8 @@ namespace emscripten { extern "C" { int __getDynamicPointerType(int p); - int __dynamicPointerCast(int p, int to); } - template<typename FromType, typename ToType> - ToType& performRawStaticCast(FromType& from) { - return *static_cast<ToType*>(&from); - }; - - template<typename FromRawType, typename ToRawType, bool isPolymorphic> - struct performShared { - static std::shared_ptr<ToRawType> cast(std::shared_ptr<FromRawType> from) { - return std::dynamic_pointer_cast<ToRawType>(from); - }; - }; - - template<typename FromRawType, typename ToRawType> - struct performShared<FromRawType, ToRawType, false> { - static std::shared_ptr<ToRawType> cast(std::shared_ptr<FromRawType> from) { - return std::shared_ptr<ToRawType>(from, static_cast<ToRawType*>(from.get())); - }; - }; - template<typename ReturnType, typename... Args, typename... Policies> void function(const char* name, ReturnType (fn)(Args...), Policies...) { using namespace internal; @@ -625,21 +590,6 @@ namespace emscripten { reinterpret_cast<GenericFunction>(&get_pointee<PointerType>)); } - - template<typename ReturnType> - register_smart_ptr& cast(const char* methodName) { - using namespace internal; - typedef typename ReturnType::element_type ReturnPointeeType; - typedef typename PointerType::element_type PointeeType; - _embind_register_smart_cast_method( - TypeID<PointerType>::get(), - TypeID<ReturnType>::get(), - TypeID<ReturnPointeeType>::get(), - std::is_polymorphic<PointeeType>::value, - methodName, - reinterpret_cast<GenericFunction>(&performShared<PointeeType, ReturnPointeeType, std::is_polymorphic<PointeeType>::value>::cast)); - return *this; - } }; //////////////////////////////////////////////////////////////////////////////// @@ -773,19 +723,6 @@ namespace emscripten { reinterpret_cast<internal::GenericFunction>(&internal::ArrayAccessSetInvoker<ClassType, ElementType, IndexType>::invoke)); return *this; } - - template<typename ReturnType> - class_& cast(const char* methodName) { - using namespace internal; - - _embind_register_raw_cast_method( - TypeID<ClassType>::get(), - std::is_polymorphic<ClassType>::value, - methodName, - TypeID<ReturnType>::get(), - reinterpret_cast<GenericFunction>(&performRawStaticCast<ClassType,ReturnType>)); - return *this; - } }; //////////////////////////////////////////////////////////////////////////////// |