diff --git a/.gitignore b/.gitignore index febbb5c96..341e6c09d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /node_modules /build + +# old npm versions +/npm-debug.log \ No newline at end of file diff --git a/.npmrc b/.npmrc index 43c97e719..9cf949503 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1 @@ -package-lock=false +package-lock=false \ No newline at end of file diff --git a/external-napi/node_api.h b/external-napi/node_api.h deleted file mode 100644 index 52c45f609..000000000 --- a/external-napi/node_api.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef EXTERNAL_NODE_API_H_ -#define EXTERNAL_NODE_API_H_ - -#define EXTERNAL_NAPI -#include "../src/node_api.h" - -#endif diff --git a/napi-inl.h b/napi-inl.h index b831f34c9..c5ce33d3a 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -339,11 +339,11 @@ inline bool Value::IsNumber() const { // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) inline bool Value::IsBigInt() const { return Type() == napi_bigint; } -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL inline bool Value::IsString() const { return Type() == napi_string; @@ -563,7 +563,7 @@ inline double Number::DoubleValue() const { // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) //////////////////////////////////////////////////////////////////////////////// // BigInt Class //////////////////////////////////////////////////////////////////////////////// @@ -624,7 +624,7 @@ inline void BigInt::ToWords(int* sign_bit, size_t* word_count, uint64_t* words) _env, _value, sign_bit, word_count, words); NAPI_THROW_IF_FAILED_VOID(_env, status); } -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL //////////////////////////////////////////////////////////////////////////////// // Name class diff --git a/napi.h b/napi.h index 16d09943a..edf103b48 100644 --- a/napi.h +++ b/napi.h @@ -1,6 +1,8 @@ #ifndef SRC_NAPI_H_ #define SRC_NAPI_H_ +#define NAPI_VERSION_EXPERIMENTAL 2147483647 + #include "node_api.h" #include #include @@ -54,9 +56,9 @@ namespace Napi { class Number; // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) class BigInt; -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL class String; class Object; class Array; @@ -79,10 +81,10 @@ namespace Napi { typedef TypedArrayOf Float64Array; ///< Typed-array of 64-bit floating-point values // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) typedef TypedArrayOf BigInt64Array; ///< Typed array of signed 64-bit integers typedef TypedArrayOf BigUint64Array; ///< Typed array of unsigned 64-bit integers -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL /// Defines the signature of a N-API C++ module's registration callback (init) function. typedef Object (*ModuleRegisterCallback)(Env env, Object exports); @@ -184,9 +186,9 @@ namespace Napi { bool IsNumber() const; ///< Tests if a value is a JavaScript number. // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) bool IsBigInt() const; ///< Tests if a value is a JavaScript bigint. -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL bool IsString() const; ///< Tests if a value is a JavaScript string. bool IsSymbol() const; ///< Tests if a value is a JavaScript symbol. bool IsArray() const; ///< Tests if a value is a JavaScript array. @@ -258,7 +260,7 @@ namespace Napi { // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) /// A JavaScript bigint value. class BigInt : public Value { public: @@ -297,7 +299,7 @@ namespace Napi { /// be needed to store this BigInt (i.e. the return value of `WordCount()`). void ToWords(int* sign_bit, size_t* word_count, uint64_t* words); }; -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL /// A JavaScript string or symbol value (that can be used as a property name). class Name : public Value { @@ -764,10 +766,10 @@ namespace Napi { : std::is_same::value ? napi_float64_array // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) : std::is_same::value ? napi_bigint64_array : std::is_same::value ? napi_biguint64_array -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL : unknown_array_type; } /// !endcond diff --git a/package.json b/package.json index cd313a30c..f66cb9220 100644 --- a/package.json +++ b/package.json @@ -53,8 +53,18 @@ "url": "git://github.com/nodejs/node-addon-api.git" }, "scripts": { - "pretest": "node-gyp rebuild -C test", + "clean": "cmake-js clean -d test", + "test": "node test", + "test:debug": "node test", + "test:debug:dev": "node test", + "test:release:dev": "node test", + + "pretest": "cmake-js rebuild -d test", + "pretest:debug": "cmake-js rebuild --debug -d test", + "pretest:release:dev": "cmake-js build -d test", + "pretest:debug:dev": "cmake-js build --debug -d test", + "doc": "doxygen doc/Doxyfile" }, "version": "1.6.2" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..e247e8268 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.11) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) # -fPIC flag + +# TODO: "${CMAKE_SOURCE_DIR}/../src" is unclean +set(INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES}" "${CMAKE_SOURCE_DIR}/../src" PARENT_SCOPE) + +if(NOT "${NAPI_VERSION}" STREQUAL "") + add_definitions(-DNAPI_VERSION=${NAPI_VERSION}) +endif() + +add_library(node-api STATIC node_api.cc node_internals.cc) +target_compile_options(node-api PRIVATE -DEXTERNAL_NAPI) +set(BINDING_LINK_LIBRARIES "${BINDING_LINK_LIBRARIES}" node-api PARENT_SCOPE) \ No newline at end of file diff --git a/src/node_api.cc b/src/node_api.cc index dd16016f3..3f6bc89fd 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -18,8 +18,6 @@ #include "node_api.h" #include "node_internals.h" -#define NAPI_VERSION 1 - static napi_status napi_set_last_error(napi_env env, napi_status error_code, uint32_t engine_error_code = 0, diff --git a/src/node_api.gyp b/src/node_api.gyp deleted file mode 100644 index 3de7da141..000000000 --- a/src/node_api.gyp +++ /dev/null @@ -1,21 +0,0 @@ -{ - 'targets': [ - { - 'target_name': 'nothing', - 'type': 'static_library', - 'sources': [ 'nothing.c' ] - }, - { - 'target_name': 'node-api', - 'type': 'static_library', - 'sources': [ - 'node_api.cc', - 'node_internals.cc', - ], - 'defines': [ - 'EXTERNAL_NAPI', - ], - 'cflags_cc': ['-fvisibility=hidden'] - } - ] -} diff --git a/src/nothing.c b/src/nothing.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/.gitignore b/test/.gitignore index 95464d3e6..7f133160c 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,2 +1,2 @@ -build/ -src/ +/build +/build-node-api \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 000000000..1c6ace8fc --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,135 @@ +cmake_minimum_required(VERSION 3.11) +set(CMAKE_CXX_STANDARD 11) + +project (node-addon-api) + +set(DISABLE_DEPRECATED_DEFAULT "false") + + +message("================================================================================") + +# NODE_VERSION_* +execute_process(COMMAND node -p "process.version" OUTPUT_VARIABLE NODE_VERSION) +string(STRIP "${NODE_VERSION}" NODE_VERSION) # remove new line at end +STRING(REGEX MATCH "^v([^\.]+)\.([^\.]+)\.([^\.]+)$" NODE_VERSION "${NODE_VERSION}") +set(NODE_VERSION_MAJOR ${CMAKE_MATCH_1}) +set(NODE_VERSION_MINOR ${CMAKE_MATCH_2}) +set(NODE_VERSION_PATCH ${CMAKE_MATCH_3}) +set(NODE_VERSION_SEMVER "${NODE_VERSION_MAJOR}.${NODE_VERSION_MINOR}.${NODE_VERSION_PATCH}") + +message("NODE_VERSION = ${NODE_VERSION}") +message("NODE_VERSION_SEMVER = ${NODE_VERSION_SEMVER}") +message("NODE_VERSION_MAJOR = ${NODE_VERSION_MAJOR}") +message("NODE_VERSION_MINOR = ${NODE_VERSION_MINOR}") +message("NODE_VERSION_PATCH = ${NODE_VERSION_PATCH}") + + +# NAPI_VERSION +execute_process(COMMAND node -p "process.env['npm_config_NAPI_VERSION'] || ''" OUTPUT_VARIABLE NAPI_VERSION) +string(STRIP "${NAPI_VERSION}" NAPI_VERSION) # remove new line at end + +message("NAPI_VERSION = ${NAPI_VERSION}") + + +# NODE_API_BUILTIN +set(NODE_API_BUILTIN "false") +if(("${NODE_VERSION_SEMVER}" VERSION_GREATER_EQUAL "9.0.0") + OR ((${NODE_VERSION_MAJOR} EQUAL 8) AND ("${NODE_VERSION_SEMVER}" VERSION_GREATER_EQUAL "8.6.0")) + OR ((${NODE_VERSION_MAJOR} EQUAL 6) AND ("${NODE_VERSION_SEMVER}" VERSION_GREATER_EQUAL "6.15.0")) + OR ((${NODE_VERSION_MAJOR} EQUAL 6) AND ("${NODE_VERSION_SEMVER}" VERSION_GREATER_EQUAL "6.14.2")) +) + set(NODE_API_BUILTIN "true") +else() + set(NAPI_VERSION 1) +endif() + +message("NODE_API_BUILTIN = ${NODE_API_BUILTIN}") + + +# disable_deprecated +execute_process(COMMAND node -p "process.env['npm_config_disable_deprecated'] || ''" OUTPUT_VARIABLE DISABLE_DEPRECATED) +string(STRIP "${DISABLE_DEPRECATED}" DISABLE_DEPRECATED) # remove new line at end + +if(NOT "${DISABLE_DEPRECATED}" STREQUAL "true") + set(DISABLE_DEPRECATED "${DISABLE_DEPRECATED_DEFAULT}") +endif() + +message("disable_deprecated = ${DISABLE_DEPRECATED}") + + +# SOURCE_FILES +file(GLOB SOURCE_FILES "src/*.test.cc") +# SOURCE_FILES will be logged later + + +# NAPI_VERSION* compile options +if(NOT "${NAPI_VERSION}" STREQUAL "") + set(DEFINITIONS_VERSION -DNAPI_VERSION=${NAPI_VERSION}) +else() + set(DEFINITIONS_VERSION -DNAPI_EXPERIMENTAL) +endif() + +message("DEFINITIONS_VERSION = ${DEFINITIONS_VERSION}") +add_definitions("${DEFINITIONS_VERSION}") + + +# DISABLE_DEPRECATED compile options, source files +if ("${DISABLE_DEPRECATED}" STREQUAL "true") + set(COMPILE_OPTIONS_DISABLE_DEPRECATED -DNODE_ADDON_API_DISABLE_DEPRECATED) + add_compile_options("${COMPILE_OPTIONS_DISABLE_DEPRECATED}") + message("COMPILE_OPTIONS_DISABLE_DEPRECATED = ${COMPILE_OPTIONS_DISABLE_DEPRECATED}") +endif() + + +#env.json configure +set(NAPI_MODULES_FLAG "false") +if((NOT "${NODE_API_BUILTIN}" STREQUAL "true") AND ("${NODE_VERSION_MAJOR}" STREQUAL 8)) + set(NAPI_MODULES_FLAG "true") +endif() + +configure_file("${CMAKE_SOURCE_DIR}/env.json.in" "${CMAKE_BINARY_DIR}/env.json") + + +# include directories +set(INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES}" "${CMAKE_SOURCE_DIR}/.." "${CMAKE_JS_INC}") +include_directories("${INCLUDE_DIRECTORIES}") + + +# use builtin node api or compile shipped for old node versions +if("${NODE_API_BUILTIN}" STREQUAL "true") + # set(INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES}" "${CMAKE_SOURCE_DIR}/../external-napi") +else() + add_subdirectory("${CMAKE_SOURCE_DIR}/../src" "${CMAKE_SOURCE_DIR}/build-node-api") + include_directories("${INCLUDE_DIRECTORIES}") # need to update +endif() + + +string(REPLACE ";" "\n" SOURCE_FILES_LIST "${SOURCE_FILES}") +message("================================================================================") +message("INCLUDE_DIRECTORIES:") +message("${INCLUDE_DIRECTORIES}") +message("================================================================================") +message("SOURCE_FILES:") +message("${SOURCE_FILES_LIST}") +message("================================================================================") + +# C/CXX flags +set(FLAGS "-Werror -Wall -Wextra -Wpedantic -Wunused-parameter") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}") + +message("CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}") +message("CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}") +message("================================================================================") + +# library binding +add_library(binding SHARED ${SOURCE_FILES}) +target_compile_options(binding PRIVATE -DNAPI_CPP_EXCEPTIONS) +set_target_properties(binding PROPERTIES PREFIX "" SUFFIX ".node") +target_link_libraries(binding "${BINDING_LINK_LIBRARIES}") + +# library binding_noexcept +add_library(binding_noexcept SHARED ${SOURCE_FILES}) +target_compile_options(binding_noexcept PRIVATE -DNAPI_DISABLE_CPP_EXCEPTIONS) +set_target_properties(binding_noexcept PROPERTIES PREFIX "" SUFFIX ".node") +target_link_libraries(binding_noexcept "${BINDING_LINK_LIBRARIES}") \ No newline at end of file diff --git a/test/binding.gyp b/test/binding.gyp deleted file mode 100644 index 77c388074..000000000 --- a/test/binding.gyp +++ /dev/null @@ -1,89 +0,0 @@ -{ - 'variables': { - 'NAPI_VERSION%': "", - 'disable_deprecated': " (item === 'Debug' || item === 'Release'))[0]; +process.config.target_defaults.default_configuration = require('./build/env.json').buildType; -// FIXME: We might need a way to load test modules automatically without -// explicit declaration as follows. -let testModules = [ - 'arraybuffer', - 'asynccontext', - 'asyncworker', - 'basic_types/array', - 'basic_types/boolean', - 'basic_types/number', - 'basic_types/value', - 'bigint', - 'buffer', - 'callbackscope', - 'dataview/dataview', - 'dataview/dataview_read_write', - 'error', - 'external', - 'function', - 'handlescope', - 'memory_management', - 'name', - 'object/delete_property', - 'object/get_property', - 'object/has_own_property', - 'object/has_property', - 'object/object', - 'object/object_deprecated', - 'object/set_property', - 'promise', - 'typedarray', - 'typedarray-bigint', - 'objectwrap', - 'objectreference', - 'version_management' -]; - -if ((process.env.npm_config_NAPI_VERSION !== undefined) && - (process.env.npm_config_NAPI_VERSION < 50000)) { - // currently experimental only test if NAPI_VERSION - // is set to experimental. We can't use C max int - // as that is not supported as a number on earlier - // Node.js versions. Once bigint is in a release - // this should be guarded on the napi version - // in which bigint was added. - testModules.splice(testModules.indexOf('bigint'), 1); - testModules.splice(testModules.indexOf('typedarray-bigint'), 1); -} - -if ((process.env.npm_config_NAPI_VERSION !== undefined) && - (process.env.npm_config_NAPI_VERSION < 3)) { - testModules.splice(testModules.indexOf('callbackscope'), 1); - testModules.splice(testModules.indexOf('version_management'), 1); -} +const testSrc = path.join(__dirname, 'src'); +const testModulesRegex = /\.test\.js$/; +const testModules = fs + .readdirSync(testSrc) + .filter(entry => testModulesRegex.test(entry)) + .map(entry => path.join(testSrc, entry)) +; if (typeof global.gc === 'function') { console.log('Starting test suite\n'); // Requiring each module runs tests in the module. testModules.forEach(name => { - console.log(`Running test '${name}'`); - require('./' + name); + const result = require(name); + console.log(`Running test '${path.basename(name)}' ${(result && result.skipped) ? '[SKIPPED]' : ''}`); }); console.log('\nAll tests passed!'); diff --git a/test/napi_child.js b/test/napi_child.js index 29a80a115..91cbe4254 100644 --- a/test/napi_child.js +++ b/test/napi_child.js @@ -1,6 +1,6 @@ // Makes sure that child processes are spawned appropriately. exports.spawnSync = function(command, args, options) { - if (require('../index').needsFlag) { + if (require('./build/env.json').needsNapiModulesFlag) { args.splice(0, 0, '--napi-modules'); } return require('child_process').spawnSync(command, args, options); diff --git a/test/arraybuffer.cc b/test/src/arraybuffer.test.cc similarity index 100% rename from test/arraybuffer.cc rename to test/src/arraybuffer.test.cc diff --git a/test/arraybuffer.js b/test/src/arraybuffer.test.js similarity index 92% rename from test/arraybuffer.js rename to test/src/arraybuffer.test.js index 43604617f..d7e038657 100644 --- a/test/arraybuffer.js +++ b/test/src/arraybuffer.test.js @@ -1,10 +1,10 @@ 'use strict'; const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -const testUtil = require('./testUtil'); +const testUtil = require('../testUtil'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { testUtil.runGCTests([ diff --git a/test/asynccontext.cc b/test/src/asynccontext.test.cc similarity index 100% rename from test/asynccontext.cc rename to test/src/asynccontext.test.cc diff --git a/test/asynccontext.js b/test/src/asynccontext.test.js similarity index 92% rename from test/asynccontext.js rename to test/src/asynccontext.test.js index e9b4aabc3..2b1926a9d 100644 --- a/test/asynccontext.js +++ b/test/src/asynccontext.test.js @@ -1,7 +1,7 @@ 'use strict'; const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -const common = require('./common'); +const common = require('../common'); // we only check async hooks on 8.x an higher were // they are closer to working properly @@ -17,8 +17,8 @@ function checkAsyncHooks() { return false; } -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function installAsyncHooksForTest() { return new Promise((resolve, reject) => { diff --git a/test/asyncworker.cc b/test/src/asyncworker.test.cc similarity index 100% rename from test/asyncworker.cc rename to test/src/asyncworker.test.cc diff --git a/test/asyncworker.js b/test/src/asyncworker.test.js similarity index 95% rename from test/asyncworker.js rename to test/src/asyncworker.test.js index 676afd537..3573ddadd 100644 --- a/test/asyncworker.js +++ b/test/src/asyncworker.test.js @@ -1,7 +1,7 @@ 'use strict'; const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -const common = require('./common'); +const common = require('../common'); // we only check async hooks on 8.x an higher were // they are closer to working properly @@ -17,8 +17,8 @@ function checkAsyncHooks() { return false; } -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function installAsyncHooksForTest() { return new Promise((resolve, reject) => { diff --git a/test/basic_types/array.cc b/test/src/basic_types.array.test.cc similarity index 97% rename from test/basic_types/array.cc rename to test/src/basic_types.array.test.cc index 401d93618..fb0074c40 100644 --- a/test/basic_types/array.cc +++ b/test/src/basic_types.array.test.cc @@ -1,4 +1,3 @@ -#define NAPI_EXPERIMENTAL #include "napi.h" using namespace Napi; diff --git a/test/basic_types/array.js b/test/src/basic_types.array.test.js similarity index 100% rename from test/basic_types/array.js rename to test/src/basic_types.array.test.js diff --git a/test/basic_types/boolean.cc b/test/src/basic_types.boolean.test.cc similarity index 100% rename from test/basic_types/boolean.cc rename to test/src/basic_types.boolean.test.cc diff --git a/test/basic_types/boolean.js b/test/src/basic_types.boolean.test.js similarity index 100% rename from test/basic_types/boolean.js rename to test/src/basic_types.boolean.test.js diff --git a/test/basic_types/number.cc b/test/src/basic_types.number.test.cc similarity index 100% rename from test/basic_types/number.cc rename to test/src/basic_types.number.test.cc diff --git a/test/basic_types/number.js b/test/src/basic_types.number.test.js similarity index 100% rename from test/basic_types/number.js rename to test/src/basic_types.number.test.js diff --git a/test/basic_types/value.cc b/test/src/basic_types.value.test.cc similarity index 100% rename from test/basic_types/value.cc rename to test/src/basic_types.value.test.cc diff --git a/test/basic_types/value.js b/test/src/basic_types.value.test.js similarity index 100% rename from test/basic_types/value.js rename to test/src/basic_types.value.test.js diff --git a/test/bigint.cc b/test/src/bigint.test.cc similarity index 97% rename from test/bigint.cc rename to test/src/bigint.test.cc index 5d1e36367..286e5be3c 100644 --- a/test/bigint.cc +++ b/test/src/bigint.test.cc @@ -1,11 +1,10 @@ -#define NAPI_EXPERIMENTAL #include "napi.h" using namespace Napi; // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) namespace { Value IsLossless(const CallbackInfo& info) { diff --git a/test/bigint.js b/test/src/bigint.test.def.js similarity index 81% rename from test/bigint.js rename to test/src/bigint.test.def.js index e4255172c..0846ef220 100644 --- a/test/bigint.js +++ b/test/src/bigint.test.def.js @@ -1,10 +1,15 @@ 'use strict'; +if ((process.env.npm_config_NAPI_VERSION !== undefined) && (process.env.npm_config_NAPI_VERSION < 50000)) { + exports.skipped = true; + return; +} + const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { const { diff --git a/test/src/bigint.test.js b/test/src/bigint.test.js new file mode 100644 index 000000000..da952c9be --- /dev/null +++ b/test/src/bigint.test.js @@ -0,0 +1,10 @@ +'use strict'; + +if ((process.env.npm_config_NAPI_VERSION !== undefined) && (process.env.npm_config_NAPI_VERSION < 50000)) { + exports.skipped = { + reason: '' + }; + return; +} + +require('./bigint.test.def'); \ No newline at end of file diff --git a/test/binding.cc b/test/src/binding.test.cc similarity index 95% rename from test/binding.cc rename to test/src/binding.test.cc index 0068e7480..9780a6b43 100644 --- a/test/binding.cc +++ b/test/src/binding.test.cc @@ -1,4 +1,3 @@ -#define NAPI_EXPERIMENTAL #include "napi.h" using namespace Napi; @@ -12,9 +11,9 @@ Object InitBasicTypesNumber(Env env); Object InitBasicTypesValue(Env env); // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) Object InitBigInt(Env env); -#endif +#endif // NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL Object InitBuffer(Env env); #if (NAPI_VERSION > 2) Object InitCallbackScope(Env env); @@ -48,7 +47,7 @@ Object Init(Env env, Object exports) { exports.Set("basic_types_value", InitBasicTypesValue(env)); // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) exports.Set("bigint", InitBigInt(env)); #endif exports.Set("buffer", InitBuffer(env)); diff --git a/test/buffer.cc b/test/src/buffer.test.cc similarity index 100% rename from test/buffer.cc rename to test/src/buffer.test.cc diff --git a/test/buffer.js b/test/src/buffer.test.js similarity index 92% rename from test/buffer.js rename to test/src/buffer.test.js index 0c6e64895..ebf7c96cf 100644 --- a/test/buffer.js +++ b/test/src/buffer.test.js @@ -1,11 +1,11 @@ 'use strict'; const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -const testUtil = require('./testUtil'); +const testUtil = require('../testUtil'); const safeBuffer = require('safe-buffer'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { testUtil.runGCTests([ diff --git a/test/callbackscope.cc b/test/src/callbackscope.test.cc similarity index 100% rename from test/callbackscope.cc rename to test/src/callbackscope.test.cc diff --git a/test/callbackscope.js b/test/src/callbackscope.test.js similarity index 77% rename from test/callbackscope.js rename to test/src/callbackscope.test.js index 523bca462..7c1cd6e00 100644 --- a/test/callbackscope.js +++ b/test/src/callbackscope.test.js @@ -1,7 +1,13 @@ 'use strict'; + +if ((process.env.npm_config_NAPI_VERSION !== undefined) && (process.env.npm_config_NAPI_VERSION < 3)) { + exports.skipped = true; + return; +} + const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -const common = require('./common'); +const common = require('../common'); // we only check async hooks on 8.x an higher were // they are closer to working properly @@ -17,8 +23,8 @@ function checkAsyncHooks() { return false; } -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { if (!checkAsyncHooks()) diff --git a/test/dataview/dataview_read_write.cc b/test/src/dataview.read_write.test.cc similarity index 100% rename from test/dataview/dataview_read_write.cc rename to test/src/dataview.read_write.test.cc diff --git a/test/dataview/dataview_read_write.js b/test/src/dataview.read_write.test.js similarity index 100% rename from test/dataview/dataview_read_write.js rename to test/src/dataview.read_write.test.js diff --git a/test/dataview/dataview.cc b/test/src/dataview.test.cc similarity index 100% rename from test/dataview/dataview.cc rename to test/src/dataview.test.cc diff --git a/test/dataview/dataview.js b/test/src/dataview.test.js similarity index 100% rename from test/dataview/dataview.js rename to test/src/dataview.test.js diff --git a/test/error.cc b/test/src/error.test.cc similarity index 100% rename from test/error.cc rename to test/src/error.test.cc diff --git a/test/error.js b/test/src/error.test.js similarity index 93% rename from test/error.js rename to test/src/error.test.js index f41874d55..9b98bd82c 100644 --- a/test/error.js +++ b/test/src/error.test.js @@ -8,8 +8,8 @@ if (process.argv[2] === 'fatal') { return; } -test(`./build/${buildType}/binding.node`); -test(`./build/${buildType}/binding_noexcept.node`); +test(`../build/${buildType}/binding.node`); +test(`../build/${buildType}/binding_noexcept.node`); function test(bindingPath) { const binding = require(bindingPath); @@ -65,7 +65,7 @@ function test(bindingPath) { return err instanceof Error && err.message === 'test' && err.caught; }); - const p = require('./napi_child').spawnSync( + const p = require('../napi_child').spawnSync( process.execPath, [ __filename, 'fatal', bindingPath ]); assert.ifError(p.error); assert.ok(p.stderr.toString().includes( diff --git a/test/external.cc b/test/src/external.test.cc similarity index 100% rename from test/external.cc rename to test/src/external.test.cc diff --git a/test/external.js b/test/src/external.test.js similarity index 88% rename from test/external.js rename to test/src/external.test.js index e2067006a..29ebaf68e 100644 --- a/test/external.js +++ b/test/src/external.test.js @@ -1,10 +1,10 @@ 'use strict'; const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -const testUtil = require('./testUtil'); +const testUtil = require('../testUtil'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { testUtil.runGCTests([ diff --git a/test/function.cc b/test/src/function.test.cc similarity index 100% rename from test/function.cc rename to test/src/function.test.cc diff --git a/test/function.js b/test/src/function.test.js similarity index 95% rename from test/function.js rename to test/src/function.test.js index 0d75ffca9..a36aa1084 100644 --- a/test/function.js +++ b/test/src/function.test.js @@ -2,8 +2,8 @@ const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { let obj = {}; diff --git a/test/handlescope.cc b/test/src/handlescope.test.cc similarity index 100% rename from test/handlescope.cc rename to test/src/handlescope.test.cc diff --git a/test/handlescope.js b/test/src/handlescope.test.js similarity index 82% rename from test/handlescope.js rename to test/src/handlescope.test.js index 71cb89783..1a5c79238 100644 --- a/test/handlescope.js +++ b/test/src/handlescope.test.js @@ -2,8 +2,8 @@ const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { assert.strictEqual(binding.handlescope.createScope(), 'scope'); diff --git a/test/memory_management.cc b/test/src/memory_management.test.cc similarity index 100% rename from test/memory_management.cc rename to test/src/memory_management.test.cc diff --git a/test/memory_management.js b/test/src/memory_management.test.js similarity index 66% rename from test/memory_management.js rename to test/src/memory_management.test.js index f4911a2a6..39b9b7afa 100644 --- a/test/memory_management.js +++ b/test/src/memory_management.test.js @@ -2,8 +2,8 @@ const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { assert.strictEqual(binding.memory_management.externalAllocatedMemory(), true) diff --git a/test/name.cc b/test/src/name.test.cc similarity index 100% rename from test/name.cc rename to test/src/name.test.cc diff --git a/test/name.js b/test/src/name.test.js similarity index 94% rename from test/name.js rename to test/src/name.test.js index 4e9659312..54c58ec61 100644 --- a/test/name.js +++ b/test/src/name.test.js @@ -2,8 +2,8 @@ const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { const expected = '123456789'; diff --git a/test/object/delete_property.cc b/test/src/object.delete_property.test.cc similarity index 100% rename from test/object/delete_property.cc rename to test/src/object.delete_property.test.cc diff --git a/test/object/delete_property.js b/test/src/object.delete_property.test.js similarity index 100% rename from test/object/delete_property.js rename to test/src/object.delete_property.test.js diff --git a/test/object/get_property.cc b/test/src/object.get_property.test.cc similarity index 100% rename from test/object/get_property.cc rename to test/src/object.get_property.test.cc diff --git a/test/object/get_property.js b/test/src/object.get_property.test.js similarity index 100% rename from test/object/get_property.js rename to test/src/object.get_property.test.js diff --git a/test/object/has_own_property.cc b/test/src/object.has_own_property.test.cc similarity index 100% rename from test/object/has_own_property.cc rename to test/src/object.has_own_property.test.cc diff --git a/test/object/has_own_property.js b/test/src/object.has_own_property.test.js similarity index 100% rename from test/object/has_own_property.js rename to test/src/object.has_own_property.test.js diff --git a/test/object/has_property.cc b/test/src/object.has_property.test.cc similarity index 100% rename from test/object/has_property.cc rename to test/src/object.has_property.test.cc diff --git a/test/object/has_property.js b/test/src/object.has_property.test.js similarity index 100% rename from test/object/has_property.js rename to test/src/object.has_property.test.js diff --git a/test/object/object.cc b/test/src/object.object.test.cc similarity index 100% rename from test/object/object.cc rename to test/src/object.object.test.cc diff --git a/test/object/object.js b/test/src/object.object.test.js similarity index 100% rename from test/object/object.js rename to test/src/object.object.test.js diff --git a/test/object/object_deprecated.cc b/test/src/object.object_deprecated.test.cc similarity index 95% rename from test/object/object_deprecated.cc rename to test/src/object.object_deprecated.test.cc index 2ec16e579..b8d32adb0 100644 --- a/test/object/object_deprecated.cc +++ b/test/src/object.object_deprecated.test.cc @@ -1,3 +1,5 @@ +#ifndef NODE_ADDON_API_DISABLE_DEPRECATED + #include "napi.h" using namespace Napi; @@ -64,3 +66,5 @@ Object InitObjectDeprecated(Env env) { return exports; } + +#endif // !NODE_ADDON_API_DISABLE_DEPRECATED \ No newline at end of file diff --git a/test/object/object_deprecated.js b/test/src/object.object_deprecated.test.js similarity index 94% rename from test/object/object_deprecated.js rename to test/src/object.object_deprecated.test.js index 153fb11e1..4c8ca306b 100644 --- a/test/object/object_deprecated.js +++ b/test/src/object.object_deprecated.test.js @@ -1,4 +1,10 @@ 'use strict'; + +if (require('../build/env.json')['disable_deprecated']) { + exports.skipped = true; + return; +} + const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); @@ -6,9 +12,6 @@ test(require(`../build/${buildType}/binding.node`)); test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { - if (!('object_deprecated' in binding)) { - return; - } function assertPropertyIs(obj, key, attribute) { const propDesc = Object.getOwnPropertyDescriptor(obj, key); assert.ok(propDesc); diff --git a/test/object/set_property.cc b/test/src/object.set_property.test.cc similarity index 100% rename from test/object/set_property.cc rename to test/src/object.set_property.test.cc diff --git a/test/object/set_property.js b/test/src/object.set_property.test.js similarity index 100% rename from test/object/set_property.js rename to test/src/object.set_property.test.js diff --git a/test/objectreference.cc b/test/src/objectreference.test.cc similarity index 100% rename from test/objectreference.cc rename to test/src/objectreference.test.cc diff --git a/test/objectreference.js b/test/src/objectreference.test.js similarity index 98% rename from test/objectreference.js rename to test/src/objectreference.test.js index 07de0bc77..1c284ab09 100644 --- a/test/objectreference.js +++ b/test/src/objectreference.test.js @@ -12,10 +12,10 @@ 'use strict'; const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -const testUtil = require('./testUtil'); +const testUtil = require('../testUtil'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { function testCastedEqual(testToCompare) { diff --git a/test/objectwrap.cc b/test/src/objectwrap.test.cc similarity index 100% rename from test/objectwrap.cc rename to test/src/objectwrap.test.cc diff --git a/test/objectwrap.js b/test/src/objectwrap.test.js similarity index 97% rename from test/objectwrap.js rename to test/src/objectwrap.test.js index 1f888234d..5835e1c5b 100644 --- a/test/objectwrap.js +++ b/test/src/objectwrap.test.js @@ -206,5 +206,5 @@ const test = (binding) => { testClass(Test); } -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); diff --git a/test/promise.cc b/test/src/promise.test.cc similarity index 100% rename from test/promise.cc rename to test/src/promise.test.cc diff --git a/test/promise.js b/test/src/promise.test.js similarity index 79% rename from test/promise.js rename to test/src/promise.test.js index 4a04ab9a0..a013b994c 100644 --- a/test/promise.js +++ b/test/src/promise.test.js @@ -1,10 +1,10 @@ 'use strict'; const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -const common = require('./common'); +const common = require('../common'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { assert.strictEqual(binding.promise.isPromise({}), false); diff --git a/test/thunking_manual.cc b/test/src/thunking_manual.test.cc similarity index 98% rename from test/thunking_manual.cc rename to test/src/thunking_manual.test.cc index d52302ea3..cdb04c2d5 100644 --- a/test/thunking_manual.cc +++ b/test/src/thunking_manual.test.cc @@ -5,7 +5,7 @@ // data must be attached to an object by way of a deleter which gets called when // the object gets garbage-collected. // -// At the very least, you can add a fprintf(stderr, ...) to the deleter in +// At the very least, you can add a fprintf(stderr, ..) to the deleter in // napi-inl.h and then count the number of times the deleter prints by running // node --expose-gc test/thunking_manual.js and counting the number of prints // between the two rows of dashes. That number should coincide with the number diff --git a/test/src/thunking_manual.test.js b/test/src/thunking_manual.test.js new file mode 100644 index 000000000..b56788337 --- /dev/null +++ b/test/src/thunking_manual.test.js @@ -0,0 +1,24 @@ +// Flags: --expose-gc +'use strict'; + +const buildType = process.config.target_defaults.default_configuration; + +if (buildType === 'Debug') { + const assert = require('assert'); + + test(require(`../build/${buildType}/binding.node`)); + test(require(`../build/${buildType}/binding_noexcept.node`)); + + function test(binding) { + console.log("Thunking: Performing initial GC"); + global.gc(); + console.log("Thunking: Creating test object"); + let object = binding.thunking_manual.createTestObject(); + object = null; + console.log("Thunking: About to GC\n--------"); + global.gc(); + console.log("--------\nThunking: GC complete"); + } +} else { + exports.skipped = true; +} diff --git a/test/typedarray-bigint.js b/test/src/typedarray-bigint.test.def.js similarity index 88% rename from test/typedarray-bigint.js rename to test/src/typedarray-bigint.test.def.js index ce66d3898..ae4235254 100644 --- a/test/typedarray-bigint.js +++ b/test/src/typedarray-bigint.test.def.js @@ -1,9 +1,15 @@ 'use strict'; + +if ((process.env.npm_config_NAPI_VERSION !== undefined) && (process.env.npm_config_NAPI_VERSION < 50000)) { + exports.skipped = true; + return; +} + const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { [ diff --git a/test/src/typedarray-bigint.test.js b/test/src/typedarray-bigint.test.js new file mode 100644 index 000000000..c093c186c --- /dev/null +++ b/test/src/typedarray-bigint.test.js @@ -0,0 +1,8 @@ +'use strict'; + +if ((process.env.npm_config_NAPI_VERSION !== undefined) && (process.env.npm_config_NAPI_VERSION < 50000)) { + exports.skipped = true; + return; +} + +require('./typedarray-bigint.test.def'); \ No newline at end of file diff --git a/test/typedarray.cc b/test/src/typedarray.test.cc similarity index 98% rename from test/typedarray.cc rename to test/src/typedarray.test.cc index 9b3a1996f..147a4590b 100644 --- a/test/typedarray.cc +++ b/test/src/typedarray.test.cc @@ -1,4 +1,3 @@ -#define NAPI_EXPERIMENTAL #include "napi.h" using namespace Napi; @@ -67,7 +66,7 @@ Value CreateTypedArray(const CallbackInfo& info) { napi_float64_array); // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) } else if (arrayType == "bigint64") { return buffer.IsUndefined() ? NAPI_TYPEDARRAY_NEW(BigInt64Array, info.Env(), length, napi_bigint64_array) : @@ -103,7 +102,7 @@ Value GetTypedArrayType(const CallbackInfo& info) { case napi_float64_array: return String::New(info.Env(), "float64"); // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) case napi_bigint64_array: return String::New(info.Env(), "bigint64"); case napi_biguint64_array: return String::New(info.Env(), "biguint64"); #endif @@ -145,7 +144,7 @@ Value GetTypedArrayElement(const CallbackInfo& info) { return Number::New(info.Env(), array.As()[index]); // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) case napi_bigint64_array: return BigInt::New(info.Env(), array.As()[index]); case napi_biguint64_array: @@ -191,7 +190,7 @@ void SetTypedArrayElement(const CallbackInfo& info) { break; // currently experimental guard with version of NAPI_VERSION that it is // released in once it is no longer experimental -#if (NAPI_VERSION > 2147483646) +#if (NAPI_VERSION == NAPI_VERSION_EXPERIMENTAL) case napi_bigint64_array: { bool lossless; array.As()[index] = value.As().Int64Value(&lossless); diff --git a/test/typedarray.js b/test/src/typedarray.test.js similarity index 94% rename from test/typedarray.js rename to test/src/typedarray.test.js index 9aa880c16..164c0e085 100644 --- a/test/typedarray.js +++ b/test/src/typedarray.test.js @@ -2,8 +2,8 @@ const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { const testData = [ diff --git a/test/version_management.cc b/test/src/version_management.test.cc similarity index 100% rename from test/version_management.cc rename to test/src/version_management.test.cc diff --git a/test/version_management.js b/test/src/version_management.test.js similarity index 79% rename from test/version_management.js rename to test/src/version_management.test.js index f52db2f73..c90375db1 100644 --- a/test/version_management.js +++ b/test/src/version_management.test.js @@ -1,9 +1,15 @@ 'use strict'; + +if ((process.env.npm_config_NAPI_VERSION !== undefined) && (process.env.npm_config_NAPI_VERSION < 3)) { + exports.skipped = true; + return; +} + const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +test(require(`../build/${buildType}/binding.node`)); +test(require(`../build/${buildType}/binding_noexcept.node`)); function parseVersion() { const expected = {}; diff --git a/test/thunking_manual.js b/test/thunking_manual.js deleted file mode 100644 index 22fb8877d..000000000 --- a/test/thunking_manual.js +++ /dev/null @@ -1,18 +0,0 @@ -// Flags: --expose-gc -'use strict'; -const buildType = 'Debug'; -const assert = require('assert'); - -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); - -function test(binding) { - console.log("Thunking: Performing initial GC"); - global.gc(); - console.log("Thunking: Creating test object"); - let object = binding.thunking_manual.createTestObject(); - object = null; - console.log("Thunking: About to GC\n--------"); - global.gc(); - console.log("--------\nThunking: GC complete"); -}