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

190 Commits

Author SHA1 Message Date
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
Daiki Ihara
de3b164f4f
assert: reduce internal usage of public require of util
PR-URL: https://github.com/nodejs/node/pull/26762
Refs: https://github.com/nodejs/node/issues/26546
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-03-22 00:42:55 +01:00
Ruben Bridgewater
5a3623af74
assert: validate required arguments
This validates most `assert` functions to verify that the required
arguments are indeed passed to the function.

PR-URL: https://github.com/nodejs/node/pull/26641
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2019-03-21 22:58:12 +01:00
Weijia Wang
c8d3a73c8b lib: use Array#includes instead of Array#indexOf
PR-URL: https://github.com/nodejs/node/pull/26732
Refs: https://github.com/nodejs/node/issues/26568
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2019-03-21 21:38:02 +08:00
Ujjwal Sharma
5f8ccecaa2
module: revert module._compile to original state if module is patched
PR-URL: https://github.com/nodejs/node/pull/21573
Fixes: https://github.com/nodejs/node/issues/17396
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-02-19 20:58:37 +05:30
Michaël Zasso
582c12260e
deps: update acorn to 6.0.7
acorn and acorn-walk are now published as two different packages. Put
them both in subdirectories of `deps/acorn`.
Adapt the REPL's recoverable error detection to use the new API for
extending acorn parsers.

PR-URL: https://github.com/nodejs/node/pull/25844
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-02-08 15:34:10 +01:00
Rich Trott
64745c3ade assert: refactor internal assert.js
Move lib/internal/assert.js to lib/internal/assert/assertion_error.js.
This is in preparation for making lib/internal/assert.js a tiny module
for use in Node.js built-ins so that we can use `assert()` without
having to load the entire ~1200 line `assert` module.

PR-URL: https://github.com/nodejs/node/pull/25956
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
2019-02-08 00:01:07 -08:00
cjihrig
39a027224e
assert: remove unused catch bindings
PR-URL: https://github.com/nodejs/node/pull/24079
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
2018-11-06 10:58:42 -05:00
Rich Trott
4d58c08865 assert: remove internal errorCache property
The internal assert module exposed an errorCache property solely for
testing. It is no longer necessary. Remove it.

PR-URL: https://github.com/nodejs/node/pull/23304
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2018-10-09 06:39:46 -07:00
Ruben Bridgewater
eee5adfab5
assert: add default operator to assert.fail()
This makes sure `assert.fail()` contains an operator instead of being
undefined.

On top of that it also fixes the `err.generatedMessage` property.
Before, it was not always set correct.

PR-URL: https://github.com/nodejs/node/pull/22694
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-09-17 15:59:12 +02:00
Ruben Bridgewater
b5430d782d
assert: align argument names
This makes sure the documented argument names and the ones thrown
in errors is aligned with the actual argument name.

PR-URL: https://github.com/nodejs/node/pull/22760
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
2018-09-11 23:45:07 +02:00
Ruben Bridgewater
43ee4d692a
assert: improve simple assert
1) If simple assert is called in the very first line of a file and
it causes an error, it used to report the wrong code. The reason
is that the column that is reported is faulty. This is fixed by
subtracting the offset from now on in such cases.

2) The actual code read is now limited to the part that is actually
required to visualize the call site. All other code in e.g. minified
files will not cause a significant overhead anymore.

3) The number of allocations is now significantly lower than it used
to be. The buffer is reused until the correct line in the code is
found. In general the algorithm tries to safe operations where
possible.

4) The indentation is now corrected depending on where the statement
actually beginns.

5) It is now possible to handle `.call()` and `.apply()` properly.

6) The user defined function name will now always be used instead of
only choosing either `assert.ok()` or `assert()`.

PR-URL: https://github.com/nodejs/node/pull/21626
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-07-16 11:30:55 +02:00
Tim Seckinger
a5d86f8c4e assert: handle undefined filename in getErrMessage
When generating an assertion error message,
`filename` might be undefined,
e.g. if `assert` is called in `eval`.

Handle this case gracefully instead of failing with
`Cannot read property 'endsWith' of undefined`.

Fixes: https://github.com/nodejs/node/issues/20847

PR-URL: https://github.com/nodejs/node/pull/20848
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-05-23 08:40:10 -07:00
Ruben Bridgewater
9c2e67ba97
assert: fix wrong message indentation
If code is read from a file and that code is indented, it would be
misaligned. This makes sure it has a natural indentation that is
relative to the starting point of the assertion.

PR-URL: https://github.com/nodejs/node/pull/20791
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-05-21 17:56:56 +02:00
Ruben Bridgewater
2c42999f7e
assert: fix EOL issue in messages on Windows
PR-URL: https://github.com/nodejs/node/pull/20754
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2018-05-18 16:09:00 +02:00
Ruben Bridgewater
17d95ea1f0
assert,util: lazy load comparison functions
PR-URL: https://github.com/nodejs/node/pull/20567
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2018-05-18 15:27:29 +02:00
Ruben Bridgewater
d478e52fe0
os: lazy loaded
PR-URL: https://github.com/nodejs/node/pull/20567
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2018-05-18 15:25:41 +02:00
Ruben Bridgewater
21c3a402d4
assert: validate input stricter
This makes sure invalid `error` objects are not ignored when using
`assert.throws` and `assert.rejects`.

PR-URL: https://github.com/nodejs/node/pull/20481
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-05-10 15:27:32 +02:00
Ruben Bridgewater
560925fe22
assert: make sure throws is able to handle primitives
This fixes some possible issues with `assert.throws` and
`assert.rejects` in combination with an validation object. It will
now properly handle primitive values being thrown as error.

It also makes sure the `generatedMessage` property is properly set
if `assert.throws` or `assert.rejects` is used in combination with
an validation object and improves the error performance in such cases
by only creating the error once.

In addition it will fix detecting regular expressions from a different
context such as n-api that are passed through as validator for
`assert.throws` or `assert.rejects`. Until now those were not tested.

PR-URL: https://github.com/nodejs/node/pull/20482
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-05-10 14:14:23 +02:00
Ruben Bridgewater
b304096a14
assert: move AssertionError into own file
This moves the `assert` parts from `internal/errors` into an own
file. `internal/errors` got bigger and bigger and it was difficult
to keep a good overview of what was going on. While doing so it
also removes the `internalAssert` function and just lazy loads
`assert`.

PR-URL: https://github.com/nodejs/node/pull/20486
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2018-05-10 13:39:19 +02:00
Ruben Bridgewater
cf7be86cd9
assert: accept regular expressions to validate
This makes sure regular expressions on validation objects validate
against strings when used with `assert.throws` and `assert.rejects`.

PR-URL: https://github.com/nodejs/node/pull/20485
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-05-10 13:17:22 +02:00
Ruben Bridgewater
7007eee6a2
assert: validate the block return type
This makes sure the returned value when calling `block` is actually
of type promise in case `assert.rejects` or `assert.doesNotReject`
is called.

PR-URL: https://github.com/nodejs/node/pull/19886
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
2018-04-20 00:21:33 +02:00
Ruben Bridgewater
2c3146d06d
assert: add direct promises support in rejects
This adds direct promise support to `assert.rejects` and
`assert.doesNotReject`. It will now accept both, functions and ES2015
promises as input.

Besides this the documentation was updated to reflect the latest
changes.

It also refactors the tests to a non blocking way to improve the
execution performance and improves the coverage.

PR-URL: https://github.com/nodejs/node/pull/19885
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2018-04-16 03:21:45 +02:00