Skip to content

Commit

Permalink
V8: automatically heap-copy and wrap temporary objects in convert<T>:…
Browse files Browse the repository at this point in the history
…:to_v8()

Signed-off-by: Tim Janik <timj@gnu.org>
  • Loading branch information
tim-janik committed Feb 20, 2017
1 parent e78da70 commit 660a04a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions v8pp/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ struct convert<T, typename std::enable_if<is_wrapped_class<T>::value>::type>
{
using from_type = T&;
using to_type = v8::Handle<v8::Object>;
using class_type = typename std::remove_cv<T>::type;

static bool is_valid(v8::Isolate* isolate, v8::Handle<v8::Value> value)
{
Expand All @@ -583,9 +584,11 @@ struct convert<T, typename std::enable_if<is_wrapped_class<T>::value>::type>

static to_type to_v8(v8::Isolate* isolate, T const& value)
{
v8::Handle<v8::Object> result = convert<T*>::to_v8(isolate, &value);
v8::Handle<v8::Object> result = class_<class_type>::find_object(isolate, &value);
if (!result.IsEmpty()) return result;
throw std::runtime_error("failed to wrap C++ object");
class_type* obj = v8pp::factory<class_type>::create(isolate, value);
if (!obj) throw std::runtime_error("failed to wrap C++ object");
return class_<class_type>::import_external(isolate, obj);
}
};

Expand Down

0 comments on commit 660a04a

Please sign in to comment.