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

refactor(ext/node): Use Deno.inspect #17960

Merged
merged 30 commits into from
Mar 23, 2023
Merged

refactor(ext/node): Use Deno.inspect #17960

merged 30 commits into from
Mar 23, 2023

Conversation

ry
Copy link
Member

@ry ry commented Feb 26, 2023

No need for two almost identical implementations of the same thing

Comment on lines -449 to -479
// Provide a hook for user-specified inspect functions.
// Check that value is an object with an inspect function on it.
if (ctx.customInspect) {
const maybeCustom = value[customInspectSymbol];
if (
typeof maybeCustom === "function" &&
// Filter out the util module, its inspect function is special.
maybeCustom !== inspect &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)
) {
// This makes sure the recurseTimes are reported as before while using
// a counter internally.
const depth = ctx.depth === null ? null : ctx.depth - recurseTimes;
const isCrossContext = proxy !== undefined ||
!(context instanceof Object);
const ret = maybeCustom.call(
context,
depth,
getUserOptions(ctx, isCrossContext),
);
// If the custom inspection method returned `this`, don't go into
// infinite recursion.
if (ret !== context) {
if (typeof ret !== "string") {
return formatValue(ctx, ret, recurseTimes);
}
return ret.replace(/\n/g, `\n${" ".repeat(ctx.indentationLvl)}`);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to keep the customInspect support for compatibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is to align Deno.inspect and util.inspect into the single implementation as they have lot of duplicated algorithms.

I think we should move these (Node.js specific) custom inspect features into Deno.inspect implementation in later PRs.

@kt3k kt3k self-assigned this Feb 28, 2023
@kt3k
Copy link
Member

kt3k commented Mar 14, 2023

Note: Deno.inspect uses double quote and util.inspect uses single quote for string literals. This difference breaks some compat test cases

@kt3k kt3k requested a review from bartlomieju March 21, 2023 12:28
@@ -752,7 +752,7 @@ class EventTarget extends WebEventTarget {
return name;
}

const opts = ObjectAssign({}, options, {
const opts = Object.assign({}, options, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this primordial?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ObjectAssign wasn't available in this scope, but probably we should fix this in the opposite way. I'll update

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand - there should be no problem getting primordials from const primordials = globalThis.__bootstrap.primordials;

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kt3k looks good in principal - is there a clear way forward to enable the tests you commented for now?

@kt3k
Copy link
Member

kt3k commented Mar 21, 2023

is there a clear way forward to enable the tests you commented for now?

I think there's no obvious path to it (Deno.inspect and util.inspect seem having a lot of actual differences in details), and I estimate that work require a lot of time.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, cool diff

@ry ry merged commit a3529d0 into denoland:main Mar 23, 2023
@ry ry deleted the node_inspect branch March 23, 2023 14:01
bartlomieju added a commit to bartlomieju/deno that referenced this pull request Mar 29, 2023
dsherret pushed a commit that referenced this pull request Mar 30, 2023
This reverts commit a3529d0.

This change made debugging Node tests very hard - `AssertionError` is
now printed as `[Circular *1]` giving no visibility what failed.

We need to align two implementations together and remove this one then.
mmastrac pushed a commit that referenced this pull request Mar 31, 2023
This reverts commit a3529d0.

This change made debugging Node tests very hard - `AssertionError` is
now printed as `[Circular *1]` giving no visibility what failed.

We need to align two implementations together and remove this one then.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants