Skip to content

FunctionReference is missing cargs overloads for Call and MakeCallback #320

Closed

Description

@Fishrock123

https://nodejs.github.io/node-addon-api/class_napi_1_1_function_reference.html

FunctionReference doesn't have these but Function does. Seems strange. cargs are easier for not very C++ affluent people like me to use.

Activity

  1. changed the title [-]FunctionReference is missing a cargs overloads for Call and MakeCallback[/-] [+]FunctionReference is missing cargs overloads for Call and MakeCallback[/+] on Aug 23, 2018
  2. NickNaso commented on Aug 24, 2018

    @NickNaso
    Member

    @gabrielschulhof @mhdawson I think that we can add the method as proposed by @Fishrock123. In the specific we should add these in napi.h :

    Napi::Value Call(napi_value recv, size_t argc, const napi_value* args) const;
    
    Napi::Value MakeCallback(napi_value recv, size_t argc, const napi_value* args) const;

    and these on napi-inl.h:

    inline Napi::Value FunctionReference::Call(
        napi_value recv, size_t argc, const napi_value* args) const {
      EscapableHandleScope scope(_env);
      Napi::Value result = Value().Call(recv, argc, args);
      if (scope.Env().IsExceptionPending()) {
        return Value();
      }
      return scope.Escape(result);
    }
    
    inline Napi::Value FunctionReference::MakeCallback(
        napi_value recv, size_t argc, const napi_value* args) const {
      EscapableHandleScope scope(_env);
      Napi::Value result = Value().MakeCallback(recv, argc, args);
      if (scope.Env().IsExceptionPending()) {
        return Value();
      }
      return scope.Escape(result);
    }

    if you agree I can work on it and at the same time start to create tests about FunctionReference.

  3. mhdawson commented on Aug 29, 2018

    @mhdawson
    Member

    Adding those make sense to me. Makes it more consistent with the methods we have on Function.

  4. self-assigned this
    on Aug 29, 2018
  5. NickNaso commented on Aug 29, 2018

    @NickNaso
    Member

    OK I will take this.

  6. NickNaso commented on Sep 20, 2018

    @NickNaso
    Member

    I'm closing the issue because the requested feature is landed with #344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions