Repository: nodejs/node-addon-api

Issue #142: node-addon-api fails to build against node 4.x
Created: 2017-09-25T09:26:06Z
$ nvm use 4
$ npm test

Observe build failure.

Duplicate issue #147: 1.0.0 compiler errors
Created: 2017-09-28T16:22:56Z
Hello, just updated to the 1.0 version. I am getting some errors though that I am not sure how should be handled.
[0/1] Re-running CMake...
-- Boost found: 1.64.0 /home/skyslope/CMakeProjects/npdf/boost-cmake/boost/boost_1_64_0
-- Boost found: 1.64.0 /home/skyslope/CMakeProjects/npdf/boost-cmake/boost/boost_1_64_0
-- Found the following ICU libraries:
--   uc (required)
--   dt (required)
--   i18n (required)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/skyslope/CMakeProjects/npdf/build
[2/17] Building CXX object CMakeFiles/npdf.dir/src/NObject.cc.o
FAILED: CMakeFiles/npdf.dir/src/NObject.cc.o 
/usr/bin/clang++  -DBOOST_ALL_NO_LIB=1 -DBOOST_DISABLE_ASSERT -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_THREAD_PROVIDES_EXECUTORS -DBOOST_THREAD_USES_CHRONO -DBOOST_THREAD_VERSION=4 -Dnpdf_EXPORTS -I/home/skyslope/.cmake-js/node-x64/v8.4.0/include/node -I../node_modules/node-addon-api/src -I../node_modules/node-addon-api -isystem ../boost-cmake/boost/boost_1_64_0 -fPIC -O3 -DNDEBUG -fPIC   -std=gnu++1z -MD -MT CMakeFiles/npdf.dir/src/NObject.cc.o -MF CMakeFiles/npdf.dir/src/NObject.cc.o.d -o CMakeFiles/npdf.dir/src/NObject.cc.o -c ../src/NObject.cc
In file included from ../src/NObject.cc:1:
In file included from ../src/NObject.h:5:
In file included from ../src/Dictionary.h:6:
In file included from ../node_modules/node-addon-api/napi.h:1454:
../node_modules/node-addon-api/napi-inl.h:1207:20: error: use of undeclared identifier 'NAPI_AUTO_LENGTH'
    env, utf8name, NAPI_AUTO_LENGTH, CbData::Wrapper, callbackData, &value);
                   ^
../node_modules/node-addon-api/napi-inl.h:1271:24: error: no matching function for call to 'napi_make_callback'
  napi_status status = napi_make_callback(
                       ^~~~~~~~~~~~~~~~~~
/home/skyslope/.cmake-js/node-x64/v8.4.0/include/node/node_api.h:324:25: note: candidate function not viable: requires 6 arguments, but 7 were provided
NAPI_EXTERN napi_status napi_make_callback(napi_env env,


this error just repeats over and over for each objectwrapper
Here is the class that the above is erroring out with
#include "Dictionary.h"
#include "ErrorHandler.h"
#include <napi.h>
#include <podofo/podofo.h>

using namespace Napi;
using namespace PoDoFo;

class NObject : public ObjectWrap<NObject>
{
public:
  explicit NObject(const CallbackInfo&);
  ~NObject() {}
  static Napi::FunctionReference constructor;
  static void Initialize(Napi::Env& env, Napi::Object& target)
  {
    HandleScope scope(env);
    Function ctor = DefineClass(
      env,
      "Object",
      { InstanceAccessor("stream", &NObject::GetStream, nullptr),
        InstanceMethod("getDictionary", &NObject::GetDictionary),
        InstanceMethod("setDictionary", &NObject::SetDictionary),
        InstanceAccessor("type", &NObject::GetDataType, nullptr),
        InstanceAccessor("length", &NObject::GetObjectLength, nullptr) });
    constructor = Napi::Persistent(ctor);
    constructor.SuppressDestruct();
    target.Set("Object", constructor);
  }
  Napi::Value GetStream(const CallbackInfo&);
  Napi::Value GetDictionary(const CallbackInfo&);
  void SetDictionary(const CallbackInfo&);
  Napi::Value GetObjectLength(const CallbackInfo&);
  Napi::Value GetDataType(const CallbackInfo&);
  const PdfObject GetObject() { return obj; }

private:
  PdfObject obj = *new PdfObject();
};

sing namespace Napi;
using namespace PoDoFo;
using namespace std;

class Dictionary : public ObjectWrap<Dictionary>
{
public:
  explicit Dictionary(const CallbackInfo&);
  ~Dictionary() {}
  static FunctionReference constructor;
  static void Initialize(Napi::Env& env, Napi::Object& target)
  {
    HandleScope scope(env);
    Function ctor = DefineClass(
      env,
      "Dictionary",
      { InstanceMethod("getKey", &Dictionary::GetKey),
        InstanceMethod("getKeys", &Dictionary::GetKeys),
        InstanceMethod("hasKey", &Dictionary::HasKey),
        InstanceMethod("addKey", &Dictionary::AddKey),
        InstanceMethod("removeKey", &Dictionary::RemoveKey),
        InstanceAccessor(
          "immutable", &Dictionary::GetImmutable, &Dictionary::SetImmutable),
        InstanceMethod("clear", &Dictionary::Clear) });

    constructor = Napi::Persistent(ctor);
    constructor.SuppressDestruct();
    target.Set("Dictionary", constructor);
    //    target.Set("Dictionary", ctor);
  }

  void AddKey(const CallbackInfo&);
  Napi::Value GetKey(const CallbackInfo&);
  Napi::Value GetKeys(const CallbackInfo&);
  Napi::Value RemoveKey(const CallbackInfo&);
  Napi::Value HasKey(const CallbackInfo&);
  Napi::Value Clear(const CallbackInfo&);
  void SetImmutable(const CallbackInfo&, const Napi::Value&);
  Napi::Value GetImmutable(const CallbackInfo&);

private:
  //    PdfDictionary* _dict;
  const PdfObject* _obj;
  PdfDictionary dict = PdfDictionary();
  //  PdfDictionary _dict = *new PdfDictionary();
};

Thanks, and thanks for taking the time to write this, it has been an overall very  pleasant experience for writing native node addons with.

Closing comment (2017-10-02T22:55:21Z): @mhdawson yes, this can be closed, as @jasongin mentioned above my concern is tracked in #142.