Joyee Cheung
9dc1f509f1
errors: move error creation helpers to errors.js
...
This commit moves error creation helpers scattered around
under lib/ into lib/internal/errors.js in the hope of being clearer
about the differences of errors that we throw into the user land.
- Move util._errnoException and util._exceptionWithHostPort
into internal/errors.js and simplify their logic so it's
clearer what the properties these helpers create.
- Move the errnoException helper in dns.js to internal/errors.js
into internal/errors.js and rename it to dnsException. Simplify
it's logic so it no longer calls errnoException and skips
the unnecessary argument checks.
Backport-PR-URL: https://github.com/nodejs/node/pull/19191
PR-URL: https://github.com/nodejs/node/pull/18546
Reviewed-By: James M Snell <jasnell@gmail.com >
2018-08-16 11:38:48 +10:00
Joyee Cheung
66520afdb8
util: skip type checks in internal getSystemErrorName
...
Backport-PR-URL: https://github.com/nodejs/node/pull/19191
PR-URL: https://github.com/nodejs/node/pull/18546
Reviewed-By: James M Snell <jasnell@gmail.com >
2018-08-16 11:38:47 +10:00
Joyee Cheung
58b5a610d8
util: implement util.getSystemErrorName()
...
Reimplement uv.errname() as internal/util.getSystemErrorName() to
avoid the memory leaks caused by unknown error codes
and avoid calling into C++ for the error names. Also
expose it as a public API for external use.
Backport-PR-URL: https://github.com/nodejs/node/pull/19191
PR-URL: https://github.com/nodejs/node/pull/18186
Refs: http://docs.libuv.org/en/v1.x/errors.html#c.uv_err_name
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2018-08-16 11:38:47 +10:00
buji
e0e0ef7bab
util: escaping object keys in util.inspect()
...
PR-URL: https://github.com/nodejs/node/pull/16986
Fixes: https://github.com/nodejs/node/issues/16979
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com >
2018-03-29 23:28:15 -04:00
Ben Noordhuis
bb5cafef55
repl: fix coloring of process.versions
...
Remove the custom formatter that was added in commit 4fb27d4 ("intl: Add
more versions from ICU"). It's not necessary anymore (and may not have
been necessary at all) and prevents proper coloring in the REPL.
PR-URL: https://github.com/nodejs/node/pull/17861
Fixes: https://github.com/nodejs/node/issues/17086
Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com >
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com >
Reviewed-By: Khaidi Chu <i@2333.moe >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2018-01-24 02:51:03 +00:00
Gus Caplan
3236944761
util: fix negative 0 check in inspect
...
PR-URL: https://github.com/nodejs/node/pull/17507
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Khaidi Chu <i@2333.moe >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2017-12-20 02:00:54 +00:00
Timothy Gu
67aed7972d
lib: faster type checks for some types
...
Backport-PR-URL: https://github.com/nodejs/node/pull/16073
PR-URL: https://github.com/nodejs/node/pull/15663
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2017-10-23 09:10:04 -05:00
Brian White
58c68c2fcb
util: use faster -0 check
...
PR-URL: https://github.com/nodejs/node/pull/15726
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com >
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com >
2017-10-11 02:05:41 -04:00
Ruben Bridgewater
fc1448f357
util: improve format performance
...
PR-URL: https://github.com/nodejs/node/pull/15422
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Refael Ackermann <refack@gmail.com >
2017-09-21 07:52:54 -07:00
Ruben Bridgewater
5b47f846b0
util: fix out of bounds indices in util.inspect
...
This fixes a issue brought up in #15288 .
PR-URL: https://github.com/nodejs/node/pull/14881
Refs: https://github.com/nodejs/node/issues/15288
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2017-09-21 07:52:53 -07:00
Ruben Bridgewater
9e8b1b3ec6
util: refactor inspect for performance and more
...
The main optimizations are
- Removed visibleKeys
- Removed proxy cache
- Removed Object.assign
- No key concatenating anymore
- No key recalculating anymore
- Improved indentation logic
- Improved string escape logic
- Added many fast paths
- Optimized code branches a lot
- Optimized (boxed) primitive handling
- Inline code if possible
- Only check extra keys if necessary
- Guard against unnecessary more expensive calls
This also fixes a bug with special array number keys as e.g. "00".
Besides that there were lots of smaller optimizations, the
code got a bit cleaned up and a few more tests got in.
PR-URL: https://github.com/nodejs/node/pull/14881
Fixes: https://github.com/nodejs/node/issues/15288
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2017-09-21 07:52:53 -07:00
Ruben Bridgewater
d5a376ab7a
lib: remove circular reference
...
PR-URL: https://github.com/nodejs/node/pull/14885
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2017-09-12 03:18:33 +02:00
Anatoli Papirovski
2aec977fa2
util: remove duplicate code in format
...
util.format contains an idential if statement within each branch
of switch. Move it before the switch statement for cleaner code
and better performance.
PR-URL: https://github.com/nodejs/node/pull/15098
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2017-09-12 03:18:21 +02:00
Ruben Bridgewater
de10c0f515
util: fix inspect array w. negative maxArrayLength
...
PR-URL: https://github.com/nodejs/node/pull/14880
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2017-09-12 03:17:04 +02:00
Anna Henningsen
c3c6cb1c13
util: use proper circular reference checking
...
Circular references are conceptually nothing that should be checked
for objects (or Sets or Maps) only, but applies to recursive structures
in general, so move the `seen` checks into a position where it is part
of the recursion itself.
Fixes: https://github.com/nodejs/node/issues/14758
PR-URL: https://github.com/nodejs/node/pull/14790
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com >
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben.bridgewater@fintura.de >
2017-09-12 03:16:59 +02:00
Ruben Bridgewater
116841056a
util: improve util.inspect performance
...
* improve util.inspect performance
This is a huge performance improvement in case of sparse arrays
when using util.inspect as the hole will simple be skipped.
* use faster visibleKeys property lookup
* add inspect-array benchmark
PR-URL: https://github.com/nodejs/node/pull/14492
Fixes: https://github.com/nodejs/node/issues/14487
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com >
Reviewed-By: Refael Ackermann <refack@gmail.com >
2017-08-13 21:43:48 +02:00
Greg Alexander
7203924fea
util: implement %o and %O as formatting specifiers
...
Implementing the %o and %O formatting specifiers for util.format.
Based on discussion in issue, this specifier should just call
util.inspect to format the value.
PR-URL: https://github.com/nodejs/node/pull/14558
Fixes: https://github.com/nodejs/node/issues/14545
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: Roman Reiss <me@silverwind.io >
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com >
2017-08-10 18:18:39 +02:00
James M Snell
9a3fc10dd4
util: implement WHATWG Encoding Standard API
...
Provide an (initially experimental) implementation of the WHATWG Encoding
Standard API (`TextDecoder` and `TextEncoder`). The is the same API
implemented on the browser side.
By default, with small-icu, only the UTF-8, UTF-16le and UTF-16be decoders
are supported. With full-icu enabled, every encoding other than iso-8859-16
is supported.
This provides a basic test, but does not include the full web platform
tests. Note: many of the web platform tests for this would fail by default
because we ship with small-icu by default.
A process warning will be emitted on first use to indicate that the
API is still experimental. No runtime flag is required to use the
feature.
Backport-PR-URL: https://github.com/nodejs/node/pull/14585
Backport-Reviewed-By: Anna Henningsen <anna@addaleax.net >
Refs: https://encoding.spec.whatwg.org/
PR-URL: https://github.com/nodejs/node/pull/13644
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2017-08-02 11:52:23 +02:00
James M Snell
f593960d35
util: refactor util module
...
* refactor util exports
* early capture of prototype methods
* use template strings and args consistently
Backport-PR-URL: https://github.com/nodejs/node/pull/14585
Backport-Reviewed-By: Anna Henningsen <anna@addaleax.net >
PR-URL: https://github.com/nodejs/node/pull/13803
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2017-08-02 11:51:55 +02:00
kadoufall
7945debe52
util: delete unused argument 'depth'
...
In lib/util.js, Line 1056, there is a 'depth' argument that is unused
for 'process.versions[exports.inspect.custom]', so delete it.
PR-URL: https://github.com/nodejs/node/pull/14267
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Refael Ackermann <refack@gmail.com >
2017-07-19 15:02:44 -04:00
Rich Trott
d9c3ccac47
lib: remove excess indentation
...
In anticipation of stricter linting for indentation, remove instances of
extra indentation that will be flagged by the new rules.
PR-URL: https://github.com/nodejs/node/pull/14090
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2017-07-19 15:02:18 -04:00
Rich Trott
3d0b66a7c2
benchmark,lib,test: use braces for multiline block
...
For if/else and loops where the bodies span more than one line, use
curly braces.
Original-PR-URL: https://github.com/nodejs/node/pull/13828
Ref: https://github.com/nodejs/node/pull/13623#discussion_r123048602
Original-Reviewed-By: Anna Henningsen <anna@addaleax.net >
Original-Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Original-Reviewed-By: Michaël Zasso <targos@protonmail.com >
Original-Reviewed-By: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/13995
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2017-07-18 19:57:15 +02:00
James M Snell
e8780ba7ae
errors: add missing ERR_ prefix on util.callbackify error
...
The `FALSY_VALUE_REJECTION` error code added by
https://github.com/nodejs/node/pull/12712 did not have the `ERR_` prefix,
nor was it added to the errors.md documentation. Add the prefix in for
consistency.
Original-PR-URL: https://github.com/nodejs/node/pull/13604
Original-Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Original-Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Original-Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com >
Original-Reviewed-By: Anna Henningsen <anna@addaleax.net >
Original-Reviewed-By: Refael Ackermann <refack@gmail.com >
Original-Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Original-Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/13750
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2017-07-18 19:56:15 +02:00
Refael Ackermann
8cba959a93
util: add callbackify
...
Add `util.callbackify(function)` for creating callback style functions
from functions returning a `Thenable`
Original-PR-URL: https://github.com/nodejs/node/pull/12712
Fixes: https://github.com/nodejs/CTC/issues/109
Original-Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Original-Reviewed-By: Teddy Katz <teddy.katz@gmail.com >
Original-Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Original-Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Original-Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Original-Reviewed-By: Anna Henningsen <anna@addaleax.net >
PR-URL: https://github.com/nodejs/node/pull/13750
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2017-07-18 19:56:14 +02:00
Vse Mozhet Byt
e786926de9
readline,repl,url,util: remove needless capturing
...
Use non-capturing grouping or remove capturing completely when:
* capturing is useless per se, e.g. in test() check;
* captured groups are not used afterwards at all;
* some of the later captured groups are not used afterwards.
PR-URL: https://github.com/nodejs/node/pull/13718
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2017-06-21 22:44:18 +02:00
Michaël Zasso
c046a21321
util: ignore invalid format specifiers
...
In util.format, if a percent sign without a known type is encountered,
just print it instead of silently ignoring it and the next character.
PR-URL: https://github.com/nodejs/node/pull/13674
Fixes: https://github.com/nodejs/node/issues/13665
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2017-06-21 22:43:09 +02:00
Vse Mozhet Byt
d51b1c2e6f
cluster, dns, repl, tls, util: fix RegExp nits
...
* Take RegExp creation out of cycles.
* Use test(), not match() in boolean context.
* Remove redundant RegExp parts.
PR-URL: https://github.com/nodejs/node/pull/13536
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2017-06-10 17:56:08 +02:00
Jesus Seijas
1bcda5efda
util: refactor format method.Performance improved.
...
Method format refactored to make it more maintenable, replacing the
switch by a function factory, that returns the appropiated function
given the character (d, i , f, j, s).
Also, performance when formatting an string that contains several
consecutive % symbols is improved. The test:
`const numSamples = 10000000;
const strPercents = '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%s%%%%%%%%%%%%%%%%%i%%%%%%%%%%%%%%%%%%%%%%%%%%';
var s;
console.time('Percents');
for (let i = 0; i < numSamples; i++) {
s = util.format(strPercents, 'test', 12);
}
console.timeEnd('Percents');`
Original time: 28399.708ms
After refactor: 23763.788ms
Improved: 16%
PR-URL: https://github.com/nodejs/node/pull/12407
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Roman Reiss <me@silverwind.io >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Brian White <mscdex@mscdex.net >
2017-06-05 12:24:21 -07:00
Anna Henningsen
99da8e8e02
util: add util.promisify()
...
Add `util.promisify(function)` for creating promisified functions.
Includes documentation and tests.
Fixes: https://github.com/nodejs/CTC/issues/12
PR-URL: https://github.com/nodejs/node/pull/12442
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Myles Borins <myles.borins@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: William Kapke <william.kapke@gmail.com >
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Reviewed-By: Teddy Katz <teddy.katz@gmail.com >
2017-05-09 15:01:41 +02:00
Brian White
d5925af8d7
util: fix permanent deoptimizations
...
PR-URL: https://github.com/nodejs/node/pull/12456
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2017-04-30 03:17:50 -04:00
Timothy Gu
3c0dd45c88
util: move getConstructorOf() to internal
...
PR-URL: https://github.com/nodejs/node/pull/12526
Reviewed-By: James M Snell <jasnell@gmail.com >
2017-04-24 16:42:49 -07:00
Brian White
4a86803f60
buffer: optimize from() and byteLength()
...
PR-URL: https://github.com/nodejs/node/pull/12361
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2017-04-14 22:35:59 +02:00
Timothy Gu
a37273c1e4
util: use V8 C++ API for inspecting Promises
...
PR-URL: https://github.com/nodejs/node/pull/12254
Refs: https://github.com/nodejs/node/issues/11875
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Josh Gavant <josh.gavant@outlook.com >
2017-04-08 11:07:00 -07:00
Anna Henningsen
3cc3e099be
util: show External values explicitly in inspect
...
Display `v8::External` values as `[External]` rather than `{}`
which makes them look like objects.
PR-URL: https://github.com/nodejs/node/pull/12151
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2017-04-03 10:08:26 +02:00
Roman Reiss
a46c43d21a
util: add %i and %f formatting specifiers
...
This change brings formatting specifiers available in `util.format` and
consequently, `console.*` closer to what is supported in all major
browsers.
- `%i` is introduced to format integer values.
- `%f` is introduced to format floating point values.
Fixes: https://github.com/nodejs/node/issues/10292
PR-URL: https://github.com/nodejs/node/pull/10308
Reviewed-By: James M Snell <jasnell@gmail.com >
2017-03-29 07:12:05 +02:00
Anna Henningsen
4a5a9445b5
util: use [Array] for deeply nested arrays
...
Prefer `[Array]` over `[Object]` because the latter is confusing.
PR-URL: https://github.com/nodejs/node/pull/12046
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com >
2017-03-28 13:11:07 -07:00
Kunal Pathak
4eb194a2b1
lib: Use regex to compare error message
...
To make node engine agnostic, use better comparison method for error
message.
Lazily populate the `circular reference` error message thrown
by `JSON.stringify()` which can be used to compare the error
message thrown.
PR-URL: https://github.com/nodejs/node/pull/11854
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Brian White <mscdex@mscdex.net >
2017-03-22 09:54:56 -07:00
James M Snell
f6dbead126
util: avoid using forEach
...
PR-URL: https://github.com/nodejs/node/pull/11582
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2017-03-17 11:09:50 -07:00
Shahar Or
5bfd13b81e
util: display Symbol keys in inspect by default
...
I use symbol key properties. And I find it awful that they do
not show up in inspection. I can alter
`util.inspect.defaultOptions.showHidden` each time I debug. Does
that sound like fun to you? Isn't fun a core principle life?
The way I see it, it is not about the spec or about what is
enumerable/hidden, etc. When inspecting, it is about ease of
access to the information. That's how I see it. Does anyone have
any other thoughts?
Fixes: https://github.com/nodejs/node/issues/9709
PR-URL: https://github.com/nodejs/node/pull/9726
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2017-03-16 13:05:58 +01:00
Timothy Gu
455e6f1dd8
util: throw toJSON errors when formatting %j
...
Previously all errors resulting from JSON.stringify were treated as a
proof for circularity of the object structure. That is not the case if
the `toJSON` method of the object throws an error. Explicitly check for
the exact error message when determining the object structure's
cyclicity.
PR-URL: https://github.com/nodejs/node/pull/11708
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2017-03-10 18:22:57 -08:00
James M Snell
98e54b0bd4
meta: restore original copyright header
...
A prior io.js era commit inappropriately removed the
original copyright statements from the source. This
restores those in any files still remaining from that
edit.
Ref: https://github.com/nodejs/TSC/issues/174
Ref: https://github.com/nodejs/node/pull/10599
PR-URL: https://github.com/nodejs/node/pull/10155
Note: This PR was required, reviewed-by and approved
by the Node.js Foundation Legal Committee and the TSC.
There is no `Approved-By:` meta data.
2017-03-10 11:23:48 -08:00
Alexey Orlenko
ec2f098156
util: change sparse arrays inspection format
...
Missing elements in sparse arrays used to be serialized to empty
placeholders delimited with commas by util.inspect() and in some cases
the result was a syntactically correct representation of a JavaScript
array with shorter length than the original one. This commit implements
@TimothyGu's suggestion to change the way util.inspect() formats sparse
arrays to something similar to how Firefox shows them.
Fixes: https://github.com/nodejs/node/issues/11570
PR-URL: https://github.com/nodejs/node/pull/11576
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2017-03-10 01:10:59 +01:00
Nemanja Stojanovic
aab0d202f8
util: convert inspect.styles and inspect.colors to prototype-less objects
...
Use a prototype-less object for inspect.styles and inspect.colors to allow
modification of Object.prototype in the REPL.
Fixes: https://github.com/nodejs/node/issues/11614
PR-URL: https://github.com/nodejs/node/pull/11624
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
2017-03-06 13:14:07 -08:00
Ali BARIN
d0b93c9fef
util: fix inspecting symbol key in string
...
PR-URL: https://github.com/nodejs/node/pull/11672
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2017-03-06 16:18:38 +01:00
Michaël Zasso
193468667b
tools: enable one-var-declaration-per-line ESLint rule
...
This rule enforces new lines around variable declarations. It is
configured to spot only variables that are initialized.
PR-URL: https://github.com/nodejs/node/pull/11462
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com >
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2017-02-21 12:53:19 +01:00
James M Snell
051047231e
util: cleanup internalUtil.deprecate
...
There were two functions `deprecate` and `_deprecate`
that were really just aliases of each other. Simplify
PR-URL: https://github.com/nodejs/node/pull/11450
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2017-02-19 15:06:39 -08:00
Shinnosuke Watanabe
5ddf72290b
util: use ES2015+ Object.is to check negative zero
...
Use `Object.is` to check whether the value is negative zero or not.
Ref: https://github.com/nodejs/node/commit/b3e4fc6a48b97b52bd19de43c76b7082dcab4988
PR-URL: https://github.com/nodejs/node/pull/11332
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2017-02-16 14:45:59 -08:00
Ben Noordhuis
2ba4eeadbb
lib: remove simd support from util.format()
...
Upstream V8 is removing SIMD support. Be proactive and follow suit.
Refs: https://bugs.chromium.org/p/v8/issues/detail?id=4124
PR-URL: https://github.com/nodejs/node/pull/11346
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com >
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com >
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2017-02-15 09:53:36 -08:00
Michaël Zasso
f65aa08b52
util: improve inspect for (Async|Generator)Function
...
Use the constructor name in the output, if present.
PR-URL: https://github.com/nodejs/node/pull/11210
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
2017-02-11 13:29:10 -08:00
James M Snell
5de3cf099c
lib: add static identifier codes for all deprecations
...
Assigns a static identifier code to all runtime and documentation
only deprecations. The identifier code is included in the emitted
DeprecationWarning.
Also adds a deprecations.md to the API docs to provide a central
location where deprecation codes can be referenced and explained.
PR-URL: https://github.com/nodejs/node/pull/10116
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Michal Zasso <targos@protonmail.com >
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com >
2017-01-30 11:11:57 -08:00