<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:darin&#64;apple.com" title="Darin Adler &lt;darin&#64;apple.com&gt;"> <span class="fn">Darin Adler</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [JSC] add missing RequireObjectCoercible() step in destructuring"
   href="https://bugs.webkit.org/show_bug.cgi?id=151596">bug 151596</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Attachment #266145 Flags</td>
           <td>review?
           </td>
           <td>review+
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [JSC] add missing RequireObjectCoercible() step in destructuring"
   href="https://bugs.webkit.org/show_bug.cgi?id=151596#c2">Comment # 2</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [JSC] add missing RequireObjectCoercible() step in destructuring"
   href="https://bugs.webkit.org/show_bug.cgi?id=151596">bug 151596</a>
              from <span class="vcard"><a class="email" href="mailto:darin&#64;apple.com" title="Darin Adler &lt;darin&#64;apple.com&gt;"> <span class="fn">Darin Adler</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=266145&amp;action=diff" name="attach_266145" title="[JSC] add missing RequireObjectCoercible() step in destructuring">attachment 266145</a> <a href="attachment.cgi?id=266145&amp;action=edit" title="[JSC] add missing RequireObjectCoercible() step in destructuring">[details]</a></span>
[JSC] add missing RequireObjectCoercible() step in destructuring

View in context: <a href="https://bugs.webkit.org/attachment.cgi?id=266145&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=266145&amp;action=review</a>

<span class="quote">&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:3849
&gt; +    emitJumpIfFalse(emitIsUndefined(newTemporary(), value), isNotUndefined.get());</span >

We can save a branch in the normal expected fast path by doing the other check first; then do emitIsUndefined only the failure case to chose which error to throw; undefined is equal to null from the point of view of op_eq_null.

<span class="quote">&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:3853
&gt; +    emitJumpIfFalse(emitUnaryOp(op_eq_null, newTemporary(), value), target.get());</span >

Unfortunately this emits the “masquerades as null” checking code, so it’s unnecessarily slow. Here we are not literally checking == null so we don’t want that extra logic; it just slows us down. One way to do this would be to add a new op_is_undefined_or_null that doesn’t bother with the masquerading logic. Or op_is_object_coercible.

<span class="quote">&gt; Source/JavaScriptCore/tests/stress/destructuring-assignment-require-object-coercible.js:15
&gt; +testTypeError(`({ } = null)`, &quot;TypeError: null is not an object&quot;);</span >

Would be much better to check all the other types here too, an object, number, boolean, string, and especially a “masquerades as null” value, making sure that they do not throw a type error.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>