[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Review Request: kjs: Implement JSON.stringify
From:       "Maks Orlovich" <maksim () kde ! org>
Date:       2012-08-12 15:42:04
Message-ID: 20120812154204.16649.47700 () vidsolbach ! de
[Download RAW message or body]

-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/105057/#review17275
-----------------------------------------------------------

Ship it!


Almost there; will be OK iff everything below is fixed.


kjs/jsonstringify.cpp
<http://git.reviewboard.kde.org/r/105057/#comment13452>

    Does this do the right thing with NaN and the like?



kjs/jsonstringify.cpp
<http://git.reviewboard.kde.org/r/105057/#comment13453>

    Resetting m_state, m_rootIsUndefined here might be a good defensive mov=
e (just in case stringify starts getting called twice)



kjs/jsonstringify.cpp
<http://git.reviewboard.kde.org/r/105057/#comment13454>

    This looks like we could end up looping indefinitely here and crashing =
with out of stack depth (if they keep returning new objects which have .toJ=
SON set0. I think some checking for m_objectStack.size() may be in order. P=
robably a good idea in case someone tries to serialize something really dee=
p, too.
    =

    =




kjs/jsonstringify.cpp
<http://git.reviewboard.kde.org/r/105057/#comment13455>

    Can get an exception here



kjs/jsonstringify.cpp
<http://git.reviewboard.kde.org/r/105057/#comment13456>

    You don't want to be keying by UString here, but rather than Identifier=
, since they guarantee reference equality of equal strings, unlike UString.
    =

    CommonIdentifiers.h has the traits for them.
    =



- Maks Orlovich


On July 25, 2012, 2:54 p.m., Bernd Buschinski wrote:
> =

> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/105057/
> -----------------------------------------------------------
> =

> (Updated July 25, 2012, 2:54 p.m.)
> =

> =

> Review request for kdelibs.
> =

> =

> Description
> -------
> =

> kjs: Implement JSON.stringify
> =

> patch needs https://git.reviewboard.kde.org/r/105056/ (JSON.parse)
> =

> =

> Diffs
> -----
> =

>   kjs/CMakeLists.txt 1188064 =

>   kjs/CommonIdentifiers.h 8ee40e8 =

>   kjs/json_object.h PRE-CREATION =

>   kjs/json_object.cpp PRE-CREATION =

>   kjs/jsonstringify.h PRE-CREATION =

>   kjs/jsonstringify.cpp PRE-CREATION =

>   kjs/ustring.h 49370ef =

> =

> Diff: http://git.reviewboard.kde.org/r/105057/diff/
> =

> =

> Testing
> -------
> =

> =

> Thanks,
> =

> Bernd Buschinski
> =

>


[Attachment #3 (text/html)]

<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 \
solid;">  <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="http://git.reviewboard.kde.org/r/105057/">http://git.reviewboard.kde.org/r/105057/</a>
  </td>
    </tr>
   </table>
   <br />



 <p>Ship it!</p>



 <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Almost there; will be OK \
iff everything below is fixed.</pre>  <br />





<div>




<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;">  <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;">  <a \
href="http://git.reviewboard.kde.org/r/105057/diff/5/?file=74786#file74786line85" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kjs/jsonstringify.cpp</a>  <span style="font-weight: normal;">

     (Diff revision 5)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td>  <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">JSONStringify::JSONStringify(ExecState* exec, JSValue* replacer, JSValue* \
spacer)</pre></td>

  </tr>
 </tbody>




 
 



 <tbody>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th>  <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>  <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">85</font></th>  <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span \
class="kt">int</span> <span class="n">spaces</span> <span class="o">=</span> <span \
class="k">static_cast</span><span class="o">&lt;</span><span \
class="kt">int</span><span class="o">&gt;</span><span class="p">(</span><span \
class="n">spacer</span><span class="o">-&gt;</span><span \
class="n">toInteger</span><span class="p">(</span><span class="n">exec</span><span \
class="p">));</span></pre></td>  </tr>

 </tbody>

</table>

<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Does this \
do the right thing with NaN and the like?</pre> </div>
<br />

<div>




<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;">  <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;">  <a \
href="http://git.reviewboard.kde.org/r/105057/diff/5/?file=74786#file74786line102" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kjs/jsonstringify.cpp</a>  <span style="font-weight: normal;">

     (Diff revision 5)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td>  <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">JSONStringify::JSONStringify(ExecState* exec, JSValue* replacer, JSValue* \
spacer)</pre></td>

  </tr>
 </tbody>




 
 



 <tbody>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th>  <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>  <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">102</font></th>  <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">    <span \
class="n">JSObject</span><span class="o">*</span> <span class="n">holder</span> <span \
class="o">=</span> <span class="k">static_cast</span><span class="o">&lt;</span><span \
class="n">JSObject</span> <span class="o">*&gt;</span><span class="p">(</span><span \
class="n">exec</span><span class="o">-&gt;</span><span \
class="n">lexicalInterpreter</span><span class="p">()</span><span \
class="o">-&gt;</span><span class="n">builtinObject</span><span \
class="p">()</span><span class="o">-&gt;</span><span class="n">construct</span><span \
class="p">(</span><span class="n">exec</span><span class="p">,</span> <span \
class="n">List</span><span class="o">::</span><span class="n">empty</span><span \
class="p">()));</span></pre></td>  </tr>

 </tbody>

</table>

<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Resetting \
m_state, m_rootIsUndefined here might be a good defensive move (just in case \
stringify starts getting called twice)</pre> </div>
<br />

<div>




<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;">  <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;">  <a \
href="http://git.reviewboard.kde.org/r/105057/diff/5/?file=74786#file74786line205" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kjs/jsonstringify.cpp</a>  <span style="font-weight: normal;">

     (Diff revision 5)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td>  <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">JSONStringify::JSONStringify(ExecState* exec, JSValue* replacer, JSValue* \
spacer)</pre></td>

  </tr>
 </tbody>




 
 



 <tbody>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th>  <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>  <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">205</font></th>  <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">            \
<span class="k">return</span> <span class="n">stringifyValue</span><span \
class="p">(</span><span class="n">exec</span><span class="p">,</span> <span \
class="n">toJSONCall</span><span class="p">,</span> <span \
class="n">propertyName</span><span class="p">,</span> <span class="n">jso</span><span \
class="p">);</span></pre></td>  </tr>

 </tbody>

</table>

<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">This looks \
like we could end up looping indefinitely here and crashing with out of stack depth \
(if they keep returning new objects which have .toJSON set0. I think some checking \
for m_objectStack.size() may be in order. Probably a good idea in case someone tries \
to serialize something really deep, too.

</pre>
</div>
<br />

<div>




<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;">  <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;">  <a \
href="http://git.reviewboard.kde.org/r/105057/diff/5/?file=74786#file74786line217" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kjs/jsonstringify.cpp</a>  <span style="font-weight: normal;">

     (Diff revision 5)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td>  <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">JSONStringify::JSONStringify(ExecState* exec, JSValue* replacer, JSValue* \
spacer)</pre></td>

  </tr>
 </tbody>




 
 



 <tbody>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th>  <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>  <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">217</font></th>  <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span \
class="k">return</span> <span class="n">quotedString</span><span \
class="p">(</span><span class="n">exec</span><span class="p">,</span> <span \
class="n">jso</span><span class="o">-&gt;</span><span class="n">toString</span><span \
class="p">(</span><span class="n">exec</span><span class="p">));</span></pre></td>  \
</tr>

 </tbody>

</table>

<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Can get an \
exception here</pre> </div>
<br />

<div>




<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;">  <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;">  <a \
href="http://git.reviewboard.kde.org/r/105057/diff/5/?file=74786#file74786line232" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kjs/jsonstringify.cpp</a>  <span style="font-weight: normal;">

     (Diff revision 5)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td>  <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">JSONStringify::JSONStringify(ExecState* exec, JSValue* replacer, JSValue* \
spacer)</pre></td>

  </tr>
 </tbody>




 
 



 <tbody>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th>  <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>  <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">232</font></th>  <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">            \
<span class="k">if</span> <span class="p">(</span><span \
class="n">isWhiteListed</span><span class="p">(</span><span \
class="n">names</span><span class="p">[</span><span class="n">i</span><span \
class="p">].</span><span class="n">ustring</span><span class="p">()))</span> <span \
class="p">{</span></pre></td>  </tr>

 </tbody>

</table>

<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">You \
don&#39;t want to be keying by UString here, but rather than Identifier, since they \
guarantee reference equality of equal strings, unlike UString.

CommonIdentifiers.h has the traits for them.
</pre>
</div>
<br />



<p>- Maks</p>


<br />
<p>On July 25th, 2012, 2:54 p.m., Bernd Buschinski wrote:</p>






<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" \
style="background-image: \
url('http://git.reviewboard.kde.org/media/rb/images/review_request_box_top_bg.png'); \
background-position: left top; background-repeat: repeat-x; border: 1px black \
solid;">  <tr>
  <td>

<div>Review request for kdelibs.</div>
<div>By Bernd Buschinski.</div>


<p style="color: grey;"><i>Updated July 25, 2012, 2:54 p.m.</i></p>






<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
 <table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" \
style="border: 1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">kjs: Implement JSON.stringify

patch needs https://git.reviewboard.kde.org/r/105056/ (JSON.parse)</pre>
  </td>
 </tr>
</table>





<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">

 <li>kjs/CMakeLists.txt <span style="color: grey">(1188064)</span></li>

 <li>kjs/CommonIdentifiers.h <span style="color: grey">(8ee40e8)</span></li>

 <li>kjs/json_object.h <span style="color: grey">(PRE-CREATION)</span></li>

 <li>kjs/json_object.cpp <span style="color: grey">(PRE-CREATION)</span></li>

 <li>kjs/jsonstringify.h <span style="color: grey">(PRE-CREATION)</span></li>

 <li>kjs/jsonstringify.cpp <span style="color: grey">(PRE-CREATION)</span></li>

 <li>kjs/ustring.h <span style="color: grey">(49370ef)</span></li>

</ul>

<p><a href="http://git.reviewboard.kde.org/r/105057/diff/" style="margin-left: \
3em;">View Diff</a></p>




  </td>
 </tr>
</table>








  </div>
 </body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic