util: fix inspect crash when getter returns a function - #64856
Closed
NeverBetterEnough wants to merge 1 commit into
Closed
util: fix inspect crash when getter returns a function#64856NeverBetterEnough wants to merge 1 commit into
NeverBetterEnough wants to merge 1 commit into
Conversation
When a property getter returns a function, formatProperty incorrectly routes the function value to formatPrimitive, which does not handle functions and falls through to Symbol.prototype.toString(), causing a TypeError. Fix by treating getter-returned functions the same as getter-returned objects in formatProperty, routing them through formatValue which properly formats functions. Before (broken): getFunction: [Getter: <Inspection threw (TypeError: ...)>] After (fixed): getFunction: [Getter] [Function: fn] Fixes: nodejs#64838
Contributor
|
Dupe of #64839 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a property getter returns a function,
formatPropertyincorrectlyroutes the function value to
formatPrimitive, which does not handlefunctions and falls through to
Symbol.prototype.toString(), causing aTypeError.
Fix by treating getter-returned functions the same as getter-returned
objects in
formatProperty, routing them throughformatValuewhichproperly formats functions.
Before (broken):
After (fixed):
Changes:
lib/internal/util/inspect.js: +1/-1 — added|| typeof tmp === 'function'to the object-branch conditiontest/parallel/test-util-inspect.js: +20 — regression test reproducing the scenarioFixes: #64838