| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
The former implementation had it's reason as well as the internal toString method is mostly not ideal. The main problem is that hasBuiltInToString does not know about the toPrimitive symbol. By checking for that, it would handle both cases right.
Sorry, something went wrong.
Thank you. Are you suggesting to modify it this way? case 115: { // 's'
const tempArg = args[++a];
if (typeof tempArg === 'number') {
tempStr = formatNumberNoColor(tempArg, inspectOptions);
} else if (typeof tempArg === 'bigint') {
tempStr = formatBigIntNoColor(tempArg, inspectOptions);
} else if (hasBuiltInToString(tempArg)) {
tempStr = String(tempArg);
} else {
tempStr = inspect(tempArg, {
...inspectOptions,
compact: 3,
colors: false,
depth: 0,
});
}
break;
}
|
Sorry, something went wrong.
|
@chenyuyang2022 no, the hasBuiltInToString method has to check for for the toPrimitive symbol as well. Please always run the tests as well. There should be test failures related to the current change. |
Sorry, something went wrong.
|
@BridgeAR Thank you for the reminder. I have modified the implementation and passed all the tests with 'make test'. |
Sorry, something went wrong.
|
Would you mind updating the hasBuiltInToString function instead as @BridgeAR suggested? Also, please add a test case in https://github.com/nodejs/node/blob/main/test/parallel/test-util-format.js as well. Thank you! |
Sorry, something went wrong.
|
@legendecas Thank you, I've made the changes according to your suggestions. Could you please take a look? |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
|
@BridgeAR would you mind taking a look again? |
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for following up upon this!
LGTM with the comment removed.
Sorry, something went wrong.
|
@BridgeAR Would you mind reviewing it again? |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
We have to change the commit message when merging. It should be e.g., util: fix %s format for objects with Symbol.toPrimitive.
Sorry, something went wrong.
|
@Ch3nYuY thank you for following up on the comments! |
Sorry, something went wrong.
Sorry, something went wrong.
|
@Ch3nYuY seems like there is a linter error that has to be resolved before it's possible to land this |
Sorry, something went wrong.
|
Thank you, @BridgeAR . I'll see how to solve it |
Sorry, something went wrong.
|
@BridgeAR I've solved all the linter error. Could you please add the 'request-ci' tag again? |
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
|
Hey @Ch3nYuY, the recent commits block the PR from being merged. Can you please rebase? :) |
Sorry, something went wrong.
|
Thanks! @BridgeAR I resolved the merge conflicts and it should look ok now. |
Sorry, something went wrong.
This commit ensures `console.log("%s", obj)` correctly invokes
`obj[Symbol.toPrimitive]` for string conversion, fixing unexpected
object display issue.
Fixes: nodejs#50909
Sorry, something went wrong.
Sorry, something went wrong.
|
Landed in 7129915068b3613f8bb525c84ca4feaa7c9c2077 Sorry, wrong commit message! Landed in dde2965 |
Sorry, something went wrong.
This commit ensures `console.log("%s", obj)` correctly invokes
`obj[Symbol.toPrimitive]` for string conversion, fixing unexpected
object display issue.
PR-URL: #50992
Fixes: #50909
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
This commit ensures `console.log("%s", obj)` correctly invokes
`obj[Symbol.toPrimitive]` for string conversion, fixing unexpected
object display issue.
PR-URL: #50992
Fixes: #50909
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
This commit ensures `console.log("%s", obj)` correctly invokes
`obj[Symbol.toPrimitive]` for string conversion, fixing unexpected
object display issue.
PR-URL: #50992
Fixes: #50909
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
This commit ensures `console.log("%s", obj)` correctly invokes
`obj[Symbol.toPrimitive]` for string conversion, fixing unexpected
object display issue.
PR-URL: nodejs#50992
Fixes: nodejs#50909
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
|
This actually broke the way Date is represented when using "%s". Prior to this commit, it would use ISO8601 format by way of utils.inspect(). After this commit, it appears to use toString() which has a radically different format. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
console.log("%s", o) invokes the inspect method to retrieve the object. This results in console.log("%s", { [Symbol.toPrimitive]: () => "hello" }) displaying the object itself, rather than 'hello'.
Fixes: #50909