Commit Graph

28 Commits

Author SHA1 Message Date
Vladimir Morozov
0b3ae01131
test: fix embedding test for Windows
PR-URL: https://github.com/nodejs/node/pull/53659
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-08-27 21:30:50 +00:00
Stefan Stojanovic
8e9686d9c9
test: fix Windows native test suites
2 PRs that landed independently caused this issue which makes every
native suites run in CI fail on Windows. This is just a quick patch to
unblock the CI.

Refs: https://github.com/nodejs/node/pull/52905
Refs: https://github.com/nodejs/node/pull/52646
PR-URL: https://github.com/nodejs/node/pull/53173
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2024-05-27 18:56:59 +00:00
Rafael Gonzaga
b9ad94b6da
src: fix external module env and kDisableNodeOptionsEnv
PR-URL: https://github.com/nodejs/node/pull/52905
Fixes: https://github.com/nodejs/node/issues/51227
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
2024-05-23 18:41:55 +00:00
Vladimir Morozov
98a1ecfc7b
test,doc: enable running embedtest for Windows
PR-URL: https://github.com/nodejs/node/pull/52646
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-05-23 18:33:40 +00:00
Yagiz Nizipli
c5cfdd4849
src: rewrite task runner in c++
PR-URL: https://github.com/nodejs/node/pull/52609
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2024-05-02 19:54:02 +00:00
Antoine du Hamel
c714cda9a7
test: add spawnSyncAndAssert util
PR-URL: https://github.com/nodejs/node/pull/52132
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2024-03-20 19:44:14 +01:00
Joyee Cheung
fea74b0f7b
src: support configurable snapshot
- Add support for --build-snapshot-config which allows passing
  snapshot configurations via a JSON configuration file.
- Add support for node::SnapshotConfig in the embedder API

The initial configurable options are:

- "builder" (SnapshotConfig::builder_script_path): path to the
  builder script.
- "withoutCodeCache" (SnapshotFlags::kWithoutCodeCache): disable
  code cache generation.

PR-URL: https://github.com/nodejs/node/pull/50453
Refs: https://github.com/nodejs/node/issues/42566
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2023-12-15 15:13:46 +01:00
Cheng Zhao
49579949a9
test: resolve path of embedtest binary correctly
PR-URL: https://github.com/nodejs/node/pull/50276
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
2023-12-05 19:28:17 +01:00
Joyee Cheung
76ac548477
test: fix argument computation in embedtest
There were a few bugs in the original test that went unnoticed
because with the bug the test did not actually get run anymore.
This patch fixes the argument computation by accounting filtering
of the arguments, and uses spawnSyncAndExit{WithoutError} in
the test to enable better logging when the test fails.

PR-URL: https://github.com/nodejs/node/pull/49506
Fixes: https://github.com/nodejs/node/issues/49501
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-09-18 00:06:20 +02:00
Jungku Lee
ea32c3ceae
test: fix warning for comment in embedtest
PR-URL: https://github.com/nodejs/node/pull/49416
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
2023-09-02 10:53:52 +00:00
Livia Medeiros
052434a0c1
test: use tmpdir.resolve()
PR-URL: https://github.com/nodejs/node/pull/49136
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-08-21 16:41:53 +00:00
Joyee Cheung
718f62bfcf
bootstrap: unify snapshot builder and embedder entry points
- Run the embedder entry point directly through
  runEmbedderEntryPoint(), instead of going through another
  JS -> C++ trip through the function returned by
  getEmbedderEntryFunction()
- For --build-snapshot, read the snapshot script code directly in C++
  and pass it to SnapshotBuilder::Generate(), this makes the entry point
  more explicit instead of hiding it in JS land, and also makes it
  possible to invoke SnapshotBuilder::Generate() internally to create
  a custom snapshot.
- Previously we used process.execPath for the embedder to create
  __filename and __dirname in the snapshot builder script while using
  process.argv[1] for --build-snapshot (where it's always set) which
  results in inconsistencies. We now require the embedder to also set
  args[1] when creating the Environment if they intend to run snapshot
  scripts with a context that contains __filename and __dirname, which
  would be derived from args[1]. If they prefer not to include
  build-time paths in the snapshot, we now provide
  node::GetAnonymousMainPath() as an alternative.

PR-URL: https://github.com/nodejs/node/pull/48242
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-06-11 00:34:19 +02:00
Sam James
ad0bbaf34a
test: add missing <algorithm> include for std::find
GCC 14 drops some transitive includes within libstdc++.

Explicitly include <algorithm> for std::find.

Signed-off-by: Sam James <sam@gentoo.org>
PR-URL: https://github.com/nodejs/node/pull/48380
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
2023-06-09 17:29:00 +00:00
Michael Dawson
fe449a20af src: fix some recently introduced coverity issues
Signed-off-by: Michael Dawson <mdawson@devrus.com>

PR-URL: https://github.com/nodejs/node/pull/47240
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-03-28 09:07:55 -04:00
Anna Henningsen
3803b028dd
src: share common code paths for SEA and embedder script
Since SEA is very similar in principle to embedding functionality,
it makes sense to share code paths where possible. This commit does
so and addresses a `TODO` while doing so.

It also adds a utility to directly run CJS code to the embedder
startup callback, which comes in handy for this purpose.

Finally, this commit is breaking because it aligns the behavior
of `require()`ing internal modules; previously, embedders could
use the `require` function that they received to do so.
(If this is not considered breaking because accessing internals
is not covered by the API, then this would need ABI compatibility
patches for becoming fully non-breaking.)

PR-URL: https://github.com/nodejs/node/pull/46825
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
2023-03-02 14:31:08 +00:00
Anna Henningsen
d592630c97
src: allow blobs in addition to FILE*s in embedder snapshot API
This is a shared follow-up to 06bb6b42b3 and a466feaca7
now that both have been merged.

PR-URL: https://github.com/nodejs/node/pull/46491
Refs: https://github.com/nodejs/node/pull/45888
Refs: https://github.com/nodejs/node/pull/46463
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2023-02-06 19:57:19 +00:00
Anna Henningsen
bfadee5e68 src: allow snapshotting from the embedder API
PR-URL: https://github.com/nodejs/node/pull/45888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2023-02-03 20:48:24 +00:00
Anna Henningsen
06bb6b42b3 src: add snapshot support for embedder API
Add experimental support for loading snapshots in the embedder API
by adding a public opaque wrapper for our `SnapshotData` struct and
allowing embedders to pass it to the relevant setup functions.
Where applicable, use these helpers to deduplicate existing code
in Node.js’s startup path.

This has shown a 40 % startup performance increase for a real-world
application, even with the somewhat limited current support for
built-in modules.

The documentation includes a note about no guarantees for API or
ABI stability for this feature while it is experimental.

PR-URL: https://github.com/nodejs/node/pull/45888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2023-02-03 20:48:22 +00:00
Anna Henningsen
b697160256
src: add detailed embedder process initialization API
So far, process initialization has been a bit all over the place
in Node.js. `InitializeNodeWithArgs()` is our main public API
for this, but inclusion of items in it vs. `InitializeOncePerProcess()`
and `PlatformInit()` has been random at best. Likewise,
some pieces of initialization have been guarded by
`NODE_SHARED_MODE`, but also fairly randomly and without
any meaningful connection to shared library usage.

This leaves embedders in a position to cherry-pick some of
the initialization code into their own code to make their
application behave like typical Node.js applications to the
degree to which they desire it.

Electron takes an alternative route and makes direct use of
`InitializeOncePerProcess()` already while it is a private
API, with a `TODO` to add it to the public API in Node.js.

This commit addresses that `TODO`, and `TODO`s around the
`NODE_SHARED_MODE` usage. Specifically:

- `InitializeOncePerProcess()` and `TearDownOncePerProcess()`
  are added to the public API.
- The `flags` option of these functions are merged with the
  `flags` option for `InitializeNodeWithArgs()`, since they
  essentially share the same semantics.
- The return value of the function is made an abstract class,
  rather than a struct, for easier API/ABI stability.
- Initialization code from `main()` is brought into these
  functions (since that makes sense in general).
- Add a `TODO` for turning `InitializeNodeWithArgs()` into
  a small wrapper around `InitializeOncePerProcess()` and
  eventually removing it (at least one major release cycle
  each, presumably).
- Remove `NODE_SHARED_MODE` guards and replace them with
  runtime options.

PR-URL: https://github.com/nodejs/node/pull/44121
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2022-08-05 19:46:08 +00:00
Michaël Zasso
86b77f7d0f
tools,doc: use V8::DisposePlatform
V8::ShutdownPlatform has been deprecated and does the same.

PR-URL: https://github.com/nodejs/node/pull/41610
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2022-02-02 17:25:01 +01:00
Anna Henningsen
9fd6122659
src: add embedding helpers to reduce boilerplate code
Provide helpers for a) spinning the event loop and
b) setting up and tearing down the objects involved in a single
Node.js instance, as they would typically be used.
The former helper is also usable inside Node.js itself,
for both Worker and main threads.

PR-URL: https://github.com/nodejs/node/pull/35597
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
2020-10-14 20:08:19 +02:00
Anna Henningsen
278d38f4cf
src: add maybe versions of EmitExit and EmitBeforeExit
This addresses a TODO comment, and removes invalid `.ToLocalChecked()`
calls from our code base.

PR-URL: https://github.com/nodejs/node/pull/35486
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-10-11 02:20:53 +02:00
cjihrig
1e59f31555 test,doc: add missing uv_setup_args() calls
libuv 1.39.0 will begin requiring uv_setup_args() to be called
before attempting to access the process title. This commit adds
uv_setup_args() calls that were missing in order for the test
suite to pass (and updates the documentation).

PR-URL: https://github.com/nodejs/node/pull/34751
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-08-14 15:29:29 -07:00
Anna Henningsen
bfebfdb149 src: fix linter failures
Fix linter failures when running the linter on all source files.

PR-URL: https://github.com/nodejs/node/pull/34582
Refs: https://github.com/nodejs/node/pull/34565
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2020-08-07 08:43:17 -07:00
Anna Henningsen
db6e6e3b26
test: add non-ASCII character embedding test
Add a test that verifies that non-ASCII characters may be used
in the source code provided to `LoadEnvironment()`.

PR-URL: https://github.com/nodejs/node/pull/33972
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-26 10:13:13 -07:00
Anna Henningsen
c3204a8787
test: use common.buildType in embedding test
This un-breaks testing in the case of `./configure --debug-node`.

PR-URL: https://github.com/nodejs/node/pull/32422
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-03-27 17:29:41 +01:00
Anna Henningsen
2061c33670
test: add extended embedder cctest
Add an embedder cctest that also covers a multi-Environment situation,
including worker_threads-style inspector support.

Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/30467
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2020-03-21 10:58:28 +01:00
Anna Henningsen
43d32b073f
src,test: add full-featured embedder API test
PR-URL: https://github.com/nodejs/node/pull/30467
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2020-03-21 10:58:23 +01:00