-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
util: prevent proxy traps being triggered by .inspect() #26241
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -495,18 +495,23 @@ function formatValue(ctx, value, recurseTimes, typedArray) { | |
| return ctx.stylize('null', 'null'); | ||
| } | ||
|
|
||
| // Memorize the context for custom inspection on proxies. | ||
| const context = value; | ||
| // Always check for proxies to prevent side effects and to prevent triggering | ||
| // any proxy handlers. | ||
| const proxy = getProxyDetails(value); | ||
| if (proxy !== undefined) { | ||
| if (ctx.showProxy && ctx.stop === undefined) { | ||
| return formatProxy(ctx, proxy, recurseTimes); | ||
| } | ||
| value = proxy[0]; | ||
| } | ||
|
|
||
| if (ctx.stop !== undefined) { | ||
| const name = getConstructorName(value, ctx) || value[Symbol.toStringTag]; | ||
| return ctx.stylize(`[${name || 'Object'}]`, 'special'); | ||
| } | ||
|
|
||
| if (ctx.showProxy) { | ||
| const proxy = getProxyDetails(value); | ||
| if (proxy !== undefined) { | ||
| return formatProxy(ctx, proxy, recurseTimes); | ||
| } | ||
| } | ||
|
|
||
| // Provide a hook for user-specified inspect functions. | ||
| // Check that value is an object with an inspect function on it. | ||
| if (ctx.customInspect) { | ||
|
|
@@ -523,11 +528,10 @@ function formatValue(ctx, value, recurseTimes, typedArray) { | |
| // This makes sure the recurseTimes are reported as before while using | ||
|
||
| // a counter internally. | ||
| const depth = ctx.depth === null ? null : ctx.depth - recurseTimes; | ||
| const ret = maybeCustom.call(value, depth, plainCtx); | ||
|
|
||
| const ret = maybeCustom.call(context, depth, plainCtx); | ||
| // If the custom inspection method returned `this`, don't go into | ||
| // infinite recursion. | ||
| if (ret !== value) { | ||
| if (ret !== context) { | ||
| if (typeof ret !== 'string') { | ||
| return formatValue(ctx, ret, recurseTimes); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.