Skip to content

Support automatic heap-copies of temporary objects #113

@tim-janik

Description

@tim-janik

Hi @pmed.

After more than 2 years, I'm still dragging along an important v8pp patch for heap-allocated temporary objects in my fork (in fact it's the only reason I still need to keep my own fork).

See, I have a large number of auto generated C++ functions (from IDL), some of which return temporary objects, and a large number of corresponding auto generated .set ("accessor", &ObjectType::accessor) method registrations.

I'd really like to find a way to upstream the possibility of automatically copying return values that are temporary objects onto the heap, so they can be passed on to V8. My patch essentially adds a one-liner to convert<T>::to_v8(), that does import_external (new Class (value)).
Since you didn't seem to like to take the patch in #39 (comment), I'm trying to find another way:

  1. I need to avoid changing all my auto-generated C++ functions (or to manually sort them apart for ones that return a temporary class and those that don't).

  2. I need to avoid changing hand-picked .set ("accessor", &ObjectType::accessor) statements. I could change all of them easily though, if that helped...

So I'd like to have your feedback on what could work:

  • Would a variant of .set() be acceptable, e.g. .xset ("accessor", &ObjectType::accessor) where xset() works exactly like set() for all types but additionally copies temporary return values instead of just throwing "failed to wrap C++ object"?

  • Or, would my patch be acceptable, if convert::to_v8() is special cased, so it only creates a heap copy if std::is_copy_constructible<T>::value or if std::is_move_constructible<T>::value?

  • Or, since you mentioned in Question: function that returns object by value #39 that you wanted some explicit user involvement to enable the copies, would a define like V8PP_AUTO_COPY_TEMPORARIES (defaulting to false) help to accept and activate the patch?

  • Are there any other ways I'm missing?

Here's the latest version of my patch (against v1.6.0): tim-janik@f272053

Here's the original patch (against v1.4.1): tim-janik@cda26b6

PS: FWIW, I'd consider #39 essentially answered and closable. This issue in contrast is about actually merging functionality that seems to be useful to several downstream projects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions