Skip to content

Nan::SetAccessor() deprecation warning with V8 10.1 and nan 2.15.0 #936

Closed

Description

@mscdex
../../../../node_modules/nan/nan.h: In function ‘void Nan::SetAccessor(v8::Local<v8::ObjectTemplate>, v8::Local<v8::String>, Nan::GetterCallback, Nan::SetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, Nan::imp::Sig)’:
../../../../node_modules/nan/nan.h:2551:16: warning: ‘void v8::ObjectTemplate::SetAccessor(v8::Local<v8::Name>, v8::AccessorNameGetterCallback, v8::AccessorNameSetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, v8::Local<v8::AccessorSignature>, v8::SideEffectType, v8::SideEffectType)’ is deprecated: Do signature check in accessor [-Wdeprecated-declarations]
 2551 |     , signature);
      |                ^
In file included from /home/foo/.cache/node-gyp/18.0.0/include/node/v8-function.h:15,
                 from /home/foo/.cache/node-gyp/18.0.0/include/node/v8.h:33,
                 from /home/foo/.cache/node-gyp/18.0.0/include/node/node.h:63,
                 from ../src/binding.cc:13:
/home/foo/.cache/node-gyp/18.0.0/include/node/v8-template.h:838:8: note: declared here
  838 |   void SetAccessor(
      |        ^~~~~~~~~~~

Activity

  1. changed the title [-]`Nan::SetAccessor()` warning with V8 10.1 and nan 2.15.0[/-] [+]`Nan::SetAccessor()` deprecation warning with V8 10.1 and nan 2.15.0[/+] on Apr 20, 2022
  2. mkrufky commented on Apr 24, 2022

    @mkrufky
    Collaborator

    @mscdex Can you confirm that this is resolved in the main branch?

  3. alejandroclaro commented on Oct 7, 2022

    @alejandroclaro

    There is now a similar problem with Electron >= 20

    see: electron/electron#35193

  4. danielweck commented on Feb 21, 2024

    @danielweck

    Electron29 / NodeJS 20 breakage:

    ../node_modules/nan/nan.h:2548:8: error: no matching member function for call to 'SetAccessor'
      tpl->SetAccessor(
      ~~~~~^~~~~~~~~~~
    /Users/danielweck/Library/Caches/node-gyp/29.0.0/include/node/v8-template.h:806:8: note: candidate function not viable: no known conversion from 'v8::AccessControl' to 'PropertyAttribute' for 5th argument
      void SetAccessor(
           ^
    /Users/danielweck/Library/Caches/node-gyp/29.0.0/include/node/v8-template.h:800:8: note: candidate function not viable: no known conversion from 'imp::NativeGetter' (aka 'void (*)(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value> &)') to 'AccessorGetterCallback' (aka 'void (*)(Local<String>, const PropertyCallbackInfo<Value> &)') for 2nd argument
      void SetAccessor(
    
  5. mscdex commented on Feb 21, 2024

    @mscdex
    ContributorAuthor

    Looks like this was fixed in 2.17.0.

  6. danielweck commented on Feb 21, 2024

    @danielweck

    Looks like this was fixed in 2.17.0.

    I am getting a fatal compiler error with NAN 2.18.0 and Electron 29 / NodeJS 20, see my message above #936 (comment)

    My current workaround is to comment out all the setAccessor functions from the postinstall script in my package.json (my project doesn't use these functions):

    nan/nan.h

    Lines 2514 to 2655 in e14bdcd

    NAN_DEPRECATED inline void SetAccessor(
    v8::Local<v8::ObjectTemplate> tpl
    , v8::Local<v8::String> name
    , GetterCallback getter
    , SetterCallback setter
    , v8::Local<v8::Value> data
    , v8::AccessControl settings
    , v8::PropertyAttribute attribute
    , imp::Sig signature) {
    HandleScope scope;
    imp::NativeGetter getter_ =
    imp::GetterCallbackWrapper;
    imp::NativeSetter setter_ =
    setter ? imp::SetterCallbackWrapper : 0;
    v8::Local<v8::ObjectTemplate> otpl = New<v8::ObjectTemplate>();
    otpl->SetInternalFieldCount(imp::kAccessorFieldCount);
    v8::Local<v8::Object> obj = NewInstance(otpl).ToLocalChecked();
    obj->SetInternalField(
    imp::kGetterIndex
    , New<v8::External>(reinterpret_cast<void *>(getter)));
    if (setter != 0) {
    obj->SetInternalField(
    imp::kSetterIndex
    , New<v8::External>(reinterpret_cast<void *>(setter)));
    }
    if (!data.IsEmpty()) {
    obj->SetInternalField(imp::kDataIndex, data);
    }
    tpl->SetAccessor(
    name
    , getter_
    , setter_
    , obj
    , settings
    , attribute
    #if (NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION)
    , signature
    #endif
    );
    }
    inline void SetAccessor(
    v8::Local<v8::ObjectTemplate> tpl
    , v8::Local<v8::String> name
    , GetterCallback getter
    , SetterCallback setter = 0
    , v8::Local<v8::Value> data = v8::Local<v8::Value>()
    , v8::AccessControl settings = v8::DEFAULT
    , v8::PropertyAttribute attribute = v8::None) {
    HandleScope scope;
    imp::NativeGetter getter_ =
    imp::GetterCallbackWrapper;
    imp::NativeSetter setter_ =
    setter ? imp::SetterCallbackWrapper : 0;
    v8::Local<v8::ObjectTemplate> otpl = New<v8::ObjectTemplate>();
    otpl->SetInternalFieldCount(imp::kAccessorFieldCount);
    v8::Local<v8::Object> obj = NewInstance(otpl).ToLocalChecked();
    obj->SetInternalField(
    imp::kGetterIndex
    , New<v8::External>(reinterpret_cast<void *>(getter)));
    if (setter != 0) {
    obj->SetInternalField(
    imp::kSetterIndex
    , New<v8::External>(reinterpret_cast<void *>(setter)));
    }
    if (!data.IsEmpty()) {
    obj->SetInternalField(imp::kDataIndex, data);
    }
    tpl->SetAccessor(
    name
    , getter_
    , setter_
    , obj
    , settings
    , attribute
    );
    }
    inline bool SetAccessor(
    v8::Local<v8::Object> obj
    , v8::Local<v8::String> name
    , GetterCallback getter
    , SetterCallback setter = 0
    , v8::Local<v8::Value> data = v8::Local<v8::Value>()
    , v8::AccessControl settings = v8::DEFAULT
    , v8::PropertyAttribute attribute = v8::None) {
    HandleScope scope;
    imp::NativeGetter getter_ =
    imp::GetterCallbackWrapper;
    imp::NativeSetter setter_ =
    setter ? imp::SetterCallbackWrapper : 0;
    v8::Local<v8::ObjectTemplate> otpl = New<v8::ObjectTemplate>();
    otpl->SetInternalFieldCount(imp::kAccessorFieldCount);
    v8::Local<v8::Object> dataobj = NewInstance(otpl).ToLocalChecked();
    dataobj->SetInternalField(
    imp::kGetterIndex
    , New<v8::External>(reinterpret_cast<void *>(getter)));
    if (!data.IsEmpty()) {
    dataobj->SetInternalField(imp::kDataIndex, data);
    }
    if (setter) {
    dataobj->SetInternalField(
    imp::kSetterIndex
    , New<v8::External>(reinterpret_cast<void *>(setter)));
    }
    #if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION)
    return obj->SetAccessor(
    GetCurrentContext()
    , name
    , getter_
    , setter_
    , dataobj
    , settings
    , attribute).FromMaybe(false);
    #else
    return obj->SetAccessor(
    name
    , getter_
    , setter_
    , dataobj
    , settings
    , attribute);
    #endif
    }

  7. danielweck commented on Feb 21, 2024

    @danielweck

    PS: a while back somebody ended-up forking NAN to remove breaking function signatures:

    electron/electron#35193 (comment)

    I personally use the official NAN NPM package and I sed into nan.h to inject comment markers /* + */.

  8. j-stahl commented on Feb 22, 2024

    @j-stahl

    I can confirm this issue persists. It's not just a warning. It throws an error now, as @danielweck mentioned.
    Create an empty folder and create this package.json:

    {
      "name": "testproject",
      "version": "1.0.0",
      "description": "Testing electron 29.0",
      "main": "main.js",
      "scripts": {
        "postinstall": "electron-builder install-app-deps"
      },
      "author": "j-stahl",
      "license": "MIT",
      "devDependencies": {
        "@electron/notarize": "^2.3.0",
        "electron": "^29.0.1",
        "electron-builder": "^24.12.0"
      },
      "dependencies": {
        "@electron/asar": "^3.2.8",
        "electron-store": "^8.1.0",
        "electron-updater": "^6.1.8",
        "node-ssh": "^13.1.0",
        "simple-ssh": "^1.1.1"
      }
    }
    

    Run npm install and play around with the electron version. Electron < 29 will succeed.

    By the way: I took more than one day to figure out what is happening here. I am not pretty familar with all those dependency stuff.

  9. ajgassner commented on Feb 23, 2024

    @ajgassner

    I can confirm, I have the same issue. Nan is not compatible with Electron 29 / Node 20. As a temporary workaround you can use following in your package.json:

      "resolutions": {
        "nan": "github:ajgassner/nan#electron-29-workaround"
      }
    

    Please note I just commented all the SetAccessor things as a dirty quick fix as I'm not familar with the V8 API.

    See #966

  10. JasonYeMSFT commented on Mar 1, 2024

    @JasonYeMSFT

    Could this be a breaking change in node-gyp's header file?

    In Electron 28.2.2's v8-template.h (you can find it at your_user_directory/.electron-gyp/Library/Caches/node-gyp/28.2.2/include/node)

      void SetAccessor(
          Local<String> name, AccessorGetterCallback getter,
          AccessorSetterCallback setter = nullptr,
          Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
          PropertyAttribute attribute = None,
          SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
          SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
      void SetAccessor(
          Local<Name> name, AccessorNameGetterCallback getter,
          AccessorNameSetterCallback setter = nullptr,
          Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
          PropertyAttribute attribute = None,
          SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
          SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
    

    In Electron 29.1.0's v8-template.h

      void SetAccessor(
          Local<String> name, AccessorGetterCallback getter,
          AccessorSetterCallback setter = nullptr,
          Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
          SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
          SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
      void SetAccessor(
          Local<Name> name, AccessorNameGetterCallback getter,
          AccessorNameSetterCallback setter = nullptr,
          Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
          SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
          SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
    

    It seems PropertyAttribute and AccessControl are not compatible given the error details:

    no known conversion from 'v8::AccessControl' to 'PropertyAttribute' for 5th argument
    

    Probably nan needs to adjust its signature to match the new signature.

  11. JCMais commented on Dec 10, 2024

    @JCMais

    This is still happening and atm it is impossible to rebuild native addons on Electron v28

    Edit: I was able to fix it by applying this patch: #982

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions