Last Comment Bug 724586 - Replace raw strcats with StringBuffer in obj_toSource
: Replace raw strcats with StringBuffer in obj_toSource
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: All All
: -- normal (vote)
: mozilla13
Assigned To: Terrence Cole [:terrence]
:
Mentors:
Depends on:
Blocks: 723346
  Show dependency treegraph
 
Reported: 2012-02-06 10:07 PST by Terrence Cole [:terrence]
Modified: 2012-02-08 09:40 PST (History)
3 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
v1 (12.39 KB, patch)
2012-02-06 10:07 PST, Terrence Cole [:terrence]
jwalden+bmo: review+
Details | Diff | Review
v2: With review feedback (14.01 KB, patch)
2012-02-06 19:34 PST, Terrence Cole [:terrence]
terrence: review+
Details | Diff | Review

Description Terrence Cole [:terrence] 2012-02-06 10:07:18 PST
Created attachment 594741 [details] [diff] [review]
v1

Also rips out some dangling sharp references and sanifies the control flow a bit.  Allows us to rip out about 75 lines of fiddly C string manipulation.  There is still more to do here before this code path is sane enough to replace the hash table.
Comment 1 Terrence Cole [:terrence] 2012-02-06 10:16:41 PST
https://tbpl.mozilla.org/?tree=Try&rev=12745cb4ba65
Comment 2 Jeff Walden [:Waldo] (remove +bmo to email) 2012-02-06 17:39:06 PST
Comment on attachment 594741 [details] [diff] [review]
v1

Review of attachment 594741 [details] [diff] [review]:
-----------------------------------------------------------------

The extra changes I suggest probably orphan a few variables -- make sure to check for unused warnings before committing a patch with changes.

::: js/src/jsobj.cpp
@@ +639,5 @@
>                      vchars = start;
>                  }
>              }
>  
> +            if (comma && !(buf.append(comma[0]) && buf.append(comma[1])))

if (comma && !buf.append(comma, 2))
    goto overflow;

Or, since I think you said comma's either NULL or ", ", make comma a bool, then buf.append(", ") -- much clearer.

@@ +650,5 @@
>                      goto overflow;
> +                if (!buf.append(gsopchars, gsop[j]->length()))
> +                    goto overflow;
> +                if (!buf.append(' '))
> +                    goto overflow;

if (!buf.append(gsop[j]) || !buf.append(' '))
    goto overflow;

Goodbye raw char* references!

@@ +655,4 @@
>              }
> +
> +            if (!buf.append(idstrchars, idstrlength))
> +                goto overflow;

if (!buf.append(idstr))
    goto overflow;

@@ +673,5 @@
> +
> +    str = buf.finishString();
> +    if (!str) {
> +        JS_ReportOutOfMemory(cx);
> +        return false;

finishString would have reported an error if it failed, so this extra report is unnecessary (bad, even, see below).

@@ +685,4 @@
>  
>    overflow:
> +    js_LeaveSharpObject(cx, &ida);
> +    JS_ReportOutOfMemory(cx);

If we can make all goto-overflows be the result of append failures, then Vector::append (whichever overload) would have reported an error, so this is unnecessary (bad, even, since we have assertions that errors aren't multiply-reported).

And at that point error/overflow are identical, so they can be unified.

And at that point, we can just make the js_LeaveSharpObject happen through a one-off RAII object.  I don't think it matters if we leave before finishing the string and setting it in the success case.

And at that point, all the error-y gotos become return false!

And at that point we declare victory!
Comment 3 Terrence Cole [:terrence] 2012-02-06 19:34:24 PST
Created attachment 594889 [details] [diff] [review]
v2: With review feedback

Worked like a charm.  Rerunning try to ensure I didn't break anything.
https://tbpl.mozilla.org/?tree=Try&rev=3eb0895f9745
Comment 4 Terrence Cole [:terrence] 2012-02-07 11:16:08 PST
http://hg.mozilla.org/integration/mozilla-inbound/rev/224e1e3e1483
Comment 5 Ed Morley [:emorley] 2012-02-08 09:40:14 PST
https://hg.mozilla.org/mozilla-central/rev/224e1e3e1483

Note You need to log in before you can comment on or make changes to this bug.