diff options
Diffstat (limited to 'system')
-rwxr-xr-x | system/include/emscripten/bind.h | 10 | ||||
-rw-r--r-- | system/include/emscripten/val.h | 21 |
2 files changed, 22 insertions, 9 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 894586a6..a3886031 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -284,8 +284,8 @@ namespace emscripten { } template<typename WrapperType, typename ClassType, typename... Args> - WrapperType wrapped_new(Args... args) { - return WrapperType(new ClassType(args...)); + WrapperType wrapped_new(Args&&... args) { + return WrapperType(new ClassType(std::forward<Args>(args)...)); } template<typename ClassType, typename... Args> @@ -718,8 +718,8 @@ namespace emscripten { template<typename T> class wrapper : public T { public: - explicit wrapper(const val& wrapped) - : wrapped(wrapped) + explicit wrapper(val&& wrapped) + : wrapped(std::forward<val>(wrapped)) {} template<typename ReturnType, typename... Args> @@ -760,7 +760,7 @@ namespace emscripten { }; #define EMSCRIPTEN_WRAPPER(T) \ - T(const ::emscripten::val& v): wrapper(v) {} + T(::emscripten::val&& v): wrapper(std::forward<::emscripten::val>(v)) {} namespace internal { struct NoBaseClass { diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index d32c9650..1fccd434 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -101,18 +101,24 @@ namespace emscripten { } template<typename T> - explicit val(const T& value) { + explicit val(T&& value) { typedef internal::BindingType<T> BT; auto taker = reinterpret_cast<internal::EM_VAL (*)(internal::TYPEID, typename BT::WireType)>(&internal::_emval_take_value); - handle = taker(internal::TypeID<T>::get(), BT::toWireType(value)); + handle = taker(internal::TypeID<T>::get(), BT::toWireType(std::forward<T>(value))); } val() = delete; - val(const char* v) + explicit val(const char* v) : handle(internal::_emval_new_cstring(v)) {} + val(val&& v) + : handle(v.handle) + { + v.handle = 0; + } + val(const val& v) : handle(v.handle) { @@ -123,6 +129,13 @@ namespace emscripten { internal::_emval_decref(handle); } + val& operator=(val&& v) { + internal::_emval_decref(handle); + handle = v.handle; + v.handle = 0; + return *this; + } + val& operator=(const val& v) { internal::_emval_incref(v.handle); internal::_emval_decref(handle); @@ -260,7 +273,7 @@ namespace emscripten { template<> struct BindingType<val> { typedef internal::EM_VAL WireType; - static WireType toWireType(val v) { + static WireType toWireType(const val& v) { _emval_incref(v.handle); return v.handle; } |