diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index dd44f3f8adb31..64fc4a0556f24 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -368,6 +368,11 @@ class EMBIND_VISIBILITY_DEFAULT val { } } + // Add an explicit overload for `val&` as well. + // Without it, C++ will try to use the `T&&` constructor instead of the more + // efficient `val(const val&)` when trying to copy a `val` instance. + val(val& v) : val(static_cast(v)) {} + ~val() { if (uses_ref_count()) { internal::_emval_decref(as_handle());