Commit Graph

212 Commits

Author SHA1 Message Date
Antoine du Hamel
fe514bf960
lib: enforce use of trailing commas for functions
PR-URL: https://github.com/nodejs/node/pull/46629
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
2023-02-14 18:45:16 +01:00
Moshe Atlow
11e7858553
assert: remove assert.snapshot
PR-URL: https://github.com/nodejs/node/pull/46112
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2023-01-07 20:24:24 +00:00
Moshe Atlow
8f9d1ab5ec
assert: add assert.Snapshot
PR-URL: https://github.com/nodejs/node/pull/44095
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2022-08-11 13:07:52 +00:00
Joyee Cheung
472edc775d
src: disambiguate terms used to refer to builtins and addons
The term "native module" dates back to some of the oldest code
in the code base. Within the context of Node.js core it usually
refers to modules that are native to Node.js (e.g. fs, http),
but it can cause confusion for people who don't work on this
part of the code base, as "native module" can also refer to
native addons - which is even the case in some of the API
docs and error messages.

This patch tries to make the usage of these terms more consistent.
Now within the context of Node.js core:

- JavaScript scripts that are built-in to Node.js are now referred
  to as "built-in(s)". If they are available as modules,
  they can also be referred to as "built-in module(s)".
- Dynamically-linked shared objects that are loaded into
  the Node.js processes are referred to as "addons".

We will try to avoid using the term "native modules" because it could
be ambiguous.

Changes in this patch:

File names:
- node_native_module.h -> node_builtins.h,
- node_native_module.cc -> node_builtins.cc

C++ binding names:
- `native_module` -> `builtins`

`node::Environment`:
- `native_modules_without_cache` -> `builtins_without_cache`
- `native_modules_with_cache` -> `builtins_with_cache`
- `native_modules_in_snapshot` -> `builtins_in_cache`
- `native_module_require` -> `builtin_module_require`

`node::EnvSerializeInfo`:
- `native_modules` -> `builtins

`node::native_module::NativeModuleLoader`:
- `native_module` namespace -> `builtins` namespace
- `NativeModuleLoader` -> `BuiltinLoader`
- `NativeModuleRecordMap` -> `BuiltinSourceMap`
- `NativeModuleCacheMap` -> `BuiltinCodeCacheMap`
- `ModuleIds` -> `BuiltinIds`
- `ModuleCategories` -> `BuiltinCategories`
- `LoadBuiltinModuleSource` -> `LoadBuiltinSource`

`loader.js`:
- `NativeModule` -> `BuiltinModule` (the `NativeModule` name used in
  `process.moduleLoadList` is kept for compatibility)

And other clarifications in the documentation and comments.

PR-URL: https://github.com/nodejs/node/pull/44135
Fixes: https://github.com/nodejs/node/issues/44036
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2022-08-09 01:36:49 +08:00
Antoine du Hamel
a055337a02
lib: refactor to avoid unsafe regex primordials
PR-URL: https://github.com/nodejs/node/pull/43475
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2022-06-27 17:16:06 +02:00
Antoine du Hamel
1e761654d3
doc: consolidate use of multiple-byte units
Refs: https://en.wikipedia.org/wiki/Byte#Multiple-byte_units

PR-URL: https://github.com/nodejs/node/pull/42587
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
2022-04-20 00:46:37 +02:00
akhil marsonya
6f8c983f90
lib: refactor to use primordials in lib/assert.js
PR-URL: https://github.com/nodejs/node/pull/41702
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
2022-03-15 00:17:12 +00:00
Darshan Sen
ced5fc3930
assert: prefer reference comparison over string comparison
Pointer comparison takes constant time and string comparison takes
linear time unless there is some string interning going on, so this
might be a little bit faster.

Signed-off-by: Darshan Sen <darshan.sen@postman.com>

PR-URL: https://github.com/nodejs/node/pull/41015
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
2021-12-14 14:58:47 +00:00
Rich Trott
c241ef1a12 lib: use consistent types in JSDoc @returns
PR-URL: https://github.com/nodejs/node/pull/41089
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2021-12-07 06:23:30 -08:00
Ruben Bridgewater
414bc7bec1
assert: use stricter stack frame detection in .ifError()
This makes sure arbitrary stack traces are not handled as stack
frames.

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

PR-URL: https://github.com/nodejs/node/pull/41006
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-12-06 17:38:26 +00:00
Michaël Zasso
189d584244
deps: update Acorn to v8.4.1
We can remove the Acorn plugins as their features are now supported
by default.

PR-URL: https://github.com/nodejs/node/pull/39166
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2021-06-29 17:20:45 +02:00
Voltrex
82d59882b1
typings: add JSDoc typings for assert
PR-URL: https://github.com/nodejs/node/pull/38188
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2021-04-15 16:43:21 +02:00
Antoine du Hamel
09c9e5dea4 lib: avoid mutating Error.stackTraceLimit when it is not writable
PR-URL: https://github.com/nodejs/node/pull/38215
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2021-04-15 00:17:16 +02:00
Antoine du Hamel
f34d8de65a lib: remove use of array destructuring
PR-URL: https://github.com/nodejs/node/pull/36818
Reviewed-By: Rich Trott <rtrott@gmail.com>
2021-03-03 19:53:24 +01:00
Rich Trott
b461a1b125 doc,lib: prepare for stricter multi-line array linting
We're about to turn on a requirement for dangling commas.

PR-URL: https://github.com/nodejs/node/pull/37088
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2021-02-19 09:55:35 -08:00
ZiJian Liu
064a7070c7 lib: refactor to use validateFunction
add validateFunction and refactor to use validateFunction

PR-URL: https://github.com/nodejs/node/pull/37045
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-01-27 20:46:54 +02:00
Antoine du Hamel
709b339878 assert: refactor to use more primordials
PR-URL: https://github.com/nodejs/node/pull/36234
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-11-27 06:17:41 -08:00
Michaël Zasso
0ddd69e2ed assert,repl: enable ecmaVersion 2021 in acorn parser
This adds support for the new logical assignment operators.

PR-URL: https://github.com/nodejs/node/pull/35827
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2020-10-30 14:52:28 +00:00
Antoine du Hamel
1da672994a lib: use primordials when calling methods of Error
This is to unsure that code using those methods won't crash if the
methods are deleted in userland.

PR-URL: https://github.com/nodejs/node/pull/35837
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
2020-10-30 11:08:20 +00:00
Michaël Zasso
16b2bc01eb deps: update acorn to v8.0.4
This adds support for nullish coalescing, optional chaining and
numeric separators.
The acorn-numeric-separator plugin can be removed.

PR-URL: https://github.com/nodejs/node/pull/35791
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
2020-10-27 03:26:56 +00:00
Michaël Zasso
21782277c2
src: use node:moduleName as builtin module filename
This change allows for easier recognition of builtin modules in stack
traces.

Refs: https://github.com/nodejs/node/issues/11893

PR-URL: https://github.com/nodejs/node/pull/35498
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2020-10-07 17:35:14 +02:00
Sebastien Ahkrin
b79829c5f5
lib: replace String global with primordials
PR-URL: https://github.com/nodejs/node/pull/35397
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Pranshu Srivastava <rexagod@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
2020-10-04 09:40:56 +02:00
ConorDavenport
50d28d4b3a assert: port common.mustCall() to assert
Fixes: https://github.com/nodejs/node/issues/31392

PR-URL: https://github.com/nodejs/node/pull/31982
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
2020-04-23 10:11:47 -07:00
Michaël Zasso
9b6e797379
Revert "assert: fix line number calculation after V8 upgrade"
This reverts commit 5981fb7faa.

PR-URL: https://github.com/nodejs/node/pull/32116
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2020-03-18 16:35:41 -07:00
Sebastien Ahkrin
9085c03806 lib: replace Map global by the primordials
PR-URL: https://github.com/nodejs/node/pull/31155
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2020-01-04 14:56:52 -08:00
Sebastien Ahkrin
c9b93e2344 lib: replace use of Error with primordials
PR-URL: https://github.com/nodejs/node/pull/31163
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2020-01-04 14:50:18 -08:00
Ruben Bridgewater
e33f773d4f
assert: implement assert.match() and assert.doesNotMatch()
This adds a new functionality to the assertion module: a dedicated
check for regular expressions. So far it's possible to use
`assert.ok(regexp.test(string))`. This is not ideal though when it
comes to the error message, since it's not possible to know how
either of the input values look like. It's just known that the
assertion failed.
This allows to pass through the regular expression and the input
string. The string is then matched against the regular expression
and reports a expressive error message in case of a failure.

PR-URL: https://github.com/nodejs/node/pull/30929
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2020-01-01 18:44:31 +01:00
Soar
145116b3a1 assert: use for...of
Refs: #30960

PR-URL: https://github.com/nodejs/node/pull/30983
Refs: https://github.com/nodejs/node/pull/30960
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2019-12-17 17:33:12 -08:00
Ruben Bridgewater
5360dd151d
assert: handle (deep) equal(NaN, NaN) as being identical
This aligns the `equal` and `deepEqual()` implementations with the
strict versions by accepting `NaN` as being identical in case both
sides are NaN.

Refs: https://github.com/nodejs/node/issues/30350#issuecomment-552191641

PR-URL: https://github.com/nodejs/node/pull/30766
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-12-07 00:43:51 +01:00
Michaël Zasso
0646eda4fc
lib: flatten access to primordials
Store all primordials as properties of the primordials object.
Static functions are prefixed by the constructor's name and prototype
methods are prefixed by the constructor's name followed by "Prototype".
For example: primordials.Object.keys becomes primordials.ObjectKeys.

PR-URL: https://github.com/nodejs/node/pull/30610
Refs: https://github.com/nodejs/node/issues/29766
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-11-25 10:28:15 +01:00
PerfectPan
cb34358dd9 assert: replace var with let in lib/assert.js
Refs: https://github.com/nodejs/code-and-learn/issues/97

PR-URL: https://github.com/nodejs/node/pull/30261
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2019-11-09 14:11:31 +08:00
Michaël Zasso
5981fb7faa
assert: fix line number calculation after V8 upgrade
PR-URL: https://github.com/nodejs/node/pull/29694
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
2019-10-07 03:20:07 -04:00
ZYSzys
739f113ba6 lib: introduce no-mixed-operators eslint rule to lib
PR-URL: https://github.com/nodejs/node/pull/29834
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-10-05 13:59:32 -07:00
Gus Caplan
70c2444155 lib: stop using prepareStackTrace
PR-URL: https://github.com/nodejs/node/pull/29777
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2019-10-02 16:17:01 -07:00
Ruben Bridgewater
48d1ea5e7f
assert: special handle identical error names in instance checks
This makes sure that using `assert.throws()` or `assert.rejects()`
in combination with Error classes log appropriate error messages
in case the expected and received constructor name are identical
but not part of the same prototype chain.

PR-URL: https://github.com/nodejs/node/pull/28263
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-10-01 22:56:01 +02:00
Ruben Bridgewater
97c52ca5dc
assert: add more information to AssertionErrors
This adds information about the actual thrown error to the
AssertionError's message property.

It also improves the logged error instances error name by using the
constructors name, if available.

PR-URL: https://github.com/nodejs/node/pull/28263
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-10-01 22:56:01 +02:00
Ruben Bridgewater
5700cd17dd
assert: do not repeat .throws() code
This refactors some code for less duplication.

PR-URL: https://github.com/nodejs/node/pull/28263
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-10-01 22:55:40 +02:00
Ruben Bridgewater
d47b6786c9
assert: wrap validation function errors
This makes sure that validation function used by `assert.throws` and
`assert.rejects` always throw validatin errors instead of rethrowing
the received error.

That should improve the debugging experience for developers since
they have a better context where the error is coming from and they
also get to know what triggered it.

PR-URL: https://github.com/nodejs/node/pull/28263
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-10-01 22:55:11 +02:00
Ruben Bridgewater
0b3242c3ce
assert: fix generatedMessage property
This makes sure the `generatedMessage` property is always set as
expected. This was not the case some `assert.throws` and
`assert.rejects` calls.

PR-URL: https://github.com/nodejs/node/pull/28263
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-10-01 22:55:11 +02:00
Ruben Bridgewater
ace3f16917
assert: improve class instance errors
This improves `assert.throws()` and `assert.rejects()` in case error
classes are used as validation for the expected error.

In case of a failure it will now throw an `AssertionError` instead
of the received error if the check fails. That error has the received
error as actual property and the expected property is set to the
expected error class.

The error message should help users to identify the problem faster
than before by providing extra context what went wrong.

PR-URL: https://github.com/nodejs/node/pull/28263
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-10-01 22:55:07 +02:00
Michaël Zasso
60a207f5f2
deps: update acorn to 6.2.0
Includes support for bigint syntax so we can remove the acorn-bigint
plugin.

PR-URL: https://github.com/nodejs/node/pull/28649
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
2019-07-15 00:04:50 +02:00
Ruben Bridgewater
1a0fd60277 assert: add partial support for evaluated code in simple assert
This makes sure using `assert.ok()` in `new Function()` statements
visualizes the actual call site in the error message.

PR-URL: https://github.com/nodejs/node/pull/27781
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-06-12 20:02:50 -07:00
Ruben Bridgewater
4a3af65a88 assert: improve regular expression validation
This makes sure `assert.throws()` and `assert.rejects()` result in
an easy to understand error message instead of rethrowing the actual
error. This should significantly improve the debugging experience in
case people use an regular expression to validate their errors.

This also adds support for primitive errors that would have caused
runtime errors using the mentioned functions. The input is now
stringified before it's passed to the RegExp to circumvent that.

As drive-by change this also adds some further comments and renames
a variable for clarity.

PR-URL: https://github.com/nodejs/node/pull/27781
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-06-12 20:02:48 -07:00
Ruben Bridgewater
d099f2f124 assert: use less read operations
This reduces the total amount of reads when using `assert.ok()` with
a falsy value. That increases the read performance significantly.

Also remove a comment that can not be addressed.

PR-URL: https://github.com/nodejs/node/pull/27525
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-05-05 14:44:21 -07:00
Ruben Bridgewater
3593af00f8 assert: fix assert.fail() stack
This makes sure the error message visible in the error stack created
when using `assert.fail()` without any arguments or the message set
to `undefined` or `null` as only argument.
That was masked before due to other changes.

PR-URL: https://github.com/nodejs/node/pull/27525
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-05-05 14:44:17 -07:00
Ruben Bridgewater
04b7c007d6
assert: use new language features
This adds new language features to acorn. Otherwise BigInt and other
input would not be parsed correct and would not result in nice error
messages when using simple assert.

PR-URL: https://github.com/nodejs/node/pull/27400
Refs: https://github.com/nodejs/node/issues/27391
Refs: https://github.com/nodejs/node/issues/25835
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-04-30 16:22:56 +02:00
Michaël Zasso
908292cf1f lib: enforce the use of Object from primordials
PR-URL: https://github.com/nodejs/node/pull/27146
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
2019-04-12 05:38:45 +02:00
szabolcsit
2a51ae424a
test: cover thenables when we check for promises
Added tests that cover the issue when assert.rejects() and
assert.doesNotReject() should not accept Thenables without
a `catch` method or any Thenable function with `catch` and
`then` methods attached.

PR-URL: https://github.com/nodejs/node/pull/24219
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-04-10 23:37:41 +02:00
Ruben Bridgewater
75463a9004
assert: fix rejects stack trace and operator
This makes sure the stack trace is not removed due to a wrong stack
start function being used. It also fixes the wrong operator caused
by the same reason. This only applies in case an validation object
was used to validate the rejection passed to `assert.reject()` as
first argument.

PR-URL: https://github.com/nodejs/node/pull/27047
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-04-07 20:25:32 +02:00
Ruben Bridgewater
3fe1e80896
lib: validate Error.captureStackTrace() calls
This adds a custom eslint rule to verify that
`Error.captureStackTrace()` is only called if necessary. In most
cases the helper function should be used instead.

PR-URL: https://github.com/nodejs/node/pull/26738
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2019-03-23 02:55:55 +01:00