Antoine du Hamel
2eeb4e1d94
lib: make primordials Promise methods safe
...
`catch` and `finally` methods on %Promise.prototype% looks up the `then`
property of the instance, making it at risk of prototype pollution.
PR-URL: https://github.com/nodejs/node/pull/38650
Refs: https://tc39.es/ecma262/#sec-promise.prototype.catch
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2021-05-19 09:21:37 -07:00
Voltrex
6e6663b8a4
events: use nullish coalencing operator
...
PR-URL: https://github.com/nodejs/node/pull/38328
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-05-17 12:26:29 -07:00
moander
417c31b69a
errors: remove input from ERR_INVALID_URL message
...
Avoid potentially huge messages and leaked secrets.
PR-URL: https://github.com/nodejs/node/pull/38614
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
2021-05-17 12:17:24 -07:00
Nitzan Uziely
3612229d44
fs: fix async iterator partial writes
...
fix an issue where chunks might be partially written when
using writeFile with an async iterator.
PR-URL: https://github.com/nodejs/node/pull/38615
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-17 12:16:27 -07:00
Filip Skokan
3ee1f9a29a
util: add util.types.isKeyObject and util.types.isCryptoKey
...
closes #38611
PR-URL: https://github.com/nodejs/node/pull/38619
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2021-05-17 10:29:18 +02:00
Filip Skokan
2130598e91
crypto: forbid NODE-ED25519 and NODE-ED448 "raw" key export
...
closes #38655
PR-URL: https://github.com/nodejs/node/pull/38668
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-05-17 10:28:37 +02:00
Antoine du Hamel
0996eb71ed
repl: fix Ctrl+C on top level await
...
PR-URL: https://github.com/nodejs/node/pull/38656
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2021-05-15 21:47:55 +02:00
Antoine du Hamel
284f74d6f9
debugger: refactor inspect_repl to use primordials
...
PR-URL: https://github.com/nodejs/node/pull/38551
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-14 15:53:34 -07:00
Rongjian Zhang
a03d3afa69
http: refactor to remove redundant argument of _deferToConnect
...
PR-URL: https://github.com/nodejs/node/pull/38598
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2021-05-14 14:43:33 +02:00
Timothy Gu
70157b9cb7
url: forbid certain confusable changes from being introduced by toASCII
...
The legacy url.parse() function attempts to convert Unicode domains
(IDNs) into their ASCII/Punycode form through the use of the toASCII
function. However, toASCII can introduce or remove various characters
that at best invalidate the parsed URL, and at worst cause hostname
spoofing:
url.parse('http://bad.c℀.good.com/ ').href === 'http://bad.ca/c.good.com/ '
(from [1])
url.parse('http://\u00AD/bad.com ').href === 'http:///bad.com/ '
While changes to the legacy URL parser are discouraged in general, the
security implications here outweigh the desire for strict compatibility.
This is since this commit only changes behavior when non-ASCII
characters appear in the hostname, an unusual situation for most use
cases. Additionally, despite the availability of the WHATWG URL API,
url.parse remain widely deployed in the Node.js ecosystem, as
exemplified by the recent un-deprecation of the legacy API.
This change is similar in spirit to CPython 3.8's change [2] fixing
bpo-36216 [3] aka CVE-2019-9636, which also occurred despite potential
compatibility concerns.
[1]: https://hackerone.com/reports/678487
[2]: https://github.com/python/cpython/commit/16e6f7dee7f02bb81aa6b385b982dcdda5b99286
[3]: https://bugs.python.org/issue36216
PR-URL: https://github.com/nodejs/node/pull/38631
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2021-05-13 23:04:23 -07:00
James M Snell
2c80048cb7
process: add 'worker' event
...
Provides a new `process.on('worker', (worker) => {})` event that
is triggered by the creation of a new `worker_thread.Worker`.
The use case is to allow hooks to be installed for monitoring
workers without having to modify the call sites around those.
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/38659
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de >
2021-05-13 18:12:52 -07:00
Voltrex
89f592cc82
path: inline conditions
...
This condition can be inlined in the first `if` statement since
if the `path`'s length is 0, it'll be a empty string so we can
return that as there's no need for an extra `if` statement.
PR-URL: https://github.com/nodejs/node/pull/38613
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-05-12 07:26:22 -07:00
Antoine du Hamel
4ebb88fea5
module: add support for URL to import.meta.resolve
...
PR-URL: https://github.com/nodejs/node/pull/38587
Refs: https://github.com/nodejs/node/pull/38585
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-10 15:09:05 -07:00
Zach Bjornson
8886b63cf6
fs: fix error when writing buffers > INT32_MAX
...
This reverts c380ee6785 .
uv_fs_write returns an int, so it is not possible to ask
it to write more than INT32_MAX.
Instead, validate 'length' is an int32 in JS to avoid
the assertion failure.
PR-URL: https://github.com/nodejs/node/pull/38546
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2021-05-10 15:04:37 -07:00
Rongjian Zhang
1b11398628
dgram: extract cluster lazy loading method to make it testable
...
PR-URL: https://github.com/nodejs/node/pull/38563
Refs: https://coverage.nodejs.org/coverage-26e318a321a872bc/lib/dgram.js.html#L202
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-05-09 09:16:22 +02:00
XadillaX
0b6f0a0ec2
buffer: remove TODOs in atob / btoa
...
Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
PR-URL: https://github.com/nodejs/node/pull/38548
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2021-05-09 09:11:38 +02:00
Rongjian Zhang
df8af88e36
buffer: remove unreachable code
...
PR-URL: https://github.com/nodejs/node/pull/38537
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-07 09:43:44 -07:00
Antoine du Hamel
9158d61deb
debugger: refactor to use internal modules
...
This avoids loading the entirety of `node:util` and `node:url` and their
dependencies while only a subset is actually used by this module.
PR-URL: https://github.com/nodejs/node/pull/38550
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
2021-05-07 11:43:26 +02:00
Stephen Belanger
f37c26b8a2
async_hooks: use new v8::Context PromiseHook API
...
PR-URL: https://github.com/nodejs/node/pull/36394
Reviewed-By: Bryan English <bryan@bryanenglish.com >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com >
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-06 15:17:49 -07:00
Rongjian Zhang
8231cc4d42
fs: use assert in fsCall argument checking
...
In the user perspective, it's not an arguemnt type error. Replace it
with an `assert` expression.
PR-URL: https://github.com/nodejs/node/pull/38519
Refs: https://coverage.nodejs.org/coverage-68e6673224365120/lib/internal/fs/promises.js.html#L268
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-06 10:37:14 -07:00
Rich Trott
7eb28e3176
debugger: disable only the lint rules required by current file state
...
PR-URL: https://github.com/nodejs/node/pull/38529
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-06 10:33:18 -07:00
Rich Trott
c42849fde4
debugger: avoid non-ASCII char in code file
...
Avoid non-ASCII char in lib code as a single non-ASCII char forces all
the chars to be stored inefficiently, bloating the binary size. This
also brings the file closer to compatibility with our lint rules.
PR-URL: https://github.com/nodejs/node/pull/38529
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-06 10:33:16 -07:00
Rich Trott
d5f0c83d80
debugger: wrap lines longer than 80 chars
...
Wrap lines more than 80 chararcters long in inspect_repl.js so we can
disable specific rules.
PR-URL: https://github.com/nodejs/node/pull/38529
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-06 10:33:14 -07:00
Antoine du Hamel
c6dc9319f3
lib: make IterableWeakMap safe to iterate
...
PR-URL: https://github.com/nodejs/node/pull/38523
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-06 10:18:50 -07:00
Antoine du Hamel
26e318a321
doc: use HEAD instead of master for links
...
PR-URL: https://github.com/nodejs/node/pull/38518
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
2021-05-05 10:45:30 +02:00
Voltrex
46d83b37ab
typings: add JSDoc typings for readline
...
Added JSDoc typings for the `readline` lib module.
PR-URL: https://github.com/nodejs/node/pull/38253
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-05-04 14:54:52 -07:00
Antoine du Hamel
2c0fd32db3
debugger: enable linter on internal/inspector/inspect_client
...
PR-URL: https://github.com/nodejs/node/pull/38417
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-05-03 13:57:15 +02:00
Antoine du Hamel
f331a1894f
debugger: refactor internal/inspector/_inspect to use more primordials
...
PR-URL: https://github.com/nodejs/node/pull/38406
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-05-03 13:55:51 +02:00
helloyou2012
d826f6bade
stream: the position of _read() is wrong
...
Fixes: https://github.com/nodejs/node/issues/33940
PR-URL: https://github.com/nodejs/node/pull/38292
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Robert Nagy <ronagy@icloud.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2021-05-03 11:55:52 +02:00
Antoine du Hamel
54dfdbcccf
readline: move utilities to internal modules
...
PR-URL: https://github.com/nodejs/node/pull/38466
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
2021-05-02 09:20:18 +02:00
XadillaX
9c7aa96703
zlib: fix brotli flush range
...
Fixes: https://github.com/nodejs/node/issues/38407
PR-URL: https://github.com/nodejs/node/pull/38408
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-05-01 16:41:37 -07:00
Yash Ladha
93f0b4d35b
perf_hooks: add toJSON to performance class
...
Added toJSON method to the InternalPerformance class as per the
convention followed in other performance classes and per the spec:
https://www.w3.org/TR/hr-time/#tojson-method
Fixes: https://github.com/nodejs/node/issues/37623
PR-URL: https://github.com/nodejs/node/pull/37771
Fixes: https://github.com/nodejs/node/issues/37623
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-04-30 13:28:27 -07:00
Ruben Bridgewater
942b76d9e5
util: fix infinite recursion during inspection
...
A specially crafted object with circular structures behind getters
could cause a infinite recursion. This is now fixed by detecting the
objects as already visited.
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de >
PR-URL: https://github.com/nodejs/node/pull/37079
Fixes: https://github.com/nodejs/node/issues/37054
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2021-04-30 12:46:48 -07:00
Rich Trott
c7ccab31e5
test: fix flaky test-crypto-timing-safe-dqual-benchmarks
...
Fixes: https://github.com/nodejs/node/issues/38226
PR-URL: https://github.com/nodejs/node/pull/38476
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Ruy Adorno <ruyadorno@github.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-04-30 11:19:37 -07:00
Antoine du Hamel
40ea8aa364
punycode: add pending deprecation
...
PR-URL: https://github.com/nodejs/node/pull/38444
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2021-04-30 10:59:28 -07:00
Antoine du Hamel
7919ced0c9
lib: harden lint checks for globals
...
PR-URL: https://github.com/nodejs/node/pull/38419
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
2021-04-28 13:13:23 -07:00
James M Snell
4af15df013
src: fix validation of negative offset to avoid abort
...
Fixes: https://github.com/nodejs/node/issues/24640
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/38421
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Nitzan Uziely <linkgoron@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
2021-04-28 11:04:42 -07:00
Rich Trott
bdb6c597a7
debugger: apply automatic lint fixes for inspect_repl.js
...
For issues that ESLint can fix automatically, fix them.
PR-URL: https://github.com/nodejs/node/pull/38411
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
2021-04-28 07:02:24 -07:00
Rich Trott
ea47bd2137
debugger: apply automatic lint fixes for _inspect.js
...
For issues that ESLint can fix automatically, fix them.
PR-URL: https://github.com/nodejs/node/pull/38411
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
2021-04-28 07:02:23 -07:00
Voltrex
32404359b6
typings: add JSDoc typings for fs
...
Added JSDoc typings for the `fs` lib module.
PR-URL: https://github.com/nodejs/node/pull/38306
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-04-27 15:06:12 -07:00
Rich Trott
751d215eb8
debugger: remove unused function argument
...
The `{colors: true}` removed here is ignored by the function it is being
sent to.
PR-URL: https://github.com/nodejs/node/pull/38400
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-04-27 08:59:38 -07:00
Rich Trott
01e0e3212d
debugger: align message with Node.js standard
...
Node.js uses (or will use) _Ctrl+C_ with no spaces. To unify the
messages from inspect with other messages from the REPL and elsewhere,
make that change in node-inspect too.
PR-URL: https://github.com/nodejs/node/pull/38400
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-04-27 08:59:34 -07:00
Rafael Gonzaga
302cc9e92c
debugger: add usage example for --port
...
PR-URL: https://github.com/nodejs/node/pull/38400
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-04-27 08:59:28 -07:00
James M Snell
ea0154814a
perf_hooks: fix PerformanceObserver 'gc' crash
...
Signed-off-by: James M Snell <jasnell@gmail.com >
Fixes: https://github.com/nodejs/node/issues/38412
PR-URL: https://github.com/nodejs/node/pull/38414
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com >
2021-04-27 07:31:15 -07:00
Nitzan Uziely
09c97b8138
crypto: fix generateKeyPair type checks
...
Change saltLength, divisorLength, primeLength and generator
checks in generateKeyPair to int32 from uint32, to align
with c++ code.
fixes: https://github.com/nodejs/node/issues/38358
PR-URL: https://github.com/nodejs/node/pull/38364
Fixes: https://github.com/nodejs/node/issues/38358
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-04-26 11:55:45 -07:00
Akhil Marsonya
00b6feec3e
lib: fix and improve os typings
...
1. marked optional params as such
2. assigned default values using jsdoc conventions.
PR-URL: https://github.com/nodejs/node/pull/38316
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Shingo Inoue <leko.noor@gmail.com >
2021-04-26 11:54:15 -07:00
Nitzan Uziely
f27b7cf95c
fs: aggregate errors in fsPromises to avoid error swallowing
...
Add AggregateError support to fsPromises, instead of
swallowing errors if fs.close throws.
PR-URL: https://github.com/nodejs/node/pull/38259
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-04-26 11:53:25 -07:00
Antoine du Hamel
27beb386a8
crypto: fix scrypt keylen validation
...
Fixes: https://github.com/nodejs/node/issues/38381
PR-URL: https://github.com/nodejs/node/pull/38385
Reviewed-By: Nitzan Uziely <linkgoron@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
2021-04-26 11:50:24 -07:00
James M Snell
bbe24e2171
lib: add support for JSTransferable as a mixin
...
Adds a new `makeTransferable()` utility that can construct a
`JSTransferable` object that does not directly extend the
`JSTransferable` JavaScript class.
Because JavaScript does not support multiple inheritance, it is
not possible (without help) to implement a class that extends
both `JSTransferable` and, for instance, `EventTarget` without
incurring a significant additional complexity and performance
cost by making all `EventTarget` instances extend `JSTransferable`...
That is, we *don't* want:
```js
class EventTarget extends JSTransferable { ... }
```
The `makeTransferable()` allows us to create objects that are
backed internally by `JSTransferable` without having to actually
extend it by leveraging the magic of `Reflect.construct()`.
```js
const {
JSTransferable,
kClone,
kDeserialize,
kConstructor,
makeTransferable,
} = require('internal/worker/js_transferable');
class E {
constructor(b) {
this.b = b;
}
}
class F extends E {
[kClone]() { /** ... **/ }
[kDeserialize]() { /** ... **/ }
static [kConstructor]() { return makeTransferable(F); }
}
const f = makeTransferable(F, 1);
f instanceof F; // true
f instanceof E; // true
f instanceof JSTransferable; // false
const mc = new MessageChannel();
mc.port1.onmessage = ({ data }) => {
data instanceof F; // true
data instanceof E; // true
data instanceof JSTransferable; // false
};
mc.port2.postMessage(f); // works!
```
The additional `internal/test/transfer.js` file is required for the
test because successfully deserializing transferable classes requires
that they be located in `lib/internal` for now.
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/38383
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Khaidi Chu <i@2333.moe >
2021-04-26 07:55:48 -07:00
legendecas
55745a1817
src: print arbitrary javascript exception value in node report
...
PR-URL: https://github.com/nodejs/node/pull/38009
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
2021-04-26 10:43:20 +08:00