Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspect: refactor to use more primodials #36730

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
Array,
ArrayIsArray,
ArrayPrototypeFilter,
ArrayPrototypeForEach,
ArrayPrototypePush,
ArrayPrototypeSort,
ArrayPrototypeUnshift,
Expand Down Expand Up @@ -462,12 +463,13 @@ function strEscape(str) {
// instead wrap the text in double quotes. If double quotes exist, check for
// backticks. If they do not exist, use those as fallback instead of the
// double quotes.
if (str.includes("'")) {
if (StringPrototypeIncludes(str, "'")) {
// This invalidates the charCode and therefore can not be matched for
// anymore.
if (!str.includes('"')) {
if (!StringPrototypeIncludes(str, '"')) {
singleQuote = -1;
} else if (!str.includes('`') && !str.includes('${')) {
} else if (!StringPrototypeIncludes(str, '`') &&
!StringPrototypeIncludes(str, '${')) {
singleQuote = -2;
}
if (singleQuote !== 39) {
Expand All @@ -488,7 +490,7 @@ function strEscape(str) {
let last = 0;
const lastIndex = str.length;
for (let i = 0; i < lastIndex; i++) {
const point = str.charCodeAt(i);
const point = StringPrototypeCharCodeAt(str, i);
if (point === singleQuote ||
point === 92 ||
point < 32 ||
Expand Down Expand Up @@ -609,13 +611,13 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {
if (depth === 0) {
keySet = new SafeSet();
} else {
keys.forEach((key) => keySet.add(key));
ArrayPrototypeForEach(keys, (key) => keySet.add(key));
}
// Get all own property names and symbols.
keys = ObjectGetOwnPropertyNames(obj);
const symbols = ObjectGetOwnPropertySymbols(obj);
if (symbols.length !== 0) {
keys.push(...symbols);
ArrayPrototypePush(keys, ...symbols);
}
for (const key of keys) {
// Ignore the `constructor` property and keys that exist on layers above.
Expand All @@ -632,9 +634,9 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {
ctx, obj, recurseTimes, key, kObjectType, desc, main);
if (ctx.colors) {
// Faint!
output.push(`\u001b[2m${value}\u001b[22m`);
ArrayPrototypePush(output, `\u001b[2m${value}\u001b[22m`);
} else {
output.push(value);
ArrayPrototypePush(output, value);
}
}
// Limit the inspection to up to three prototype layers. Using `recurseTimes`
Expand Down