diff --git a/.travis.yml b/.travis.yml index fb406331..a5f21f67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,10 @@ env: - TRAVIS_NODE_VERSION="12" - TRAVIS_NODE_VERSION="13" - TRAVIS_NODE_VERSION="14" + - TRAVIS_NODE_VERSION="15" + - TRAVIS_NODE_VERSION="16" + - TRAVIS_NODE_VERSION="17" + - TRAVIS_NODE_VERSION="18" - TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="2.0.18" - TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="3.1.13" - TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="4.2.12" diff --git a/CHANGELOG.md b/CHANGELOG.md index 44858c70..d82f56fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ # NAN ChangeLog -**Version 2.14.1: current Node 14.0.0, Node 0.12: 0.12.18, Node 0.10: 0.10.48, iojs: 3.3.1** +**Version 2.16.0: current Node 18.2.0, Node 0.12: 0.12.18, Node 0.10: 0.10.48, iojs: 3.3.1** + +### 2.16.0 May 25 2022 + + - Feature: Add support for Node 18 (#937) 16fa32231e2ccd89d2804b3f765319128b20c4ac + +### 2.15.0 Aug 4 2021 + + - Feature: add ScriptOrigin (#918) d09debf9eeedcb7ca4073e84ffe5fbb455ecb709 + +### 2.14.2 Oct 13 2020 + + - Bugfix: fix gcc 8 function cast warning (#899) 35f0fab205574b2cbda04e6347c8b2db755e124f ### 2.14.1 Apr 21 2020 diff --git a/LICENSE.md b/LICENSE.md index dddd13d5..2d33043d 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,10 +1,6 @@ The MIT License (MIT) -===================== -Copyright (c) 2018 NAN contributors ------------------------------------ - -*NAN contributors listed at * +Copyright (c) 2018 [NAN contributors]() Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/Makefile b/Makefile index ce1cfdad..4042443f 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ LINT_SOURCES = \ nan_persistent_12_inl.h \ nan_persistent_pre_12_inl.h \ nan_private.h \ + nan_scriptorigin.h \ nan_string_bytes.h \ nan_weak.h \ test/cpp/accessors.cpp \ @@ -111,5 +112,6 @@ $(ADDONS): nan.h nan_new.h nan_implementation_pre_12_inl.h nan_implementation_12 nan_define_own_property_helper.h \ nan_json.h nan_maybe_43_inl.h nan_maybe_pre_43_inl.h \ nan_persistent_12_inl.h nan_persistent_pre_12_inl.h nan_private.h \ - nan_weak.h nan_string_bytes.h test/binding.gyp $(SOURCES) + nan_weak.h nan_scriptorigin.h nan_string_bytes.h \ + test/binding.gyp $(SOURCES) cd test/ && ../node_modules/.bin/node-gyp rebuild diff --git a/README.md b/README.md index 9b5f38ab..0913333f 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ Native Abstractions for Node.js =============================== -**A header file filled with macro and utility goodness for making add-on development for Node.js easier across versions 0.8, 0.10, 0.12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 and 14.** +**A header file filled with macro and utility goodness for making add-on development for Node.js easier across versions 0.8, 0.10, 0.12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 and 18.** -***Current version: 2.14.1*** +***Current version: 2.16.0*** *(See [CHANGELOG.md](https://github.com/nodejs/nan/blob/master/CHANGELOG.md) for complete ChangeLog)* [![NPM](https://nodei.co/npm/nan.png?downloads=true&downloadRank=true)](https://nodei.co/npm/nan/) [![NPM](https://nodei.co/npm-dl/nan.png?months=6&height=3)](https://nodei.co/npm/nan/) -[![Build Status](https://api.travis-ci.org/nodejs/nan.svg?branch=master)](https://travis-ci.org/nodejs/nan) +[![Build Status](https://api.travis-ci.com/nodejs/nan.svg?branch=master)](https://travis-ci.com/nodejs/nan) [![Build status](https://ci.appveyor.com/api/projects/status/kh73pbm9dsju7fgh)](https://ci.appveyor.com/project/RodVagg/nan) Thanks to the crazy changes in V8 (and some in Node core), keeping native addons compiling happily across versions, particularly 0.10 to 0.12 to 4.0, is a minor nightmare. The goal of this project is to store all logic necessary to develop native Node.js addons without having to inspect `NODE_MODULE_VERSION` and get yourself into a macro-tangle. @@ -205,15 +205,16 @@ The `Nan::MaybeLocal` and `Nan::Maybe` types are monads that encapsulate `v8::Lo ### Script -NAN provides a `v8::Script` helpers as the API has changed over the supported versions of V8. +NAN provides `v8::Script` helpers as the API has changed over the supported versions of V8. - Nan::CompileScript() - Nan::RunScript() + - Nan::ScriptOrigin ### JSON -The _JSON_ object provides the c++ versions of the methods offered by the `JSON` object in javascript. V8 exposes these methods via the `v8::JSON` object. +The _JSON_ object provides the C++ versions of the methods offered by the `JSON` object in javascript. V8 exposes these methods via the `v8::JSON` object. - Nan::JSON.Parse - Nan::JSON.Stringify diff --git a/appveyor.yml b/appveyor.yml index 1f2b26ed..9d37ae0c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,7 +4,6 @@ environment: matrix: # node.js - - nodejs_version: "0.8" - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" @@ -18,12 +17,15 @@ environment: - nodejs_version: "12" - nodejs_version: "13" - nodejs_version: "14" + - nodejs_version: "15" + - nodejs_version: "16" + - nodejs_version: "17" + - nodejs_version: "18" # Install scripts. (runs after repo cloning) install: # Get the latest stable version of Node 0.STABLE.latest - - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) - - IF %nodejs_version% EQU 0.8 npm config set strict-ssl false + - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) x64 - IF %nodejs_version% LSS 4 npm -g install npm@2 - IF %nodejs_version% EQU 5 npm -g install npm@3 - set PATH=%APPDATA%\npm;%PATH% diff --git a/doc/json.md b/doc/json.md index d1425978..55beb262 100644 --- a/doc/json.md +++ b/doc/json.md @@ -1,6 +1,6 @@ ## JSON -The _JSON_ object provides the c++ versions of the methods offered by the `JSON` object in javascript. V8 exposes these methods via the `v8::JSON` object. +The _JSON_ object provides the C++ versions of the methods offered by the `JSON` object in javascript. V8 exposes these methods via the `v8::JSON` object. - Nan::JSON.Parse - Nan::JSON.Stringify diff --git a/doc/script.md b/doc/script.md index 213320ad..301c1b3d 100644 --- a/doc/script.md +++ b/doc/script.md @@ -1,9 +1,10 @@ ## Script -NAN provides a `v8::Script` helpers as the API has changed over the supported versions of V8. +NAN provides `v8::Script` helpers as the API has changed over the supported versions of V8. - Nan::CompileScript() - Nan::RunScript() + - Nan::ScriptOrigin @@ -34,5 +35,24 @@ Signature: ```c++ Nan::MaybeLocal Nan::RunScript(v8::Local script) -Nan::MaybeLocal Nan::RunScript(v8::Local script) +Nan::MaybeLocal Nan::RunScript(v8::Local script) +``` + + +### Nan::ScriptOrigin + +A class transparently extending [`v8::ScriptOrigin`](https://v8docs.nodesource.com/node-16.0/db/d84/classv8_1_1_script_origin.html#pub-methods) +to provide backwards compatibility. Only the listed methods are guaranteed to +be available on all versions of Node. + +Declaration: + +```c++ +class Nan::ScriptOrigin : public v8::ScriptOrigin { + public: + ScriptOrigin(v8::Local name, v8::Local line = v8::Local(), v8::Local column = v8::Local()) + v8::Local ResourceName() const; + v8::Local ResourceLineOffset() const; + v8::Local ResourceColumnOffset() const; +} ``` diff --git a/examples/async_pi_estimate/addon.cc b/examples/async_pi_estimate/addon.cc index f36f7ffd..2772b1b5 100644 --- a/examples/async_pi_estimate/addon.cc +++ b/examples/async_pi_estimate/addon.cc @@ -11,7 +11,6 @@ #include "async.h" // NOLINT(build/include) using v8::FunctionTemplate; -using v8::Handle; using v8::Object; using v8::String; using Nan::GetFunction; diff --git a/examples/async_pi_estimate/sync.cc b/examples/async_pi_estimate/sync.cc index f27895d0..1ecef9bb 100644 --- a/examples/async_pi_estimate/sync.cc +++ b/examples/async_pi_estimate/sync.cc @@ -13,7 +13,7 @@ // Simple synchronous access to the `Estimate()` function NAN_METHOD(CalculateSync) { // expect a number as the first argument - int points = info[0]->Uint32Value(); + int points = Nan::To(info[0]).FromJust(); double est = Estimate(points); info.GetReturnValue().Set(est); diff --git a/nan.h b/nan.h index 648e6e26..9e7c59e4 100644 --- a/nan.h +++ b/nan.h @@ -13,7 +13,7 @@ * * MIT License * - * Version 2.14.1: current Node 14.0.0, Node 0.12: 0.12.18, Node 0.10: 0.10.48, iojs: 3.3.1 + * Version 2.16.0: current Node 18.2.0, Node 0.12: 0.12.18, Node 0.10: 0.10.48, iojs: 3.3.1 * * See https://github.com/nodejs/nan for the latest update to this file **********************************************************************************/ @@ -41,6 +41,10 @@ #define NODE_12_0_MODULE_VERSION 72 #define NODE_13_0_MODULE_VERSION 79 #define NODE_14_0_MODULE_VERSION 83 +#define NODE_15_0_MODULE_VERSION 88 +#define NODE_16_0_MODULE_VERSION 93 +#define NODE_17_0_MODULE_VERSION 102 +#define NODE_18_0_MODULE_VERSION 108 #ifdef _MSC_VER # define NAN_HAS_CPLUSPLUS_11 (_MSC_VER >= 1800) @@ -2280,18 +2284,25 @@ inline void AsyncExecute (uv_work_t* req) { worker->Execute(); } -inline void AsyncExecuteComplete (uv_work_t* req) { +/* uv_after_work_cb has 1 argument before node-v0.9.4 and + * 2 arguments since node-v0.9.4 + * https://github.com/libuv/libuv/commit/92fb84b751e18f032c02609467f44bfe927b80c5 + */ +inline void AsyncExecuteComplete(uv_work_t *req) { AsyncWorker* worker = static_cast(req->data); worker->WorkComplete(); worker->Destroy(); } +inline void AsyncExecuteComplete (uv_work_t* req, int status) { + AsyncExecuteComplete(req); +} inline void AsyncQueueWorker (AsyncWorker* worker) { uv_queue_work( GetCurrentEventLoop() , &worker->request , AsyncExecute - , reinterpret_cast(AsyncExecuteComplete) + , AsyncExecuteComplete ); } @@ -2539,7 +2550,10 @@ inline void SetAccessor( , obj , settings , attribute - , signature); +#if (NODE_MODULE_VERSION < NODE_18_0_MODULE_VERSION) + , signature +#endif + ); } inline bool SetAccessor( @@ -2886,6 +2900,10 @@ MakeMaybe(MaybeMaybe v) { #include "nan_json.h" // NOLINT(build/include) +//=== ScriptOrigin ============================================================= + +#include "nan_scriptorigin.h" // NOLINT(build/include) + } // end of namespace Nan #endif // NAN_H_ diff --git a/nan_scriptorigin.h b/nan_scriptorigin.h new file mode 100644 index 00000000..ce79cdf8 --- /dev/null +++ b/nan_scriptorigin.h @@ -0,0 +1,76 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2021 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_SCRIPTORIGIN_H_ +#define NAN_SCRIPTORIGIN_H_ + +class ScriptOrigin : public v8::ScriptOrigin { + public: +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 9 || \ + (V8_MAJOR_VERSION == 9 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 0\ + || (V8_MINOR_VERSION == 0 && defined(V8_BUILD_NUMBER) \ + && V8_BUILD_NUMBER >= 1))))) + explicit ScriptOrigin(v8::Local name) : + v8::ScriptOrigin(v8::Isolate::GetCurrent(), name) {} + + ScriptOrigin(v8::Local name + , v8::Local line) : + v8::ScriptOrigin(v8::Isolate::GetCurrent() + , name + , To(line).FromMaybe(0)) {} + + ScriptOrigin(v8::Local name + , v8::Local line + , v8::Local column) : + v8::ScriptOrigin(v8::Isolate::GetCurrent() + , name + , To(line).FromMaybe(0) + , To(column).FromMaybe(0)) {} +#elif defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 8 || \ + (V8_MAJOR_VERSION == 8 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 9\ + || (V8_MINOR_VERSION == 9 && defined(V8_BUILD_NUMBER) \ + && V8_BUILD_NUMBER >= 45))))) + explicit ScriptOrigin(v8::Local name) : v8::ScriptOrigin(name) {} + + ScriptOrigin(v8::Local name + , v8::Local line) : + v8::ScriptOrigin(name, To(line).FromMaybe(0)) {} + + ScriptOrigin(v8::Local name + , v8::Local line + , v8::Local column) : + v8::ScriptOrigin(name + , To(line).FromMaybe(0) + , To(column).FromMaybe(0)) {} +#else + explicit ScriptOrigin(v8::Local name) : v8::ScriptOrigin(name) {} + + ScriptOrigin(v8::Local name + , v8::Local line) : v8::ScriptOrigin(name, line) {} + + ScriptOrigin(v8::Local name + , v8::Local line + , v8::Local column) : + v8::ScriptOrigin(name, line, column) {} +#endif + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 8 || \ + (V8_MAJOR_VERSION == 8 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 9\ + || (V8_MINOR_VERSION == 9 && defined(V8_BUILD_NUMBER) \ + && V8_BUILD_NUMBER >= 45))))) + v8::Local ResourceLineOffset() const { + return New(LineOffset()); + } + + v8::Local ResourceColumnOffset() const { + return New(ColumnOffset()); + } +#endif +}; + +#endif // NAN_SCRIPTORIGIN_H_ diff --git a/package.json b/package.json index c7182c0b..d7ca99bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nan", - "version": "2.14.1", + "version": "2.16.0", "description": "Native Abstractions for Node.js: C++ header for Node 0.8 -> 14 compatibility", "main": "include_dirs.js", "repository": { @@ -28,7 +28,7 @@ "commander": "^2.8.1", "glob": "^5.0.14", "request": "=2.81.0", - "node-gyp": "~3.6.2", + "node-gyp": "~8.4.1", "readable-stream": "^2.1.4", "tap": "~0.7.1", "xtend": "~4.0.0" diff --git a/test/cpp/nannew.cpp b/test/cpp/nannew.cpp index a489f940..e36ce4f8 100644 --- a/test/cpp/nannew.cpp +++ b/test/cpp/nannew.cpp @@ -246,7 +246,7 @@ NAN_METHOD(testScript) { t.plan(6); - ScriptOrigin origin(New("foo").ToLocalChecked(), New(5)); + Nan::ScriptOrigin origin(New("foo").ToLocalChecked(), New(5)); t.ok(_( assertType