Skip to content

Commit bd935f9

Browse files
committed
Add an rvalue reference version of toWireType.
1 parent c134dd6 commit bd935f9

File tree

1 file changed

+16
-0
lines changed
  • system/include/emscripten

1 file changed

+16
-0
lines changed

system/include/emscripten/val.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,13 @@ class val {
405405
return handle;
406406
}
407407

408+
// Takes ownership of the handle away from, and invalidates, this instance.
409+
EM_VAL take_handle() {
410+
EM_VAL taken = as_handle();
411+
handle = 0;
412+
return taken;
413+
}
414+
408415
val& operator=(val&& v) & {
409416
val tmp(std::move(v));
410417
this->~val();
@@ -795,6 +802,15 @@ template<typename T>
795802
struct BindingType<T, typename std::enable_if<std::is_base_of<val, T>::value &&
796803
!std::is_const<T>::value>::type> {
797804
typedef EM_VAL WireType;
805+
806+
// Marshall to JS with move semantics when we can invalidate the temporary val
807+
// object.
808+
static WireType toWireType(val&& v) {
809+
return v.take_handle();
810+
}
811+
812+
// Marshal to JS with copy semantics when we cannot transfer the val objects
813+
// reference count.
798814
static WireType toWireType(const val& v) {
799815
EM_VAL handle = v.as_handle();
800816
if (v.uses_refcount()) {

0 commit comments

Comments
 (0)