Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 602: Add template methods to ObjectWrap #604

Closed
wants to merge 2 commits into from
Closed

Issue 602: Add template methods to ObjectWrap #604

wants to merge 2 commits into from

Commits on Nov 22, 2019

  1. Issue 602: Add template methods to ObjectWrap

    ObjectWrap<T> was enhanced to support template methods for
    defining properties and methods of JS class. Now C++ methods and
    functions may be passed as template parameters for
    ObjectWrap<T>::InstanceMethod, ObjectWrap<T>::StaticAccessor, etc.
    
    There are several benefits:
    
      - no need to allocate extra memory for passing C++ function
        napi callback and use add_finalizer() to free memory;
      - a compiler can see whole chain of calls up to napi callback
        that may allow better optimisation.
    
    Some examples:
    
    ```cpp
    // Method
    InstanceMethod<&MyClass::method>("method");
    
    // Read-write property
    InstanceAccessor<&MyClass::get, &MyClass::set>("rw_prop");
    
    // Read-only property
    InstanceAccessor<&MyClass::get>("ro_prop");
    ```
    
    Closes #602.
    dmitryash committed Nov 22, 2019
    Configuration menu
    Copy the full SHA
    b88e797 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    3ff5c03 View commit details
    Browse the repository at this point in the history