test: partition N-API tests

Partition test/addons-napi into test/js-native-api and test/node-api to
isolate the Node.js-agnostic portion of the N-API tests from the
Node.js-specific portion.

PR-URL: https://github.com/nodejs/node/pull/24557
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit is contained in:
Gabriel Schulhof 2018-11-17 12:34:54 -08:00
parent 83ee137c45
commit 938e11882b
178 changed files with 654 additions and 436 deletions

113
Makefile
View File

@ -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-addons-napi-clean
test-addons-napi-clean:
$(RM) -r test/addons-napi/*/build
$(RM) test/addons-napi/.buildstamp
.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-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 \
))

View File

@ -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. |

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "binding",
"sources": [ "binding.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "binding",
"sources": [ "binding.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "binding",
"sources": [ "binding.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "binding",
"sources": [ "binding.c" ]
}
]
}

View File

@ -1,10 +0,0 @@
#include <node_api.h>
#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)

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "binding",
"sources": [ "binding.cc", "myobject.cc" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "binding",
"sources": [ "binding.cc", "myobject.cc" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "binding",
"sources": [ "binding.cc", "myobject.cc" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_array",
"sources": [ "test_array.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_bigint",
"sources": [ "test_bigint.c" ]
}
]
}

View File

@ -1,12 +0,0 @@
{
"targets": [
{
"target_name": "test_constructor",
"sources": [ "test_constructor.c" ]
},
{
"target_name": "test_constructor_name",
"sources": [ "test_constructor_name.c" ]
}
]
}

View File

@ -1,18 +0,0 @@
#include <node_api.h>
#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)

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_conversions",
"sources": [ "test_conversions.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_dataview",
"sources": [ "test_dataview.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_error",
"sources": [ "test_error.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_function",
"sources": [ "test_function.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_handle_scope",
"sources": [ "test_handle_scope.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_number",
"sources": [ "test_number.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_object",
"sources": [ "test_object.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_promise",
"sources": [ "test_promise.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_properties",
"sources": [ "test_properties.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_reference",
"sources": [ "test_reference.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_string",
"sources": [ "test_string.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_symbol",
"sources": [ "test_symbol.c" ]
}
]
}

View File

@ -1,8 +0,0 @@
{
"targets": [
{
"target_name": "test_typedarray",
"sources": [ "test_typedarray.c" ]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "binding",
"sources": [
"../entry_point.c",
"binding.c"
]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#include "../common.h"
#include <string.h>
@ -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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "binding",
"sources": [
"../entry_point.c",
"binding.c"
]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "binding",
"sources": [
"../entry_point.c",
"binding.c"
]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "binding",
"sources": [
"../entry_point.c",
"binding.c"
]
}
]
}

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "binding",
"sources": [
"../entry_point.c",
"myobject.cc"
]
}
]
}

View File

@ -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

View File

@ -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 <js_native_api.h>
@ -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_

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,12 @@
{
"targets": [
{
"target_name": "binding",
"sources": [
"../entry_point.c",
"binding.cc",
"myobject.cc"
]
}
]
}

View File

@ -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 <js_native_api.h>
@ -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_

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,12 @@
{
"targets": [
{
"target_name": "binding",
"sources": [
"../entry_point.c",
"binding.cc",
"myobject.cc"
]
}
]
}

View File

@ -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 <js_native_api.h>
@ -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_

View File

@ -0,0 +1,7 @@
#include <node_api.h>
EXTERN_C_START
napi_value Init(napi_env env, napi_value exports);
EXTERN_C_END
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_array",
"sources": [
"../entry_point.c",
"test_array.c"
]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#include <string.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_bigint",
"sources": [
"../entry_point.c",
"test_bigint.c"
]
}
]
}

View File

@ -2,7 +2,7 @@
#include <inttypes.h>
#include <stdio.h>
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_constructor",
"sources": [
"../entry_point.c",
"test_constructor.c"
]
}
]
}

View File

@ -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');

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_conversions",
"sources": [
"../entry_point.c",
"test_conversions.c"
]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_dataview",
"sources": [
"../entry_point.c",
"test_dataview.c"
]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#include <string.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_error",
"sources": [
"../entry_point.c",
"test_error.c"
]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_exception",
"sources": [
"../entry_point.c",
"test_exception.c"
]
}
]
}

View File

@ -77,4 +77,3 @@ function testFinalize(binding) {
(function() {})(x);
}
testFinalize('createExternal');
testFinalize('createExternalBuffer');

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_function",
"sources": [
"../entry_point.c",
"test_function.c"
]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_general",
"sources": [
"../entry_point.c",
"test_general.c"
]
}
]
}

View File

@ -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',

View File

@ -1,5 +1,5 @@
#define NAPI_EXPERIMENTAL
#include <node_api.h>
#include <js_native_api.h>
#include <stdlib.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_handle_scope",
"sources": [
"../entry_point.c",
"test_handle_scope.c"
]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#include "../common.h"
#include <string.h>
@ -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

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -3,7 +3,10 @@
{
'target_name': 'binding',
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
'sources': [ 'binding.c' ]
'sources': [
'../entry_point.c',
'binding.c'
]
}
]
}

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_number",
"sources": [
"../entry_point.c",
"test_number.c"
]
}
]
}

View File

@ -1,4 +1,4 @@
#include <node_api.h>
#include <js_native_api.h>
#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

View File

@ -0,0 +1,11 @@
{
"targets": [
{
"target_name": "test_object",
"sources": [
"../entry_point.c",
"test_object.c"
]
}
]
}

Some files were not shown because too many files have changed in this diff Show More