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

n-api: add napi_define_subclass #36148

Closed

Commits on Nov 17, 2020

  1. n-api: add napi_define_subclass

    Add the ability to define a subclass of a JS class by generating a JS
    snippet that uses the `extends` syntax and calls the native bindings
    which are passed in as parameters to the generated function responsible
    for defining the subclass.
    
    An example of a generated JS snippet might be:
    
    ```js
    (function(parent, ctor, getSuperParams, prop0, prop1) {
      'use strict';
      class NativeSubclass extends parent {
        constructor() {
          super(...getSuperParams.apply(null, arguments));
          ctor.apply(this, arguments);
        }
        subMethod() {
          if (!(this instanceof NativeSubclass))
            throw new Error('Illegal invocation');
          return prop0.apply(this, arguments);
        }
        chainableMethod() {
          if (!(this instanceof NativeSubclass))
            throw new Error('Illegal invocation');
          return prop1.apply(this, arguments);
        }
      }
    
      return NativeSubclass;
    })
    ```
    
    where `ctor`, `getSuperParams`, `prop0`, and `prop1` are native
    functions supplied to `napi_define_subclass`.
    
    Signed-off-by: Gabriel Schulhof <[email protected]>
    Refs: nodejs/node-addon-api#229
    Gabriel Schulhof committed Nov 17, 2020
    Configuration menu
    Copy the full SHA
    e3db130 View commit details
    Browse the repository at this point in the history
  2. fixup! make key always a prop

    Gabriel Schulhof committed Nov 17, 2020
    Configuration menu
    Copy the full SHA
    6c3a53d View commit details
    Browse the repository at this point in the history
  3. fixup! add benchmark

    Gabriel Schulhof committed Nov 17, 2020
    Configuration menu
    Copy the full SHA
    b0a5c47 View commit details
    Browse the repository at this point in the history
  4. fixup! add proto tests

    Gabriel Schulhof committed Nov 17, 2020
    Configuration menu
    Copy the full SHA
    a5c8e6c View commit details
    Browse the repository at this point in the history
  5. fixup! heed the linter

    Gabriel Schulhof committed Nov 17, 2020
    Configuration menu
    Copy the full SHA
    9f1c615 View commit details
    Browse the repository at this point in the history
  6. fixup! PushArg always needs a napi_value

    Gabriel Schulhof committed Nov 17, 2020
    Configuration menu
    Copy the full SHA
    d28a5ae View commit details
    Browse the repository at this point in the history