diff --git a/Makefile b/Makefile index 0bd83a21ba045c..81c8197d4f8fc8 100644 --- a/Makefile +++ b/Makefile @@ -270,7 +270,7 @@ v8: tools/make-v8.sh $(V8_ARCH).$(BUILDTYPE_LOWER) $(V8_BUILD_OPTIONS) .PHONY: jstest -jstest: build-addons build-addons-napi ## Runs addon tests and JS tests +jstest: build-addons build-js-native-api-tests build-node-api-tests ## Runs addon tests and JS tests $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) \ --skip-tests=$(CI_SKIP_TESTS) \ $(CI_JS_SUITES) \ @@ -281,21 +281,24 @@ jstest: build-addons build-addons-napi ## Runs addon tests and JS tests test: all ## Runs default tests, linters, and builds docs. $(MAKE) -s test-doc $(MAKE) -s build-addons - $(MAKE) -s build-addons-napi + $(MAKE) -s build-js-native-api-tests + $(MAKE) -s build-node-api-tests $(MAKE) -s cctest $(MAKE) -s jstest .PHONY: test-only test-only: all ## For a quick test, does not run linter or build docs. $(MAKE) build-addons - $(MAKE) build-addons-napi + $(MAKE) build-js-native-api-tests + $(MAKE) build-node-api-tests $(MAKE) cctest $(MAKE) jstest # Used by `make coverage-test` test-cov: all $(MAKE) build-addons - $(MAKE) build-addons-napi + $(MAKE) build-js-native-api-tests + $(MAKE) build-node-api-tests # $(MAKE) cctest CI_SKIP_TESTS=core_line_numbers.js $(MAKE) jstest @@ -381,30 +384,55 @@ test/addons/.buildstamp: $(ADDONS_PREREQS) \ # TODO(bnoordhuis) Force rebuild after gyp update. build-addons: | $(NODE_EXE) test/addons/.buildstamp -ADDONS_NAPI_BINDING_GYPS := \ - $(filter-out test/addons-napi/??_*/binding.gyp, \ - $(wildcard test/addons-napi/*/binding.gyp)) +JS_NATIVE_API_BINDING_GYPS := \ + $(filter-out test/js-native-api/??_*/binding.gyp, \ + $(wildcard test/js-native-api/*/binding.gyp)) -ADDONS_NAPI_BINDING_SOURCES := \ - $(filter-out test/addons-napi/??_*/*.c, $(wildcard test/addons-napi/*/*.c)) \ - $(filter-out test/addons-napi/??_*/*.cc, $(wildcard test/addons-napi/*/*.cc)) \ - $(filter-out test/addons-napi/??_*/*.h, $(wildcard test/addons-napi/*/*.h)) +JS_NATIVE_API_BINDING_SOURCES := \ + $(filter-out test/js-native-api/??_*/*.c, $(wildcard test/js-native-api/*/*.c)) \ + $(filter-out test/js-native-api/??_*/*.cc, $(wildcard test/js-native-api/*/*.cc)) \ + $(filter-out test/js-native-api/??_*/*.h, $(wildcard test/js-native-api/*/*.h)) -# Implicitly depends on $(NODE_EXE), see the build-addons-napi rule for rationale. -test/addons-napi/.buildstamp: $(ADDONS_PREREQS) \ - $(ADDONS_NAPI_BINDING_GYPS) $(ADDONS_NAPI_BINDING_SOURCES) \ +# Implicitly depends on $(NODE_EXE), see the build-js-native-api-tests rule for rationale. +test/js-native-api/.buildstamp: $(ADDONS_PREREQS) \ + $(JS_NATIVE_API_BINDING_GYPS) $(JS_NATIVE_API_BINDING_SOURCES) \ src/node_api.h src/node_api_types.h src/js_native_api.h \ src/js_native_api_types.h src/js_native_api_v8.h src/js_native_api_v8_internals.h - @$(call run_build_addons,"$$PWD/test/addons-napi",$@) + @$(call run_build_addons,"$$PWD/test/js-native-api",$@) -.PHONY: build-addons-napi +.PHONY: build-js-native-api-tests # .buildstamp needs $(NODE_EXE) but cannot depend on it # directly because it calls make recursively. The parent make cannot know # if the subprocess touched anything so it pessimistically assumes that # .buildstamp is out of date and need a rebuild. # Just goes to show that recursive make really is harmful... # TODO(bnoordhuis) Force rebuild after gyp or node-gyp update. -build-addons-napi: | $(NODE_EXE) test/addons-napi/.buildstamp +build-js-native-api-tests: | $(NODE_EXE) test/js-native-api/.buildstamp + +NODE_API_BINDING_GYPS := \ + $(filter-out test/node-api/??_*/binding.gyp, \ + $(wildcard test/node-api/*/binding.gyp)) + +NODE_API_BINDING_SOURCES := \ + $(filter-out test/node-api/??_*/*.c, $(wildcard test/node-api/*/*.c)) \ + $(filter-out test/node-api/??_*/*.cc, $(wildcard test/node-api/*/*.cc)) \ + $(filter-out test/node-api/??_*/*.h, $(wildcard test/node-api/*/*.h)) + +# Implicitly depends on $(NODE_EXE), see the build-node-api-tests rule for rationale. +test/node-api/.buildstamp: $(ADDONS_PREREQS) \ + $(NODE_API_BINDING_GYPS) $(NODE_API_BINDING_SOURCES) \ + src/node_api.h src/node_api_types.h src/js_native_api.h \ + src/js_native_api_types.h src/js_native_api_v8.h src/js_native_api_v8_internals.h + @$(call run_build_addons,"$$PWD/test/node-api",$@) + +.PHONY: build-node-api-tests +# .buildstamp needs $(NODE_EXE) but cannot depend on it +# directly because it calls make recursively. The parent make cannot know +# if the subprocess touched anything so it pessimistically assumes that +# .buildstamp is out of date and need a rebuild. +# Just goes to show that recursive make really is harmful... +# TODO(bnoordhuis) Force rebuild after gyp or node-gyp update. +build-node-api-tests: | $(NODE_EXE) test/node-api/.buildstamp .PHONY: clear-stalled clear-stalled: @@ -415,9 +443,11 @@ clear-stalled: echo $${PS_OUT} | xargs kill -9; \ fi -test-build: | all build-addons build-addons-napi +test-build: | all build-addons build-js-native-api-tests build-node-api-tests -test-build-addons-napi: all build-addons-napi +test-build-js-native-api: all build-js-native-api-tests + +test-build-node-api: all build-node-api-tests .PHONY: test-all test-all: test-build ## Run everything in test/. @@ -426,7 +456,7 @@ test-all: test-build ## Run everything in test/. test-all-valgrind: test-build $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=debug,release --valgrind -CI_NATIVE_SUITES ?= addons addons-napi +CI_NATIVE_SUITES ?= addons js-native-api node-api CI_JS_SUITES ?= default CI_DOC := doctool @@ -434,7 +464,7 @@ CI_DOC := doctool # Build and test addons without building anything else # Related CI job: node-test-commit-arm-fanned test-ci-native: LOGLEVEL := info -test-ci-native: | test/addons/.buildstamp test/addons-napi/.buildstamp +test-ci-native: | test/addons/.buildstamp test/js-native-api/.buildstamp test/node-api/.buildstamp $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ --mode=$(BUILDTYPE_LOWER) --flaky-tests=$(FLAKY_TESTS) \ $(TEST_CI_ARGS) $(CI_NATIVE_SUITES) @@ -456,7 +486,7 @@ test-ci-js: | clear-stalled .PHONY: test-ci # Related CI jobs: most CI tests, excluding node-test-commit-arm-fanned test-ci: LOGLEVEL := info -test-ci: | clear-stalled build-addons build-addons-napi doc-only +test-ci: | clear-stalled build-addons build-js-native-api-tests build-node-api-tests doc-only out/Release/cctest --gtest_output=tap:cctest.tap $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ --mode=$(BUILDTYPE_LOWER) --flaky-tests=$(FLAKY_TESTS) \ @@ -539,17 +569,26 @@ test-npm: $(NODE_EXE) ## Run the npm test suite on deps/npm. test-npm-publish: $(NODE_EXE) npm_package_config_publishtest=true $(NODE) deps/npm/test/run.js -.PHONY: test-addons-napi -test-addons-napi: test-build-addons-napi - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) addons-napi +.PHONY: test-js-native-api +test-js-native-api: test-build-js-native-api + $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) js-native-api + +.PHONY: test-js-native-api-clean +test-js-native-api-clean: + $(RM) -r test/js-native-api/*/build + $(RM) test/js-native-api/.buildstamp + +.PHONY: test-node-api +test-node-api: test-build-node-api + $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) node-api -.PHONY: test-addons-napi-clean -test-addons-napi-clean: - $(RM) -r test/addons-napi/*/build - $(RM) test/addons-napi/.buildstamp +.PHONY: test-node-api-clean +test-node-api-clean: + $(RM) -r test/node-api/*/build + $(RM) test/node-api/.buildstamp .PHONY: test-addons -test-addons: test-build test-addons-napi +test-addons: test-build test-js-native-api test-node-api $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) addons .PHONY: test-addons-clean @@ -557,14 +596,16 @@ test-addons-clean: $(RM) -r test/addons/??_*/ $(RM) -r test/addons/*/build $(RM) test/addons/.buildstamp test/addons/.docbuildstamp - $(MAKE) test-addons-napi-clean + $(MAKE) test-js-native-api-clean + $(MAKE) test-node-api-clean test-async-hooks: $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) async-hooks test-with-async-hooks: $(MAKE) build-addons - $(MAKE) build-addons-napi + $(MAKE) build-js-native-api-tests + $(MAKE) build-node-api-tests $(MAKE) cctest NODE_TEST_WITH_ASYNC_HOOKS=1 $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) \ $(CI_JS_SUITES) \ @@ -1136,7 +1177,7 @@ LINT_CPP_ADDON_DOC_FILES = $(wildcard $(LINT_CPP_ADDON_DOC_FILES_GLOB)) LINT_CPP_EXCLUDE ?= LINT_CPP_EXCLUDE += src/node_root_certs.h LINT_CPP_EXCLUDE += $(LINT_CPP_ADDON_DOC_FILES) -LINT_CPP_EXCLUDE += $(wildcard test/addons-napi/??_*/*.cc test/addons-napi/??_*/*.h) +LINT_CPP_EXCLUDE += $(wildcard test/js-native-api/??_*/*.cc test/js-native-api/??_*/*.h test/node-api/??_*/*.cc test/node-api/??_*/*.h) # These files were copied more or less verbatim from V8. LINT_CPP_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h @@ -1152,8 +1193,10 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \ test/addons/*/*.h \ test/cctest/*.cc \ test/cctest/*.h \ - test/addons-napi/*/*.cc \ - test/addons-napi/*/*.h \ + test/js-native-api/*/*.cc \ + test/js-native-api/*/*.h \ + test/node-api/*/*.cc \ + test/node-api/*/*.h \ tools/icu/*.cc \ tools/icu/*.h \ )) diff --git a/test/README.md b/test/README.md index 25243d7687d133..8b496f4875f6d5 100644 --- a/test/README.md +++ b/test/README.md @@ -17,7 +17,6 @@ GitHub with the `autocrlf` git config flag set to true. | ------------------- | --------------- | --------------- | | `abort` | Yes | Tests for when the ``` --abort-on-uncaught-exception ``` flag is used. | | `addons` | Yes | Tests for [addon](https://nodejs.org/api/addons.html) functionality along with some tests that require an addon to function properly. | -| `addons-napi` | Yes | Tests for [n-api](https://nodejs.org/api/n-api.html) functionality. | | `async-hooks` | Yes | Tests for [async_hooks](https://nodejs.org/api/async_hooks.html) functionality. | | `benchmark` | No | Test minimal functionality of benchmarks. | | `cctest` | Yes | C++ tests that are run as part of the build process. | @@ -27,8 +26,10 @@ GitHub with the `autocrlf` git config flag set to true. | `es-module` | Yes | Test ESM module loading. | | `fixtures` | | Test fixtures used in various tests throughout the test suite. | | `internet` | No | Tests that make real outbound connections (mainly networking related modules). Tests for networking related modules may also be present in other directories, but those tests do not make outbound connections. | +| `js-native-api` | Yes | Tests for Node.js-agnostic [n-api](https://nodejs.org/api/n-api.html) functionality. | | `known_issues` | Yes | Tests reproducing known issues within the system. All tests inside of this directory are expected to fail consistently. If a test doesn't fail on certain platforms, those should be skipped via `known_issues.status`. | | `message` | Yes | Tests for messages that are output for various conditions (```console.log```, error messages etc.) | +| `node-api` | Yes | Tests for Node.js-specific [n-api](https://nodejs.org/api/n-api.html) functionality. | | `parallel` | Yes | Various tests that are able to be run in parallel. | | `pseudo-tty` | Yes | Tests that require stdin/stdout/stderr to be a TTY. | | `pummel` | No | Various tests for various modules / system functionality operating under load. | diff --git a/test/addons-napi/2_function_arguments/binding.gyp b/test/addons-napi/2_function_arguments/binding.gyp deleted file mode 100644 index 62381d5e54f22b..00000000000000 --- a/test/addons-napi/2_function_arguments/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "binding", - "sources": [ "binding.c" ] - } - ] -} diff --git a/test/addons-napi/3_callbacks/binding.gyp b/test/addons-napi/3_callbacks/binding.gyp deleted file mode 100644 index 62381d5e54f22b..00000000000000 --- a/test/addons-napi/3_callbacks/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "binding", - "sources": [ "binding.c" ] - } - ] -} diff --git a/test/addons-napi/4_object_factory/binding.gyp b/test/addons-napi/4_object_factory/binding.gyp deleted file mode 100644 index 62381d5e54f22b..00000000000000 --- a/test/addons-napi/4_object_factory/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "binding", - "sources": [ "binding.c" ] - } - ] -} diff --git a/test/addons-napi/5_function_factory/binding.gyp b/test/addons-napi/5_function_factory/binding.gyp deleted file mode 100644 index 62381d5e54f22b..00000000000000 --- a/test/addons-napi/5_function_factory/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "binding", - "sources": [ "binding.c" ] - } - ] -} diff --git a/test/addons-napi/6_object_wrap/binding.cc b/test/addons-napi/6_object_wrap/binding.cc deleted file mode 100644 index 380ca6b27bb306..00000000000000 --- a/test/addons-napi/6_object_wrap/binding.cc +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "myobject.h" -#include "../common.h" - -napi_value Init(napi_env env, napi_value exports) { - MyObject::Init(env, exports); - return exports; -} - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/test/addons-napi/6_object_wrap/binding.gyp b/test/addons-napi/6_object_wrap/binding.gyp deleted file mode 100644 index d8f91601e9c588..00000000000000 --- a/test/addons-napi/6_object_wrap/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "binding", - "sources": [ "binding.cc", "myobject.cc" ] - } - ] -} diff --git a/test/addons-napi/7_factory_wrap/binding.gyp b/test/addons-napi/7_factory_wrap/binding.gyp deleted file mode 100644 index d8f91601e9c588..00000000000000 --- a/test/addons-napi/7_factory_wrap/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "binding", - "sources": [ "binding.cc", "myobject.cc" ] - } - ] -} diff --git a/test/addons-napi/8_passing_wrapped/binding.gyp b/test/addons-napi/8_passing_wrapped/binding.gyp deleted file mode 100644 index d8f91601e9c588..00000000000000 --- a/test/addons-napi/8_passing_wrapped/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "binding", - "sources": [ "binding.cc", "myobject.cc" ] - } - ] -} diff --git a/test/addons-napi/test_array/binding.gyp b/test/addons-napi/test_array/binding.gyp deleted file mode 100644 index 44920de0986fdc..00000000000000 --- a/test/addons-napi/test_array/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_array", - "sources": [ "test_array.c" ] - } - ] -} diff --git a/test/addons-napi/test_bigint/binding.gyp b/test/addons-napi/test_bigint/binding.gyp deleted file mode 100644 index 1b9f75bab4f737..00000000000000 --- a/test/addons-napi/test_bigint/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_bigint", - "sources": [ "test_bigint.c" ] - } - ] -} diff --git a/test/addons-napi/test_constructor/binding.gyp b/test/addons-napi/test_constructor/binding.gyp deleted file mode 100644 index 1945a9fd5a711e..00000000000000 --- a/test/addons-napi/test_constructor/binding.gyp +++ /dev/null @@ -1,12 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_constructor", - "sources": [ "test_constructor.c" ] - }, - { - "target_name": "test_constructor_name", - "sources": [ "test_constructor_name.c" ] - } - ] -} diff --git a/test/addons-napi/test_constructor/test_constructor_name.c b/test/addons-napi/test_constructor/test_constructor_name.c deleted file mode 100644 index e12deb80d23af8..00000000000000 --- a/test/addons-napi/test_constructor/test_constructor_name.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include "../common.h" - -static napi_value New(napi_env env, napi_callback_info info) { - napi_value _this; - NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &_this, NULL)); - - return _this; -} - -static napi_value Init(napi_env env, napi_value exports) { - napi_value cons; - NAPI_CALL(env, napi_define_class( - env, "MyObject_Extra", 8, New, NULL, 0, NULL, &cons)); - return cons; -} - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/test/addons-napi/test_conversions/binding.gyp b/test/addons-napi/test_conversions/binding.gyp deleted file mode 100644 index 8d8d6fc0128294..00000000000000 --- a/test/addons-napi/test_conversions/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_conversions", - "sources": [ "test_conversions.c" ] - } - ] -} diff --git a/test/addons-napi/test_dataview/binding.gyp b/test/addons-napi/test_dataview/binding.gyp deleted file mode 100644 index bf014dc9e7b373..00000000000000 --- a/test/addons-napi/test_dataview/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_dataview", - "sources": [ "test_dataview.c" ] - } - ] -} diff --git a/test/addons-napi/test_error/binding.gyp b/test/addons-napi/test_error/binding.gyp deleted file mode 100644 index 2923e15adca1a1..00000000000000 --- a/test/addons-napi/test_error/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_error", - "sources": [ "test_error.c" ] - } - ] -} diff --git a/test/addons-napi/test_function/binding.gyp b/test/addons-napi/test_function/binding.gyp deleted file mode 100644 index 2b015bddd7d222..00000000000000 --- a/test/addons-napi/test_function/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_function", - "sources": [ "test_function.c" ] - } - ] -} diff --git a/test/addons-napi/test_handle_scope/binding.gyp b/test/addons-napi/test_handle_scope/binding.gyp deleted file mode 100644 index daa96681a52018..00000000000000 --- a/test/addons-napi/test_handle_scope/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_handle_scope", - "sources": [ "test_handle_scope.c" ] - } - ] -} diff --git a/test/addons-napi/test_number/binding.gyp b/test/addons-napi/test_number/binding.gyp deleted file mode 100644 index c934d5ef03bfc7..00000000000000 --- a/test/addons-napi/test_number/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_number", - "sources": [ "test_number.c" ] - } - ] -} diff --git a/test/addons-napi/test_object/binding.gyp b/test/addons-napi/test_object/binding.gyp deleted file mode 100644 index be225ace779027..00000000000000 --- a/test/addons-napi/test_object/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_object", - "sources": [ "test_object.c" ] - } - ] -} diff --git a/test/addons-napi/test_promise/binding.gyp b/test/addons-napi/test_promise/binding.gyp deleted file mode 100644 index bf266f93db74be..00000000000000 --- a/test/addons-napi/test_promise/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_promise", - "sources": [ "test_promise.c" ] - } - ] -} diff --git a/test/addons-napi/test_properties/binding.gyp b/test/addons-napi/test_properties/binding.gyp deleted file mode 100644 index 345e5c88d7c6b9..00000000000000 --- a/test/addons-napi/test_properties/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_properties", - "sources": [ "test_properties.c" ] - } - ] -} diff --git a/test/addons-napi/test_reference/binding.gyp b/test/addons-napi/test_reference/binding.gyp deleted file mode 100644 index 3a6d69a65c81f5..00000000000000 --- a/test/addons-napi/test_reference/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_reference", - "sources": [ "test_reference.c" ] - } - ] -} diff --git a/test/addons-napi/test_string/binding.gyp b/test/addons-napi/test_string/binding.gyp deleted file mode 100644 index d4825de933985f..00000000000000 --- a/test/addons-napi/test_string/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_string", - "sources": [ "test_string.c" ] - } - ] -} diff --git a/test/addons-napi/test_symbol/binding.gyp b/test/addons-napi/test_symbol/binding.gyp deleted file mode 100644 index 6ef3407968db94..00000000000000 --- a/test/addons-napi/test_symbol/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_symbol", - "sources": [ "test_symbol.c" ] - } - ] -} diff --git a/test/addons-napi/test_typedarray/binding.gyp b/test/addons-napi/test_typedarray/binding.gyp deleted file mode 100644 index 8b4a4dc622b2ef..00000000000000 --- a/test/addons-napi/test_typedarray/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "test_typedarray", - "sources": [ "test_typedarray.c" ] - } - ] -} diff --git a/test/addons-napi/.gitignore b/test/js-native-api/.gitignore similarity index 100% rename from test/addons-napi/.gitignore rename to test/js-native-api/.gitignore diff --git a/test/addons-napi/2_function_arguments/binding.c b/test/js-native-api/2_function_arguments/binding.c similarity index 88% rename from test/addons-napi/2_function_arguments/binding.c rename to test/js-native-api/2_function_arguments/binding.c index 7d88c3d9e4ff19..c9f2d03c7d2117 100644 --- a/test/addons-napi/2_function_arguments/binding.c +++ b/test/js-native-api/2_function_arguments/binding.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static napi_value Add(napi_env env, napi_callback_info info) { @@ -29,10 +29,10 @@ static napi_value Add(napi_env env, napi_callback_info info) { return sum; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor desc = DECLARE_NAPI_PROPERTY("add", Add); NAPI_CALL(env, napi_define_properties(env, exports, 1, &desc)); return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/2_function_arguments/binding.gyp b/test/js-native-api/2_function_arguments/binding.gyp new file mode 100644 index 00000000000000..2a144bab42827e --- /dev/null +++ b/test/js-native-api/2_function_arguments/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ + "../entry_point.c", + "binding.c" + ] + } + ] +} diff --git a/test/addons-napi/2_function_arguments/test.js b/test/js-native-api/2_function_arguments/test.js similarity index 100% rename from test/addons-napi/2_function_arguments/test.js rename to test/js-native-api/2_function_arguments/test.js diff --git a/test/addons-napi/3_callbacks/binding.c b/test/js-native-api/3_callbacks/binding.c similarity index 93% rename from test/addons-napi/3_callbacks/binding.c rename to test/js-native-api/3_callbacks/binding.c index 1c0dd8126ce4ef..5384fb1fc569b0 100644 --- a/test/addons-napi/3_callbacks/binding.c +++ b/test/js-native-api/3_callbacks/binding.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" #include @@ -45,7 +45,8 @@ static napi_value RunCallbackWithRecv(napi_env env, napi_callback_info info) { return NULL; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor desc[2] = { DECLARE_NAPI_PROPERTY("RunCallback", RunCallback), DECLARE_NAPI_PROPERTY("RunCallbackWithRecv", RunCallbackWithRecv), @@ -53,5 +54,4 @@ static napi_value Init(napi_env env, napi_value exports) { NAPI_CALL(env, napi_define_properties(env, exports, 2, desc)); return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/3_callbacks/binding.gyp b/test/js-native-api/3_callbacks/binding.gyp new file mode 100644 index 00000000000000..2a144bab42827e --- /dev/null +++ b/test/js-native-api/3_callbacks/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ + "../entry_point.c", + "binding.c" + ] + } + ] +} diff --git a/test/addons-napi/3_callbacks/test.js b/test/js-native-api/3_callbacks/test.js similarity index 100% rename from test/addons-napi/3_callbacks/test.js rename to test/js-native-api/3_callbacks/test.js diff --git a/test/addons-napi/4_object_factory/binding.c b/test/js-native-api/4_object_factory/binding.c similarity index 79% rename from test/addons-napi/4_object_factory/binding.c rename to test/js-native-api/4_object_factory/binding.c index 0ed95e93512a0b..5e1403a892143a 100644 --- a/test/addons-napi/4_object_factory/binding.c +++ b/test/js-native-api/4_object_factory/binding.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static napi_value CreateObject(napi_env env, napi_callback_info info) { @@ -14,10 +14,10 @@ static napi_value CreateObject(napi_env env, napi_callback_info info) { return obj; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { NAPI_CALL(env, napi_create_function(env, "exports", -1, CreateObject, NULL, &exports)); return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/4_object_factory/binding.gyp b/test/js-native-api/4_object_factory/binding.gyp new file mode 100644 index 00000000000000..2a144bab42827e --- /dev/null +++ b/test/js-native-api/4_object_factory/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ + "../entry_point.c", + "binding.c" + ] + } + ] +} diff --git a/test/addons-napi/4_object_factory/test.js b/test/js-native-api/4_object_factory/test.js similarity index 100% rename from test/addons-napi/4_object_factory/test.js rename to test/js-native-api/4_object_factory/test.js diff --git a/test/addons-napi/5_function_factory/binding.c b/test/js-native-api/5_function_factory/binding.c similarity index 80% rename from test/addons-napi/5_function_factory/binding.c rename to test/js-native-api/5_function_factory/binding.c index 19460b9ddc55f2..73c6890253d580 100644 --- a/test/addons-napi/5_function_factory/binding.c +++ b/test/js-native-api/5_function_factory/binding.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static napi_value MyFunction(napi_env env, napi_callback_info info) { @@ -14,10 +14,10 @@ static napi_value CreateFunction(napi_env env, napi_callback_info info) { return fn; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { NAPI_CALL(env, napi_create_function(env, "exports", -1, CreateFunction, NULL, &exports)); return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/5_function_factory/binding.gyp b/test/js-native-api/5_function_factory/binding.gyp new file mode 100644 index 00000000000000..2a144bab42827e --- /dev/null +++ b/test/js-native-api/5_function_factory/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ + "../entry_point.c", + "binding.c" + ] + } + ] +} diff --git a/test/addons-napi/5_function_factory/test.js b/test/js-native-api/5_function_factory/test.js similarity index 100% rename from test/addons-napi/5_function_factory/test.js rename to test/js-native-api/5_function_factory/test.js diff --git a/test/js-native-api/6_object_wrap/binding.gyp b/test/js-native-api/6_object_wrap/binding.gyp new file mode 100644 index 00000000000000..0456804aaff8b9 --- /dev/null +++ b/test/js-native-api/6_object_wrap/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ + "../entry_point.c", + "myobject.cc" + ] + } + ] +} diff --git a/test/addons-napi/6_object_wrap/myobject.cc b/test/js-native-api/6_object_wrap/myobject.cc similarity index 96% rename from test/addons-napi/6_object_wrap/myobject.cc rename to test/js-native-api/6_object_wrap/myobject.cc index aca91877d3a2ae..4d3e16ca121382 100644 --- a/test/addons-napi/6_object_wrap/myobject.cc +++ b/test/js-native-api/6_object_wrap/myobject.cc @@ -148,3 +148,10 @@ napi_value MyObject::Multiply(napi_env env, napi_callback_info info) { return instance; } + +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { + MyObject::Init(env, exports); + return exports; +} +EXTERN_C_END diff --git a/test/addons-napi/6_object_wrap/myobject.h b/test/js-native-api/6_object_wrap/myobject.h similarity index 80% rename from test/addons-napi/6_object_wrap/myobject.h rename to test/js-native-api/6_object_wrap/myobject.h index f67dddf406299f..337180598bc042 100644 --- a/test/addons-napi/6_object_wrap/myobject.h +++ b/test/js-native-api/6_object_wrap/myobject.h @@ -1,5 +1,5 @@ -#ifndef TEST_ADDONS_NAPI_6_OBJECT_WRAP_MYOBJECT_H_ -#define TEST_ADDONS_NAPI_6_OBJECT_WRAP_MYOBJECT_H_ +#ifndef TEST_JS_NATIVE_API_6_OBJECT_WRAP_MYOBJECT_H_ +#define TEST_JS_NATIVE_API_6_OBJECT_WRAP_MYOBJECT_H_ #include @@ -23,4 +23,4 @@ class MyObject { napi_ref wrapper_; }; -#endif // TEST_ADDONS_NAPI_6_OBJECT_WRAP_MYOBJECT_H_ +#endif // TEST_JS_NATIVE_API_6_OBJECT_WRAP_MYOBJECT_H_ diff --git a/test/addons-napi/6_object_wrap/test.js b/test/js-native-api/6_object_wrap/test.js similarity index 100% rename from test/addons-napi/6_object_wrap/test.js rename to test/js-native-api/6_object_wrap/test.js diff --git a/test/addons-napi/7_factory_wrap/binding.cc b/test/js-native-api/7_factory_wrap/binding.cc similarity index 92% rename from test/addons-napi/7_factory_wrap/binding.cc rename to test/js-native-api/7_factory_wrap/binding.cc index a5df612393ccec..4a75156bd5359b 100644 --- a/test/addons-napi/7_factory_wrap/binding.cc +++ b/test/js-native-api/7_factory_wrap/binding.cc @@ -1,4 +1,4 @@ -#include +#include #include "myobject.h" #include "../common.h" @@ -13,6 +13,7 @@ napi_value CreateObject(napi_env env, napi_callback_info info) { return instance; } +EXTERN_C_START napi_value Init(napi_env env, napi_value exports) { NAPI_CALL(env, MyObject::Init(env)); @@ -26,5 +27,4 @@ napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/7_factory_wrap/binding.gyp b/test/js-native-api/7_factory_wrap/binding.gyp new file mode 100644 index 00000000000000..4071c9fe8cf87a --- /dev/null +++ b/test/js-native-api/7_factory_wrap/binding.gyp @@ -0,0 +1,12 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ + "../entry_point.c", + "binding.cc", + "myobject.cc" + ] + } + ] +} diff --git a/test/addons-napi/7_factory_wrap/myobject.cc b/test/js-native-api/7_factory_wrap/myobject.cc similarity index 100% rename from test/addons-napi/7_factory_wrap/myobject.cc rename to test/js-native-api/7_factory_wrap/myobject.cc diff --git a/test/addons-napi/7_factory_wrap/myobject.h b/test/js-native-api/7_factory_wrap/myobject.h similarity index 80% rename from test/addons-napi/7_factory_wrap/myobject.h rename to test/js-native-api/7_factory_wrap/myobject.h index 24883dfa3a0c29..455ec1c52c5760 100644 --- a/test/addons-napi/7_factory_wrap/myobject.h +++ b/test/js-native-api/7_factory_wrap/myobject.h @@ -1,5 +1,5 @@ -#ifndef TEST_ADDONS_NAPI_7_FACTORY_WRAP_MYOBJECT_H_ -#define TEST_ADDONS_NAPI_7_FACTORY_WRAP_MYOBJECT_H_ +#ifndef TEST_JS_NATIVE_API_7_FACTORY_WRAP_MYOBJECT_H_ +#define TEST_JS_NATIVE_API_7_FACTORY_WRAP_MYOBJECT_H_ #include @@ -24,4 +24,4 @@ class MyObject { napi_ref wrapper_; }; -#endif // TEST_ADDONS_NAPI_7_FACTORY_WRAP_MYOBJECT_H_ +#endif // TEST_JS_NATIVE_API_7_FACTORY_WRAP_MYOBJECT_H_ diff --git a/test/addons-napi/7_factory_wrap/test.js b/test/js-native-api/7_factory_wrap/test.js similarity index 100% rename from test/addons-napi/7_factory_wrap/test.js rename to test/js-native-api/7_factory_wrap/test.js diff --git a/test/addons-napi/8_passing_wrapped/binding.cc b/test/js-native-api/8_passing_wrapped/binding.cc similarity index 92% rename from test/addons-napi/8_passing_wrapped/binding.cc rename to test/js-native-api/8_passing_wrapped/binding.cc index f978fe151954ae..8670a86879eb1c 100644 --- a/test/addons-napi/8_passing_wrapped/binding.cc +++ b/test/js-native-api/8_passing_wrapped/binding.cc @@ -1,4 +1,4 @@ -#include +#include #include "myobject.h" #include "../common.h" @@ -38,7 +38,8 @@ static napi_value FinalizeCount(napi_env env, napi_callback_info info) { return return_value; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { MyObject::Init(env); napi_property_descriptor desc[] = { @@ -52,5 +53,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/8_passing_wrapped/binding.gyp b/test/js-native-api/8_passing_wrapped/binding.gyp new file mode 100644 index 00000000000000..4071c9fe8cf87a --- /dev/null +++ b/test/js-native-api/8_passing_wrapped/binding.gyp @@ -0,0 +1,12 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ + "../entry_point.c", + "binding.cc", + "myobject.cc" + ] + } + ] +} diff --git a/test/addons-napi/8_passing_wrapped/myobject.cc b/test/js-native-api/8_passing_wrapped/myobject.cc similarity index 100% rename from test/addons-napi/8_passing_wrapped/myobject.cc rename to test/js-native-api/8_passing_wrapped/myobject.cc diff --git a/test/addons-napi/8_passing_wrapped/myobject.h b/test/js-native-api/8_passing_wrapped/myobject.h similarity index 76% rename from test/addons-napi/8_passing_wrapped/myobject.h rename to test/js-native-api/8_passing_wrapped/myobject.h index f1637b8dfee34e..445cf560aaffd8 100644 --- a/test/addons-napi/8_passing_wrapped/myobject.h +++ b/test/js-native-api/8_passing_wrapped/myobject.h @@ -1,5 +1,5 @@ -#ifndef TEST_ADDONS_NAPI_8_PASSING_WRAPPED_MYOBJECT_H_ -#define TEST_ADDONS_NAPI_8_PASSING_WRAPPED_MYOBJECT_H_ +#ifndef TEST_JS_NATIVE_API_8_PASSING_WRAPPED_MYOBJECT_H_ +#define TEST_JS_NATIVE_API_8_PASSING_WRAPPED_MYOBJECT_H_ #include @@ -23,4 +23,4 @@ class MyObject { napi_ref wrapper_; }; -#endif // TEST_ADDONS_NAPI_8_PASSING_WRAPPED_MYOBJECT_H_ +#endif // TEST_JS_NATIVE_API_8_PASSING_WRAPPED_MYOBJECT_H_ diff --git a/test/addons-napi/8_passing_wrapped/test.js b/test/js-native-api/8_passing_wrapped/test.js similarity index 100% rename from test/addons-napi/8_passing_wrapped/test.js rename to test/js-native-api/8_passing_wrapped/test.js diff --git a/test/addons-napi/common.h b/test/js-native-api/common.h similarity index 100% rename from test/addons-napi/common.h rename to test/js-native-api/common.h diff --git a/test/js-native-api/entry_point.c b/test/js-native-api/entry_point.c new file mode 100644 index 00000000000000..6b7b50a38c9535 --- /dev/null +++ b/test/js-native-api/entry_point.c @@ -0,0 +1,7 @@ +#include + +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports); +EXTERN_C_END + +NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/test/js-native-api/test_array/binding.gyp b/test/js-native-api/test_array/binding.gyp new file mode 100644 index 00000000000000..feb6bd37d88b28 --- /dev/null +++ b/test/js-native-api/test_array/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_array", + "sources": [ + "../entry_point.c", + "test_array.c" + ] + } + ] +} diff --git a/test/addons-napi/test_array/test.js b/test/js-native-api/test_array/test.js similarity index 100% rename from test/addons-napi/test_array/test.js rename to test/js-native-api/test_array/test.js diff --git a/test/addons-napi/test_array/test_array.c b/test/js-native-api/test_array/test_array.c similarity index 97% rename from test/addons-napi/test_array/test_array.c rename to test/js-native-api/test_array/test_array.c index bd4f867c0c9117..044f8636f5b9ce 100644 --- a/test/addons-napi/test_array/test_array.c +++ b/test/js-native-api/test_array/test_array.c @@ -1,4 +1,4 @@ -#include +#include #include #include "../common.h" @@ -169,7 +169,8 @@ static napi_value NewWithLength(napi_env env, napi_callback_info info) { return ret; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("TestGetElement", TestGetElement), DECLARE_NAPI_PROPERTY("TestHasElement", TestHasElement), @@ -183,5 +184,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_bigint/binding.gyp b/test/js-native-api/test_bigint/binding.gyp new file mode 100644 index 00000000000000..84db32bf3ea131 --- /dev/null +++ b/test/js-native-api/test_bigint/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_bigint", + "sources": [ + "../entry_point.c", + "test_bigint.c" + ] + } + ] +} diff --git a/test/addons-napi/test_bigint/test.js b/test/js-native-api/test_bigint/test.js similarity index 100% rename from test/addons-napi/test_bigint/test.js rename to test/js-native-api/test_bigint/test.js diff --git a/test/addons-napi/test_bigint/test_bigint.c b/test/js-native-api/test_bigint/test_bigint.c similarity index 96% rename from test/addons-napi/test_bigint/test_bigint.c rename to test/js-native-api/test_bigint/test_bigint.c index b1e6c359db6add..4befc171baa5da 100644 --- a/test/addons-napi/test_bigint/test_bigint.c +++ b/test/js-native-api/test_bigint/test_bigint.c @@ -2,7 +2,7 @@ #include #include -#include +#include #include "../common.h" static napi_value IsLossless(napi_env env, napi_callback_info info) { @@ -124,7 +124,8 @@ static napi_value CreateTooBigBigInt(napi_env env, napi_callback_info info) { return output; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("IsLossless", IsLossless), DECLARE_NAPI_PROPERTY("TestInt64", TestInt64), @@ -138,5 +139,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_constructor/binding.gyp b/test/js-native-api/test_constructor/binding.gyp new file mode 100644 index 00000000000000..0b256fd234a693 --- /dev/null +++ b/test/js-native-api/test_constructor/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_constructor", + "sources": [ + "../entry_point.c", + "test_constructor.c" + ] + } + ] +} diff --git a/test/addons-napi/test_constructor/test.js b/test/js-native-api/test_constructor/test.js similarity index 100% rename from test/addons-napi/test_constructor/test.js rename to test/js-native-api/test_constructor/test.js diff --git a/test/addons-napi/test_constructor/test2.js b/test/js-native-api/test_constructor/test2.js similarity index 74% rename from test/addons-napi/test_constructor/test2.js rename to test/js-native-api/test_constructor/test2.js index 64c03cbc684ac3..230a2250e20ae7 100644 --- a/test/addons-napi/test_constructor/test2.js +++ b/test/js-native-api/test_constructor/test2.js @@ -4,5 +4,5 @@ const assert = require('assert'); // Testing api calls for a constructor that defines properties const TestConstructor = - require(`./build/${common.buildType}/test_constructor_name`); + require(`./build/${common.buildType}/test_constructor`).constructorName; assert.strictEqual(TestConstructor.name, 'MyObject'); diff --git a/test/addons-napi/test_constructor/test_constructor.c b/test/js-native-api/test_constructor/test_constructor.c similarity index 83% rename from test/addons-napi/test_constructor/test_constructor.c rename to test/js-native-api/test_constructor/test_constructor.c index 8cc092049aef10..9084c76a1a2f51 100644 --- a/test/addons-napi/test_constructor/test_constructor.c +++ b/test/js-native-api/test_constructor/test_constructor.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static double value_ = 1; @@ -58,10 +58,21 @@ static napi_value GetStaticValue(napi_env env, napi_callback_info info) { } -static napi_value Init(napi_env env, napi_value exports) { - napi_value number; +static napi_value NewExtra(napi_env env, napi_callback_info info) { + napi_value _this; + NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &_this, NULL)); + + return _this; +} + +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { + napi_value number, cons; NAPI_CALL(env, napi_create_double(env, value_, &number)); + NAPI_CALL(env, napi_define_class( + env, "MyObject_Extra", 8, NewExtra, NULL, 0, NULL, &cons)); + napi_property_descriptor properties[] = { { "echo", 0, Echo, 0, 0, 0, napi_enumerable, 0 }, { "readwriteValue", 0, 0, 0, 0, number, napi_enumerable | napi_writable, 0 }, @@ -73,13 +84,12 @@ static napi_value Init(napi_env env, napi_value exports) { { "readonlyAccessor2", 0, 0, GetValue, NULL, 0, napi_writable, 0}, { "staticReadonlyAccessor1", 0, 0, GetStaticValue, NULL, 0, napi_default | napi_static, 0}, + { "constructorName", 0, 0, 0, 0, cons, napi_enumerable | napi_static, 0 }, }; - napi_value cons; NAPI_CALL(env, napi_define_class(env, "MyObject", NAPI_AUTO_LENGTH, New, NULL, sizeof(properties)/sizeof(*properties), properties, &cons)); return cons; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_conversions/binding.gyp b/test/js-native-api/test_conversions/binding.gyp new file mode 100644 index 00000000000000..e4b1889fecb728 --- /dev/null +++ b/test/js-native-api/test_conversions/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_conversions", + "sources": [ + "../entry_point.c", + "test_conversions.c" + ] + } + ] +} diff --git a/test/addons-napi/test_conversions/test.js b/test/js-native-api/test_conversions/test.js similarity index 100% rename from test/addons-napi/test_conversions/test.js rename to test/js-native-api/test_conversions/test.js diff --git a/test/addons-napi/test_conversions/test_conversions.c b/test/js-native-api/test_conversions/test_conversions.c similarity index 97% rename from test/addons-napi/test_conversions/test_conversions.c rename to test/js-native-api/test_conversions/test_conversions.c index 845b7e7c56d7df..85f7783d627aae 100644 --- a/test/addons-napi/test_conversions/test_conversions.c +++ b/test/js-native-api/test_conversions/test_conversions.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static napi_value AsBool(napi_env env, napi_callback_info info) { @@ -131,7 +131,8 @@ static napi_value ToString(napi_env env, napi_callback_info info) { return output; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("asBool", AsBool), DECLARE_NAPI_PROPERTY("asInt32", AsInt32), @@ -150,5 +151,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_dataview/binding.gyp b/test/js-native-api/test_dataview/binding.gyp new file mode 100644 index 00000000000000..b8d641f5c0f34e --- /dev/null +++ b/test/js-native-api/test_dataview/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_dataview", + "sources": [ + "../entry_point.c", + "test_dataview.c" + ] + } + ] +} diff --git a/test/addons-napi/test_dataview/test.js b/test/js-native-api/test_dataview/test.js similarity index 100% rename from test/addons-napi/test_dataview/test.js rename to test/js-native-api/test_dataview/test.js diff --git a/test/addons-napi/test_dataview/test_dataview.c b/test/js-native-api/test_dataview/test_dataview.c similarity index 96% rename from test/addons-napi/test_dataview/test_dataview.c rename to test/js-native-api/test_dataview/test_dataview.c index 8d29743522022f..ff3b42e63aec1e 100644 --- a/test/addons-napi/test_dataview/test_dataview.c +++ b/test/js-native-api/test_dataview/test_dataview.c @@ -1,4 +1,4 @@ -#include +#include #include #include "../common.h" @@ -85,7 +85,8 @@ static napi_value CreateDataViewFromJSDataView(napi_env env, napi_callback_info return output_dataview; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("CreateDataView", CreateDataView), DECLARE_NAPI_PROPERTY("CreateDataViewFromJSDataView", @@ -97,5 +98,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_error/binding.gyp b/test/js-native-api/test_error/binding.gyp new file mode 100644 index 00000000000000..617ececb89fcb5 --- /dev/null +++ b/test/js-native-api/test_error/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_error", + "sources": [ + "../entry_point.c", + "test_error.c" + ] + } + ] +} diff --git a/test/addons-napi/test_error/test.js b/test/js-native-api/test_error/test.js similarity index 100% rename from test/addons-napi/test_error/test.js rename to test/js-native-api/test_error/test.js diff --git a/test/addons-napi/test_error/test_error.c b/test/js-native-api/test_error/test_error.c similarity index 97% rename from test/addons-napi/test_error/test_error.c rename to test/js-native-api/test_error/test_error.c index 52a9ac7956954e..bb55272c537468 100644 --- a/test/addons-napi/test_error/test_error.c +++ b/test/js-native-api/test_error/test_error.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static napi_value checkError(napi_env env, napi_callback_info info) { @@ -135,7 +135,8 @@ static napi_value throwArbitrary(napi_env env, napi_callback_info info) { return NULL; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("checkError", checkError), DECLARE_NAPI_PROPERTY("throwExistingError", throwExistingError), @@ -159,5 +160,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_exception/binding.gyp b/test/js-native-api/test_exception/binding.gyp new file mode 100644 index 00000000000000..4844346a139338 --- /dev/null +++ b/test/js-native-api/test_exception/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_exception", + "sources": [ + "../entry_point.c", + "test_exception.c" + ] + } + ] +} diff --git a/test/addons-napi/test_exception/test.js b/test/js-native-api/test_exception/test.js similarity index 98% rename from test/addons-napi/test_exception/test.js rename to test/js-native-api/test_exception/test.js index c572b459e6027d..6ec878453f0c22 100644 --- a/test/addons-napi/test_exception/test.js +++ b/test/js-native-api/test_exception/test.js @@ -77,4 +77,3 @@ function testFinalize(binding) { (function() {})(x); } testFinalize('createExternal'); -testFinalize('createExternalBuffer'); diff --git a/test/addons-napi/test_exception/test_exception.c b/test/js-native-api/test_exception/test_exception.c similarity index 84% rename from test/addons-napi/test_exception/test_exception.c rename to test/js-native-api/test_exception/test_exception.c index 61116d0603bfae..01adf42c942b8f 100644 --- a/test/addons-napi/test_exception/test_exception.c +++ b/test/js-native-api/test_exception/test_exception.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static bool exceptionWasPending = false; @@ -59,22 +59,13 @@ static napi_value createExternal(napi_env env, napi_callback_info info) { return external; } -static char buffer_data[12]; - -static napi_value createExternalBuffer(napi_env env, napi_callback_info info) { - napi_value buffer; - NAPI_CALL(env, napi_create_external_buffer(env, sizeof(buffer_data), - buffer_data, finalizer, NULL, &buffer)); - return buffer; -} - -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("returnException", returnException), DECLARE_NAPI_PROPERTY("allowException", allowException), DECLARE_NAPI_PROPERTY("wasPending", wasPending), DECLARE_NAPI_PROPERTY("createExternal", createExternal), - DECLARE_NAPI_PROPERTY("createExternalBuffer", createExternalBuffer), }; NAPI_CALL(env, napi_define_properties( env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); @@ -89,5 +80,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_function/binding.gyp b/test/js-native-api/test_function/binding.gyp new file mode 100644 index 00000000000000..c34c18d9811e8a --- /dev/null +++ b/test/js-native-api/test_function/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_function", + "sources": [ + "../entry_point.c", + "test_function.c" + ] + } + ] +} diff --git a/test/addons-napi/test_function/test.js b/test/js-native-api/test_function/test.js similarity index 100% rename from test/addons-napi/test_function/test.js rename to test/js-native-api/test_function/test.js diff --git a/test/addons-napi/test_function/test_function.c b/test/js-native-api/test_function/test_function.c similarity index 97% rename from test/addons-napi/test_function/test_function.c rename to test/js-native-api/test_function/test_function.c index 068999a6e5bc5c..faa520b9070bf8 100644 --- a/test/addons-napi/test_function/test_function.c +++ b/test/js-native-api/test_function/test_function.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static napi_value TestCallFunction(napi_env env, napi_callback_info info) { @@ -102,7 +102,8 @@ static napi_value MakeTrackedFunction(napi_env env, napi_callback_info info) { return result; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_value fn1; NAPI_CALL(env, napi_create_function( env, NULL, NAPI_AUTO_LENGTH, TestCallFunction, NULL, &fn1)); @@ -133,5 +134,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_general/binding.gyp b/test/js-native-api/test_general/binding.gyp new file mode 100644 index 00000000000000..6a766dc5e40131 --- /dev/null +++ b/test/js-native-api/test_general/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_general", + "sources": [ + "../entry_point.c", + "test_general.c" + ] + } + ] +} diff --git a/test/addons-napi/test_general/test.js b/test/js-native-api/test_general/test.js similarity index 93% rename from test/addons-napi/test_general/test.js rename to test/js-native-api/test_general/test.js index fe38c1b9a2828c..a8548bcdf916a4 100644 --- a/test/addons-napi/test_general/test.js +++ b/test/js-native-api/test_general/test.js @@ -36,11 +36,6 @@ assert.notStrictEqual(test_general.testGetPrototype(baseObject), // expected version is currently 3 assert.strictEqual(test_general.testGetVersion(), 3); -const [ major, minor, patch, release ] = test_general.testGetNodeVersion(); -assert.strictEqual(process.version.split('-')[0], - `v${major}.${minor}.${patch}`); -assert.strictEqual(release, process.release.name); - [ 123, 'test string', diff --git a/test/addons-napi/test_general/testFinalizer.js b/test/js-native-api/test_general/testFinalizer.js similarity index 100% rename from test/addons-napi/test_general/testFinalizer.js rename to test/js-native-api/test_general/testFinalizer.js diff --git a/test/addons-napi/test_general/testGlobals.js b/test/js-native-api/test_general/testGlobals.js similarity index 100% rename from test/addons-napi/test_general/testGlobals.js rename to test/js-native-api/test_general/testGlobals.js diff --git a/test/addons-napi/test_general/testInstanceOf.js b/test/js-native-api/test_general/testInstanceOf.js similarity index 100% rename from test/addons-napi/test_general/testInstanceOf.js rename to test/js-native-api/test_general/testInstanceOf.js diff --git a/test/addons-napi/test_general/testNapiRun.js b/test/js-native-api/test_general/testNapiRun.js similarity index 100% rename from test/addons-napi/test_general/testNapiRun.js rename to test/js-native-api/test_general/testNapiRun.js diff --git a/test/addons-napi/test_general/testNapiStatus.js b/test/js-native-api/test_general/testNapiStatus.js similarity index 100% rename from test/addons-napi/test_general/testNapiStatus.js rename to test/js-native-api/test_general/testNapiStatus.js diff --git a/test/addons-napi/test_general/test_general.c b/test/js-native-api/test_general/test_general.c similarity index 88% rename from test/addons-napi/test_general/test_general.c rename to test/js-native-api/test_general/test_general.c index 498aec4983c0c8..0e717e46ec604f 100644 --- a/test/addons-napi/test_general/test_general.c +++ b/test/js-native-api/test_general/test_general.c @@ -1,5 +1,5 @@ #define NAPI_EXPERIMENTAL -#include +#include #include #include "../common.h" @@ -35,25 +35,6 @@ static napi_value testGetVersion(napi_env env, napi_callback_info info) { return result; } -static napi_value testGetNodeVersion(napi_env env, napi_callback_info info) { - const napi_node_version* node_version; - napi_value result, major, minor, patch, release; - NAPI_CALL(env, napi_get_node_version(env, &node_version)); - NAPI_CALL(env, napi_create_uint32(env, node_version->major, &major)); - NAPI_CALL(env, napi_create_uint32(env, node_version->minor, &minor)); - NAPI_CALL(env, napi_create_uint32(env, node_version->patch, &patch)); - NAPI_CALL(env, napi_create_string_utf8(env, - node_version->release, - NAPI_AUTO_LENGTH, - &release)); - NAPI_CALL(env, napi_create_array_with_length(env, 4, &result)); - NAPI_CALL(env, napi_set_element(env, result, 0, major)); - NAPI_CALL(env, napi_set_element(env, result, 1, minor)); - NAPI_CALL(env, napi_set_element(env, result, 2, patch)); - NAPI_CALL(env, napi_set_element(env, result, 3, release)); - return result; -} - static napi_value doInstanceOf(napi_env env, napi_callback_info info) { size_t argc = 2; napi_value args[2]; @@ -271,12 +252,12 @@ static napi_value add_finalizer_only(napi_env env, napi_callback_info info) { return NULL; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("testStrictEquals", testStrictEquals), DECLARE_NAPI_PROPERTY("testGetPrototype", testGetPrototype), DECLARE_NAPI_PROPERTY("testGetVersion", testGetVersion), - DECLARE_NAPI_PROPERTY("testGetNodeVersion", testGetNodeVersion), DECLARE_NAPI_PROPERTY("testNapiRun", testNapiRun), DECLARE_NAPI_PROPERTY("doInstanceOf", doInstanceOf), DECLARE_NAPI_PROPERTY("getUndefined", getUndefined), @@ -299,5 +280,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_handle_scope/binding.gyp b/test/js-native-api/test_handle_scope/binding.gyp new file mode 100644 index 00000000000000..842bd5af7444ae --- /dev/null +++ b/test/js-native-api/test_handle_scope/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_handle_scope", + "sources": [ + "../entry_point.c", + "test_handle_scope.c" + ] + } + ] +} diff --git a/test/addons-napi/test_handle_scope/test.js b/test/js-native-api/test_handle_scope/test.js similarity index 100% rename from test/addons-napi/test_handle_scope/test.js rename to test/js-native-api/test_handle_scope/test.js diff --git a/test/addons-napi/test_handle_scope/test_handle_scope.c b/test/js-native-api/test_handle_scope/test_handle_scope.c similarity index 95% rename from test/addons-napi/test_handle_scope/test_handle_scope.c rename to test/js-native-api/test_handle_scope/test_handle_scope.c index 76f31f7882b61b..e6029398aa66dc 100644 --- a/test/addons-napi/test_handle_scope/test_handle_scope.c +++ b/test/js-native-api/test_handle_scope/test_handle_scope.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" #include @@ -68,7 +68,8 @@ static napi_value NewScopeWithException(napi_env env, napi_callback_info info) { return NULL; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor properties[] = { DECLARE_NAPI_PROPERTY("NewScope", NewScope), DECLARE_NAPI_PROPERTY("NewScopeEscape", NewScopeEscape), @@ -81,5 +82,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/addons-napi/test_new_target/binding.c b/test/js-native-api/test_new_target/binding.c similarity index 95% rename from test/addons-napi/test_new_target/binding.c rename to test/js-native-api/test_new_target/binding.c index 0c542ebaba693d..bfb4138f719faf 100644 --- a/test/addons-napi/test_new_target/binding.c +++ b/test/js-native-api/test_new_target/binding.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static napi_value BaseClass(napi_env env, napi_callback_info info) { @@ -56,7 +56,8 @@ static napi_value OrdinaryFunction(napi_env env, napi_callback_info info) { return _true; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { const napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("BaseClass", BaseClass), DECLARE_NAPI_PROPERTY("OrdinaryFunction", OrdinaryFunction), @@ -65,5 +66,4 @@ static napi_value Init(napi_env env, napi_value exports) { NAPI_CALL(env, napi_define_properties(env, exports, 3, desc)); return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/addons-napi/test_new_target/binding.gyp b/test/js-native-api/test_new_target/binding.gyp similarity index 60% rename from test/addons-napi/test_new_target/binding.gyp rename to test/js-native-api/test_new_target/binding.gyp index 23daf507916ff6..dc050e6839b465 100644 --- a/test/addons-napi/test_new_target/binding.gyp +++ b/test/js-native-api/test_new_target/binding.gyp @@ -3,7 +3,10 @@ { 'target_name': 'binding', 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], - 'sources': [ 'binding.c' ] + 'sources': [ + '../entry_point.c', + 'binding.c' + ] } ] } diff --git a/test/addons-napi/test_new_target/test.js b/test/js-native-api/test_new_target/test.js similarity index 100% rename from test/addons-napi/test_new_target/test.js rename to test/js-native-api/test_new_target/test.js diff --git a/test/js-native-api/test_number/binding.gyp b/test/js-native-api/test_number/binding.gyp new file mode 100644 index 00000000000000..8e047bd4708682 --- /dev/null +++ b/test/js-native-api/test_number/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_number", + "sources": [ + "../entry_point.c", + "test_number.c" + ] + } + ] +} diff --git a/test/addons-napi/test_number/test.js b/test/js-native-api/test_number/test.js similarity index 100% rename from test/addons-napi/test_number/test.js rename to test/js-native-api/test_number/test.js diff --git a/test/addons-napi/test_number/test_number.c b/test/js-native-api/test_number/test_number.c similarity index 96% rename from test/addons-napi/test_number/test_number.c rename to test/js-native-api/test_number/test_number.c index 63290bf6d64d7e..d49bac29eff3f5 100644 --- a/test/addons-napi/test_number/test_number.c +++ b/test/js-native-api/test_number/test_number.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static napi_value Test(napi_env env, napi_callback_info info) { @@ -89,7 +89,8 @@ static napi_value TestInt64Truncation(napi_env env, napi_callback_info info) { return output; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("Test", Test), DECLARE_NAPI_PROPERTY("TestInt32Truncation", TestInt32Truncation), @@ -102,5 +103,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_object/binding.gyp b/test/js-native-api/test_object/binding.gyp new file mode 100644 index 00000000000000..94a4cd72fb6d22 --- /dev/null +++ b/test/js-native-api/test_object/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_object", + "sources": [ + "../entry_point.c", + "test_object.c" + ] + } + ] +} diff --git a/test/addons-napi/test_object/test.js b/test/js-native-api/test_object/test.js similarity index 100% rename from test/addons-napi/test_object/test.js rename to test/js-native-api/test_object/test.js diff --git a/test/addons-napi/test_object/test_object.c b/test/js-native-api/test_object/test_object.c similarity index 98% rename from test/addons-napi/test_object/test_object.c rename to test/js-native-api/test_object/test_object.c index 046f71fa414735..c7f3d55f901340 100644 --- a/test/addons-napi/test_object/test_object.c +++ b/test/js-native-api/test_object/test_object.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" #include @@ -216,7 +216,8 @@ static napi_value Unwrap(napi_env env, napi_callback_info info) { return result; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("Get", Get), DECLARE_NAPI_PROPERTY("Set", Set), @@ -234,5 +235,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_promise/binding.gyp b/test/js-native-api/test_promise/binding.gyp new file mode 100644 index 00000000000000..fd777daf5e02cc --- /dev/null +++ b/test/js-native-api/test_promise/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_promise", + "sources": [ + "../entry_point.c", + "test_promise.c" + ] + } + ] +} diff --git a/test/addons-napi/test_promise/test.js b/test/js-native-api/test_promise/test.js similarity index 100% rename from test/addons-napi/test_promise/test.js rename to test/js-native-api/test_promise/test.js diff --git a/test/addons-napi/test_promise/test_promise.c b/test/js-native-api/test_promise/test_promise.c similarity index 92% rename from test/addons-napi/test_promise/test_promise.c rename to test/js-native-api/test_promise/test_promise.c index 3e2ec48572af4c..11f7dea1917723 100644 --- a/test/addons-napi/test_promise/test_promise.c +++ b/test/js-native-api/test_promise/test_promise.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" napi_deferred deferred = NULL; @@ -47,7 +47,8 @@ static napi_value isPromise(napi_env env, napi_callback_info info) { return result; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("createPromise", createPromise), DECLARE_NAPI_PROPERTY("concludeCurrentPromise", concludeCurrentPromise), @@ -59,5 +60,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_properties/binding.gyp b/test/js-native-api/test_properties/binding.gyp new file mode 100644 index 00000000000000..adb6dd5ea151c3 --- /dev/null +++ b/test/js-native-api/test_properties/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_properties", + "sources": [ + "../entry_point.c", + "test_properties.c" + ] + } + ] +} diff --git a/test/addons-napi/test_properties/test.js b/test/js-native-api/test_properties/test.js similarity index 100% rename from test/addons-napi/test_properties/test.js rename to test/js-native-api/test_properties/test.js diff --git a/test/addons-napi/test_properties/test_properties.c b/test/js-native-api/test_properties/test_properties.c similarity index 96% rename from test/addons-napi/test_properties/test_properties.c rename to test/js-native-api/test_properties/test_properties.c index 2754812f4dad27..f26335ef1be842 100644 --- a/test/addons-napi/test_properties/test_properties.c +++ b/test/js-native-api/test_properties/test_properties.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static double value_ = 1; @@ -59,7 +59,8 @@ static napi_value HasNamedProperty(napi_env env, napi_callback_info info) { return result; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_value number; NAPI_CALL(env, napi_create_double(env, value_, &number)); @@ -98,5 +99,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_reference/binding.gyp b/test/js-native-api/test_reference/binding.gyp new file mode 100644 index 00000000000000..518fd21c37c566 --- /dev/null +++ b/test/js-native-api/test_reference/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_reference", + "sources": [ + "../entry_point.c", + "test_reference.c" + ] + } + ] +} diff --git a/test/addons-napi/test_reference/test.js b/test/js-native-api/test_reference/test.js similarity index 100% rename from test/addons-napi/test_reference/test.js rename to test/js-native-api/test_reference/test.js diff --git a/test/addons-napi/test_reference/test_reference.c b/test/js-native-api/test_reference/test_reference.c similarity index 94% rename from test/addons-napi/test_reference/test_reference.c rename to test/js-native-api/test_reference/test_reference.c index f3dc3644770ab0..6a02eb3d005a6f 100644 --- a/test/addons-napi/test_reference/test_reference.c +++ b/test/js-native-api/test_reference/test_reference.c @@ -1,5 +1,5 @@ #include -#include +#include #include "../common.h" static int test_value = 1; @@ -146,11 +146,11 @@ static napi_value ValidateDeleteBeforeFinalize(napi_env env, napi_callback_info napi_ref* ref_t = malloc(sizeof(napi_ref)); NAPI_CALL(env, napi_wrap(env, - wrapObject, - ref_t, - DeleteBeforeFinalizeFinalizer, - NULL, - NULL)); + wrapObject, + ref_t, + DeleteBeforeFinalizeFinalizer, + NULL, + NULL)); // Create a reference that will be eligible for collection at the same // time as the wrapped object by passing in the same wrapObject. @@ -165,7 +165,8 @@ static napi_value ValidateDeleteBeforeFinalize(napi_env env, napi_callback_info return wrapObject; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_GETTER("finalizeCount", GetFinalizeCount), DECLARE_NAPI_PROPERTY("createExternal", CreateExternal), @@ -178,7 +179,7 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_PROPERTY("decrementRefcount", DecrementRefcount), DECLARE_NAPI_GETTER("referenceValue", GetReferenceValue), DECLARE_NAPI_PROPERTY("validateDeleteBeforeFinalize", - ValidateDeleteBeforeFinalize), + ValidateDeleteBeforeFinalize), }; NAPI_CALL(env, napi_define_properties( @@ -186,5 +187,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_string/binding.gyp b/test/js-native-api/test_string/binding.gyp new file mode 100644 index 00000000000000..8b0f3e33543d39 --- /dev/null +++ b/test/js-native-api/test_string/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_string", + "sources": [ + "../entry_point.c", + "test_string.c" + ] + } + ] +} diff --git a/test/addons-napi/test_string/test.js b/test/js-native-api/test_string/test.js similarity index 100% rename from test/addons-napi/test_string/test.js rename to test/js-native-api/test_string/test.js diff --git a/test/addons-napi/test_string/test_string.c b/test/js-native-api/test_string/test_string.c similarity index 98% rename from test/addons-napi/test_string/test_string.c rename to test/js-native-api/test_string/test_string.c index 4e6da7bf86849f..5b62d9de6cbcec 100644 --- a/test/addons-napi/test_string/test_string.c +++ b/test/js-native-api/test_string/test_string.c @@ -1,5 +1,5 @@ #include // INT_MAX -#include +#include #include "../common.h" static napi_value TestLatin1(napi_env env, napi_callback_info info) { @@ -216,7 +216,8 @@ static napi_value TestLargeUtf8(napi_env env, napi_callback_info info) { return output; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor properties[] = { DECLARE_NAPI_PROPERTY("TestLatin1", TestLatin1), DECLARE_NAPI_PROPERTY("TestLatin1Insufficient", TestLatin1Insufficient), @@ -234,5 +235,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_symbol/binding.gyp b/test/js-native-api/test_symbol/binding.gyp new file mode 100644 index 00000000000000..254531dfa92869 --- /dev/null +++ b/test/js-native-api/test_symbol/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_symbol", + "sources": [ + "../entry_point.c", + "test_symbol.c" + ] + } + ] +} diff --git a/test/addons-napi/test_symbol/test1.js b/test/js-native-api/test_symbol/test1.js similarity index 100% rename from test/addons-napi/test_symbol/test1.js rename to test/js-native-api/test_symbol/test1.js diff --git a/test/addons-napi/test_symbol/test2.js b/test/js-native-api/test_symbol/test2.js similarity index 100% rename from test/addons-napi/test_symbol/test2.js rename to test/js-native-api/test_symbol/test2.js diff --git a/test/addons-napi/test_symbol/test3.js b/test/js-native-api/test_symbol/test3.js similarity index 100% rename from test/addons-napi/test_symbol/test3.js rename to test/js-native-api/test_symbol/test3.js diff --git a/test/addons-napi/test_symbol/test_symbol.c b/test/js-native-api/test_symbol/test_symbol.c similarity index 86% rename from test/addons-napi/test_symbol/test_symbol.c rename to test/js-native-api/test_symbol/test_symbol.c index e2c969b3b6aba6..b50ae78928f84f 100644 --- a/test/addons-napi/test_symbol/test_symbol.c +++ b/test/js-native-api/test_symbol/test_symbol.c @@ -1,4 +1,4 @@ -#include +#include #include "../common.h" static napi_value New(napi_env env, napi_callback_info info) { @@ -23,7 +23,8 @@ static napi_value New(napi_env env, napi_callback_info info) { return symbol; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor properties[] = { DECLARE_NAPI_PROPERTY("New", New), }; @@ -33,5 +34,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/test_typedarray/binding.gyp b/test/js-native-api/test_typedarray/binding.gyp new file mode 100644 index 00000000000000..0caf90049cac5d --- /dev/null +++ b/test/js-native-api/test_typedarray/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "test_typedarray", + "sources": [ + "../entry_point.c", + "test_typedarray.c" + ] + } + ] +} diff --git a/test/addons-napi/test_typedarray/test.js b/test/js-native-api/test_typedarray/test.js similarity index 100% rename from test/addons-napi/test_typedarray/test.js rename to test/js-native-api/test_typedarray/test.js diff --git a/test/addons-napi/test_typedarray/test_typedarray.c b/test/js-native-api/test_typedarray/test_typedarray.c similarity index 97% rename from test/addons-napi/test_typedarray/test_typedarray.c rename to test/js-native-api/test_typedarray/test_typedarray.c index a0ac02665864f1..98480a4ea23e1f 100644 --- a/test/addons-napi/test_typedarray/test_typedarray.c +++ b/test/js-native-api/test_typedarray/test_typedarray.c @@ -1,4 +1,4 @@ -#include +#include #include #include "../common.h" @@ -165,7 +165,8 @@ static napi_value CreateTypedArray(napi_env env, napi_callback_info info) { return output_array; } -static napi_value Init(napi_env env, napi_value exports) { +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor descriptors[] = { DECLARE_NAPI_PROPERTY("Multiply", Multiply), DECLARE_NAPI_PROPERTY("External", External), @@ -177,5 +178,4 @@ static napi_value Init(napi_env env, napi_value exports) { return exports; } - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) +EXTERN_C_END diff --git a/test/js-native-api/testcfg.py b/test/js-native-api/testcfg.py new file mode 100644 index 00000000000000..4e5d67709a87c3 --- /dev/null +++ b/test/js-native-api/testcfg.py @@ -0,0 +1,6 @@ +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +import testpy + +def GetConfiguration(context, root): + return testpy.AddonTestConfiguration(context, root, 'js-native-api') diff --git a/test/addons-napi/1_hello_world/binding.c b/test/node-api/1_hello_world/binding.c similarity index 92% rename from test/addons-napi/1_hello_world/binding.c rename to test/node-api/1_hello_world/binding.c index 02cd5dd2f19418..b896da2cba4d84 100644 --- a/test/addons-napi/1_hello_world/binding.c +++ b/test/node-api/1_hello_world/binding.c @@ -1,5 +1,5 @@ #include -#include "../common.h" +#include "../../js-native-api/common.h" #include static napi_value Method(napi_env env, napi_callback_info info) { diff --git a/test/addons-napi/1_hello_world/binding.gyp b/test/node-api/1_hello_world/binding.gyp similarity index 100% rename from test/addons-napi/1_hello_world/binding.gyp rename to test/node-api/1_hello_world/binding.gyp diff --git a/test/addons-napi/1_hello_world/test.js b/test/node-api/1_hello_world/test.js similarity index 100% rename from test/addons-napi/1_hello_world/test.js rename to test/node-api/1_hello_world/test.js diff --git a/test/addons-napi/test_async/binding.gyp b/test/node-api/test_async/binding.gyp similarity index 100% rename from test/addons-napi/test_async/binding.gyp rename to test/node-api/test_async/binding.gyp diff --git a/test/addons-napi/test_async/test-async-hooks.js b/test/node-api/test_async/test-async-hooks.js similarity index 100% rename from test/addons-napi/test_async/test-async-hooks.js rename to test/node-api/test_async/test-async-hooks.js diff --git a/test/addons-napi/test_async/test-loop.js b/test/node-api/test_async/test-loop.js similarity index 100% rename from test/addons-napi/test_async/test-loop.js rename to test/node-api/test_async/test-loop.js diff --git a/test/addons-napi/test_async/test-uncaught.js b/test/node-api/test_async/test-uncaught.js similarity index 100% rename from test/addons-napi/test_async/test-uncaught.js rename to test/node-api/test_async/test-uncaught.js diff --git a/test/addons-napi/test_async/test.js b/test/node-api/test_async/test.js similarity index 100% rename from test/addons-napi/test_async/test.js rename to test/node-api/test_async/test.js diff --git a/test/addons-napi/test_async/test_async.cc b/test/node-api/test_async/test_async.cc similarity index 99% rename from test/addons-napi/test_async/test_async.cc rename to test/node-api/test_async/test_async.cc index a7ea0eb64c0537..49db7aa66f190b 100644 --- a/test/addons-napi/test_async/test_async.cc +++ b/test/node-api/test_async/test_async.cc @@ -1,6 +1,6 @@ #include #include -#include "../common.h" +#include "../../js-native-api/common.h" #if defined _WIN32 #include diff --git a/test/addons-napi/test_buffer/binding.gyp b/test/node-api/test_buffer/binding.gyp similarity index 100% rename from test/addons-napi/test_buffer/binding.gyp rename to test/node-api/test_buffer/binding.gyp diff --git a/test/addons-napi/test_buffer/test.js b/test/node-api/test_buffer/test.js similarity index 100% rename from test/addons-napi/test_buffer/test.js rename to test/node-api/test_buffer/test.js diff --git a/test/addons-napi/test_buffer/test_buffer.c b/test/node-api/test_buffer/test_buffer.c similarity index 99% rename from test/addons-napi/test_buffer/test_buffer.c rename to test/node-api/test_buffer/test_buffer.c index 552d280615739f..15d7c46e975d9a 100644 --- a/test/addons-napi/test_buffer/test_buffer.c +++ b/test/node-api/test_buffer/test_buffer.c @@ -1,7 +1,7 @@ #include #include #include -#include "../common.h" +#include "../../js-native-api/common.h" static const char theText[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; diff --git a/test/addons-napi/test_callback_scope/binding.cc b/test/node-api/test_callback_scope/binding.cc similarity index 99% rename from test/addons-napi/test_callback_scope/binding.cc rename to test/node-api/test_callback_scope/binding.cc index e6631b6ac7bb52..1a06d04fce53e3 100644 --- a/test/addons-napi/test_callback_scope/binding.cc +++ b/test/node-api/test_callback_scope/binding.cc @@ -1,6 +1,6 @@ #include "node_api.h" #include "uv.h" -#include "../common.h" +#include "../../js-native-api/common.h" namespace { diff --git a/test/addons-napi/test_callback_scope/binding.gyp b/test/node-api/test_callback_scope/binding.gyp similarity index 100% rename from test/addons-napi/test_callback_scope/binding.gyp rename to test/node-api/test_callback_scope/binding.gyp diff --git a/test/addons-napi/test_callback_scope/test-async-hooks.js b/test/node-api/test_callback_scope/test-async-hooks.js similarity index 100% rename from test/addons-napi/test_callback_scope/test-async-hooks.js rename to test/node-api/test_callback_scope/test-async-hooks.js diff --git a/test/addons-napi/test_callback_scope/test-resolve-async.js b/test/node-api/test_callback_scope/test-resolve-async.js similarity index 100% rename from test/addons-napi/test_callback_scope/test-resolve-async.js rename to test/node-api/test_callback_scope/test-resolve-async.js diff --git a/test/addons-napi/test_callback_scope/test.js b/test/node-api/test_callback_scope/test.js similarity index 100% rename from test/addons-napi/test_callback_scope/test.js rename to test/node-api/test_callback_scope/test.js diff --git a/test/addons-napi/test_cleanup_hook/binding.cc b/test/node-api/test_cleanup_hook/binding.cc similarity index 92% rename from test/addons-napi/test_cleanup_hook/binding.cc rename to test/node-api/test_cleanup_hook/binding.cc index 66d53508c69f13..9426716e674d22 100644 --- a/test/addons-napi/test_cleanup_hook/binding.cc +++ b/test/node-api/test_cleanup_hook/binding.cc @@ -1,6 +1,6 @@ #include "node_api.h" #include "uv.h" -#include "../common.h" +#include "../../js-native-api/common.h" namespace { diff --git a/test/addons-napi/test_cleanup_hook/binding.gyp b/test/node-api/test_cleanup_hook/binding.gyp similarity index 100% rename from test/addons-napi/test_cleanup_hook/binding.gyp rename to test/node-api/test_cleanup_hook/binding.gyp diff --git a/test/addons-napi/test_cleanup_hook/test.js b/test/node-api/test_cleanup_hook/test.js similarity index 100% rename from test/addons-napi/test_cleanup_hook/test.js rename to test/node-api/test_cleanup_hook/test.js diff --git a/test/addons-napi/test_env_sharing/binding.gyp b/test/node-api/test_env_sharing/binding.gyp similarity index 100% rename from test/addons-napi/test_env_sharing/binding.gyp rename to test/node-api/test_env_sharing/binding.gyp diff --git a/test/addons-napi/test_env_sharing/compare_env.c b/test/node-api/test_env_sharing/compare_env.c similarity index 94% rename from test/addons-napi/test_env_sharing/compare_env.c rename to test/node-api/test_env_sharing/compare_env.c index 3326a34067219a..0c365f7e343dca 100644 --- a/test/addons-napi/test_env_sharing/compare_env.c +++ b/test/node-api/test_env_sharing/compare_env.c @@ -1,5 +1,5 @@ #include -#include "../common.h" +#include "../../js-native-api/common.h" static napi_value compare(napi_env env, napi_callback_info info) { napi_value external; diff --git a/test/addons-napi/test_env_sharing/store_env.c b/test/node-api/test_env_sharing/store_env.c similarity index 85% rename from test/addons-napi/test_env_sharing/store_env.c rename to test/node-api/test_env_sharing/store_env.c index 0559b178cba68b..6f59cf1fc0f2d9 100644 --- a/test/addons-napi/test_env_sharing/store_env.c +++ b/test/node-api/test_env_sharing/store_env.c @@ -1,5 +1,5 @@ #include -#include "../common.h" +#include "../../js-native-api/common.h" static napi_value Init(napi_env env, napi_value exports) { napi_value external; diff --git a/test/addons-napi/test_env_sharing/test.js b/test/node-api/test_env_sharing/test.js similarity index 100% rename from test/addons-napi/test_env_sharing/test.js rename to test/node-api/test_env_sharing/test.js diff --git a/test/addons-napi/test_exception/binding.gyp b/test/node-api/test_exception/binding.gyp similarity index 100% rename from test/addons-napi/test_exception/binding.gyp rename to test/node-api/test_exception/binding.gyp diff --git a/test/node-api/test_exception/test.js b/test/node-api/test_exception/test.js new file mode 100644 index 00000000000000..d5d675ab7e2066 --- /dev/null +++ b/test/node-api/test_exception/test.js @@ -0,0 +1,17 @@ +'use strict'; +// Flags: --expose-gc + +const common = require('../../common'); +const assert = require('assert'); +const test_exception = require(`./build/${common.buildType}/test_exception`); + +// Make sure that exceptions that occur during finalization are propagated. +function testFinalize(binding) { + let x = test_exception[binding](); + x = null; + assert.throws(() => { global.gc(); }, /Error during Finalize/); + + // To assuage the linter's concerns. + (function() {})(x); +} +testFinalize('createExternalBuffer'); diff --git a/test/node-api/test_exception/test_exception.c b/test/node-api/test_exception/test_exception.c new file mode 100644 index 00000000000000..78744bee2cc60f --- /dev/null +++ b/test/node-api/test_exception/test_exception.c @@ -0,0 +1,27 @@ +#include +#include "../../js-native-api/common.h" + +static void finalizer(napi_env env, void *data, void *hint) { + NAPI_CALL_RETURN_VOID(env, + napi_throw_error(env, NULL, "Error during Finalize")); +} + +static char buffer_data[12]; + +static napi_value createExternalBuffer(napi_env env, napi_callback_info info) { + napi_value buffer; + NAPI_CALL(env, napi_create_external_buffer(env, sizeof(buffer_data), + buffer_data, finalizer, NULL, &buffer)); + return buffer; +} + +static napi_value Init(napi_env env, napi_value exports) { + napi_property_descriptor descriptors[] = { + DECLARE_NAPI_PROPERTY("createExternalBuffer", createExternalBuffer), + }; + NAPI_CALL(env, napi_define_properties( + env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); + return exports; +} + +NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/test/addons-napi/test_fatal/binding.gyp b/test/node-api/test_fatal/binding.gyp similarity index 100% rename from test/addons-napi/test_fatal/binding.gyp rename to test/node-api/test_fatal/binding.gyp diff --git a/test/addons-napi/test_fatal/test.js b/test/node-api/test_fatal/test.js similarity index 100% rename from test/addons-napi/test_fatal/test.js rename to test/node-api/test_fatal/test.js diff --git a/test/addons-napi/test_fatal/test2.js b/test/node-api/test_fatal/test2.js similarity index 100% rename from test/addons-napi/test_fatal/test2.js rename to test/node-api/test_fatal/test2.js diff --git a/test/addons-napi/test_fatal/test_fatal.c b/test/node-api/test_fatal/test_fatal.c similarity index 95% rename from test/addons-napi/test_fatal/test_fatal.c rename to test/node-api/test_fatal/test_fatal.c index b9248d40d49e6a..70bb458ef20e4e 100644 --- a/test/addons-napi/test_fatal/test_fatal.c +++ b/test/node-api/test_fatal/test_fatal.c @@ -1,5 +1,5 @@ #include -#include "../common.h" +#include "../../js-native-api/common.h" static napi_value Test(napi_env env, napi_callback_info info) { napi_fatal_error("test_fatal::Test", NAPI_AUTO_LENGTH, diff --git a/test/addons-napi/test_fatal_exception/binding.gyp b/test/node-api/test_fatal_exception/binding.gyp similarity index 100% rename from test/addons-napi/test_fatal_exception/binding.gyp rename to test/node-api/test_fatal_exception/binding.gyp diff --git a/test/addons-napi/test_fatal_exception/test.js b/test/node-api/test_fatal_exception/test.js similarity index 100% rename from test/addons-napi/test_fatal_exception/test.js rename to test/node-api/test_fatal_exception/test.js diff --git a/test/addons-napi/test_fatal_exception/test_fatal_exception.c b/test/node-api/test_fatal_exception/test_fatal_exception.c similarity index 93% rename from test/addons-napi/test_fatal_exception/test_fatal_exception.c rename to test/node-api/test_fatal_exception/test_fatal_exception.c index 3cc810ccc0d10c..0e14b9b435871a 100644 --- a/test/addons-napi/test_fatal_exception/test_fatal_exception.c +++ b/test/node-api/test_fatal_exception/test_fatal_exception.c @@ -1,5 +1,5 @@ #include -#include "../common.h" +#include "../../js-native-api/common.h" static napi_value Test(napi_env env, napi_callback_info info) { napi_value err; diff --git a/test/addons-napi/test_general/binding.gyp b/test/node-api/test_general/binding.gyp similarity index 100% rename from test/addons-napi/test_general/binding.gyp rename to test/node-api/test_general/binding.gyp diff --git a/test/node-api/test_general/test.js b/test/node-api/test_general/test.js new file mode 100644 index 00000000000000..108d51a1e11ac9 --- /dev/null +++ b/test/node-api/test_general/test.js @@ -0,0 +1,10 @@ +'use strict'; + +const common = require('../../common'); +const test_general = require(`./build/${common.buildType}/test_general`); +const assert = require('assert'); + +const [ major, minor, patch, release ] = test_general.testGetNodeVersion(); +assert.strictEqual(process.version.split('-')[0], + `v${major}.${minor}.${patch}`); +assert.strictEqual(release, process.release.name); diff --git a/test/node-api/test_general/test_general.c b/test/node-api/test_general/test_general.c new file mode 100644 index 00000000000000..05bccaf5c2cf4f --- /dev/null +++ b/test/node-api/test_general/test_general.c @@ -0,0 +1,36 @@ +#define NAPI_EXPERIMENTAL +#include +#include +#include "../../js-native-api/common.h" + +static napi_value testGetNodeVersion(napi_env env, napi_callback_info info) { + const napi_node_version* node_version; + napi_value result, major, minor, patch, release; + NAPI_CALL(env, napi_get_node_version(env, &node_version)); + NAPI_CALL(env, napi_create_uint32(env, node_version->major, &major)); + NAPI_CALL(env, napi_create_uint32(env, node_version->minor, &minor)); + NAPI_CALL(env, napi_create_uint32(env, node_version->patch, &patch)); + NAPI_CALL(env, napi_create_string_utf8(env, + node_version->release, + NAPI_AUTO_LENGTH, + &release)); + NAPI_CALL(env, napi_create_array_with_length(env, 4, &result)); + NAPI_CALL(env, napi_set_element(env, result, 0, major)); + NAPI_CALL(env, napi_set_element(env, result, 1, minor)); + NAPI_CALL(env, napi_set_element(env, result, 2, patch)); + NAPI_CALL(env, napi_set_element(env, result, 3, release)); + return result; +} + +static napi_value Init(napi_env env, napi_value exports) { + napi_property_descriptor descriptors[] = { + DECLARE_NAPI_PROPERTY("testGetNodeVersion", testGetNodeVersion), + }; + + NAPI_CALL(env, napi_define_properties( + env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); + + return exports; +} + +NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/test/addons-napi/test_make_callback/binding.c b/test/node-api/test_make_callback/binding.c similarity index 97% rename from test/addons-napi/test_make_callback/binding.c rename to test/node-api/test_make_callback/binding.c index 8eedd5b1b3b167..04e95e2570afe3 100644 --- a/test/addons-napi/test_make_callback/binding.c +++ b/test/node-api/test_make_callback/binding.c @@ -1,5 +1,5 @@ #include -#include "../common.h" +#include "../../js-native-api/common.h" #define MAX_ARGUMENTS 10 diff --git a/test/addons-napi/test_make_callback/binding.gyp b/test/node-api/test_make_callback/binding.gyp similarity index 100% rename from test/addons-napi/test_make_callback/binding.gyp rename to test/node-api/test_make_callback/binding.gyp diff --git a/test/addons-napi/test_make_callback/test-async-hooks.js b/test/node-api/test_make_callback/test-async-hooks.js similarity index 100% rename from test/addons-napi/test_make_callback/test-async-hooks.js rename to test/node-api/test_make_callback/test-async-hooks.js diff --git a/test/addons-napi/test_make_callback/test.js b/test/node-api/test_make_callback/test.js similarity index 100% rename from test/addons-napi/test_make_callback/test.js rename to test/node-api/test_make_callback/test.js diff --git a/test/addons-napi/test_make_callback_recurse/binding.cc b/test/node-api/test_make_callback_recurse/binding.cc similarity index 97% rename from test/addons-napi/test_make_callback_recurse/binding.cc rename to test/node-api/test_make_callback_recurse/binding.cc index bfe9a457d237c8..93440ee4ce54c2 100644 --- a/test/addons-napi/test_make_callback_recurse/binding.cc +++ b/test/node-api/test_make_callback_recurse/binding.cc @@ -1,5 +1,5 @@ #include -#include "../common.h" +#include "../../js-native-api/common.h" #include namespace { diff --git a/test/addons-napi/test_make_callback_recurse/binding.gyp b/test/node-api/test_make_callback_recurse/binding.gyp similarity index 100% rename from test/addons-napi/test_make_callback_recurse/binding.gyp rename to test/node-api/test_make_callback_recurse/binding.gyp diff --git a/test/addons-napi/test_make_callback_recurse/test.js b/test/node-api/test_make_callback_recurse/test.js similarity index 100% rename from test/addons-napi/test_make_callback_recurse/test.js rename to test/node-api/test_make_callback_recurse/test.js diff --git a/test/addons-napi/test_null_init/binding.gyp b/test/node-api/test_null_init/binding.gyp similarity index 100% rename from test/addons-napi/test_null_init/binding.gyp rename to test/node-api/test_null_init/binding.gyp diff --git a/test/addons-napi/test_null_init/test.js b/test/node-api/test_null_init/test.js similarity index 100% rename from test/addons-napi/test_null_init/test.js rename to test/node-api/test_null_init/test.js diff --git a/test/addons-napi/test_null_init/test_null_init.c b/test/node-api/test_null_init/test_null_init.c similarity index 100% rename from test/addons-napi/test_null_init/test_null_init.c rename to test/node-api/test_null_init/test_null_init.c diff --git a/test/addons-napi/test_threadsafe_function/binding.c b/test/node-api/test_threadsafe_function/binding.c similarity index 99% rename from test/addons-napi/test_threadsafe_function/binding.c rename to test/node-api/test_threadsafe_function/binding.c index 354012a288b3ca..c985178c5a7fa4 100644 --- a/test/addons-napi/test_threadsafe_function/binding.c +++ b/test/node-api/test_threadsafe_function/binding.c @@ -6,7 +6,7 @@ #include #define NAPI_EXPERIMENTAL #include -#include "../common.h" +#include "../../js-native-api/common.h" #define ARRAY_LENGTH 10 #define MAX_QUEUE_SIZE 2 diff --git a/test/addons-napi/test_threadsafe_function/binding.gyp b/test/node-api/test_threadsafe_function/binding.gyp similarity index 100% rename from test/addons-napi/test_threadsafe_function/binding.gyp rename to test/node-api/test_threadsafe_function/binding.gyp diff --git a/test/addons-napi/test_threadsafe_function/test.js b/test/node-api/test_threadsafe_function/test.js similarity index 100% rename from test/addons-napi/test_threadsafe_function/test.js rename to test/node-api/test_threadsafe_function/test.js diff --git a/test/addons-napi/test_uv_loop/binding.gyp b/test/node-api/test_uv_loop/binding.gyp similarity index 100% rename from test/addons-napi/test_uv_loop/binding.gyp rename to test/node-api/test_uv_loop/binding.gyp diff --git a/test/addons-napi/test_uv_loop/test.js b/test/node-api/test_uv_loop/test.js similarity index 100% rename from test/addons-napi/test_uv_loop/test.js rename to test/node-api/test_uv_loop/test.js diff --git a/test/addons-napi/test_uv_loop/test_uv_loop.cc b/test/node-api/test_uv_loop/test_uv_loop.cc similarity index 98% rename from test/addons-napi/test_uv_loop/test_uv_loop.cc rename to test/node-api/test_uv_loop/test_uv_loop.cc index 048e25af9ddfb3..c5eaac52736240 100644 --- a/test/addons-napi/test_uv_loop/test_uv_loop.cc +++ b/test/node-api/test_uv_loop/test_uv_loop.cc @@ -3,7 +3,7 @@ #include #include #include -#include "../common.h" +#include "../../js-native-api/common.h" template void* SetImmediate(napi_env env, T&& cb) { diff --git a/test/addons-napi/testcfg.py b/test/node-api/testcfg.py similarity index 65% rename from test/addons-napi/testcfg.py rename to test/node-api/testcfg.py index b112eb009924fc..3453f3bc373856 100644 --- a/test/addons-napi/testcfg.py +++ b/test/node-api/testcfg.py @@ -3,4 +3,4 @@ import testpy def GetConfiguration(context, root): - return testpy.AddonTestConfiguration(context, root, 'addons-napi') + return testpy.AddonTestConfiguration(context, root, 'node-api') diff --git a/tools/test.py b/tools/test.py index 46235ab05aec92..e59dd8b782e13c 100755 --- a/tools/test.py +++ b/tools/test.py @@ -1499,7 +1499,8 @@ def PrintCrashed(code): # addons/ requires compilation. IGNORED_SUITES = [ 'addons', - 'addons-napi', + 'js-native-api', + 'node-api', 'benchmark', 'doctool', 'internet', diff --git a/vcbuild.bat b/vcbuild.bat index 11f623ad0d35c1..97f88c4266a4c6 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -44,13 +44,14 @@ set configure_flags= set build_addons= set dll= set enable_static= -set build_addons_napi= +set build_js_native_api_tests= +set build_node_api_tests= set test_node_inspect= set test_check_deopts= set js_test_suites=default set v8_test_options= set v8_build_options= -set "common_test_suites=%js_test_suites% doctool addons addons-napi&set build_addons=1&set build_addons_napi=1" +set "common_test_suites=%js_test_suites% doctool addons js-native-api node-api&set build_addons=1&set build_js_native_api_tests=1&set build_node_api_tests=1" set http2_debug= set nghttp2_debug= set link_module= @@ -81,9 +82,11 @@ if /i "%1"=="licensertf" set licensertf=1&goto arg-ok if /i "%1"=="test" set test_args=%test_args% -J %common_test_suites%&set lint_cpp=1&set lint_js=1&set lint_md=1&goto arg-ok if /i "%1"=="test-ci" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap %common_test_suites%&set cctest_args=%cctest_args% --gtest_output=tap:cctest.tap&goto arg-ok if /i "%1"=="build-addons" set build_addons=1&goto arg-ok -if /i "%1"=="build-addons-napi" set build_addons_napi=1&goto arg-ok +if /i "%1"=="build-js-native-api-tests" set build_js_native_api_tests=1&goto arg-ok +if /i "%1"=="build-node-api-tests" set build_node_api_tests=1&goto arg-ok if /i "%1"=="test-addons" set test_args=%test_args% addons&set build_addons=1&goto arg-ok -if /i "%1"=="test-addons-napi" set test_args=%test_args% addons-napi&set build_addons_napi=1&goto arg-ok +if /i "%1"=="test-js-native-api" set test_args=%test_args% js-native-api&set build_js_native_api_tests=1&goto arg-ok +if /i "%1"=="test-node-api" set test_args=%test_args% node-api&set build_node_api_tests=1&goto arg-ok if /i "%1"=="test-benchmark" set test_args=%test_args% benchmark&goto arg-ok if /i "%1"=="test-simple" set test_args=%test_args% sequential parallel -J&goto arg-ok if /i "%1"=="test-message" set test_args=%test_args% message&goto arg-ok @@ -475,10 +478,10 @@ for %%F in (%config%\doc\api\*.md) do ( :run @rem Run tests if requested. -if not defined build_addons goto build-addons-napi +if not defined build_addons goto build-js-native-api-tests if not exist "%node_exe%" ( echo Failed to find node.exe - goto build-addons-napi + goto build-js-native-api-tests ) echo Building addons :: clear @@ -495,21 +498,40 @@ set npm_config_nodedir=%~dp0 if errorlevel 1 exit /b 1 endlocal -:build-addons-napi -if not defined build_addons_napi goto run-tests +:build-js-native-api-tests +if not defined build_js_native_api_tests goto build-node-api-tests +if not exist "%node_exe%" ( + echo Failed to find node.exe + goto build-node-api-tests +) +echo Building js-native-api +:: clear +for /d %%F in (test\js-native-api\??_*) do ( + rd /s /q %%F +) +:: building js-native-api +setlocal +set npm_config_nodedir=%~dp0 +"%node_exe%" "%~dp0tools\build-addons.js" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\js-native-api" +if errorlevel 1 exit /b 1 +endlocal +goto build-node-api-tests + +:build-node-api-tests +if not defined build_node_api_tests goto run-tests if not exist "%node_exe%" ( echo Failed to find node.exe goto run-tests ) -echo Building addons-napi +echo Building node-api :: clear -for /d %%F in (test\addons-napi\??_*) do ( +for /d %%F in (test\node-api\??_*) do ( rd /s /q %%F ) -:: building addons-napi +:: building node-api setlocal set npm_config_nodedir=%~dp0 -"%node_exe%" "%~dp0tools\build-addons.js" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\addons-napi" +"%node_exe%" "%~dp0tools\build-addons.js" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\node-api" if errorlevel 1 exit /b 1 endlocal goto run-tests @@ -557,7 +579,7 @@ goto lint-cpp :lint-cpp if not defined lint_cpp goto lint-js -call :run-lint-cpp src\*.c src\*.cc src\*.h test\addons\*.cc test\addons\*.h test\addons-napi\*.cc test\addons-napi\*.h test\cctest\*.cc test\cctest\*.h tools\icu\*.cc tools\icu\*.h +call :run-lint-cpp src\*.c src\*.cc src\*.h test\addons\*.cc test\addons\*.h test\js-native-api\*.cc test\js-native-api\*.cc test\js-native-api\*.h test\node-api\*.cc test\node-api\*.cc test\node-api\*.h test\cctest\*.cc test\cctest\*.h tools\icu\*.cc tools\icu\*.h python tools/check-imports.py goto lint-js @@ -594,7 +616,10 @@ if %errorlevel% equ 0 goto exit echo %1 | findstr /r /c:"test\\addons\\[0-9].*_.*\.cc" > nul 2>&1 if %errorlevel% equ 0 goto exit -echo %1 | findstr /c:"test\addons-napi\common.h" > nul 2>&1 +echo %1 | findstr /c:"test\js-native-api\common.h" > nul 2>&1 +if %errorlevel% equ 0 goto exit + +echo %1 | findstr /c:"test\node-api\common.h" > nul 2>&1 if %errorlevel% equ 0 goto exit set "localcppfilelist=%localcppfilelist% %1" @@ -643,7 +668,7 @@ del .used_configure_flags goto exit :help -echo vcbuild.bat [debug/release] [msi] [doc] [test/test-ci/test-all/test-addons/test-addons-napi/test-benchmark/test-internet/test-pummel/test-simple/test-message/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-async-hooks/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [noetw] [ltcg] [nopch] [licensetf] [sign] [ia32/x86/x64] [vs2017] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-js-ci/lint-md] [lint-md-build] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm] +echo vcbuild.bat [debug/release] [msi] [doc] [test/test-ci/test-all/test-addons/test-js-native-api/test-node-api/test-benchmark/test-internet/test-pummel/test-simple/test-message/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-async-hooks/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [noetw] [ltcg] [nopch] [licensetf] [sign] [ia32/x86/x64] [vs2017] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-js-ci/lint-md] [lint-md-build] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm] echo Examples: echo vcbuild.bat : builds release build echo vcbuild.bat debug : builds debug build