0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
Commit Graph

30826 Commits

Author SHA1 Message Date
Ruben Bridgewater
2c4864762d
util: gracefully handle unknown colors
This makes sure colors that are unknown won't cause an error. This
is especially important in case a library wants to use colors
defined by Node.js core, if available and fall back to the default
otherwise.

Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>

PR-URL: https://github.com/nodejs/node/pull/33797
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2020-06-19 17:36:21 +02:00
Anna Henningsen
52de4cb107
src: minor updates to FastHrtime
- Don’t use 12 as a magic number for the buffer size
- Mark the object as weak (which is conceptually the right thing to do,
  even if there is little practical impact)
- Keep a reference to the `ArrayBuffer` in question for memory tracking

PR-URL: https://github.com/nodejs/node/pull/33851
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-19 17:35:36 +02:00
Anna Henningsen
2899588f28
src: simplify alignment-handling code
Use a common function to handle alignment computations in
multiple places.

PR-URL: https://github.com/nodejs/node/pull/33884
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2020-06-19 17:34:20 +02:00
Rich Trott
563062eddf doc: standardize on sentence case for headers
Previously, our documentation headers were a mixture of title case,
sentence case, and things that were neither. For technical
documentation, the _de facto_ standard seems to be sentence case. (See
refs below.) So let's standardize on that. This commit follows a
commit implementing this standard. This commit adds it to the style
guide.

Refs: https://developers.google.com/style/capitalization#capitalization-in-titles-and-headings
Refs: https://docs.microsoft.com/en-us/style-guide/capitalization

PR-URL: https://github.com/nodejs/node/pull/33889
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-19 08:09:59 -07:00
Rich Trott
d1d412b413 doc: use sentence-case for headings in docs
PR-URL: https://github.com/nodejs/node/pull/33889
Refs: https://developers.google.com/style/capitalization#capitalization-in-titles-and-headings
Refs: https://docs.microsoft.com/en-us/style-guide/capitalization
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-19 08:09:05 -07:00
rickyes
9918bdf5cb
lib: replace charCodeAt with fixed Unicode
PR-URL: https://github.com/nodejs/node/pull/32758
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2020-06-19 07:46:37 -07:00
Sarat Addepalli
f0fb511e3b
dgram: allow typed arrays in .send()
PR-URL: https://github.com/nodejs/node/pull/22413
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
2020-06-19 07:40:11 -07:00
Daniel Bevenius
88ef15812c
quic: remove unused string include http3_application
PR-URL: https://github.com/nodejs/node/pull/33926
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-19 07:19:07 -07:00
Daniel Bevenius
1bd88a3ac6
quic: fix up node_quic_stream includes
This commit removes the unused <array> and <limits> includes, and adds
<memory> (for std::unique_ptr), and <utility> (for std::move).

PR-URL: https://github.com/nodejs/node/pull/33921
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-19 07:14:06 -07:00
Stephen Belanger
56967afdca
deps: V8: cherry-pick eec10a2fd8fa
Original commit message:

    [promisehook] Add before/after hooks to thenable tasks

    This will allow Node.js to properly track async context in thenables.

    Change-Id: If441423789a78307a57ad7e645daabf551cddb57
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2215624
    Reviewed-by: Camillo Bruni <cbruni@chromium.org>
    Reviewed-by: Sathya Gunasekaran  <gsathya@chromium.org>
    Commit-Queue: Gus Caplan <me@gus.host>
    Cr-Commit-Position: refs/heads/master@{#68207}

Refs: eec10a2fd8

PR-URL: https://github.com/nodejs/node/pull/33778
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2020-06-18 20:52:45 -07:00
Pranshu Srivastava
ddfed69168
doc: link readable._read in stream.md
Refs: https://github.com/nodejs/node/issues/33715

PR-URL: https://github.com/nodejs/node/pull/33767
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-18 20:47:01 -07:00
Pranshu Srivastava
9dcde529a4
doc: specify default encoding in writable.write
Refs: https://github.com/nodejs/node/issues/33715

PR-URL: https://github.com/nodejs/node/pull/33765
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-18 20:43:24 -07:00
Benjamin Gruenbaum
ea866dc81b
events: use property, primordials
PR-URL: https://github.com/nodejs/node/pull/33775
Fixes: https://github.com/nodejs/node/issues/33773
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-18 15:12:23 -07:00
James M Snell
d7d79f2163
quic: avoid memory fragmentation issue
Original PR: https://github.com/nodejs/quic/pull/388

Previously, QuicPacket was allocating an std::vector<uint8_t> of
NGTCP2_MAX_PKT_SIZE bytes, then the packet would be serialized into the
buffer, and the std::vector would be resized based on the number of
bytes serialized. I suspect the memory fragmentation that you're seeing
is because of those resize operations not freeing memory in chunks that
are aligned with the allocation. This changes QuicPacket to use a stack
allocation that is always NGTCP2_MAX_PKT_SIZE bytes and the size of the
serialized packet is just recorded without any resizing. When the memory
is freed now, it should be freed in large enough chunks to cover
subsequent allocations.

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/33912
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
2020-06-18 15:00:13 -07:00
Robert Nagy
16116f5f5f
quic: remove noop code
this.unidirectional depends on #id which is never set
in the constructor, hence this condition will never run
and can be removed.

PR-URL: https://github.com/nodejs/node/pull/33914
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-06-18 14:44:29 -07:00
James M Snell
bfbdc84738
timers: allow promisified timeouts/immediates to be canceled
Using the new experimental AbortController...

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/33833
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
2020-06-18 11:40:10 -07:00
Rich Trott
0ef6956225 tools: update remark-preset-lint-node@1.15.1 to 1.16.0
This adds linting for code fence language/grammar strings. This is so,
for example, we have only one of ```text and ```txt and not both.

PR-URL: https://github.com/nodejs/node/pull/33852
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
2020-06-18 06:05:38 -07:00
Rich Trott
7407fc2aea doc: update code language flag for internal doc
Use `bash` instead of `shell` for code language flag in
doc/guides/maintaining-ngtcp2-nghttp3.md to conform with our other docs
and upcoming lint requirements.

PR-URL: https://github.com/nodejs/node/pull/33852
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
2020-06-18 06:05:32 -07:00
Brian White
a4f3206b76
events: improve listeners() performance
PR-URL: https://github.com/nodejs/node/pull/33863
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
2020-06-17 12:12:49 -07:00
James M Snell
272b46e04d
quic: skip test-quic-preferred-address-ipv6.js when no ipv6
PR-URL: https://github.com/nodejs/node/pull/33919
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
2020-06-17 11:35:02 -07:00
Daniel Bevenius
4b70f95d64
quic: use Check instead of FromJust in QuicStream
This commit uses Maybe::Check() instead of Maybe::FromJust() as the
return value is not used.

PR-URL: https://github.com/nodejs/node/pull/33909
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-17 11:17:48 -07:00
Anna Henningsen
133a97f60d
quic: always copy stateless reset token
Take ownership of the token value, since the memory for it is allocated
anyway and the buffer size is just 16, i.e. copyable very cheaply.

This makes valgrind stop complaining about a use-after-free error
when running `sequential/test-quic-preferred-address-ipv6`.

PR-URL: https://github.com/nodejs/node/pull/33917
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2020-06-17 11:12:28 -07:00
Shelley Vohr
e9145dbaef
2020-06-17, Version 12.18.1 'Erbium' (LTS)
Notable changes:

deps:
  * V8: cherry-pick 548f6c81d424 (Dominykas Blyžė) [#33484](https://github.com/nodejs/node/pull/33484)
  * update to uvwasi 0.0.9 (Colin Ihrig) [#33445](https://github.com/nodejs/node/pull/33445)
  * upgrade to libuv 1.38.0 (Colin Ihrig) [#33446](https://github.com/nodejs/node/pull/33446)
  * upgrade npm to 6.14.5 (Ruy Adorno) [#33239](https://github.com/nodejs/node/pull/33239)

PR-URL: https://github.com/nodejs/node/pull/33811
2020-06-17 09:26:19 -07:00
Mathias Buus
50fb0199cd n-api: document nextTick timing in callbacks
PR-URL: https://github.com/nodejs/node/pull/33804
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2020-06-17 18:24:26 +02:00
Pranshu Srivastava
1e4187fcf4 http2: add invalidheaders test
Refs: https://github.com/nodejs/node/issues/29829

PR-URL: https://github.com/nodejs/node/pull/33161
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
2020-06-17 10:26:03 +02:00
Rich Trott
ee7f0e3f75 doc,stream: split finish and end events into separate entries
The stream doc has the only instance in our docs where two events are
combined into a single entry. Split them into separate adjacent entries.

PR-URL: https://github.com/nodejs/node/pull/33881
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-06-16 21:43:45 -07:00
James M Snell
14d012ef96
quic: fix minor linting issue
PR-URL: https://github.com/nodejs/node/pull/33913
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2020-06-16 13:34:32 -07:00
Dan Fabulich
ff74e35c0b
process: add unhandled-rejection throw and warn-with-error-code
This PR defines two new modes for the --unhandled-rejections flag.

The first mode is called "throw". The "throw" mode first emits
unhandledRejection. If this hook is not set, the "throw" mode will
raise the unhandled rejection as an uncaught exception.

The second mode is called "warn-with-error-code". The
"warn-with-error-code" mode first emits unhandledRejection. If this
hook is not set, the "warn-with-error-code" mode will trigger a
warning and set the process's exit code to 1.

The PR doesn't change the default behavior for unhandled rejections.
That will come in a separate PR.

Refs: https://github.com/nodejs/node/pull/33021

PR-URL: https://github.com/nodejs/node/pull/33475
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-06-16 13:03:05 -07:00
James M Snell
bc71278563
events: lazy load perf_hooks for EventTarget
PR-URL: https://github.com/nodejs/node/pull/33717
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2020-06-16 12:27:23 -07:00
James M Snell
55360443ce
quic: initial QUIC implementation
Co-authored-by: Anna Henningsen <anna@addaleax.net>
Co-authored-by: Daniel Bevenius <daniel.bevenius@gmail.com>
Co-authored-by: gengjiawen <technicalcute@gmail.com>
Co-authored-by: James M Snell <jasnell@gmail.com>
Co-authored-by: Lucas Pardue <lucaspardue.24.7@gmail.com>
Co-authored-by: Ouyang Yadong <oyydoibh@gmail.com>
Co-authored-by: Juan Jos<C3><A9> Arboleda <soyjuanarbol@gmail.com>
Co-authored-by: Trivikram Kamat <trivikr.dev@gmail.com>
Co-authored-by: Denys Otrishko <shishugi@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/32379
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-06-16 09:23:34 -07:00
James M Snell
bccb514936
deps: maintaining ngtcp2 and nghttp3
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/32379
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-06-16 09:23:24 -07:00
James M Snell
834fa8f23f
deps: add ngtcp2 and nghttp3
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/32379
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-06-16 09:23:16 -07:00
James M Snell
f96b981528
deps: details for updating openssl quic support
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/32379
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-06-16 09:23:06 -07:00
James M Snell
98c8498552
deps: update archs files for OpenSSL-1.1.0
After an OpenSSL source update, all the config files need to be
regenerated and committed by:
  $ make -C deps/openssl/config
  $ git add deps/openssl/config/archs
  $ git add deps/openssl/openssl/include/crypto/bn_conf.h
  $ git add deps/openssl/openssl/include/crypto/dso_conf.h
  $ git add deps/openssl/openssl/include/openssl/opensslconf.h
  $ git commit

PR-URL: https://github.com/nodejs/node/pull/32379
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-06-16 09:22:54 -07:00
Todd Short
2c549e505e
deps: add support for BoringSSL QUIC APIs
Acquired from: https://github.com/akamai/openssl/tree/OpenSSL_1_1_1f-quic

Squashed:

*
2ef7c58b2c
*
3f8eda3128
*
b37f665884
*
6b235895a1
*
3a793e06a5

PR-URL: https://github.com/nodejs/node/pull/32379
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-06-16 09:22:39 -07:00
James M Snell
a808cb76ce
test: add common/udppair utility
Extracted from the QUIC PR. This adds a utility used to
deterministically test UDP traffic. It is currently only
used by the experimental QUIC implementation. Separated
out on request to make review easier.

PR-URL: https://github.com/nodejs/node/pull/33380
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2020-06-16 06:56:06 -07:00
Anna Henningsen
b371213d3d
src: add public APIs to manage v8::TracingController
We added a hack for this a while ago for Electron, so let’s remove
that hack and make this an official API.

Refs: https://github.com/nodejs/node/pull/28724
Refs: https://github.com/nodejs/node/issues/33800

PR-URL: https://github.com/nodejs/node/pull/33850
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2020-06-16 01:04:31 +02:00
Daniel Bevenius
f645cc7318 tools: prevent js2c from running if nothing changed
This commit updates tools/js2c.py to touch the target output file
, <(SHARED_INTERMEDIATE_DIR)/node_javascript.cc, even if the content
has not changed. This is to "help" the build system so that it can
compare the inputs against the output to determine if the gyp action
should be run.

I believe the issue here is that if js2c.py is updated this can
cause the action to be run as the node_javascript.cc target would be
older than js2c.py. But when the target is run the timestamp for
node_javascript.cc will not be updated (because we have not changed
anything that would change the contents of the file) so the js2c.py
prerequisite will always be passed and the target always run.

Using the update in this commit one would have to touch/modify one of
the js files specified in the library_files list, config.gypi, or
tools/js2c.py for this action to be run again.

PR-URL: https://github.com/nodejs/node/pull/33844
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-06-15 06:05:08 +02:00
Daniel Bevenius
aa40bad230 tools: remove unused vector include in mkdcodecache
PR-URL: https://github.com/nodejs/node/pull/33828
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-06-15 06:02:30 +02:00
Daniel Bevenius
5959ae3cc1 src: remove ref to tools/generate_code_cache.js
This commit removes the reference to tools/generate_code_cache.js
and replaces it with a note about more information being available
in tools/code_cache/README.md.

PR-URL: https://github.com/nodejs/node/pull/33825
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
2020-06-15 06:00:15 +02:00
Daniel Bevenius
74d80115b6 src: remove unused vector include in string_bytes
PR-URL: https://github.com/nodejs/node/pull/33824
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
2020-06-15 05:52:52 +02:00
Daniel Bevenius
8f7211a60a src: avoid unnecessary ToLocalChecked calls
This commit removes two unnecessary ToLocalChecked calls in
StringBytes::Encode.

PR-URL: https://github.com/nodejs/node/pull/33824
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
2020-06-15 05:52:33 +02:00
Daniel Bevenius
418f5b61eb doc: move --force-context-aware option in cli.md
This commit moves the --force-context-aware option so that the options
list is in alphabetical order.

PR-URL: https://github.com/nodejs/node/pull/33823
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2020-06-15 05:49:28 +02:00
Anna Henningsen
e1ad548cd4
worker: emit 'messagerror' events for failed deserialization
This is much nicer than just treating exceptions as uncaught, and
enables reporting of exceptions from the internal C++ deserialization
machinery.

PR-URL: https://github.com/nodejs/node/pull/33772
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2020-06-14 14:53:40 +02:00
Anna Henningsen
8641d94189
worker,fs: make FileHandle transferable
Allow passing `FileHandle` instances in the transfer list
of a `.postMessage()` call.

PR-URL: https://github.com/nodejs/node/pull/33772
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2020-06-14 14:53:40 +02:00
Anna Henningsen
9129cf21ab
worker: allow passing JS wrapper objects via postMessage
Enable JS wrapper objects to be used as transferable or cloneable
objects in `postMessage()` calls, by having them extend a C++-backed
class.

This requires a few internal changes:
- This commit adds the possibility for transferred objects to
  read/write JS values at the end of the serialization/deserialization
  phases.
- This commit adds the possibility for transferred objects to list
  sub-transferables, e.g. typically the public JS wrapper class
  would list its C++ handle in there.
- This commit adds usage of `BaseObject` in a few more places, because
  now during deserialization weakly held objects can also be involved,
  in addition to `MessagePort`s.

PR-URL: https://github.com/nodejs/node/pull/33772
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2020-06-14 14:53:39 +02:00
Anna Henningsen
8ead0211d7
src: add equality operators for BaseObjectPtr
PR-URL: https://github.com/nodejs/node/pull/33772
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2020-06-14 14:53:39 +02:00
Anna Henningsen
57e7c63f74
worker: allow transferring/cloning generic BaseObjects
Extend support for transferring objects à la `MessagePort` to other
types of `BaseObject` subclasses, as well as implement cloning
support for cases in which destructive transferring is not needed
or optional.

PR-URL: https://github.com/nodejs/node/pull/33772
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2020-06-14 14:53:38 +02:00
Anna Henningsen
8a7201b25f
src: introduce BaseObject base FunctionTemplate
PR-URL: https://github.com/nodejs/node/pull/33772
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2020-06-14 14:53:38 +02:00
Derek Lewis
c17d2f9901 esm: fix loader hooks doc annotations
Prior to this commit, the type annotations on the ESM loader hooks
were invalid. This has been corrected and is ensured to be compatible
with both the TypeScript and Closure type systems.

Notes:
    https://www.typescriptlang.org/play/index.html?useJavaScript=true#code/PQKhCgAIUgBAHAhgJ0QW0gbwM4BdkCWAdgOYC+kArsgDZQwIrpYDyARgFYCmAxrhTwD2RXFwAeuSAAoe1ZFxE0AnpC5p4uJQEp6cJKgyYAYpSJ8CwigBMuAM0SUauAOJdcRwcjSJcu2PNxqImwsAAVkQTQCbC4AHkxIW09vXAAuSDxCUkgyAD4yemBwcXhPSURsJTNE03NhSBI3Dy8fKWoaABpIIRFxXC6be0cXJuSfLSwoSAJbaQBZHwALADpUIitIqQncyAAGZYBWCYTgYEgAZUiubuErAlwLImWpyEhTyGaMq8hPSEQaGiQACqACUADLYAaCL5oa6yPCRSA0QQkAg8RK-GyiLzEYgkDEtXDPV6vd4AQRoAHdEEoQgEgn8iD9OLxJIJZrhFtckl4sDyUulYpk8fkupSufJIJyuC83md+T5piFhNd2VKuRl8HiQsR1ddcIg2DRrobBAA3LjEkn05BMzCy14KtKQADkaEEVkcXBdHVlZAA3FMCqSzgAROxcZBS6EAOQ9lo4IR5fwBP2lUdBEKtNqZgwcTlc7jGuDatC6PVEEgGdnzIyLhK0gbIQA
    https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540warning_level%2520VERBOSE%250A%252F%252F%2520%2540jscomp_error%2520strictCheckTypes%250A%252F%252F%2520%2540language_out%2520ECMASCRIPT_NEXT%250A%252F%252F%2520%2540checks_only%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F**%250A%2520*%2520%2540param%2520%257Bstring%257D%2520url%250A%2520*%2520%2540param%2520%257BObject%257D%2520context%2520(currently%2520empty)%250A%2520*%2520%2540param%2520%257BFunction%257D%2520defaultGetFormat%250A%2520*%2520%2540returns%2520%257BPromise%253C%257B%2520format%253A%2520string%2520%257D%253E%257D%250A%2520*%252F%250Aexport%2520async%2520function%2520getFormat(url%252C%2520context%252C%2520defaultGetFormat)%2520%257B%250A%2520%2520if%2520(Math.random()%2520%253E%25200.5)%2520%257B%2520%252F%252F%2520Some%2520condition.%250A%2520%2520%2520%2520%252F%252F%2520For%2520some%2520or%2520all%2520URLs%252C%2520do%2520some%2520custom%2520logic%2520for%2520determining%2520format.%250A%2520%2520%2520%2520%252F%252F%2520Always%2520return%2520an%2520object%2520of%2520the%2520form%2520%257Bformat%253A%2520%253Cstring%253E%257D%252C%2520where%2520the%250A%2520%2520%2520%2520%252F%252F%2520format%2520is%2520one%2520of%2520the%2520strings%2520in%2520the%2520table%2520above.%250A%2520%2520%2520%2520return%2520%257B%250A%2520%2520%2520%2520%2520%2520format%253A%2520'module'%252C%250A%2520%2520%2520%2520%257D%253B%250A%2520%2520%257D%250A%2520%2520%252F%252F%2520Defer%2520to%2520Node.js%2520for%2520all%2520other%2520URLs.%250A%2520%2520return%2520defaultGetFormat(url%252C%2520context%252C%2520defaultGetFormat)%253B%250A%257D

    https://www.typescriptlang.org/play/?useJavaScript=true#code/PQKhCgAIUgBAHAhgJ0QW0gbwM4BdkCWAdgOYC+k28ApgMYEBmB1yUMCK6WmbkfSyakVwBVAEoAZAFyQAhAAo8hUpAA+kAK5EAJtSZFq2gJQAaXn1oB7HQVwFr2GQoCCyVAE8APEuIkAfKa8ZBRWwtQAHri8HKgYmABiWrR21hS6DIgaADa4YtTYllkAbtTRgrgayETYWAoACsiWaATY1J6YmshZMj4qZAFkbMDgEfCWyLiQiNjuRLSQDEkpRJCCBcXUijT0TCwmkKG4Ebj76Zk5eeslRlhQBw6THQJCopKQALyQRNlZkBSfh2OAG47oxIPIALKIXAACwAdKgdE15Dc-JAAAxwgCsNw6wGAkAAyk1qPcbMs4Xc+PjIPFxpQSZB6Ygsr8qHRGMxkNhTpYGWhSbQNHgmpAspYSAR5gx6WtCkVfJS+NSCc4sgB3RDuGrlSorRArSwAIwAVnRJpYGJBYaSZcg4pVupBvPhfH4yErlbqqrdlcrHTJnsJxBJIAB+Kl+r7UdWQENbDm7ZD7IOvCRGOEwwRWqSRv0GWPx9k7LkZrN6Mx+sggviDPhgyHQ+GI7TIm6eDHY3GQGnOIiWG3IMnaWz2IielWQADqMKEBxZWV8kAABmdsrl8vLqMv9japsgSBoBcIarQDZAjaS0JYR7ttHDIABJFawlqRmln1qQWwAchqiG0EcVANAdZyHIoWQ0W16TQaFaBhJdQhHZYWUgUZxlwbAJ1WagKh9NcLk3DYExLPZfSjOFKMBSJKyjJDRwcGQAG1KLhajcDY6xkLHHlIB-EDBwAWno5YfwAXVo2sjBrP47hpAARPQWGtPkADkb2oOETRqO0plZJlB0obZORYLC7m9FYCI3K5NmLEzkzJI4aMgKzLi3aTwDIIA
    https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540warning_level%2520VERBOSE%250A%252F%252F%2520%2540jscomp_error%2520strictCheckTypes%250A%252F%252F%2520%2540language_out%2520ECMASCRIPT_NEXT%250A%252F%252F%2520%2540checks_only%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F**%250A%2520*%2520%2540param%2520%257Bstring%257D%2520specifier%250A%2520*%2520%2540param%2520%257B%257B%250A%2520*%2520%2520%2520parentURL%253A%2520!(string%2520%257C%2520undefined)%252C%250A%2520*%2520%2520%2520conditions%253A%2520!(Array%253Cstring%253E)%252C%250A%2520*%2520%257D%257D%2520context%250A%2520*%2520%2540param%2520%257BFunction%257D%2520defaultResolve%250A%2520*%2520%2540returns%2520%257B!(Promise%253C%257B%2520url%253A%2520string%2520%257D%253E)%257D%250A%2520*%252F%250Aexport%2520async%2520function%2520resolve(specifier%252C%2520context%252C%2520defaultResolve)%2520%257B%250A%2520%2520const%2520%257B%2520parentURL%2520%253D%2520null%2520%257D%2520%253D%2520context%253B%250A%2520%2520if%2520(Math.random()%2520%253E%25200.5)%2520%257B%2520%252F%252F%2520Some%2520condition.%250A%2520%2520%2520%2520%252F%252F%2520For%2520some%2520or%2520all%2520specifiers%252C%2520do%2520some%2520custom%2520logic%2520for%2520resolving.%250A%2520%2520%2520%2520%252F%252F%2520Always%2520return%2520an%2520object%2520of%2520the%2520form%2520%257Burl%253A%2520%253Cstring%253E%257D.%250A%2520%2520%2520%2520return%2520%257B%250A%2520%2520%2520%2520%2520%2520url%253A%2520parentURL%2520%253F%250A%2520%2520%2520%2520%2520%2520%2520%2520new%2520URL(specifier%252C%2520parentURL).href%2520%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520new%2520URL(specifier).href%252C%250A%2520%2520%2520%2520%257D%253B%250A%2520%2520%257D%250A%2520%2520if%2520(Math.random()%2520%253C%25200.5)%2520%257B%2520%252F%252F%2520Another%2520condition.%250A%2520%2520%2520%2520%252F%252F%2520When%2520calling%2520%2560defaultResolve%2560%252C%2520the%2520arguments%2520can%2520be%2520modified.%2520In%2520this%250A%2520%2520%2520%2520%252F%252F%2520case%2520it's%2520adding%2520another%2520value%2520for%2520matching%2520conditional%2520exports.%250A%2520%2520%2520%2520return%2520defaultResolve(specifier%252C%2520%257B%250A%2520%2520%2520%2520%2520%2520...context%252C%250A%2520%2520%2520%2520%2520%2520conditions%253A%2520%255B...context.conditions%252C%2520'another-condition'%255D%252C%250A%2520%2520%2520%2520%257D)%253B%250A%2520%2520%257D%250A%2520%2520%252F%252F%2520Defer%2520to%2520Node.js%2520for%2520all%2520other%2520specifiers.%250A%2520%2520return%2520defaultResolve(specifier%252C%2520context%252C%2520defaultResolve)%253B%250A%257D

    https://www.typescriptlang.org/play/?useJavaScript=true#code/PQKhCgAIUgBAHAhgJ0QW0gbwM4BdkCWAdgOYC+kArsgDZQwIrpaaQBmA9smorgFyQ8hUpDIUAxhyK4ApgA9c9OElQZMAMUpFxuAlIoATGW0SUauAOIzcAZQ7VxMpbGTXqRbFgAKyDmgLYMgA8rNj2yI4CAIQAFDYAFigyBgCCyKgAngBClGxsMsiQAD6C+MQkxZAAqsS4ABxpmQCUogB8ZPTA4PLwXLiQiNgZ2uxaOnpEkCTWdg4yMdQ0ADSQktLyuCtGJmaWM+GOLZhQq1J4WOxcPP0UALyn6woA3CcEbJAxALK88QB0qEQDH4Yi1WpAAAy-ACsR0gwGAkDsaBkDwMBF0Ul+J0gcIR6i4gj8KIJiBoNGqACUADLYLYcQnI1aUPB+SA0DgkAjiS6FVxlGQAN3KkFw8RRYTmWJxOPhkBSNAA7ogMp4+e4BpMOAAjABWMh0kA471FKM43CwEoiMgEQSE5SKWty+WQ7Sl0rVyEmx2l0stkUgAHJfsGA0tsaIXjiOjKEQARYwFEX0gByHCMvx1njNAzJhpNhSq1Owbo9k22pnMVlsB3mixWa1kCi2xgre2rcyaLzIQA
    https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540warning_level%2520VERBOSE%250A%252F%252F%2520%2540jscomp_error%2520strictCheckTypes%250A%252F%252F%2520%2540language_out%2520ECMASCRIPT_NEXT%250A%252F%252F%2520%2540checks_only%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F**%250A%2520*%2520%2540param%2520%257Bstring%257D%2520url%250A%2520*%2520%2540param%2520%257B%257B%2520format%253A%2520string%2520%257D%257D%2520context%250A%2520*%2520%2540param%2520%257BFunction%257D%2520defaultGetSource%250A%2520*%2520%2540returns%2520%257BPromise%253C%257B%2520source%253A%2520!(SharedArrayBuffer%2520%257C%2520string%2520%257C%2520Uint8Array)%2520%257D%253E%257D%250A%2520*%252F%250Aexport%2520async%2520function%2520getSource(url%252C%2520context%252C%2520defaultGetSource)%2520%257B%250A%2520%2520const%2520%257B%2520format%2520%257D%2520%253D%2520context%253B%250A%2520%2520if%2520(Math.random()%2520%253E%25200.5)%2520%257B%2520%252F%252F%2520Some%2520condition.%250A%2520%2520%2520%2520%252F%252F%2520For%2520some%2520or%2520all%2520URLs%252C%2520do%2520some%2520custom%2520logic%2520for%2520retrieving%2520the%2520source.%250A%2520%2520%2520%2520%252F%252F%2520Always%2520return%2520an%2520object%2520of%2520the%2520form%2520%257Bsource%253A%2520%253Cstring%257Cbuffer%253E%257D.%250A%2520%2520%2520%2520return%2520%257B%250A%2520%2520%2520%2520%2520%2520source%253A%2520'...'%252C%250A%2520%2520%2520%2520%257D%253B%250A%2520%2520%257D%250A%2520%2520%252F%252F%2520Defer%2520to%2520Node.js%2520for%2520all%2520other%2520URLs.%250A%2520%2520return%2520defaultGetSource(url%252C%2520context%252C%2520defaultGetSource)%253B%250A%257D

    https://www.typescriptlang.org/play/?useJavaScript=true#code/PQKhCgAIUgBAHAhgJ0QW0gbwIQAoDKAFigKYAmAgsqgJ4BCArgGZMnKQA+kAzgC7IBLAHYBzTpACqw3gA4qtAJQBfHgHsGyAMYkoMBCnRZMuyKY0AbAFw9+wkQBoTppquRpEva30GjH0SEoqmqpCvCQAHrwm+qgYmABiDEKavAIhKmQkTIgM5rwAKqhC3C5u+OpaOv6wyCS8GsVYAArIqmgC3CQAPJhqGtrWeESklNSI9Mys7FzeduJSoXJjNAoBAHxKusDgEfCuvJCI3DTJkExJKWlCkPyIxaVo5f0kuNwV2vaQwaERvJ+Z2VyBSKJVcj3eJFWxlM3z4WEgFk+Dw8AUgAF4viEwpEANxQSACJiQXAAWQ8hAAdEUyG1cKs1pAAAwUgCsUMgwGAkHKaBImKEZAEqRCFPxpk5kHirjUvMg0sQ5nMkgASgAZbj-VQyvmaBh8NqQcyqEQCTRnaVoVSCpg0Oa8Qh8t7PUWmcVcijmADu424kFq9WQ1zucoARgArEgpOVE+18h5YJ2VaxdWaiDghyZsDYu13+hpYMWuxMDSAAcgpFdLfldSjxpk2bsgABEsmwblqAHJWkgUsO+0qHRVy2PsYskbg5vOByAAnJ5Qp3UFlCGvCGfb7Yv4zrJz4GLh5PSoKPFKIA
    https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540warning_level%2520VERBOSE%250A%252F%252F%2520%2540jscomp_error%2520strictCheckTypes%250A%252F%252F%2520%2540language_out%2520ECMASCRIPT_NEXT%250A%252F%252F%2520%2540checks_only%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F**%250A%2520*%2520%2540param%2520%257B!(SharedArrayBuffer%2520%257C%2520string%2520%257C%2520Uint8Array)%257D%2520source%250A%2520*%2520%2540param%2520%257B%257B%250A%2520*%2520%2520%2520url%253A%2520string%252C%250A%2520*%2520%2520%2520format%253A%2520string%252C%250A%2520*%2520%257D%257D%2520context%250A%2520*%2520%2540param%2520%257BFunction%257D%2520defaultTransformSource%250A%2520*%2520%2540returns%2520%257BPromise%253C%257B%2520source%253A%2520!(SharedArrayBuffer%2520%257C%2520string%2520%257C%2520Uint8Array)%2520%257D%253E%257D%250A%2520*%252F%250Aexport%2520async%2520function%2520transformSource(source%252C%2520context%252C%2520defaultTransformSource)%2520%257B%250A%2520%2520const%2520%257B%2520url%252C%2520format%2520%257D%2520%253D%2520context%253B%250A%2520%2520if%2520(Math.random()%2520%253E%25200.5)%2520%257B%2520%252F%252F%2520Some%2520condition.%250A%2520%2520%2520%2520%252F%252F%2520For%2520some%2520or%2520all%2520URLs%252C%2520do%2520some%2520custom%2520logic%2520for%2520modifying%2520the%2520source.%250A%2520%2520%2520%2520%252F%252F%2520Always%2520return%2520an%2520object%2520of%2520the%2520form%2520%257Bsource%253A%2520%253Cstring%257Cbuffer%253E%257D.%250A%2520%2520%2520%2520return%2520%257B%250A%2520%2520%2520%2520%2520%2520source%253A%2520'...'%252C%250A%2520%2520%2520%2520%257D%253B%250A%2520%2520%257D%250A%2520%2520%252F%252F%2520Defer%2520to%2520Node.js%2520for%2520all%2520other%2520sources.%250A%2520%2520return%2520defaultTransformSource(source%252C%2520context%252C%2520defaultTransformSource)%253B%250A%257D

PR-URL: https://github.com/nodejs/node/pull/33563
Co-authored-by: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
2020-06-13 20:48:40 -07:00