NEW 288605
`toString` method of `obj` is triggered by `console.log(obj)`
https://bugs.webkit.org/show_bug.cgi?id=288605
Summary `toString` method of `obj` is triggered by `console.log(obj)`
Joe
Reported 2025-02-26 07:50:34 PST
Developers expect `console.log` to be minimally disruptive - i.e. simply log the arguments and nothing else. In some cases it is actually invalid to call `toString` on certain objects, and yet the developer stills wants to be able to log the object so they can inspect it in the console with the interactive object explorer. In other words, `toString` should be considered user-land, not for developer tools to use. ```js let a = {}; a.toString = function() { console.log("toString() called!"); return "123"; } console.log(a); // only in Safari this triggers the "toString() called!" to be logged ``` It would be great if WebKit could become compatible with other browsers on this issue.
Attachments
Radar WebKit Bug Importer
Comment 1 2025-02-27 05:08:56 PST
Razvan Caliman
Comment 2 2025-02-27 05:25:25 PST
Breadcrumbs for investigation: WI.RuntimeManager.evaluateInInspectedWindow() ----- inspector protocol ----- - PageRuntimeAgent::evaluate() --> gets or creates InjectedScript via PageRuntimeAgent::injectedScriptForEval() - InspectorRuntimeAgent::evaluate() - InjectedScript::evaluate() --> creates ScriptFunctionCall - InjectedScriptBase::makeEvalCall() - InjectedScriptBase::makeCall() - InjectedScriptBase::toInspectorValue() --> using result from ScriptFunctionCall::call()
Note You need to log in before you can comment on or make changes to this bug.