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
Rich Trott
8628c93499
test,util: remove lint workarounds
...
Remove assignments to `SIMD` that are only to pacify ESLint. Instead,
use either `global.SIMD` or provide an comment letting ESLint know in
cases where `SIMD` is guaranteed to be a defined global identifier.
PR-URL: https://github.com/nodejs/node/pull/10785
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Teddy Katz <teddy.katz@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2017-01-16 10:40:26 -08:00
Rich Trott
a68987c154
benchmark,lib,test: adjust for linting
...
Formatting changes for upcoming linter update.
PR-URL: https://github.com/nodejs/node/pull/10561
Reviewed-By: Teddy Katz <teddy.katz@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Sam Roberts <vieuxtech@gmail.com >
2017-01-06 14:36:01 -08:00
Teddy Katz
26f2a6e87c
util: avoid out-of-bounds arguments index access
...
This updates util.inspect() to avoid accessing out-of-range indices of
the `arguments` object, which is known to cause optimization bailout.
Based on an average of 10 runs of the benchmark in
`benchmark/util/inspect.js`, this change improves the performance of
`util.inspect` by about 10%.
Relates to https://github.com/nodejs/node/issues/10323
PR-URL: https://github.com/nodejs/node/pull/10569
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Brian White <mscdex@mscdex.net >
Reviewed-By: Jackson Tian <shyvo1987@gmail.com >
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2017-01-05 01:49:57 -05:00
Steven R. Loomis
4fb27d43f0
intl: Add more versions from ICU
...
* Adds process.versions.cldr, .tz, and .unicode
* Changes how process.versions.icu is loaded
* Lazy loads the process.versions.* values for these
* add an exception to util.js
to cause 'node -p process.versions' to still work
* update process.version docs
Fixes: https://github.com/nodejs/node/issues/9237
2016-10-26 19:24:22 -07:00
Alejandro Oviedo Garcia
1ee36f614c
util: use template strings
...
This commit changes string manipulation in favor of template
literals in the `util` module.
PR-URL: https://github.com/nodejs/node/pull/9120
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2016-10-26 12:53:31 -07:00
Myles Borins
2e568d95bd
lib: remove let from for loops
...
This is a known de-opt. It may not be 100% necessary in all cases but it
seems like a decent enough idea to avoid it.
PR-URL: https://github.com/nodejs/node/pull/8873
Reviewed-By: Brian White <mscdex@mscdex.net >
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com >
Reviewed-By: Johan Bergström <bugs@bergstroem.nu >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
2016-10-04 12:17:32 -04:00
Yosuke Furukawa
ce7d3077dc
util: Add format for SharedArrayBuffer
...
PR-URL: https://github.com/nodejs/node/pull/8587
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2016-09-26 08:07:04 -07:00
Bryan English
be07458b11
util: don't init Debug if it's not needed yet
...
Because any call to util.inspect() with an object results in
inspectPromise() being called, Debug was being initialized even when
it's not needed. Instead, the initialization is placed after the
isPromise check.
PR-URL: https://github.com/nodejs/node/pull/8452
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
2016-09-20 10:04:26 -07:00
Dany Shaanan
5f29947230
util: simplify SIMD setup
...
PR-URL: https://github.com/nodejs/node/pull/8579
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com >
2016-09-20 14:11:31 +02:00
Sakthipriyan Vairamani
b3e7ac2605
util: improve function signature of util._extend
...
The function signature of `util._extend` is not intuitive and the
documentation doesn't specify the necessary second parameter. This
patch changes the parameter names in the code and the function params
in doc.
PR-URL: https://github.com/nodejs/node/pull/8187
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <mic.besace@gmail.com >
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com >
Reviewed-By: Brian White <mscdex@mscdex.net >
2016-08-26 18:53:39 +05:30
Anna Henningsen
a60ed89178
util: allow returning this from custom inspect
...
If a custom inspection function returned `this`, use that value
for further formatting instead of going into infinite recursion.
This is particularly useful when combined with `util.inspect.custom`
because returning `this` from such a method makes it easy to
have an `inspect()` function that is ignored by `util.inspect` without
actually having to provide an alternative for custom inspection.
PR-URL: https://github.com/nodejs/node/pull/8174
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <mic.besace@gmail.com >
2016-08-25 07:18:12 +02:00
Anna Henningsen
59714cb7b3
util: allow symbol-based custom inspection methods
...
Add a `util.inspect.custom` Symbol which can be used to customize
`util.inspect()` output. Providing `obj[util.inspect.custom]`
works like providing `obj.inspect`, except that the former allows
avoiding name clashes with other `inspect()` methods.
Fixes: https://github.com/nodejs/node/issues/8071
PR-URL: https://github.com/nodejs/node/pull/8174
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <mic.besace@gmail.com >
2016-08-25 07:13:00 +02:00
Evan Lucas
76007079ec
Revert "repl,util: insert carriage returns in output"
...
This reverts commit fce4b981ea .
This was a breaking change and should have been marked semver-major.
The change that was made altered the output of util.format() and
util.inspect(). With how much those are used in the wild, this type of
change deserves more justification.
Fixes: https://github.com/nodejs/node/issues/8138
PR-URL: https://github.com/nodejs/node/pull/8143
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
2016-08-19 11:48:52 -05:00
JungMinu
fce4b981ea
repl,util: insert carriage returns in output
...
`\n` is not enough for Linux with some custom stream
add carriage returns to ensure that the output is displayed correctly
using `\r\n` should not be a problem, even on non-Windows platforms.
Fixes: https://github.com/nodejs/node/issues/7954
PR-URL: https://github.com/nodejs/node/pull/8028
Reviewed-By: Brian White <mscdex@mscdex.net >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2016-08-13 23:03:30 +09:00
Roman Reiss
1a6a69a8e0
util: add inspect.defaultOptions
...
Adds util.inspect.defaultOptions which allows customization of the
default util.inspect options, which is useful for functions like
console.log or util.format which implicitly call into util.inspect.
PR-URL: https://github.com/nodejs/node/pull/8013
Fixes: https://github.com/nodejs/node/issues/7566
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
2016-08-09 20:57:24 +02:00
Anna Henningsen
1b24b37299
util: fix formatting of objects with SIMD enabled
...
When SIMD is enabled, `util.format` couldn’t display objects
(with at least 1 key) because the formatter function got
overridden.
PR-URL: https://github.com/nodejs/node/pull/7864
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Michaël Zasso <mic.besace@gmail.com >
2016-08-02 15:00:59 +02:00
Anna Henningsen
35e8c9481f
util: inspect boxed symbols like other primitives
...
Inspect boxed symbol objects in the same way other boxed primitives
are inspected.
Fixes: https://github.com/nodejs/node/issues/7639
PR-URL: https://github.com/nodejs/node/pull/7641
Reviewed-By: Michaël Zasso <mic.besace@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com >
2016-07-17 17:50:01 +02:00
cjihrig
a2ee21db84
util: add an option for configuring break length
...
This commit adds a breakLength option to util.inspect(). This
option allows users to control the length at which object keys
are split across multiple lines. For backwards compatibility,
this option defaults to 60.
Fixes: https://github.com/nodejs/node/issues/7305
PR-URL: https://github.com/nodejs/node/pull/7499
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com >
2016-07-05 10:17:28 -04:00
Ben Noordhuis
ee8e7cd25d
util: pretty-print SIMD types
...
Before:
Bool32x4 {}
Float32x4 {}
Int32x4 {}
// etc.
After:
Bool32x4 [ false, false, false, false ]
Float32x4 [ NaN, NaN, NaN, NaN ]
Int32x4 [ 0, 0, 0, 0 ]
// etc.
PR-URL: https://github.com/nodejs/node/pull/6917
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Robert Jefe Lindstaedt <robert.lindstaedt@gmail.com >
2016-05-23 12:16:41 +02:00
Rumkin
9c33e0ebe7
util: fix invalid date output with util.inspect
...
Prevent util.inspect of throwing on date object with invalid date value.
It changed to output result of toString method call.
PR-URL: https://github.com/nodejs/node/pull/6504
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2016-05-16 11:17:25 +02:00
Rich Trott
4e6dc00401
tools: lint for object literal spacing
...
There has been occasional nits for spacing in object literals in PRs but
the project does not lint for it and it is not always handled
consistently in the existing code, even on adjacent lines of a file.
This change enables a linting rule requiring no space between the key
and the colon, and requiring at least one space (but allowing for more
so property values can be lined up if desired) between the colon and the
value. This appears to be the most common style used in the current code
base.
Example code the complies with lint rule:
myObj = { foo: 'bar' };
Examples that do not comply with the lint rule:
myObj = { foo : 'bar' };
myObj = { foo:'bar' };
PR-URL: https://github.com/nodejs/node/pull/6592
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Brian White <mscdex@mscdex.net >
2016-05-08 22:45:20 -07:00