Ignore:
Timestamp:
Oct 21, 2019, 12:06:48 PM (6 years ago)
Author:
[email protected]
Message:

Post increment/decrement should only call ToNumber once
https://bugs.webkit.org/show_bug.cgi?id=202711

Reviewed by Saam Barati.

JSTests:

  • stress/postinc-custom-valueOf.js: Added.

(postInc):
(postDec):

Source/JavaScriptCore:

The problem is that we first called ToNumber on the object being incremented (to have the result that we'll eventually return), but we then do emitIncOrDec on the original object, which can call ToNumber again.
Instead we must do the ToNumber once, then copy its result, emitIncOrDec on the copy, put the copy back in the original location, and finally return the old value.
Since the result of ToNumber is guaranteed not to be an object, emitIncOrDec won't call ToNumber a second time.

  • bytecompiler/NodesCodegen.cpp:

(JSC::emitPostIncOrDec):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r251106 r251371  
    17851785    if (dst == srcDst)
    17861786        return generator.emitToNumber(generator.finalDestination(dst), srcDst);
    1787     RefPtr<RegisterID> tmp = generator.emitToNumber(generator.tempDestination(dst), srcDst);
    1788     emitIncOrDec(generator, srcDst, oper);
     1787    RefPtr<RegisterID> tmp = generator.emitToNumber(generator.newTemporary(), srcDst);
     1788    RefPtr<RegisterID> result = generator.tempDestination(srcDst);
     1789    generator.move(result.get(), tmp.get());
     1790    emitIncOrDec(generator, result.get(), oper);
     1791    generator.move(srcDst, result.get());
    17891792    return generator.move(dst, tmp.get());
    17901793}
Note: See TracChangeset for help on using the changeset viewer.