<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>202710</bug_id>
          
          <creation_ts>2019-10-08 16:05:01 -0700</creation_ts>
          <short_desc>Post increment/decrement should only call ToNumber once</short_desc>
          <delta_ts>2019-10-11 00:04:02 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>202711</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Robin Morisset">rmorisset</reporter>
          <assigned_to name="Robin Morisset">rmorisset</assigned_to>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1577997</commentid>
    <comment_count>0</comment_count>
    <who name="Robin Morisset">rmorisset</who>
    <bug_when>2019-10-08 16:05:01 -0700</bug_when>
    <thetext>Currently they call it twice, see the following test case:
```
var o = {};
var counter = 0;
o.valueOf = () =&gt; {counter ++; return 42};
o++;
if (counter != 1)
    throw &quot;valueOf was executed &quot; + counter + &quot; times during a post-increment instead of once!&quot;;
```

As far as I can tell this is not spec-compliant:
12.4.4 Postfix Increment Operator requires a single call to ToNumeric.
Then there is a single chain of ToNumeric -&gt; ToNumber -&gt; ToPrimitive -&gt; OrdinaryToPrimitive -&gt; valueOf with no reason for the call to be duplicated anywhere.

The problem appears to be from:
```
static RegisterID* emitPostIncOrDec(BytecodeGenerator&amp; generator, RegisterID* dst, RegisterID* srcDst, Operator oper)
{
    if (dst == srcDst)
        return generator.emitToNumber(generator.finalDestination(dst), srcDst);
    RefPtr&lt;RegisterID&gt; tmp = generator.emitToNumber(generator.tempDestination(dst), srcDst);
    emitIncOrDec(generator, srcDst, oper);
    return generator.move(dst, tmp.get());
}
```
which uses an emitToNumber, but then does an emitIncOrDec on the original value, which itself can lead to a slow path that does ToNumber anew.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1579019</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2019-10-11 00:04:02 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 202711 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>