File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
system/include/emscripten Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -405,6 +405,13 @@ class val {
405
405
return handle;
406
406
}
407
407
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
+
408
415
val& operator =(val&& v) & {
409
416
val tmp (std::move (v));
410
417
this ->~val ();
@@ -795,6 +802,15 @@ template<typename T>
795
802
struct BindingType <T, typename std::enable_if<std::is_base_of<val, T>::value &&
796
803
!std::is_const<T>::value>::type> {
797
804
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.
798
814
static WireType toWireType (const val& v) {
799
815
EM_VAL handle = v.as_handle ();
800
816
if (v.uses_refcount ()) {
You can’t perform that action at this time.
0 commit comments