diff options
author | jinsuck <jkim@imvu.com> | 2012-11-13 13:23:23 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:21:50 +0300 |
commit | 2c34b6dc6cf61087ff4f341bc33aefaa968803ba (patch) | |
tree | 3e6dedd98fb95e297b3daac2cef165b2a86e966b | |
parent | 69f2f335d3194ae6ef482169e23ad8edcd8dd1ca (diff) |
Allow constructing interface wrapper from existing interface object
-rw-r--r-- | system/include/emscripten/bind.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 97a9b5cc..cb8f396d 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -767,7 +767,15 @@ namespace emscripten { initialized = true; return *this; } - + + optional& operator=(optional& o) { + if (initialized) { + get()->~T(); + } + new(get()) T(*o); + initialized = true; + } + private: T* get() { return reinterpret_cast<T*>(&data); @@ -785,6 +793,14 @@ namespace emscripten { template<typename InterfaceType> class wrapper : public InterfaceType { public: + wrapper() {} // to avoid error "call to implicitly deleted construrtor..." + + wrapper(InterfaceType* interface) { + // why dynamic_cast causes javascript crash? + wrapper<InterfaceType>* iw = static_cast<wrapper<InterfaceType>*>(interface); + jsobj = iw->jsobj; + } + // Not necessary in any example so far, but appeases a compiler warning. virtual ~wrapper() {} |