Bug 84781

Summary: objectProtoFuncToString creates new string every invocation
Product: WebKit Reporter: Michael Saboff <msaboff>
Component: JavaScriptCoreAssignee: Michael Saboff <msaboff>
Severity: Normal CC: webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Description Flags
ggaren: review-
Updated Patch with Suggested Fixes
ggaren: review+, webkit-ews: commit-queue-
Updated patch with speculative Qt fix none

Description Michael Saboff 2012-04-24 14:33:29 PDT
objectProtoFuncToString creates and returns a JSString with the contents of "[object <object_type]" (e.g. "[object Number]").  This creates a new string each time possibly increasing memory and using CPU.  This value should be created once and cached for each object.
Comment 1 Michael Saboff 2012-04-24 14:49:16 PDT
Created attachment 138653 [details]

This fails the style checker due to using a PassRefPtr as a local, but reused pattern from JSStringBuilder.h.
Comment 2 WebKit Review Bot 2012-04-24 14:51:01 PDT
Attachment 138653 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/JavaScriptCore/ChangeLog', u'Source..." exit_code: 1
Source/JavaScriptCore/runtime/ObjectPrototype.cpp:260:  Local variables should never be PassRefPtr (see http://webkit.org/coding/RefPtr.html).  [readability/pass_ptr] [5]
Total errors found: 1 in 4 files

If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Geoffrey Garen 2012-04-24 15:15:46 PDT
Comment on attachment 138653 [details]

View in context: https://bugs.webkit.org/attachment.cgi?id=138653&action=review

Patch looks good, but some minor changes needed here before committing.

> Source/JavaScriptCore/runtime/ObjectPrototype.cpp:259
> +    if (!thisObject->structure()->hasObjectToStringValue()) {

Our typical style here is just to call objectToStringValue():
RefPtr<> toStringValue = thisObject->structure()->objectToStringValue();
if (!toStringValue) {
    toStringValue = ...

> Source/JavaScriptCore/runtime/ObjectPrototype.cpp:264
> +        thisObject->structure()->setObjectToStringValue(exec->globalData(), thisObject, jsNontrivialString(exec, result));

The appropriate pattern is to make the local a RefPtr, to avoid accidentally dereferencing NULL, and then use .release() when passing it to setObjectToStringValue here.

> Source/JavaScriptCore/runtime/Structure.cpp:797
> +#if 1

Please remove the #if.
Comment 4 Michael Saboff 2012-04-24 15:35:21 PDT
Created attachment 138669 [details]
Updated Patch with Suggested Fixes
Comment 5 Geoffrey Garen 2012-04-24 15:37:54 PDT
Comment on attachment 138669 [details]
Updated Patch with Suggested Fixes

Comment 6 Early Warning System Bot 2012-04-24 16:15:49 PDT
Comment on attachment 138669 [details]
Updated Patch with Suggested Fixes

Attachment 138669 [details] did not pass qt-wk2-ews (qt):
Output: http://queues.webkit.org/results/12525366
Comment 7 Michael Saboff 2012-04-24 16:44:12 PDT
Created attachment 138686 [details]
Updated patch with speculative Qt fix
Comment 8 Michael Saboff 2012-04-24 17:57:32 PDT
Committed r115151: <http://trac.webkit.org/changeset/115151>