Livia Medeiros
afd318db67
assert: support Float16Array in loose deep equality checks
...
PR-URL: https://github.com/nodejs/node/pull/57881
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2025-04-19 17:04:03 +00:00
Ruben Bridgewater
733e0fc2c4
assert,util: fix constructor lookup in deep equal comparison
...
The latest performance optimization did not take into account that
an object may have a property called constructor. This is addressed
in this PR by adding a new fast path and using fallbacks.
PR-URL: https://github.com/nodejs/node/pull/57876
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2025-04-19 11:10:40 +00:00
Shima Ryuhei
d8e9e05a27
util: fix formatting of objects with built-in Symbol.toPrimitive
...
Fixes: https://github.com/nodejs/node/issues/57818
PR-URL: https://github.com/nodejs/node/pull/57832
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2025-04-17 13:35:56 +00:00
Livia Medeiros
e61937b82c
util: add types.isFloat16Array()
...
PR-URL: https://github.com/nodejs/node/pull/57879
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2025-04-16 22:09:02 +00:00
Ruben Bridgewater
e739559e46
assert,util: improve deep object comparison performance
...
This improves the performance for almost all objects when comparing
them deeply.
PR-URL: https://github.com/nodejs/node/pull/57648
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: Bryan English <bryan@bryanenglish.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2025-04-05 08:53:31 +00:00
Ruben Bridgewater
657f818532
assert,util: improve unequal number comparison performance
...
This improves the performance to compare unequal numbers while doing
a deep equal comparison. Comparing for NaN is faster by checking
`variable !== variable` than by using `Number.isNaN()`.
PR-URL: https://github.com/nodejs/node/pull/57619
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2025-04-02 23:45:37 +00:00
Ruben Bridgewater
b9c9bf4945
assert,util: improve array comparison
...
Sparse arrays and arrays containing undefined are now compared faster
using assert.deepStrictEqual() or util.isDeepStrictEqual().
PR-URL: https://github.com/nodejs/node/pull/57619
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2025-04-02 23:45:36 +00:00
Ruben Bridgewater
4abad0763e
Revert "assert,util: revert recursive breaking change"
...
This reverts commit 575784b4cf .
PR-URL: https://github.com/nodejs/node/pull/57622
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
2025-04-02 23:37:44 +00:00
fengmk2
afe3909483
util: avoid run debug when enabled is false
...
it can improve performace 700x faster
PR-URL: https://github.com/nodejs/node/pull/57494
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Jordan Harband <ljharb@gmail.com >
2025-03-21 00:00:52 +00:00
Giovanni Bucci
6b42554342
util: expose diff function used by the assertion errors
...
fix: https://github.com/nodejs/node/issues/51740
PR-URL: https://github.com/nodejs/node/pull/57462
Fixes: https://github.com/nodejs/node/issues/51740
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2025-03-19 23:59:07 +00:00
Ruben Bridgewater
1fbe3351ba
assert: improve partialDeepStrictEqual performance
...
This implements fast paths for typed arrays, array buffers and sets
and maps that contain only objects as keys.
PR-URL: https://github.com/nodejs/node/pull/57509
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2025-03-19 23:50:56 +00:00
Gürgün Dayıoğlu
a20acd407d
lib: limit split function calls to prevent excessive array length
...
PR-URL: https://github.com/nodejs/node/pull/57501
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Jacob Smith <jacob@frende.me >
2025-03-18 15:52:50 +00:00
Ruben Bridgewater
ebbc5f7017
assert: implement partial error comparison
...
assert.partialDeepStrictEqual now also handled error properties as
expected. On top of that, the main implementation also handles
non-string `name` and `message` properties and the comparison is a
tad faster by removing duplicated comparison steps.
As a drive-by fix this also cleans up some code by abstracting code
and renaming variables for clarity.
PR-URL: https://github.com/nodejs/node/pull/57370
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
2025-03-12 18:26:17 +00:00
Ruben Bridgewater
64f56e4156
assert,util: improve performance
...
This improves the performance for array comparison by making the
sparse array detection simpler. On top of that it adds a fast path
for sets and maps that only contain objects as key.
PR-URL: https://github.com/nodejs/node/pull/57370
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
2025-03-12 18:26:16 +00:00
Ruben Bridgewater
f1b0812754
assert: improve partialDeepStrictEqual
...
This significantly improves the assert.partialDeepStrictEqual
implementation by reusing the already existing algorithm.
It is significantly faster and handles edge cases like symbols
identical as the deepStrictEqual algorithm. This is crucial to
remove the experimental status from the implementation.
PR-URL: https://github.com/nodejs/node/pull/57370
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
2025-03-12 18:26:13 +00:00
Jordan Harband
19fabc0e31
util: inspect: do not crash on an Error stack that contains a Symbol
...
See #56570
PR-URL: https://github.com/nodejs/node/pull/56573
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Jason Zhang <xzha4350@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2025-01-24 08:05:27 -08:00
Jordan Harband
e96072ad57
util: inspect: do not crash on an Error with a regex name
...
See #56570
PR-URL: https://github.com/nodejs/node/pull/56574
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com >
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2025-01-15 19:27:22 +00:00
Jordan Harband
2570f95ad1
util: do not crash on inspecting function with Symbol name
...
Refs: https://github.com/nodejs/node/issues/56570
PR-URL: https://github.com/nodejs/node/pull/56572
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2025-01-15 01:16:48 +01:00
Antoine du Hamel
80e3ef38ee
util: harden more built-in classes against prototype pollution
...
PR-URL: https://github.com/nodejs/node/pull/56225
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
2024-12-16 22:33:08 +00:00
Antoine du Hamel
4a91507b25
util: do not rely on mutable Object and Function' constructor prop
...
PR-URL: https://github.com/nodejs/node/pull/56188
Fixes: https://github.com/nodejs/node/issues/55924
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Jordan Harband <ljharb@gmail.com >
2024-12-11 11:11:38 +00:00
Gürgün Dayıoğlu
eef06f72eb
lib: remove redundant global regexps
...
PR-URL: https://github.com/nodejs/node/pull/56182
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: LiviaMedeiros <livia@cirno.name >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2024-12-10 12:18:18 +00:00
Pietro Marchini
24a8662359
lib: refactor code to improve readability
...
PR-URL: https://github.com/nodejs/node/pull/55995
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: LiviaMedeiros <livia@cirno.name >
2024-11-27 20:48:21 +00:00
Jordan Harband
e577618227
util: inspect: enumerable Symbols no longer have square brackets
...
Implements https://github.com/orgs/nodejs/discussions/41283#discussioncomment-11188239
PR-URL: https://github.com/nodejs/node/pull/55778
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
2024-11-17 06:57:37 +00:00
Antoine du Hamel
6af5c4e2b4
assert: differentiate cases where cause is undefined or missing
...
PR-URL: https://github.com/nodejs/node/pull/55738
Reviewed-By: LiviaMedeiros <livia@cirno.name >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2024-11-08 01:01:09 +00:00
Aviv Keller and Colin Ihrig
c185e11623
util: do not catch on circular @@toStringTag errors
...
PR-URL: https://github.com/nodejs/node/pull/55544
Fixes: https://github.com/nodejs/node/issues/55539
Reviewed-By: James M Snell <jasnell@gmail.com >
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com >
2024-11-06 10:57:15 +01:00
Pietro Marchini
025d8ada5f
lib: ensure FORCE_COLOR forces color output in non-TTY environments
...
PR-URL: https://github.com/nodejs/node/pull/55404
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: James M Snell <jasnell@gmail.com >
2024-10-23 06:51:50 +00:00
Gürgün Dayıoğlu
8ed50bcbe5
lib: remove startsWith/endsWith primordials for char checks
...
PR-URL: https://github.com/nodejs/node/pull/55407
Reviewed-By: Jacob Smith <jacob@frende.me >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Mattias Buelens <mattias@buelens.com >
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev >
2024-10-19 10:18:10 +00:00
Xuguang Mei
ac49b20c75
assert: fix deepEqual always return true on URL
...
PR-URL: https://github.com/nodejs/node/pull/50853
Fixes: https://github.com/nodejs/node/issues/50836
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2024-10-13 14:01:47 +00:00
Aviv Keller
71785889c8
lib: prefer logical assignment
...
PR-URL: https://github.com/nodejs/node/pull/55044
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: LiviaMedeiros <livia@cirno.name >
2024-10-09 06:42:16 +00:00
Antoine du Hamel
78f421de88
lib: fix module print timing when specifier includes "
...
PR-URL: https://github.com/nodejs/node/pull/55150
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
2024-10-08 16:59:37 +00:00
Aviv Keller
574f2dd517
lib: prefer optional chaining
...
PR-URL: https://github.com/nodejs/node/pull/55045
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Paolo Insogna <paolo@cowtech.it >
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com >
2024-09-24 19:48:15 +00:00
Aviv Keller
e42ad5e80c
util: update ansi regex
...
PR-URL: https://github.com/nodejs/node/pull/54865
Refs: https://github.com/chalk/ansi-regex/pull/58
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: James M Snell <jasnell@gmail.com >
2024-09-21 09:27:57 -07:00
Pietro Marchini
0c8c107aaa
test_runner: replace ansi clear with ansi reset
...
PR-URL: https://github.com/nodejs/node/pull/55013
Fixes: https://github.com/nodejs/node/issues/55009
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2024-09-21 13:42:14 +00:00
Vinicius Lourenço
a7271ab47d
lib: fix emit warning for debuglog.time when disabled
...
PR-URL: https://github.com/nodejs/node/pull/54275
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
2024-08-27 16:20:35 +00:00
Vinicius Lourenço
01cf9bccdf
lib: support dynamic trace events on debugWithTimer
...
PR-URL: https://github.com/nodejs/node/pull/53913
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
2024-07-28 17:20:38 +00:00
Joyee Cheung
10099bb3f7
src: refactor embedded entrypoint loading
...
This patch:
1. Refactor the routines used to compile and run an embedder
entrypoint. In JS land special handling for SEA is done
directly in main/embedding.js instead of clobbering the CJS
loader. Add warnings to remind users that currently the
require() in SEA bundled scripts only supports loading builtins.
2. Don't use the bundled SEA code cache when compiling CJS
loaded from disk, since in that case we are certainly not
compiling the code bundled into the SEA. Use a is_sea_main
flag in CompileFunctionForCJSLoader() (which replaces an unused
argument) to pass this into the C++ land - the code cache is
still read directly from C++ to avoid the overhead of
ArrayBuffer creation.
3. Move SEA loading code into
MaybeLoadSingleExecutableApplication() which calls
LoadEnvironment() with its own StartExecutionCallback().
This avoids more hidden switches in StartExecution() and
make them explicit. Also add some TODOs about how to support
ESM in embedded applications.
4. Add more comments
PR-URL: https://github.com/nodejs/node/pull/53573
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2024-07-05 19:58:35 +00:00
Cristian Barlutiu
764b13d75c
assert,util: change WeakMap and WeakSet comparison handling
...
PR-URL: https://github.com/nodejs/node/pull/53495
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
2024-06-28 07:28:55 +00:00
Zhenwei Jin
4a72b2f927
util: support --no- for argument with boolean type for parseArgs
...
PR-URL: https://github.com/nodejs/node/pull/53107
Refs: https://github.com/nodejs/node/issues/53095
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2024-06-19 15:36:18 +00:00
Daniel Lemire and Chris Harvey
ee5c6b6604
assert,util: correct comparison when both contain same reference
...
Co-authored-by: Chris Harvey <1362083+chharvey@users.noreply.github.com >
PR-URL: https://github.com/nodejs/node/pull/53431
Refs: https://github.com/nodejs/node/issues/53423
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2024-06-17 13:30:24 +00:00
Vinicius Lourenço
f88386561c
module: print amount of load time of a cjs module
...
PR-URL: https://github.com/nodejs/node/pull/52213
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2024-05-30 16:58:59 +00:00
Chengzhong Wu
c0c598d753
lib: allow CJS source map cache to be reclaimed
...
Unifies the CJS and ESM source map cache map with SourceMapCacheMap
and allows the CJS cache entries to be queried more efficiently with
a source url without iteration on an IterableWeakMap.
Add a test to verify that the CJS source map cache entry can be
reclaimed.
PR-URL: https://github.com/nodejs/node/pull/51711
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2024-05-28 22:56:56 +00:00
Zhenwei Jin
c8a4f70265
assert: add deep equal check for more Error type
...
PR-URL: https://github.com/nodejs/node/pull/51805
Fixes: https://github.com/nodejs/node/issues/51793
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2024-05-12 19:46:13 +00:00
Chenyu Yang
dde2965765
util: fix %s format behavior with Symbol.toPrimitive
...
This commit ensures `console.log("%s", obj)` correctly invokes
`obj[Symbol.toPrimitive]` for string conversion, fixing unexpected
object display issue.
PR-URL: https://github.com/nodejs/node/pull/50992
Fixes: https://github.com/nodejs/node/issues/50909
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com >
2024-05-12 12:37:31 +02:00
Antoine du Hamel
231548b5cf
lib: enforce ASCII order in error code imports
...
PR-URL: https://github.com/nodejs/node/pull/52625
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2024-04-23 17:05:38 +00:00
Antoine du Hamel
a596af0819
tools: add lint rule to keep primordials in ASCII order
...
PR-URL: https://github.com/nodejs/node/pull/52592
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io >
Reviewed-By: Jacob Smith <jacob@frende.me >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
2024-04-21 16:53:08 +00:00
Joyee Cheung
5f7fad2605
module: support require()ing synchronous ESM graphs
...
This patch adds `require()` support for synchronous ESM graphs under
the flag `--experimental-require-module`
This is based on the the following design aspect of ESM:
- The resolution can be synchronous (up to the host)
- The evaluation of a synchronous graph (without top-level await) is
also synchronous, and, by the time the module graph is instantiated
(before evaluation starts), this is is already known.
If `--experimental-require-module` is enabled, and the ECMAScript
module being loaded by `require()` meets the following requirements:
- Explicitly marked as an ES module with a `"type": "module"` field in
the closest package.json or a `.mjs` extension.
- Fully synchronous (contains no top-level `await`).
`require()` will load the requested module as an ES Module, and return
the module name space object. In this case it is similar to dynamic
`import()` but is run synchronously and returns the name space object
directly.
```mjs
// point.mjs
export function distance(a, b) {
return (b.x - a.x) ** 2 + (b.y - a.y) ** 2;
}
class Point {
constructor(x, y) { this.x = x; this.y = y; }
}
export default Point;
```
```cjs
const required = require('./point.mjs');
// [Module: null prototype] {
// default: [class Point],
// distance: [Function: distance]
// }
console.log(required);
(async () => {
const imported = await import('./point.mjs');
console.log(imported === required); // true
})();
```
If the module being `require()`'d contains top-level `await`, or the
module graph it `import`s contains top-level `await`,
[`ERR_REQUIRE_ASYNC_MODULE`][] will be thrown. In this case, users
should load the asynchronous module using `import()`.
If `--experimental-print-required-tla` is enabled, instead of throwing
`ERR_REQUIRE_ASYNC_MODULE` before evaluation, Node.js will evaluate the
module, try to locate the top-level awaits, and print their location to
help users fix them.
PR-URL: https://github.com/nodejs/node/pull/51977
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Guy Bedford <guybedford@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
2024-03-18 18:10:06 +08:00
Joyee Cheung
bec9b5fccc
src: use dedicated routine to compile function for builtin CJS loader
...
So that we can use it to handle code caching in a central place.
Drive-by: use per-isolate persistent strings for the parameters
and mark GetHostDefinedOptions() since it's only used in one
compilation unit
PR-URL: https://github.com/nodejs/node/pull/52016
Refs: https://github.com/nodejs/node/issues/47472
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
2024-03-11 19:18:53 +00:00
Filip Skokan
0afe731d35
assert,crypto: make KeyObject and CryptoKey testable for equality
...
PR-URL: https://github.com/nodejs/node/pull/50897
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2023-12-17 12:55:38 +00:00
Liu Jia
1045f287b8
util: improve performance of function areSimilarFloatArrays
...
Improve performance of areSimilarFloatArrays by using primordial.
Refs: https://github.com/nodejs/node/pull/50621
PR-URL: https://github.com/nodejs/node/pull/51040
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
Reviewed-By: James M Snell <jasnell@gmail.com >
2023-12-10 08:41:25 +00:00
Vinicius Lourenço
952cf0d17a
lib: reduce overhead of validateObject
...
PR-URL: https://github.com/nodejs/node/pull/49928
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2023-10-02 12:56:39 +00:00