diff --git a/.gitignore b/.gitignore index a6e530f24963..0ff301ace382 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ ipch/ /npm.wxs /tools/msvs/npm.wixobj /tools/msvs/genfiles/ +/test/addons/??_*/ email.md deps/v8-* deps/icu diff --git a/Makefile b/Makefile index 33159d4af4d9..66bca71097f9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ --include .deps # Generated by GYP. -include config.mk BUILDTYPE ?= Release @@ -66,9 +65,9 @@ V ?= 1 # BUILDTYPE=Debug builds both release and debug builds. If you want to compile # just the debug build, run `make -C out BUILDTYPE=Debug` instead. ifeq ($(BUILDTYPE),Release) -all: $(NODE_EXE) ## Default target, builds node in out/Release/node. +all: out/Makefile $(NODE_EXE) ## Default target, builds node in out/Release/node. else -all: $(NODE_EXE) $(NODE_G_EXE) +all: out/Makefile $(NODE_EXE) $(NODE_G_EXE) endif .PHONY: help @@ -78,24 +77,32 @@ help: ## Print help for targets with comments. @grep -E '^[a-zA-Z0-9._-]+:.*?## .*$$' Makefile | sort | \ awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' -$(NODE_EXE): out/Release/node - ln -fs $< $@ +# The .PHONY is needed to ensure that we recursively use the out/Makefile +# to check for changes. +.PHONY: $(NODE_EXE) $(NODE_G_EXE) -$(NODE_G_EXE): out/Debug/node - ln -fs $< $@ - -out/Release/node: out/Makefile $(ALL_DEPS) +# The -r/-L check stops it recreating the link if it is already in place, +# otherwise $(NODE_EXE) being a .PHONY target means it is always re-run. +# Without the check there is a race condition between the link being deleted +# and recreated which can break the addons build when running test-ci +# See comments on the build-addons target for some more info +$(NODE_EXE): config.gypi out/Makefile $(MAKE) -C out BUILDTYPE=Release V=$(V) + if [ ! -r $@ -o ! -L $@ ]; then ln -fs out/Release/$(NODE_EXE) $@; fi -out/Debug/node: out/Makefile $(ALL_DEPS) +$(NODE_G_EXE): config.gypi out/Makefile $(MAKE) -C out BUILDTYPE=Debug V=$(V) + if [ ! -r $@ -o ! -L $@ ]; then ln -fs out/Debug/$(NODE_EXE) $@; fi -out/Makefile .deps: deps/uv/uv.gyp deps/http_parser/http_parser.gyp \ +out/Makefile: common.gypi deps/uv/uv.gyp deps/http_parser/http_parser.gyp \ deps/zlib/zlib.gyp deps/v8/gypfiles/toolchain.gypi \ deps/v8/gypfiles/features.gypi deps/v8/src/v8.gyp node.gyp \ - common.gypi config.gypi + config.gypi $(PYTHON) tools/gyp_node.py -f make +config.gypi: configure + $(error Missing or stale $@, please run ./$<) + .PHONY: install install: all ## Installs node into $PREFIX (default=/usr/local). $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)' @@ -225,7 +232,9 @@ v8: .PHONY: test # This does not run tests of third-party libraries inside deps. -test: all check-doc-addons build-addons ## Runs default tests, linters, and builds docs. +test: all ## Runs default tests, linters, and builds docs. + $(MAKE) -s build-addons + $(MAKE) -s build-addons-napi $(MAKE) -s doc-only $(MAKE) -s lint $(MAKE) -s cctest @@ -234,19 +243,19 @@ test: all check-doc-addons build-addons ## Runs default tests, linters, and buil $(CI_NATIVE_SUITES) \ $(CI_DOC) -.PHONY: check-doc-addons -check-doc-addons: $(NODE) - $(NODE) tools/doc/addon-verify.js --check - .PHONY: test-only -test-only: all build-addons ## For a quick test, does not run linter or build docs. +test-only: all ## For a quick test, does not run linter or build docs. + $(MAKE) build-addons + $(MAKE) build-addons-napi $(MAKE) cctest $(PYTHON) tools/test.py --mode=release -J \ $(CI_JS_SUITES) \ $(CI_NATIVE_SUITES) # Used by `make coverage-test` -test-cov: all build-addons +test-cov: all + $(MAKE) build-addons + $(MAKE) build-addons-napi # $(MAKE) cctest $(PYTHON) tools/test.py --mode=release -J \ $(CI_JS_SUITES) \ @@ -262,53 +271,115 @@ test-valgrind: all test-check-deopts: all $(PYTHON) tools/test.py --mode=release --check-deopts parallel sequential -J -ADDON_PREREQS := \ - common.gypi \ - config.gypi \ - deps/npm/node_modules/node-gyp/package.json \ - src/node.h \ - src/node_api.h \ - src/node_api_types.h \ - src/node_buffer.h \ - src/node_object_wrap.h \ - src/node_version.h \ - $(wildcard deps/openssl/openssl/include/openssl/*.h) \ - $(wildcard deps/uv/include/*.h) \ - $(wildcard deps/v8/include/*.h) \ - $(wildcard deps/zlib/*.h) \ +benchmark/misc/function_call/build/Release/binding.node: all \ + benchmark/misc/function_call/binding.cc \ + benchmark/misc/function_call/binding.gyp + $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \ + --python="$(PYTHON)" \ + --directory="$(shell pwd)/benchmark/misc/function_call" \ + --nodedir="$(shell pwd)" + +# Implicitly depends on $(NODE_EXE). We don't depend on it explicitly because +# it always triggers a rebuild due to it being a .PHONY rule. See the comment +# near the build-addons rule for more background. +test/gc/build/Release/binding.node: test/gc/binding.cc test/gc/binding.gyp + $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \ + --python="$(PYTHON)" \ + --directory="$(shell pwd)/test/gc" \ + --nodedir="$(shell pwd)" + +DOCBUILDSTAMP_PREREQS = tools/doc/addon-verify.js doc/api/addons.md ifeq ($(OSTYPE),aix) -ADDON_PREREQS := $(ADDON_PREREQS) out/$(BUILDTYPE)/node.exp +DOCBUILDSTAMP_PREREQS := $(DOCBUILDSTAMP_PREREQS) out/$(BUILDTYPE)/node.exp endif -ADDON_DIRS := \ - $(dir benchmark/misc/function_call/ test/gc/ \ - $(wildcard test/addons-napi/*/binding.gyp) \ - $(wildcard test/addons/*/binding.gyp)) - -ADDON_FILES := \ - $(foreach d, $(ADDON_DIRS), $(d)build/$(BUILDTYPE)/binding.node) +test/addons/.docbuildstamp: $(DOCBUILDSTAMP_PREREQS) + $(RM) -r test/addons/??_*/ + [ -x $(NODE) ] && $(NODE) $< || node $< + touch $@ -NODE_GYP := \ - env MAKEFLAGS="-j1" \ - $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp \ - --loglevel="$(LOGLEVEL)" --nodedir="$(CURDIR)" --python="$(PYTHON)" +ADDONS_BINDING_GYPS := \ + $(filter-out test/addons/??_*/binding.gyp, \ + $(wildcard test/addons/*/binding.gyp)) -define do_addon -$(1)build/Makefile: $(1)binding.gyp common.gypi - $(NODE_GYP) --directory=$(1) configure -$(1)build/Release/.buildstamp: $(1)build/Makefile $(2) $(ADDON_PREREQS) - $(NODE_GYP) --directory=$(1) build - @touch $$@ -$(1)build/Release/binding.node: $(1)build/Release/.buildstamp -endef +ADDONS_BINDING_SOURCES := \ + $(filter-out test/addons/??_*/*.cc, $(wildcard test/addons/*/*.cc)) \ + $(filter-out test/addons/??_*/*.h, $(wildcard test/addons/*/*.h)) -$(foreach x, $(ADDON_DIRS), \ - $(eval $(call do_addon,$(x),$(wildcard $(x)/*.{c,cc,h})))) +# Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale. +# Depends on node-gyp package.json so that build-addons is (re)executed when +# node-gyp is updated as part of an npm update. +test/addons/.buildstamp: config.gypi \ + deps/npm/node_modules/node-gyp/package.json \ + $(ADDONS_BINDING_GYPS) $(ADDONS_BINDING_SOURCES) \ + deps/uv/include/*.h deps/v8/include/*.h \ + src/node.h src/node_buffer.h src/node_object_wrap.h src/node_version.h \ + test/addons/.docbuildstamp +# Cannot use $(wildcard test/addons/*/) here, it's evaluated before +# embedded addons have been generated from the documentation. +# Ignore folders without binding.gyp +# (https://github.com/nodejs/node/issues/14843) + @for dirname in test/addons/*/; do \ + if [ ! -f "$$PWD/$${dirname}binding.gyp" ]; then \ + continue; fi ; \ + printf "\nBuilding addon $$PWD/$$dirname\n" ; \ + env MAKEFLAGS="-j1" $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp \ + --loglevel=$(LOGLEVEL) rebuild \ + --python="$(PYTHON)" \ + --directory="$$PWD/$$dirname" \ + --nodedir="$$PWD" || exit 1 ; \ + done + touch $@ .PHONY: build-addons -build-addons: $(NODE) - @$(MAKE) -s $(ADDON_FILES) +# .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 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)) + +ADDONS_NAPI_BINDING_SOURCES := \ + $(filter-out test/addons-napi/??_*/*.cc, $(wildcard test/addons-napi/*/*.cc)) \ + $(filter-out test/addons-napi/??_*/*.h, $(wildcard test/addons-napi/*/*.h)) + +# Implicitly depends on $(NODE_EXE), see the build-addons-napi rule for rationale. +test/addons-napi/.buildstamp: config.gypi \ + deps/npm/node_modules/node-gyp/package.json \ + $(ADDONS_NAPI_BINDING_GYPS) $(ADDONS_NAPI_BINDING_SOURCES) \ + deps/uv/include/*.h deps/v8/include/*.h \ + src/node.h src/node_buffer.h src/node_object_wrap.h src/node_version.h \ + src/node_api.h src/node_api_types.h +# Cannot use $(wildcard test/addons-napi/*/) here, it's evaluated before +# embedded addons have been generated from the documentation. +# Ignore folders without binding.gyp +# (https://github.com/nodejs/node/issues/14843) + @for dirname in test/addons-napi/*/; do \ + if [ ! -f "$$PWD/$${dirname}binding.gyp" ]; then \ + continue; fi ; \ + printf "\nBuilding addon $$PWD/$$dirname\n" ; \ + env MAKEFLAGS="-j1" $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp \ + --loglevel=$(LOGLEVEL) rebuild \ + --python="$(PYTHON)" \ + --directory="$$PWD/$$dirname" \ + --nodedir="$$PWD" || exit 1 ; \ + done + touch $@ + +.PHONY: build-addons-napi +# .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 .PHONY: clear-stalled clear-stalled: @@ -327,11 +398,15 @@ test-gc: all test/gc/build/Release/binding.node test-gc-clean: $(RM) -r test/gc/build +test-build: | all build-addons build-addons-napi + +test-build-addons-napi: all build-addons-napi + .PHONY: test-all -test-all: test/gc/build/Release/binding.node ## Run everything in test/. +test-all: test-build test/gc/build/Release/binding.node ## Run everything in test/. $(PYTHON) tools/test.py --mode=debug,release -test-all-valgrind: build-addons +test-all-valgrind: test-build $(PYTHON) tools/test.py --mode=debug,release --valgrind CI_NATIVE_SUITES ?= addons addons-napi @@ -342,7 +417,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: $(ADDON_FILES) +test-ci-native: | test/addons/.buildstamp test/addons-napi/.buildstamp $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ --mode=release --flaky-tests=$(FLAKY_TESTS) \ $(TEST_CI_ARGS) $(CI_NATIVE_SUITES) @@ -364,7 +439,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: build-addons | clear-stalled doc-only +test-ci: | clear-stalled build-addons build-addons-napi doc-only out/Release/cctest --gtest_output=tap:cctest.tap $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ --mode=release --flaky-tests=$(FLAKY_TESTS) \ @@ -393,13 +468,13 @@ build-ci: run-ci: build-ci $(MAKE) test-ci -test-release: build-addons +test-release: test-build $(PYTHON) tools/test.py --mode=release -test-debug: build-addons +test-debug: test-build $(PYTHON) tools/test.py --mode=debug -test-message: all +test-message: test-build $(PYTHON) tools/test.py message test-simple: | cctest # Depends on 'all'. @@ -439,21 +514,23 @@ test-npm-publish: $(NODE_EXE) npm_package_config_publishtest=true $(NODE) deps/npm/test/run.js .PHONY: test-addons-napi -test-addons-napi: build-addons +test-addons-napi: test-build-addons-napi $(PYTHON) tools/test.py --mode=release addons-napi .PHONY: test-addons-napi-clean test-addons-napi-clean: $(RM) -r test/addons-napi/*/build + $(RM) test/addons-napi/.buildstamp .PHONY: test-addons -test-addons: build-addons +test-addons: test-build test-addons-napi $(PYTHON) tools/test.py --mode=release addons .PHONY: test-addons-clean test-addons-clean: $(RM) -r test/addons/??_*/ $(RM) -r test/addons/*/build + $(RM) test/addons/.buildstamp test/addons/.docbuildstamp $(MAKE) test-addons-napi-clean test-timers: @@ -466,7 +543,9 @@ test-timers-clean: test-async-hooks: $(PYTHON) tools/test.py --mode=release async-hooks -test-with-async-hooks: build-addons +test-with-async-hooks: + $(MAKE) build-addons + $(MAKE) build-addons-napi $(MAKE) cctest NODE_TEST_WITH_ASYNC_HOOKS=1 $(PYTHON) tools/test.py --mode=release -J \ $(CI_JS_SUITES) \ @@ -1029,32 +1108,36 @@ lint-js-ci: jslint-ci: lint-js-ci @echo "Please use lint-js-ci instead of jslint-ci" +LINT_CPP_ADDON_DOC_FILES = $(wildcard test/addons/??_*/*.cc test/addons/??_*/*.h) 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) # These files were copied more or less verbatim from V8. LINT_CPP_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h -LINT_CPP_FILES := \ - $(filter-out \ - $(LINT_CPP_EXCLUDE), \ - $(wildcard \ - benchmark/misc/function_call/binding.cc \ - src/*.c \ - src/*.cc \ - src/*.h \ - src/*/*.c \ - src/*/*.cc \ - src/*/*.h \ - test/addons/*/*.cc \ - test/addons/*/*.h \ - test/cctest/*.cc \ - test/cctest/*.h \ - test/addons-napi/*/*.cc \ - test/addons-napi/*/*.h \ - test/gc/binding.cc \ - tools/icu/*.cc \ - tools/icu/*.h \ - )) +LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \ + benchmark/misc/function_call/binding.cc \ + src/*.c \ + src/*.cc \ + src/*.h \ + src/*/*.c \ + src/*/*.cc \ + src/*/*.h \ + test/addons/*/*.cc \ + test/addons/*/*.h \ + test/cctest/*.cc \ + test/cctest/*.h \ + test/addons-napi/*/*.cc \ + test/addons-napi/*/*.h \ + test/gc/binding.cc \ + tools/icu/*.cc \ + tools/icu/*.h \ + )) + +# Code blocks don't have newline at the end, +# and the actual filename is generated so it won't match header guards +ADDON_DOC_LINT_FLAGS=-whitespace/ending_newline,-build/header_guard .PHONY: lint-cpp # Lints the C++ code with cpplint.py and check-imports.py. @@ -1066,6 +1149,10 @@ tools/.cpplintstamp: $(LINT_CPP_FILES) @$(PYTHON) tools/check-imports.py @touch $@ +lint-addon-docs: test/addons/.docbuildstamp + @echo "Running C++ linter on addon docs..." + @$(PYTHON) tools/cpplint.py --filter=$(ADDON_DOC_LINT_FLAGS) $(LINT_CPP_ADDON_DOC_FILES) + cpplint: lint-cpp @echo "Please use lint-cpp instead of cpplint" @@ -1076,11 +1163,12 @@ lint: ## Run JS, C++, MD and doc linters. @EXIT_STATUS=0 ; \ $(MAKE) lint-js || EXIT_STATUS=$$? ; \ $(MAKE) lint-cpp || EXIT_STATUS=$$? ; \ + $(MAKE) lint-addon-docs || EXIT_STATUS=$$? ; \ exit $$EXIT_STATUS CONFLICT_RE=^>>>>>>> [0-9A-Fa-f]+|^<<<<<<< [A-Za-z]+ # Related CI job: node-test-linter -lint-ci: lint-js-ci lint-cpp lint-md +lint-ci: lint-js-ci lint-cpp lint-md lint-addon-docs @if ! ( grep -IEqrs "$(CONFLICT_RE)" benchmark deps doc lib src test tools ) \ && ! ( find . -maxdepth 1 -type f | xargs grep -IEqs "$(CONFLICT_RE)" ); then \ exit 0 ; \ diff --git a/doc/api/addons.md b/doc/api/addons.md index 6b847237918a..e2df5f30e9a3 100644 --- a/doc/api/addons.md +++ b/doc/api/addons.md @@ -1,6 +1,3 @@ - # C++ Addons @@ -97,12 +94,12 @@ The `module_name` must match the filename of the final binary (excluding the .node suffix). In the `hello.cc` example, then, the initialization function is `init` and the -Addon module name is `binding`. +Addon module name is `addon`. ### Building Once the source code has been written, it must be compiled into the binary -`binding.node` file. To do so, create a file called `binding.gyp` in the +`addon.node` file. To do so, create a file called `binding.gyp` in the top-level of the project describing the build configuration of the module using a JSON-like format. This file is used by [node-gyp][] -- a tool written specifically to compile Node.js Addons. @@ -111,7 +108,7 @@ specifically to compile Node.js Addons. { "targets": [ { - "target_name": "binding", + "target_name": "addon", "sources": [ "hello.cc" ] } ] @@ -131,21 +128,21 @@ generate the appropriate project build files for the current platform. This will generate either a `Makefile` (on Unix platforms) or a `vcxproj` file (on Windows) in the `build/` directory. -Next, invoke the `node-gyp build` command to generate the compiled -`binding.node` file. This will be put into the `build/Release/` directory. +Next, invoke the `node-gyp build` command to generate the compiled `addon.node` +file. This will be put into the `build/Release/` directory. When using `npm install` to install a Node.js Addon, npm uses its own bundled version of `node-gyp` to perform this same set of actions, generating a compiled version of the Addon for the user's platform on demand. Once built, the binary Addon can be used from within Node.js by pointing -[`require()`][require] to the built `binding.node` module: +[`require()`][require] to the built `addon.node` module: ```js // hello.js -const binding = require('./build/Release/binding'); +const addon = require('./build/Release/addon'); -console.log(binding.hello()); +console.log(addon.hello()); // Prints: 'world' ``` @@ -162,9 +159,9 @@ similar to: ```js try { - return require('./build/Release/binding.node'); + return require('./build/Release/addon.node'); } catch (err) { - return require('./build/Debug/binding.node'); + return require('./build/Debug/addon.node'); } ``` @@ -198,9 +195,9 @@ When calling [`require()`][require], the `.node` extension can usually be omitted and Node.js will still find and initialize the Addon. One caveat, however, is that Node.js will first attempt to locate and load modules or JavaScript files that happen to share the same base name. For instance, if -there is a file `binding.js` in the same directory as the binary `binding.node`, -then [`require('binding')`][require] will give precedence to the `binding.js` -file and load it instead. +there is a file `addon.js` in the same directory as the binary `addon.node`, +then [`require('addon')`][require] will give precedence to the `addon.js` file +and load it instead. ## Native Abstractions for Node.js @@ -287,8 +284,8 @@ Each of these examples using the following `binding.gyp` file: { "targets": [ { - "target_name": "binding", - "sources": [ "binding.cc" ] + "target_name": "addon", + "sources": [ "addon.cc" ] } ] } @@ -298,7 +295,7 @@ In cases where there is more than one `.cc` file, simply add the additional filename to the `sources` array. For example: ```json -"sources": ["binding.cc", "myexample.cc"] +"sources": ["addon.cc", "myexample.cc"] ``` Once the `binding.gyp` file is ready, the example Addons can be configured and @@ -320,7 +317,7 @@ The following example illustrates how to read function arguments passed from JavaScript and how to return a result: ```cpp -// binding.cc +// addon.cc #include namespace demo { @@ -377,9 +374,9 @@ Once compiled, the example Addon can be required and used from within Node.js: ```js // test.js -const binding = require('./build/Release/binding'); +const addon = require('./build/Release/addon'); -console.log('This should be eight:', binding.add(3, 5)); +console.log('This should be eight:', addon.add(3, 5)); ``` @@ -390,7 +387,7 @@ function and execute them from there. The following example illustrates how to invoke such callbacks: ```cpp -// binding.cc +// addon.cc #include namespace demo { @@ -430,9 +427,9 @@ To test it, run the following JavaScript: ```js // test.js -const binding = require('./build/Release/binding'); +const addon = require('./build/Release/addon'); -binding((msg) => { +addon((msg) => { console.log(msg); // Prints: 'hello world' }); @@ -447,7 +444,7 @@ illustrated in the following example. An object is created and returned with a property `msg` that echoes the string passed to `createObject()`: ```cpp -// binding.cc +// addon.cc #include namespace demo { @@ -481,10 +478,10 @@ To test it in JavaScript: ```js // test.js -const binding = require('./build/Release/binding'); +const addon = require('./build/Release/addon'); -const obj1 = binding('hello'); -const obj2 = binding('world'); +const obj1 = addon('hello'); +const obj2 = addon('world'); console.log(obj1.msg, obj2.msg); // Prints: 'hello world' ``` @@ -496,7 +493,7 @@ Another common scenario is creating JavaScript functions that wrap C++ functions and returning those back to JavaScript: ```cpp -// binding.cc +// addon.cc #include namespace demo { @@ -540,9 +537,9 @@ To test: ```js // test.js -const binding = require('./build/Release/binding'); +const addon = require('./build/Release/addon'); -const fn = binding(); +const fn = addon(); console.log(fn()); // Prints: 'hello world' ``` @@ -554,7 +551,7 @@ It is also possible to wrap C++ objects/classes in a way that allows new instances to be created using the JavaScript `new` operator: ```cpp -// binding.cc +// addon.cc #include #include "myobject.h" @@ -689,9 +686,9 @@ To build this example, the `myobject.cc` file must be added to the { "targets": [ { - "target_name": "binding", + "target_name": "addon", "sources": [ - "binding.cc", + "addon.cc", "myobject.cc" ] } @@ -703,9 +700,9 @@ Test it with: ```js // test.js -const binding = require('./build/Release/binding'); +const addon = require('./build/Release/addon'); -const obj = new binding.MyObject(10); +const obj = new addon.MyObject(10); console.log(obj.plusOne()); // Prints: 11 console.log(obj.plusOne()); @@ -720,15 +717,15 @@ Alternatively, it is possible to use a factory pattern to avoid explicitly creating object instances using the JavaScript `new` operator: ```js -const obj = binding.createObject(); +const obj = addon.createObject(); // instead of: -// const obj = new binding.Object(); +// const obj = new addon.Object(); ``` -First, the `createObject()` method is implemented in `binding.cc`: +First, the `createObject()` method is implemented in `addon.cc`: ```cpp -// binding.cc +// addon.cc #include #include "myobject.h" @@ -884,9 +881,9 @@ Once again, to build this example, the `myobject.cc` file must be added to the { "targets": [ { - "target_name": "binding", + "target_name": "addon", "sources": [ - "binding.cc", + "addon.cc", "myobject.cc" ] } @@ -898,7 +895,7 @@ Test it with: ```js // test.js -const createObject = require('./build/Release/binding'); +const createObject = require('./build/Release/addon'); const obj = createObject(10); console.log(obj.plusOne()); @@ -926,7 +923,7 @@ wrapped objects around by unwrapping them with the Node.js helper function that can take two `MyObject` objects as input arguments: ```cpp -// binding.cc +// addon.cc #include #include #include "myobject.h" @@ -1080,11 +1077,11 @@ Test it with: ```js // test.js -const binding = require('./build/Release/binding'); +const addon = require('./build/Release/addon'); -const obj1 = binding.createObject(10); -const obj2 = binding.createObject(20); -const result = binding.add(obj1, obj2); +const obj1 = addon.createObject(10); +const obj2 = addon.createObject(20); +const result = addon.add(obj1, obj2); console.log(result); // Prints: 30 @@ -1109,10 +1106,10 @@ and a pointer to untyped context data to be passed to that callback. Callbacks are run in last-in first-out order. -The following `binding.cc` implements AtExit: +The following `addon.cc` implements AtExit: ```cpp -// binding.cc +// addon.cc #include #include #include @@ -1164,7 +1161,7 @@ Test in JavaScript by running: ```js // test.js -require('./build/Release/binding'); +require('./build/Release/addon'); ``` [Embedder's Guide]: https://github.com/v8/v8/wiki/Embedder's%20Guide diff --git a/node.gyp b/node.gyp index ddb8e4c15fc3..d0c8f05e66a9 100644 --- a/node.gyp +++ b/node.gyp @@ -537,6 +537,14 @@ # node_dtrace_ustack.o not supported on mac and linux # node_dtrace_provider.o All except OS X. "dtrace -G" is not # used on OS X. + # + # Note that node_dtrace_provider.cc and node_dtrace_ustack.cc do not + # actually exist. They're listed here to trick GYP into linking the + # corresponding object files into the final "node" executable. These + # object files are generated by "dtrace -G" using custom actions + # below, and the GYP-generated Makefiles will properly build them when + # needed. + # 'sources': [ 'src/node_dtrace.cc' ], 'conditions': [ [ 'OS=="linux"', { @@ -546,8 +554,8 @@ }], [ 'OS!="mac" and OS!="linux"', { 'sources': [ - '<(OBJ_DIR)/<(node_lib_target_name)/src/node_dtrace_provider.o', - '<(OBJ_DIR)/<(node_lib_target_name)/src/node_dtrace_ustack.o', + 'src/node_dtrace_ustack.cc', + 'src/node_dtrace_provider.cc', ] } ] ] diff --git a/test/addons-napi/test_array/binding.gyp b/test/addons-napi/test_array/binding.gyp index bb8f4b453aae..44920de0986f 100644 --- a/test/addons-napi/test_array/binding.gyp +++ b/test/addons-napi/test_array/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_array", "sources": [ "test_array.c" ] } ] diff --git a/test/addons-napi/test_array/test.js b/test/addons-napi/test_array/test.js index bba951d921d8..75c181d9da82 100644 --- a/test/addons-napi/test_array/test.js +++ b/test/addons-napi/test_array/test.js @@ -3,7 +3,7 @@ const common = require('../../common'); const assert = require('assert'); // Testing api calls for arrays -const test_array = require(`./build/${common.buildType}/binding`); +const test_array = require(`./build/${common.buildType}/test_array`); const array = [ 1, diff --git a/test/addons-napi/test_async/binding.gyp b/test/addons-napi/test_async/binding.gyp index 2837dfb294b7..cf8beb70c68e 100644 --- a/test/addons-napi/test_async/binding.gyp +++ b/test/addons-napi/test_async/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_async", "sources": [ "test_async.cc" ] } ] diff --git a/test/addons-napi/test_async/test-async-hooks.js b/test/addons-napi/test_async/test-async-hooks.js index 32c798d08582..db6e0cbd1679 100644 --- a/test/addons-napi/test_async/test-async-hooks.js +++ b/test/addons-napi/test_async/test-async-hooks.js @@ -2,7 +2,7 @@ const common = require('../../common'); const assert = require('assert'); const async_hooks = require('async_hooks'); -const test_async = require(`./build/${common.buildType}/binding`); +const test_async = require(`./build/${common.buildType}/test_async`); const events = []; let testId; diff --git a/test/addons-napi/test_async/test.js b/test/addons-napi/test_async/test.js index 1e5194abea74..34ecae08e67f 100644 --- a/test/addons-napi/test_async/test.js +++ b/test/addons-napi/test_async/test.js @@ -2,7 +2,7 @@ const common = require('../../common'); const assert = require('assert'); const child_process = require('child_process'); -const test_async = require(`./build/${common.buildType}/binding`); +const test_async = require(`./build/${common.buildType}/test_async`); const testException = 'test_async_cb_exception'; diff --git a/test/addons-napi/test_buffer/binding.gyp b/test/addons-napi/test_buffer/binding.gyp index b3a6cee217f7..e41a3993cd7c 100644 --- a/test/addons-napi/test_buffer/binding.gyp +++ b/test/addons-napi/test_buffer/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_buffer", "sources": [ "test_buffer.c" ] } ] diff --git a/test/addons-napi/test_buffer/test.js b/test/addons-napi/test_buffer/test.js index 29104b906fe6..740b0474a79c 100644 --- a/test/addons-napi/test_buffer/test.js +++ b/test/addons-napi/test_buffer/test.js @@ -2,7 +2,7 @@ // Flags: --expose-gc const common = require('../../common'); -const binding = require(`./build/${common.buildType}/binding`); +const binding = require(`./build/${common.buildType}/test_buffer`); const assert = require('assert'); assert.strictEqual(binding.newBuffer().toString(), binding.theText); diff --git a/test/addons-napi/test_constructor/binding.gyp b/test/addons-napi/test_constructor/binding.gyp index e194da9da2a0..1945a9fd5a71 100644 --- a/test/addons-napi/test_constructor/binding.gyp +++ b/test/addons-napi/test_constructor/binding.gyp @@ -1,8 +1,12 @@ { "targets": [ { - "target_name": "binding", + "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.js b/test/addons-napi/test_constructor/test.js index 6fd124c8920b..616ba6c2a292 100644 --- a/test/addons-napi/test_constructor/test.js +++ b/test/addons-napi/test_constructor/test.js @@ -3,7 +3,7 @@ const common = require('../../common'); const assert = require('assert'); // Testing api calls for a constructor that defines properties -const TestConstructor = require(`./build/${common.buildType}/binding`); +const TestConstructor = require(`./build/${common.buildType}/test_constructor`); const test_object = new TestConstructor(); assert.strictEqual(test_object.echo('hello'), 'hello'); diff --git a/test/addons-napi/test_constructor_name/test.js b/test/addons-napi/test_constructor/test2.js similarity index 69% rename from test/addons-napi/test_constructor_name/test.js rename to test/addons-napi/test_constructor/test2.js index 0f713ff55c7c..64c03cbc684a 100644 --- a/test/addons-napi/test_constructor_name/test.js +++ b/test/addons-napi/test_constructor/test2.js @@ -3,5 +3,6 @@ const common = require('../../common'); const assert = require('assert'); // Testing api calls for a constructor that defines properties -const TestConstructor = require(`./build/${common.buildType}/binding`); +const TestConstructor = + require(`./build/${common.buildType}/test_constructor_name`); assert.strictEqual(TestConstructor.name, 'MyObject'); diff --git a/test/addons-napi/test_constructor_name/test_constructor_name.c b/test/addons-napi/test_constructor/test_constructor_name.c similarity index 100% rename from test/addons-napi/test_constructor_name/test_constructor_name.c rename to test/addons-napi/test_constructor/test_constructor_name.c diff --git a/test/addons-napi/test_constructor_name/binding.gyp b/test/addons-napi/test_constructor_name/binding.gyp deleted file mode 100644 index 8beb20988872..000000000000 --- a/test/addons-napi/test_constructor_name/binding.gyp +++ /dev/null @@ -1,8 +0,0 @@ -{ - "targets": [ - { - "target_name": "binding", - "sources": [ "test_constructor_name.c" ] - } - ] -} diff --git a/test/addons-napi/test_conversions/binding.gyp b/test/addons-napi/test_conversions/binding.gyp index b667ffd6de81..8d8d6fc01282 100644 --- a/test/addons-napi/test_conversions/binding.gyp +++ b/test/addons-napi/test_conversions/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_conversions", "sources": [ "test_conversions.c" ] } ] diff --git a/test/addons-napi/test_conversions/test.js b/test/addons-napi/test_conversions/test.js index 9604bb738185..73d2c3314f60 100644 --- a/test/addons-napi/test_conversions/test.js +++ b/test/addons-napi/test_conversions/test.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../../common'); const assert = require('assert'); -const test = require(`./build/${common.buildType}/binding`); +const test = require(`./build/${common.buildType}/test_conversions`); const boolExpected = /boolean was expected/; const numberExpected = /number was expected/; diff --git a/test/addons-napi/test_dataview/binding.gyp b/test/addons-napi/test_dataview/binding.gyp index 88a14ae84875..bf014dc9e7b3 100644 --- a/test/addons-napi/test_dataview/binding.gyp +++ b/test/addons-napi/test_dataview/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_dataview", "sources": [ "test_dataview.c" ] } ] diff --git a/test/addons-napi/test_dataview/test.js b/test/addons-napi/test_dataview/test.js index b24a7880357f..a6be58494069 100644 --- a/test/addons-napi/test_dataview/test.js +++ b/test/addons-napi/test_dataview/test.js @@ -3,7 +3,7 @@ const common = require('../../common'); const assert = require('assert'); // Testing api calls for arrays -const test_dataview = require(`./build/${common.buildType}/binding`); +const test_dataview = require(`./build/${common.buildType}/test_dataview`); // Test for creating dataview { diff --git a/test/addons-napi/test_env_sharing/binding.gyp b/test/addons-napi/test_env_sharing/binding.gyp index 8e38a63a1e38..5699a8391dd3 100644 --- a/test/addons-napi/test_env_sharing/binding.gyp +++ b/test/addons-napi/test_env_sharing/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "store_env", "sources": [ "store_env.c" ] }, { diff --git a/test/addons-napi/test_env_sharing/test.js b/test/addons-napi/test_env_sharing/test.js index edae60e1eb28..6e21bf4c638b 100644 --- a/test/addons-napi/test_env_sharing/test.js +++ b/test/addons-napi/test_env_sharing/test.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../../common'); -const storeEnv = require(`./build/${common.buildType}/binding`); +const storeEnv = require(`./build/${common.buildType}/store_env`); const compareEnv = require(`./build/${common.buildType}/compare_env`); const assert = require('assert'); diff --git a/test/addons-napi/test_error/binding.gyp b/test/addons-napi/test_error/binding.gyp index 8e80d2bfa28f..c2defd9551a3 100644 --- a/test/addons-napi/test_error/binding.gyp +++ b/test/addons-napi/test_error/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_error", "sources": [ "test_error.cc" ] } ] diff --git a/test/addons-napi/test_error/test.js b/test/addons-napi/test_error/test.js index 154294fca555..d5c92cb4c3cd 100644 --- a/test/addons-napi/test_error/test.js +++ b/test/addons-napi/test_error/test.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../../common'); -const test_error = require(`./build/${common.buildType}/binding`); +const test_error = require(`./build/${common.buildType}/test_error`); const assert = require('assert'); const theError = new Error('Some error'); const theTypeError = new TypeError('Some type error'); diff --git a/test/addons-napi/test_exception/binding.gyp b/test/addons-napi/test_exception/binding.gyp index 3a20bafabca7..d2e4586e46bc 100644 --- a/test/addons-napi/test_exception/binding.gyp +++ b/test/addons-napi/test_exception/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_exception", "sources": [ "test_exception.c" ] } ] diff --git a/test/addons-napi/test_exception/test.js b/test/addons-napi/test_exception/test.js index dc82249e6c03..8bd2f50b12b1 100644 --- a/test/addons-napi/test_exception/test.js +++ b/test/addons-napi/test_exception/test.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../../common'); -const test_exception = require(`./build/${common.buildType}/binding`); +const test_exception = require(`./build/${common.buildType}/test_exception`); const assert = require('assert'); const theError = new Error('Some error'); function throwTheError() { diff --git a/test/addons-napi/test_fatal/binding.gyp b/test/addons-napi/test_fatal/binding.gyp index 99c7e5de4c16..ad661825f1fa 100644 --- a/test/addons-napi/test_fatal/binding.gyp +++ b/test/addons-napi/test_fatal/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_fatal", "sources": [ "test_fatal.c" ] } ] diff --git a/test/addons-napi/test_fatal/test.js b/test/addons-napi/test_fatal/test.js index c8724d054b61..7ff9a395635d 100644 --- a/test/addons-napi/test_fatal/test.js +++ b/test/addons-napi/test_fatal/test.js @@ -2,7 +2,7 @@ const common = require('../../common'); const assert = require('assert'); const child_process = require('child_process'); -const test_fatal = require(`./build/${common.buildType}/binding`); +const test_fatal = require(`./build/${common.buildType}/test_fatal`); // Test in a child process because the test code will trigger a fatal error // that crashes the process. diff --git a/test/addons-napi/test_fatal/test2.js b/test/addons-napi/test_fatal/test2.js index 52a18deedd46..b9bde8f13016 100644 --- a/test/addons-napi/test_fatal/test2.js +++ b/test/addons-napi/test_fatal/test2.js @@ -2,7 +2,7 @@ const common = require('../../common'); const assert = require('assert'); const child_process = require('child_process'); -const test_fatal = require(`./build/${common.buildType}/binding`); +const test_fatal = require(`./build/${common.buildType}/test_fatal`); // Test in a child process because the test code will trigger a fatal error // that crashes the process. diff --git a/test/addons-napi/test_function/binding.gyp b/test/addons-napi/test_function/binding.gyp index 61035d9c6bdd..2b015bddd7d2 100644 --- a/test/addons-napi/test_function/binding.gyp +++ b/test/addons-napi/test_function/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_function", "sources": [ "test_function.c" ] } ] diff --git a/test/addons-napi/test_function/test.js b/test/addons-napi/test_function/test.js index 6f496796bd01..752e9965b230 100644 --- a/test/addons-napi/test_function/test.js +++ b/test/addons-napi/test_function/test.js @@ -3,7 +3,7 @@ const common = require('../../common'); const assert = require('assert'); // testing api calls for function -const test_function = require(`./build/${common.buildType}/binding`); +const test_function = require(`./build/${common.buildType}/test_function`); function func1() { diff --git a/test/addons-napi/test_general/binding.gyp b/test/addons-napi/test_general/binding.gyp index cf2a8574fe2f..f8ef9f596133 100644 --- a/test/addons-napi/test_general/binding.gyp +++ b/test/addons-napi/test_general/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_general", "sources": [ "test_general.c" ] } ] diff --git a/test/addons-napi/test_general/test.js b/test/addons-napi/test_general/test.js index fba407d8dafb..ee6618c81212 100644 --- a/test/addons-napi/test_general/test.js +++ b/test/addons-napi/test_general/test.js @@ -2,7 +2,7 @@ // Flags: --expose-gc const common = require('../../common'); -const test_general = require(`./build/${common.buildType}/binding`); +const test_general = require(`./build/${common.buildType}/test_general`); const assert = require('assert'); const val1 = '1'; diff --git a/test/addons-napi/test_general/testGlobals.js b/test/addons-napi/test_general/testGlobals.js index ffde6de47cce..38cf3f3edbcc 100644 --- a/test/addons-napi/test_general/testGlobals.js +++ b/test/addons-napi/test_general/testGlobals.js @@ -2,7 +2,7 @@ const common = require('../../common'); const assert = require('assert'); -const test_globals = require(`./build/${common.buildType}/binding`); +const test_globals = require(`./build/${common.buildType}/test_general`); assert.strictEqual(test_globals.getUndefined(), undefined); assert.strictEqual(test_globals.getNull(), null); diff --git a/test/addons-napi/test_general/testInstanceOf.js b/test/addons-napi/test_general/testInstanceOf.js index 40e081b9aac2..3b37188ab4d2 100644 --- a/test/addons-napi/test_general/testInstanceOf.js +++ b/test/addons-napi/test_general/testInstanceOf.js @@ -6,7 +6,7 @@ const assert = require('assert'); // addon is referenced through the eval expression in testFile // eslint-disable-next-line no-unused-vars -const addon = require(`./build/${common.buildType}/binding`); +const addon = require(`./build/${common.buildType}/test_general`); const path = require('path'); // This test depends on a number of V8 tests. diff --git a/test/addons-napi/test_general/testNapiRun.js b/test/addons-napi/test_general/testNapiRun.js index 2425d5db524e..af9f89fa29d5 100644 --- a/test/addons-napi/test_general/testNapiRun.js +++ b/test/addons-napi/test_general/testNapiRun.js @@ -5,7 +5,7 @@ const assert = require('assert'); // addon is referenced through the eval expression in testFile // eslint-disable-next-line no-unused-vars -const addon = require(`./build/${common.buildType}/binding`); +const addon = require(`./build/${common.buildType}/test_general`); const testCase = '(41.92 + 0.08);'; const expected = 42; diff --git a/test/addons-napi/test_general/testNapiStatus.js b/test/addons-napi/test_general/testNapiStatus.js index e71bdc6892c8..a588862098f6 100644 --- a/test/addons-napi/test_general/testNapiStatus.js +++ b/test/addons-napi/test_general/testNapiStatus.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../../common'); -const addon = require(`./build/${common.buildType}/binding`); +const addon = require(`./build/${common.buildType}/test_general`); const assert = require('assert'); addon.createNapiError(); diff --git a/test/addons-napi/test_handle_scope/binding.gyp b/test/addons-napi/test_handle_scope/binding.gyp index a063d28d81fb..daa96681a520 100644 --- a/test/addons-napi/test_handle_scope/binding.gyp +++ b/test/addons-napi/test_handle_scope/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_handle_scope", "sources": [ "test_handle_scope.c" ] } ] diff --git a/test/addons-napi/test_handle_scope/test.js b/test/addons-napi/test_handle_scope/test.js index eed99f81bd70..53abfe178c8d 100644 --- a/test/addons-napi/test_handle_scope/test.js +++ b/test/addons-napi/test_handle_scope/test.js @@ -3,7 +3,8 @@ const common = require('../../common'); const assert = require('assert'); // testing handle scope api calls -const testHandleScope = require(`./build/${common.buildType}/binding`); +const testHandleScope = + require(`./build/${common.buildType}/test_handle_scope`); testHandleScope.NewScope(); diff --git a/test/addons-napi/test_number/binding.gyp b/test/addons-napi/test_number/binding.gyp index 9a7b2a3d319c..c934d5ef03bf 100644 --- a/test/addons-napi/test_number/binding.gyp +++ b/test/addons-napi/test_number/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_number", "sources": [ "test_number.c" ] } ] diff --git a/test/addons-napi/test_number/test.js b/test/addons-napi/test_number/test.js index 18d39ec91feb..e92c6d0cd299 100644 --- a/test/addons-napi/test_number/test.js +++ b/test/addons-napi/test_number/test.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../../common'); const assert = require('assert'); -const test_number = require(`./build/${common.buildType}/binding`); +const test_number = require(`./build/${common.buildType}/test_number`); // testing api calls for number diff --git a/test/addons-napi/test_object/binding.gyp b/test/addons-napi/test_object/binding.gyp index f589ab92fab4..be225ace7790 100644 --- a/test/addons-napi/test_object/binding.gyp +++ b/test/addons-napi/test_object/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_object", "sources": [ "test_object.c" ] } ] diff --git a/test/addons-napi/test_object/test.js b/test/addons-napi/test_object/test.js index 13defcc512a1..8e44a1b5ed64 100644 --- a/test/addons-napi/test_object/test.js +++ b/test/addons-napi/test_object/test.js @@ -3,7 +3,7 @@ const common = require('../../common'); const assert = require('assert'); // Testing api calls for objects -const test_object = require(`./build/${common.buildType}/binding`); +const test_object = require(`./build/${common.buildType}/test_object`); const object = { diff --git a/test/addons-napi/test_promise/binding.gyp b/test/addons-napi/test_promise/binding.gyp index f9a3f75744e9..bf266f93db74 100644 --- a/test/addons-napi/test_promise/binding.gyp +++ b/test/addons-napi/test_promise/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_promise", "sources": [ "test_promise.c" ] } ] diff --git a/test/addons-napi/test_promise/test.js b/test/addons-napi/test_promise/test.js index c038c969951c..6dc51b3fa558 100644 --- a/test/addons-napi/test_promise/test.js +++ b/test/addons-napi/test_promise/test.js @@ -5,7 +5,7 @@ const common = require('../../common'); // This tests the promise-related n-api calls const assert = require('assert'); -const test_promise = require(`./build/${common.buildType}/binding`); +const test_promise = require(`./build/${common.buildType}/test_promise`); common.crashOnUnhandledRejection(); diff --git a/test/addons-napi/test_properties/binding.gyp b/test/addons-napi/test_properties/binding.gyp index c897a825031a..345e5c88d7c6 100644 --- a/test/addons-napi/test_properties/binding.gyp +++ b/test/addons-napi/test_properties/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_properties", "sources": [ "test_properties.c" ] } ] diff --git a/test/addons-napi/test_properties/test.js b/test/addons-napi/test_properties/test.js index 9d7c9ba34148..13a546c7b87f 100644 --- a/test/addons-napi/test_properties/test.js +++ b/test/addons-napi/test_properties/test.js @@ -5,7 +5,7 @@ const readonlyErrorRE = /^TypeError: Cannot assign to read only property '.*' of object '#'$/; // Testing api calls for defining properties -const test_object = require(`./build/${common.buildType}/binding`); +const test_object = require(`./build/${common.buildType}/test_properties`); assert.strictEqual(test_object.echo('hello'), 'hello'); diff --git a/test/addons-napi/test_reference/binding.gyp b/test/addons-napi/test_reference/binding.gyp index 9a4583cb8335..3a6d69a65c81 100644 --- a/test/addons-napi/test_reference/binding.gyp +++ b/test/addons-napi/test_reference/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_reference", "sources": [ "test_reference.c" ] } ] diff --git a/test/addons-napi/test_reference/test.js b/test/addons-napi/test_reference/test.js index caaa9b599e8c..14932a74ca70 100644 --- a/test/addons-napi/test_reference/test.js +++ b/test/addons-napi/test_reference/test.js @@ -4,7 +4,7 @@ const common = require('../../common'); const assert = require('assert'); -const test_reference = require(`./build/${common.buildType}/binding`); +const test_reference = require(`./build/${common.buildType}/test_reference`); // This test script uses external values with finalizer callbacks // in order to track when values get garbage-collected. Each invocation diff --git a/test/addons-napi/test_string/binding.gyp b/test/addons-napi/test_string/binding.gyp index f49410e3dd88..d4825de93398 100644 --- a/test/addons-napi/test_string/binding.gyp +++ b/test/addons-napi/test_string/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_string", "sources": [ "test_string.c" ] } ] diff --git a/test/addons-napi/test_string/test.js b/test/addons-napi/test_string/test.js index fd58ea0983be..5ce3d739c7a9 100644 --- a/test/addons-napi/test_string/test.js +++ b/test/addons-napi/test_string/test.js @@ -3,7 +3,7 @@ const common = require('../../common'); const assert = require('assert'); // testing api calls for string -const test_string = require(`./build/${common.buildType}/binding`); +const test_string = require(`./build/${common.buildType}/test_string`); const empty = ''; assert.strictEqual(test_string.TestLatin1(empty), empty); diff --git a/test/addons-napi/test_symbol/binding.gyp b/test/addons-napi/test_symbol/binding.gyp index bae042ee0e6a..6ef3407968db 100644 --- a/test/addons-napi/test_symbol/binding.gyp +++ b/test/addons-napi/test_symbol/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_symbol", "sources": [ "test_symbol.c" ] } ] diff --git a/test/addons-napi/test_symbol/test1.js b/test/addons-napi/test_symbol/test1.js index 83f2f71f6f80..25eb473c4b1b 100644 --- a/test/addons-napi/test_symbol/test1.js +++ b/test/addons-napi/test_symbol/test1.js @@ -3,7 +3,7 @@ const common = require('../../common'); const assert = require('assert'); // testing api calls for symbol -const test_symbol = require(`./build/${common.buildType}/binding`); +const test_symbol = require(`./build/${common.buildType}/test_symbol`); const sym = test_symbol.New('test'); assert.strictEqual(sym.toString(), 'Symbol(test)'); diff --git a/test/addons-napi/test_symbol/test2.js b/test/addons-napi/test_symbol/test2.js index 4ff0955c5dbe..60512431110a 100644 --- a/test/addons-napi/test_symbol/test2.js +++ b/test/addons-napi/test_symbol/test2.js @@ -3,7 +3,7 @@ const common = require('../../common'); const assert = require('assert'); // testing api calls for symbol -const test_symbol = require(`./build/${common.buildType}/binding`); +const test_symbol = require(`./build/${common.buildType}/test_symbol`); const fooSym = test_symbol.New('foo'); const myObj = {}; diff --git a/test/addons-napi/test_symbol/test3.js b/test/addons-napi/test_symbol/test3.js index 72379644cb08..a7c6c18c0254 100644 --- a/test/addons-napi/test_symbol/test3.js +++ b/test/addons-napi/test_symbol/test3.js @@ -3,7 +3,7 @@ const common = require('../../common'); const assert = require('assert'); // testing api calls for symbol -const test_symbol = require(`./build/${common.buildType}/binding`); +const test_symbol = require(`./build/${common.buildType}/test_symbol`); assert.notStrictEqual(test_symbol.New(), test_symbol.New()); assert.notStrictEqual(test_symbol.New('foo'), test_symbol.New('foo')); diff --git a/test/addons-napi/test_typedarray/binding.gyp b/test/addons-napi/test_typedarray/binding.gyp index 29fb299d329e..8b4a4dc622b2 100644 --- a/test/addons-napi/test_typedarray/binding.gyp +++ b/test/addons-napi/test_typedarray/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_typedarray", "sources": [ "test_typedarray.c" ] } ] diff --git a/test/addons-napi/test_typedarray/test.js b/test/addons-napi/test_typedarray/test.js index debf99b80aee..ed37f3c5d4da 100644 --- a/test/addons-napi/test_typedarray/test.js +++ b/test/addons-napi/test_typedarray/test.js @@ -3,7 +3,7 @@ const common = require('../../common'); const assert = require('assert'); // Testing api calls for arrays -const test_typedarray = require(`./build/${common.buildType}/binding`); +const test_typedarray = require(`./build/${common.buildType}/test_typedarray`); const byteArray = new Uint8Array(3); byteArray[0] = 0; diff --git a/test/addons-napi/test_uv_loop/binding.gyp b/test/addons-napi/test_uv_loop/binding.gyp index e403df924558..81fcfdc592a5 100644 --- a/test/addons-napi/test_uv_loop/binding.gyp +++ b/test/addons-napi/test_uv_loop/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_uv_loop", "sources": [ "test_uv_loop.cc" ] } ] diff --git a/test/addons-napi/test_uv_loop/test.js b/test/addons-napi/test_uv_loop/test.js index ce13a482bdce..4efc3c6fcd70 100644 --- a/test/addons-napi/test_uv_loop/test.js +++ b/test/addons-napi/test_uv_loop/test.js @@ -1,5 +1,5 @@ 'use strict'; const common = require('../../common'); -const { SetImmediate } = require(`./build/${common.buildType}/binding`); +const { SetImmediate } = require(`./build/${common.buildType}/test_uv_loop`); SetImmediate(common.mustCall()); diff --git a/test/addons-napi/test_warning/binding.gyp b/test/addons-napi/test_warning/binding.gyp index d84028f085db..a44593e2518c 100644 --- a/test/addons-napi/test_warning/binding.gyp +++ b/test/addons-napi/test_warning/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "binding", + "target_name": "test_warning", "sources": [ "test_warning.c" ] }, { diff --git a/test/addons-napi/test_warning/test.js b/test/addons-napi/test_warning/test.js index 6909a1ebcddf..c82008435fd8 100644 --- a/test/addons-napi/test_warning/test.js +++ b/test/addons-napi/test_warning/test.js @@ -2,7 +2,7 @@ if (process.argv[2] === 'child') { const common = require('../../common'); - console.log(require(`./build/${common.buildType}/binding`)); + console.log(require(`./build/${common.buildType}/test_warning`)); console.log(require(`./build/${common.buildType}/test_warning2`)); } else { const run = require('child_process').spawnSync; diff --git a/test/addons/.gitignore b/test/addons/.gitignore index ff6b00794319..bde1cf3ab966 100644 --- a/test/addons/.gitignore +++ b/test/addons/.gitignore @@ -1,3 +1,5 @@ +.buildstamp +.docbuildstamp Makefile *.Makefile *.mk diff --git a/test/addons/01_function_arguments/binding.cc b/test/addons/01_function_arguments/binding.cc deleted file mode 100644 index 1379699453d8..000000000000 --- a/test/addons/01_function_arguments/binding.cc +++ /dev/null @@ -1,52 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// binding.cc -#include - -namespace demo { - -using v8::Exception; -using v8::FunctionCallbackInfo; -using v8::Isolate; -using v8::Local; -using v8::Number; -using v8::Object; -using v8::String; -using v8::Value; - -// This is the implementation of the "add" method -// Input arguments are passed using the -// const FunctionCallbackInfo& args struct -void Add(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - // Check the number of arguments passed. - if (args.Length() < 2) { - // Throw an Error that is passed back to JavaScript - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong number of arguments"))); - return; - } - - // Check the argument types - if (!args[0]->IsNumber() || !args[1]->IsNumber()) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong arguments"))); - return; - } - - // Perform the operation - double value = args[0]->NumberValue() + args[1]->NumberValue(); - Local num = Number::New(isolate, value); - - // Set the return value (using the passed in - // FunctionCallbackInfo&) - args.GetReturnValue().Set(num); -} - -void Init(Local exports) { - NODE_SET_METHOD(exports, "add", Add); -} - -NODE_MODULE(NODE_GYP_MODULE_NAME, Init) - -} // namespace demo diff --git a/test/addons/01_function_arguments/binding.gyp b/test/addons/01_function_arguments/binding.gyp deleted file mode 100644 index 6cd05e5bba3c..000000000000 --- a/test/addons/01_function_arguments/binding.gyp +++ /dev/null @@ -1,2 +0,0 @@ -# Auto-generated by `node tools/doc/addon-verify.js` -{"targets":[{"target_name":"binding","defines":["V8_DEPRECATION_WARNINGS=1"],"sources":["binding.cc","test.js"]}]} \ No newline at end of file diff --git a/test/addons/01_function_arguments/test.js b/test/addons/01_function_arguments/test.js deleted file mode 100644 index 3372ff3329ca..000000000000 --- a/test/addons/01_function_arguments/test.js +++ /dev/null @@ -1,7 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -'use strict'; -const common = require('../../common'); -// test.js -const binding = require(`./build/${common.buildType}/binding`); - -console.log('This should be eight:', binding.add(3, 5)); diff --git a/test/addons/02_callbacks/binding.cc b/test/addons/02_callbacks/binding.cc deleted file mode 100644 index 53996f648bc1..000000000000 --- a/test/addons/02_callbacks/binding.cc +++ /dev/null @@ -1,30 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// binding.cc -#include - -namespace demo { - -using v8::Function; -using v8::FunctionCallbackInfo; -using v8::Isolate; -using v8::Local; -using v8::Null; -using v8::Object; -using v8::String; -using v8::Value; - -void RunCallback(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - Local cb = Local::Cast(args[0]); - const unsigned argc = 1; - Local argv[argc] = { String::NewFromUtf8(isolate, "hello world") }; - cb->Call(Null(isolate), argc, argv); -} - -void Init(Local exports, Local module) { - NODE_SET_METHOD(module, "exports", RunCallback); -} - -NODE_MODULE(NODE_GYP_MODULE_NAME, Init) - -} // namespace demo diff --git a/test/addons/02_callbacks/binding.gyp b/test/addons/02_callbacks/binding.gyp deleted file mode 100644 index 6cd05e5bba3c..000000000000 --- a/test/addons/02_callbacks/binding.gyp +++ /dev/null @@ -1,2 +0,0 @@ -# Auto-generated by `node tools/doc/addon-verify.js` -{"targets":[{"target_name":"binding","defines":["V8_DEPRECATION_WARNINGS=1"],"sources":["binding.cc","test.js"]}]} \ No newline at end of file diff --git a/test/addons/02_callbacks/test.js b/test/addons/02_callbacks/test.js deleted file mode 100644 index e18c44e269e6..000000000000 --- a/test/addons/02_callbacks/test.js +++ /dev/null @@ -1,10 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -'use strict'; -const common = require('../../common'); -// test.js -const binding = require(`./build/${common.buildType}/binding`); - -binding((msg) => { - console.log(msg); -// Prints: 'hello world' -}); diff --git a/test/addons/03_object_factory/binding.cc b/test/addons/03_object_factory/binding.cc deleted file mode 100644 index d727552cd712..000000000000 --- a/test/addons/03_object_factory/binding.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// binding.cc -#include - -namespace demo { - -using v8::FunctionCallbackInfo; -using v8::Isolate; -using v8::Local; -using v8::Object; -using v8::String; -using v8::Value; - -void CreateObject(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - Local obj = Object::New(isolate); - obj->Set(String::NewFromUtf8(isolate, "msg"), args[0]->ToString()); - - args.GetReturnValue().Set(obj); -} - -void Init(Local exports, Local module) { - NODE_SET_METHOD(module, "exports", CreateObject); -} - -NODE_MODULE(NODE_GYP_MODULE_NAME, Init) - -} // namespace demo diff --git a/test/addons/03_object_factory/binding.gyp b/test/addons/03_object_factory/binding.gyp deleted file mode 100644 index 6cd05e5bba3c..000000000000 --- a/test/addons/03_object_factory/binding.gyp +++ /dev/null @@ -1,2 +0,0 @@ -# Auto-generated by `node tools/doc/addon-verify.js` -{"targets":[{"target_name":"binding","defines":["V8_DEPRECATION_WARNINGS=1"],"sources":["binding.cc","test.js"]}]} \ No newline at end of file diff --git a/test/addons/03_object_factory/test.js b/test/addons/03_object_factory/test.js deleted file mode 100644 index abe0ebb5254c..000000000000 --- a/test/addons/03_object_factory/test.js +++ /dev/null @@ -1,10 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -'use strict'; -const common = require('../../common'); -// test.js -const binding = require(`./build/${common.buildType}/binding`); - -const obj1 = binding('hello'); -const obj2 = binding('world'); -console.log(obj1.msg, obj2.msg); -// Prints: 'hello world' diff --git a/test/addons/04_function_factory/binding.cc b/test/addons/04_function_factory/binding.cc deleted file mode 100644 index 4891aa6b7b33..000000000000 --- a/test/addons/04_function_factory/binding.cc +++ /dev/null @@ -1,39 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// binding.cc -#include - -namespace demo { - -using v8::Function; -using v8::FunctionCallbackInfo; -using v8::FunctionTemplate; -using v8::Isolate; -using v8::Local; -using v8::Object; -using v8::String; -using v8::Value; - -void MyFunction(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world")); -} - -void CreateFunction(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - Local tpl = FunctionTemplate::New(isolate, MyFunction); - Local fn = tpl->GetFunction(); - - // omit this to make it anonymous - fn->SetName(String::NewFromUtf8(isolate, "theFunction")); - - args.GetReturnValue().Set(fn); -} - -void Init(Local exports, Local module) { - NODE_SET_METHOD(module, "exports", CreateFunction); -} - -NODE_MODULE(NODE_GYP_MODULE_NAME, Init) - -} // namespace demo diff --git a/test/addons/04_function_factory/binding.gyp b/test/addons/04_function_factory/binding.gyp deleted file mode 100644 index 6cd05e5bba3c..000000000000 --- a/test/addons/04_function_factory/binding.gyp +++ /dev/null @@ -1,2 +0,0 @@ -# Auto-generated by `node tools/doc/addon-verify.js` -{"targets":[{"target_name":"binding","defines":["V8_DEPRECATION_WARNINGS=1"],"sources":["binding.cc","test.js"]}]} \ No newline at end of file diff --git a/test/addons/04_function_factory/test.js b/test/addons/04_function_factory/test.js deleted file mode 100644 index 71e726806910..000000000000 --- a/test/addons/04_function_factory/test.js +++ /dev/null @@ -1,9 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -'use strict'; -const common = require('../../common'); -// test.js -const binding = require(`./build/${common.buildType}/binding`); - -const fn = binding(); -console.log(fn()); -// Prints: 'hello world' diff --git a/test/addons/05_wrapping_c_objects/binding.cc b/test/addons/05_wrapping_c_objects/binding.cc deleted file mode 100644 index 93609a4ecb76..000000000000 --- a/test/addons/05_wrapping_c_objects/binding.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// binding.cc -#include -#include "myobject.h" - -namespace demo { - -using v8::Local; -using v8::Object; - -void InitAll(Local exports) { - MyObject::Init(exports); -} - -NODE_MODULE(NODE_GYP_MODULE_NAME, InitAll) - -} // namespace demo diff --git a/test/addons/05_wrapping_c_objects/binding.gyp b/test/addons/05_wrapping_c_objects/binding.gyp deleted file mode 100644 index 5d967d0948c3..000000000000 --- a/test/addons/05_wrapping_c_objects/binding.gyp +++ /dev/null @@ -1,2 +0,0 @@ -# Auto-generated by `node tools/doc/addon-verify.js` -{"targets":[{"target_name":"binding","defines":["V8_DEPRECATION_WARNINGS=1"],"sources":["binding.cc","myobject.h","myobject.cc","test.js"]}]} \ No newline at end of file diff --git a/test/addons/05_wrapping_c_objects/myobject.cc b/test/addons/05_wrapping_c_objects/myobject.cc deleted file mode 100644 index 4383ec44edff..000000000000 --- a/test/addons/05_wrapping_c_objects/myobject.cc +++ /dev/null @@ -1,73 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// myobject.cc -#include "myobject.h" - -namespace demo { - -using v8::Context; -using v8::Function; -using v8::FunctionCallbackInfo; -using v8::FunctionTemplate; -using v8::Isolate; -using v8::Local; -using v8::Number; -using v8::Object; -using v8::Persistent; -using v8::String; -using v8::Value; - -Persistent MyObject::constructor; - -MyObject::MyObject(double value) : value_(value) { -} - -MyObject::~MyObject() { -} - -void MyObject::Init(Local exports) { - Isolate* isolate = exports->GetIsolate(); - - // Prepare constructor template - Local tpl = FunctionTemplate::New(isolate, New); - tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject")); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - - // Prototype - NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne); - - constructor.Reset(isolate, tpl->GetFunction()); - exports->Set(String::NewFromUtf8(isolate, "MyObject"), - tpl->GetFunction()); -} - -void MyObject::New(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - if (args.IsConstructCall()) { - // Invoked as constructor: `new MyObject(...)` - double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue(); - MyObject* obj = new MyObject(value); - obj->Wrap(args.This()); - args.GetReturnValue().Set(args.This()); - } else { - // Invoked as plain function `MyObject(...)`, turn into construct call. - const int argc = 1; - Local argv[argc] = { args[0] }; - Local context = isolate->GetCurrentContext(); - Local cons = Local::New(isolate, constructor); - Local result = - cons->NewInstance(context, argc, argv).ToLocalChecked(); - args.GetReturnValue().Set(result); - } -} - -void MyObject::PlusOne(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - MyObject* obj = ObjectWrap::Unwrap(args.Holder()); - obj->value_ += 1; - - args.GetReturnValue().Set(Number::New(isolate, obj->value_)); -} - -} // namespace demo diff --git a/test/addons/05_wrapping_c_objects/myobject.h b/test/addons/05_wrapping_c_objects/myobject.h deleted file mode 100644 index 9dcff129f46f..000000000000 --- a/test/addons/05_wrapping_c_objects/myobject.h +++ /dev/null @@ -1,27 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// myobject.h -#ifndef MYOBJECT_H // NOLINT(build/header_guard) -#define MYOBJECT_H // NOLINT(build/header_guard) - -#include -#include - -namespace demo { - -class MyObject : public node::ObjectWrap { - public: - static void Init(v8::Local exports); - - private: - explicit MyObject(double value = 0); - ~MyObject(); - - static void New(const v8::FunctionCallbackInfo& args); - static void PlusOne(const v8::FunctionCallbackInfo& args); - static v8::Persistent constructor; - double value_; -}; - -} // namespace demo - -#endif // NOLINT(build/header_guard) diff --git a/test/addons/05_wrapping_c_objects/test.js b/test/addons/05_wrapping_c_objects/test.js deleted file mode 100644 index b8d903798852..000000000000 --- a/test/addons/05_wrapping_c_objects/test.js +++ /dev/null @@ -1,13 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -'use strict'; -const common = require('../../common'); -// test.js -const binding = require(`./build/${common.buildType}/binding`); - -const obj = new binding.MyObject(10); -console.log(obj.plusOne()); -// Prints: 11 -console.log(obj.plusOne()); -// Prints: 12 -console.log(obj.plusOne()); -// Prints: 13 diff --git a/test/addons/06_factory_of_wrapped_objects/binding.cc b/test/addons/06_factory_of_wrapped_objects/binding.cc deleted file mode 100644 index 71bf45ca6e66..000000000000 --- a/test/addons/06_factory_of_wrapped_objects/binding.cc +++ /dev/null @@ -1,27 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// binding.cc -#include -#include "myobject.h" - -namespace demo { - -using v8::FunctionCallbackInfo; -using v8::Isolate; -using v8::Local; -using v8::Object; -using v8::String; -using v8::Value; - -void CreateObject(const FunctionCallbackInfo& args) { - MyObject::NewInstance(args); -} - -void InitAll(Local exports, Local module) { - MyObject::Init(exports->GetIsolate()); - - NODE_SET_METHOD(module, "exports", CreateObject); -} - -NODE_MODULE(NODE_GYP_MODULE_NAME, InitAll) - -} // namespace demo diff --git a/test/addons/06_factory_of_wrapped_objects/binding.gyp b/test/addons/06_factory_of_wrapped_objects/binding.gyp deleted file mode 100644 index 5d967d0948c3..000000000000 --- a/test/addons/06_factory_of_wrapped_objects/binding.gyp +++ /dev/null @@ -1,2 +0,0 @@ -# Auto-generated by `node tools/doc/addon-verify.js` -{"targets":[{"target_name":"binding","defines":["V8_DEPRECATION_WARNINGS=1"],"sources":["binding.cc","myobject.h","myobject.cc","test.js"]}]} \ No newline at end of file diff --git a/test/addons/06_factory_of_wrapped_objects/myobject.cc b/test/addons/06_factory_of_wrapped_objects/myobject.cc deleted file mode 100644 index c1286f42a349..000000000000 --- a/test/addons/06_factory_of_wrapped_objects/myobject.cc +++ /dev/null @@ -1,83 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// myobject.cc -#include -#include "myobject.h" - -namespace demo { - -using v8::Context; -using v8::Function; -using v8::FunctionCallbackInfo; -using v8::FunctionTemplate; -using v8::Isolate; -using v8::Local; -using v8::Number; -using v8::Object; -using v8::Persistent; -using v8::String; -using v8::Value; - -Persistent MyObject::constructor; - -MyObject::MyObject(double value) : value_(value) { -} - -MyObject::~MyObject() { -} - -void MyObject::Init(Isolate* isolate) { - // Prepare constructor template - Local tpl = FunctionTemplate::New(isolate, New); - tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject")); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - - // Prototype - NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne); - - constructor.Reset(isolate, tpl->GetFunction()); -} - -void MyObject::New(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - if (args.IsConstructCall()) { - // Invoked as constructor: `new MyObject(...)` - double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue(); - MyObject* obj = new MyObject(value); - obj->Wrap(args.This()); - args.GetReturnValue().Set(args.This()); - } else { - // Invoked as plain function `MyObject(...)`, turn into construct call. - const int argc = 1; - Local argv[argc] = { args[0] }; - Local cons = Local::New(isolate, constructor); - Local context = isolate->GetCurrentContext(); - Local instance = - cons->NewInstance(context, argc, argv).ToLocalChecked(); - args.GetReturnValue().Set(instance); - } -} - -void MyObject::NewInstance(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - const unsigned argc = 1; - Local argv[argc] = { args[0] }; - Local cons = Local::New(isolate, constructor); - Local context = isolate->GetCurrentContext(); - Local instance = - cons->NewInstance(context, argc, argv).ToLocalChecked(); - - args.GetReturnValue().Set(instance); -} - -void MyObject::PlusOne(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - MyObject* obj = ObjectWrap::Unwrap(args.Holder()); - obj->value_ += 1; - - args.GetReturnValue().Set(Number::New(isolate, obj->value_)); -} - -} // namespace demo diff --git a/test/addons/06_factory_of_wrapped_objects/myobject.h b/test/addons/06_factory_of_wrapped_objects/myobject.h deleted file mode 100644 index 323c7a8739b0..000000000000 --- a/test/addons/06_factory_of_wrapped_objects/myobject.h +++ /dev/null @@ -1,28 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// myobject.h -#ifndef MYOBJECT_H // NOLINT(build/header_guard) -#define MYOBJECT_H // NOLINT(build/header_guard) - -#include -#include - -namespace demo { - -class MyObject : public node::ObjectWrap { - public: - static void Init(v8::Isolate* isolate); - static void NewInstance(const v8::FunctionCallbackInfo& args); - - private: - explicit MyObject(double value = 0); - ~MyObject(); - - static void New(const v8::FunctionCallbackInfo& args); - static void PlusOne(const v8::FunctionCallbackInfo& args); - static v8::Persistent constructor; - double value_; -}; - -} // namespace demo - -#endif // NOLINT(build/header_guard) diff --git a/test/addons/06_factory_of_wrapped_objects/test.js b/test/addons/06_factory_of_wrapped_objects/test.js deleted file mode 100644 index 1d02c0e1a20b..000000000000 --- a/test/addons/06_factory_of_wrapped_objects/test.js +++ /dev/null @@ -1,21 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -'use strict'; -const common = require('../../common'); -// test.js -const createObject = require(`./build/${common.buildType}/binding`); - -const obj = createObject(10); -console.log(obj.plusOne()); -// Prints: 11 -console.log(obj.plusOne()); -// Prints: 12 -console.log(obj.plusOne()); -// Prints: 13 - -const obj2 = createObject(20); -console.log(obj2.plusOne()); -// Prints: 21 -console.log(obj2.plusOne()); -// Prints: 22 -console.log(obj2.plusOne()); -// Prints: 23 diff --git a/test/addons/07_passing_wrapped_objects_around/binding.cc b/test/addons/07_passing_wrapped_objects_around/binding.cc deleted file mode 100644 index 36ba3a710ec1..000000000000 --- a/test/addons/07_passing_wrapped_objects_around/binding.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// binding.cc -#include -#include -#include "myobject.h" - -namespace demo { - -using v8::FunctionCallbackInfo; -using v8::Isolate; -using v8::Local; -using v8::Number; -using v8::Object; -using v8::String; -using v8::Value; - -void CreateObject(const FunctionCallbackInfo& args) { - MyObject::NewInstance(args); -} - -void Add(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - MyObject* obj1 = node::ObjectWrap::Unwrap( - args[0]->ToObject()); - MyObject* obj2 = node::ObjectWrap::Unwrap( - args[1]->ToObject()); - - double sum = obj1->value() + obj2->value(); - args.GetReturnValue().Set(Number::New(isolate, sum)); -} - -void InitAll(Local exports) { - MyObject::Init(exports->GetIsolate()); - - NODE_SET_METHOD(exports, "createObject", CreateObject); - NODE_SET_METHOD(exports, "add", Add); -} - -NODE_MODULE(NODE_GYP_MODULE_NAME, InitAll) - -} // namespace demo diff --git a/test/addons/07_passing_wrapped_objects_around/binding.gyp b/test/addons/07_passing_wrapped_objects_around/binding.gyp deleted file mode 100644 index 5d967d0948c3..000000000000 --- a/test/addons/07_passing_wrapped_objects_around/binding.gyp +++ /dev/null @@ -1,2 +0,0 @@ -# Auto-generated by `node tools/doc/addon-verify.js` -{"targets":[{"target_name":"binding","defines":["V8_DEPRECATION_WARNINGS=1"],"sources":["binding.cc","myobject.h","myobject.cc","test.js"]}]} \ No newline at end of file diff --git a/test/addons/07_passing_wrapped_objects_around/myobject.cc b/test/addons/07_passing_wrapped_objects_around/myobject.cc deleted file mode 100644 index 3dd5bb697602..000000000000 --- a/test/addons/07_passing_wrapped_objects_around/myobject.cc +++ /dev/null @@ -1,70 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// myobject.cc -#include -#include "myobject.h" - -namespace demo { - -using v8::Context; -using v8::Function; -using v8::FunctionCallbackInfo; -using v8::FunctionTemplate; -using v8::Isolate; -using v8::Local; -using v8::Object; -using v8::Persistent; -using v8::String; -using v8::Value; - -Persistent MyObject::constructor; - -MyObject::MyObject(double value) : value_(value) { -} - -MyObject::~MyObject() { -} - -void MyObject::Init(Isolate* isolate) { - // Prepare constructor template - Local tpl = FunctionTemplate::New(isolate, New); - tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject")); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - - constructor.Reset(isolate, tpl->GetFunction()); -} - -void MyObject::New(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - if (args.IsConstructCall()) { - // Invoked as constructor: `new MyObject(...)` - double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue(); - MyObject* obj = new MyObject(value); - obj->Wrap(args.This()); - args.GetReturnValue().Set(args.This()); - } else { - // Invoked as plain function `MyObject(...)`, turn into construct call. - const int argc = 1; - Local argv[argc] = { args[0] }; - Local context = isolate->GetCurrentContext(); - Local cons = Local::New(isolate, constructor); - Local instance = - cons->NewInstance(context, argc, argv).ToLocalChecked(); - args.GetReturnValue().Set(instance); - } -} - -void MyObject::NewInstance(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - - const unsigned argc = 1; - Local argv[argc] = { args[0] }; - Local cons = Local::New(isolate, constructor); - Local context = isolate->GetCurrentContext(); - Local instance = - cons->NewInstance(context, argc, argv).ToLocalChecked(); - - args.GetReturnValue().Set(instance); -} - -} // namespace demo diff --git a/test/addons/07_passing_wrapped_objects_around/myobject.h b/test/addons/07_passing_wrapped_objects_around/myobject.h deleted file mode 100644 index 5d430a208134..000000000000 --- a/test/addons/07_passing_wrapped_objects_around/myobject.h +++ /dev/null @@ -1,28 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// myobject.h -#ifndef MYOBJECT_H // NOLINT(build/header_guard) -#define MYOBJECT_H // NOLINT(build/header_guard) - -#include -#include - -namespace demo { - -class MyObject : public node::ObjectWrap { - public: - static void Init(v8::Isolate* isolate); - static void NewInstance(const v8::FunctionCallbackInfo& args); - inline double value() const { return value_; } - - private: - explicit MyObject(double value = 0); - ~MyObject(); - - static void New(const v8::FunctionCallbackInfo& args); - static v8::Persistent constructor; - double value_; -}; - -} // namespace demo - -#endif // NOLINT(build/header_guard) diff --git a/test/addons/07_passing_wrapped_objects_around/test.js b/test/addons/07_passing_wrapped_objects_around/test.js deleted file mode 100644 index 0175835c7c3b..000000000000 --- a/test/addons/07_passing_wrapped_objects_around/test.js +++ /dev/null @@ -1,12 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -'use strict'; -const common = require('../../common'); -// test.js -const binding = require(`./build/${common.buildType}/binding`); - -const obj1 = binding.createObject(10); -const obj2 = binding.createObject(20); -const result = binding.add(obj1, obj2); - -console.log(result); -// Prints: 30 diff --git a/test/addons/08_void_atexitcallback_args/binding.cc b/test/addons/08_void_atexitcallback_args/binding.cc deleted file mode 100644 index 33fdc6baf95f..000000000000 --- a/test/addons/08_void_atexitcallback_args/binding.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -// binding.cc -#include -#include -#include - -namespace demo { - -using node::AtExit; -using v8::HandleScope; -using v8::Isolate; -using v8::Local; -using v8::Object; - -static char cookie[] = "yum yum"; -static int at_exit_cb1_called = 0; -static int at_exit_cb2_called = 0; - -static void at_exit_cb1(void* arg) { - Isolate* isolate = static_cast(arg); - HandleScope scope(isolate); - Local obj = Object::New(isolate); - assert(!obj.IsEmpty()); // assert VM is still alive - assert(obj->IsObject()); - at_exit_cb1_called++; -} - -static void at_exit_cb2(void* arg) { - assert(arg == static_cast(cookie)); - at_exit_cb2_called++; -} - -static void sanity_check(void*) { - assert(at_exit_cb1_called == 1); - assert(at_exit_cb2_called == 2); -} - -void init(Local exports) { - AtExit(at_exit_cb2, cookie); - AtExit(at_exit_cb2, cookie); - AtExit(at_exit_cb1, exports->GetIsolate()); - AtExit(sanity_check); -} - -NODE_MODULE(NODE_GYP_MODULE_NAME, init) - -} // namespace demo diff --git a/test/addons/08_void_atexitcallback_args/binding.gyp b/test/addons/08_void_atexitcallback_args/binding.gyp deleted file mode 100644 index 6cd05e5bba3c..000000000000 --- a/test/addons/08_void_atexitcallback_args/binding.gyp +++ /dev/null @@ -1,2 +0,0 @@ -# Auto-generated by `node tools/doc/addon-verify.js` -{"targets":[{"target_name":"binding","defines":["V8_DEPRECATION_WARNINGS=1"],"sources":["binding.cc","test.js"]}]} \ No newline at end of file diff --git a/test/addons/08_void_atexitcallback_args/test.js b/test/addons/08_void_atexitcallback_args/test.js deleted file mode 100644 index 43672ff82331..000000000000 --- a/test/addons/08_void_atexitcallback_args/test.js +++ /dev/null @@ -1,5 +0,0 @@ -// Auto-generated by `node tools/doc/addon-verify.js` -'use strict'; -const common = require('../../common'); -// test.js -require(`./build/${common.buildType}/binding`); diff --git a/test/addons/openssl-client-cert-engine/binding.cc b/test/addons/openssl-client-cert-engine/binding.cc deleted file mode 100644 index 60340815ed20..000000000000 --- a/test/addons/openssl-client-cert-engine/binding.cc +++ /dev/null @@ -1,6 +0,0 @@ -#include "node.h" -#include "v8.h" - -inline void Initialize(v8::Local) {} - -NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize) diff --git a/test/addons/openssl-client-cert-engine/binding.gyp b/test/addons/openssl-client-cert-engine/binding.gyp index 48a6aa3480d4..b069e43429c1 100644 --- a/test/addons/openssl-client-cert-engine/binding.gyp +++ b/test/addons/openssl-client-cert-engine/binding.gyp @@ -1,9 +1,5 @@ { 'targets': [ - { - 'target_name': 'binding', - 'sources': [ 'binding.cc' ], - }, { 'target_name': 'testengine', 'type': 'none', diff --git a/tools/doc/addon-verify.js b/tools/doc/addon-verify.js index e9b43a2b60cf..2e72abb77f92 100644 --- a/tools/doc/addon-verify.js +++ b/tools/doc/addon-verify.js @@ -1,48 +1,59 @@ 'use strict'; -const { strictEqual } = require('assert'); const fs = require('fs'); const path = require('path'); const marked = require('marked'); -const auto = 'Auto-generated by `node tools/doc/addon-verify.js`'; const rootDir = path.resolve(__dirname, '..', '..'); const doc = path.resolve(rootDir, 'doc', 'api', 'addons.md'); const verifyDir = path.resolve(rootDir, 'test', 'addons'); -const changed = []; -const checkOnly = process.argv.includes('--check'); +const contents = fs.readFileSync(doc).toString(); +const tokens = marked.lexer(contents); let id = 0; -let currentHeader; +let currentHeader; const addons = {}; -const content = fs.readFileSync(doc, 'utf8'); -for (const { text, type } of marked.lexer(content)) { - if (type === 'heading' && text) { - currentHeader = text; +tokens.forEach((token) => { + if (token.type === 'heading' && token.text) { + currentHeader = token.text; addons[currentHeader] = { files: {} }; } - if (type === 'code') { - const match = text.match(/^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/); + if (token.type === 'code') { + var match = token.text.match(/^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/); if (match !== null) { - addons[currentHeader].files[match[1]] = text; + addons[currentHeader].files[match[1]] = token.text; } } +}); +for (var header in addons) { + verifyFiles(addons[header].files, + header, + console.log.bind(null, 'wrote'), + function(err) { if (err) throw err; }); } -for (const header in addons) { - let { files } = addons[header]; +function once(fn) { + var once = false; + return function() { + if (once) + return; + once = true; + fn.apply(this, arguments); + }; +} +function verifyFiles(files, blockName, onprogress, ondone) { // must have a .cc and a .js to be a valid test if (!Object.keys(files).some((name) => /\.cc$/.test(name)) || !Object.keys(files).some((name) => /\.js$/.test(name))) { - continue; + return; } - const blockName = header + blockName = blockName .toLowerCase() .replace(/\s/g, '_') .replace(/[^a-z\d_]/g, ''); @@ -51,25 +62,29 @@ for (const header in addons) { `${(++id < 10 ? '0' : '') + id}_${blockName}` ); - files = Object.entries(files).map(([name, content]) => { - if (name === 'test.js') content = boilerplate(name, content); - content = `// ${auto}\n${content}`; - if (name.endsWith('.h')) { - content = content.replace(/(#(ifndef|define) \w+_H)/g, - '$1 // NOLINT(build/header_guard)'); - content = content.replace(/(#endif)$/, - '$1 // NOLINT(build/header_guard)'); + files = Object.keys(files).map(function(name) { + if (name === 'test.js') { + files[name] = `'use strict'; +const common = require('../../common'); +${files[name].replace( + "'./build/Release/addon'", + // eslint-disable-next-line no-template-curly-in-string + '`./build/${common.buildType}/addon`')} +`; } - if (!content.endsWith('\n')) content += '\n'; // Pacify linter. - return { name, content, path: path.resolve(dir, name) }; + return { + path: path.resolve(dir, name), + name: name, + content: files[name] + }; }); files.push({ path: path.resolve(dir, 'binding.gyp'), - content: `# ${auto}\n` + JSON.stringify({ + content: JSON.stringify({ targets: [ { - target_name: 'binding', + target_name: 'addon', defines: [ 'V8_DEPRECATION_WARNINGS=1' ], sources: files.map(function(file) { return file.name; @@ -79,44 +94,22 @@ for (const header in addons) { }) }); - for (const file of files) { - let content; - try { - content = fs.readFileSync(file.path, 'utf8'); - } catch (e) { - strictEqual(e.code, 'ENOENT'); - } + fs.mkdir(dir, function() { + // Ignore errors - // Only update when file content has changed to prevent unneeded rebuilds. - if (content === file.content) continue; - changed.push(file); + const done = once(ondone); + var waiting = files.length; + files.forEach(function(file) { + fs.writeFile(file.path, file.content, function(err) { + if (err) + return done(err); - if (checkOnly) continue; - - try { - fs.mkdirSync(dir); - } catch (e) { - strictEqual(e.code, 'EEXIST'); - } + if (onprogress) + onprogress(file.path); - fs.writeFileSync(file.path, file.content); - console.log('wrote', file.path); - } -} - -if (checkOnly && changed.length > 0) { - console.error('The following files are out of date:'); - for (const { path } of changed) console.error(' ', path); - console.error('Run `node tools/doc/addon-verify.js` to update.'); - process.exit(1); -} - -function boilerplate(name, content) { - return `'use strict'; -const common = require('../../common'); -${content.replace( - "'./build/Release/binding'", - // eslint-disable-next-line no-template-curly-in-string - '`./build/${common.buildType}/binding`')} -`; + if (--waiting === 0) + done(); + }); + }); + }); } diff --git a/tools/gyp/pylib/gyp/generator/make.py b/tools/gyp/pylib/gyp/generator/make.py index eaf02ae734bd..f7f519b3e6b8 100644 --- a/tools/gyp/pylib/gyp/generator/make.py +++ b/tools/gyp/pylib/gyp/generator/make.py @@ -2136,7 +2136,6 @@ def CalculateMakefilePath(build_file, base_name): for target in gyp.common.AllTargets(target_list, target_dicts, build_file): needed_targets.add(target) - all_deps = set() build_files = set() include_list = set() for qualified_target in target_list: @@ -2185,12 +2184,6 @@ def CalculateMakefilePath(build_file, base_name): os.path.dirname(makefile_path)) include_list.add(mkfile_rel_path) - if 'actions' in spec: - for action in spec['actions']: - all_deps.update(map(writer.Absolutify, action['inputs'])) - if 'sources' in spec: - all_deps.update(map(writer.Absolutify, spec['sources'])) - # Write out per-gyp (sub-project) Makefiles. depth_rel_path = gyp.common.RelativePath(options.depth, os.getcwd()) for build_file in build_files: @@ -2234,10 +2227,3 @@ def CalculateMakefilePath(build_file, base_name): root_makefile.write(SHARED_FOOTER) root_makefile.close() - - # Hack to get rid of $(obj)/path/to/foo.o deps that node.gyp adds manually. - all_deps = [s for s in all_deps if not '$' in s] - all_deps_path = os.path.join(options.toplevel_dir, '.deps') - with open(all_deps_path, 'w') as f: - f.write('ALL_DEPS := \\\n\t') - f.write(' \\\n\t'.join(sorted(all_deps)))