Title: [251371] trunk
- Revision
- 251371
- Author
- [email protected]
- Date
- 2019-10-21 12:06:48 -0700 (Mon, 21 Oct 2019)
Log 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/_javascript_Core:
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):
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (251370 => 251371)
--- trunk/JSTests/ChangeLog 2019-10-21 18:59:22 UTC (rev 251370)
+++ trunk/JSTests/ChangeLog 2019-10-21 19:06:48 UTC (rev 251371)
@@ -1,3 +1,14 @@
+2019-10-21 Robin Morisset <[email protected]>
+
+ Post increment/decrement should only call ToNumber once
+ https://bugs.webkit.org/show_bug.cgi?id=202711
+
+ Reviewed by Saam Barati.
+
+ * stress/postinc-custom-valueOf.js: Added.
+ (postInc):
+ (postDec):
+
2019-10-18 Yusuke Suzuki <[email protected]>
[JSC] DFG::CommonData modification by DFG reallyAdd should be guarded by CodeBlock's lock
Added: trunk/JSTests/stress/postinc-custom-valueOf.js (0 => 251371)
--- trunk/JSTests/stress/postinc-custom-valueOf.js (rev 0)
+++ trunk/JSTests/stress/postinc-custom-valueOf.js 2019-10-21 19:06:48 UTC (rev 251371)
@@ -0,0 +1,22 @@
+function postInc() {
+ var counter = 0;
+ var o = {};
+ o.valueOf = () => {counter++; return 42};
+ var x = o++; // The "var x =" part is required, or this gets transformed into ++o super early
+ if (counter != 1)
+ throw "A post-increment called valueOf " + counter + " times instead of just once.";
+}
+
+function postDec() {
+ var counter = 0;
+ var o = {};
+ o.valueOf = () => {counter++; return 42};
+ var x = o--; // The "var x =" part is required, or this gets transformed into --o super early
+ if (counter != 1)
+ throw "A pre-increment called valueOf " + counter + " times instead of just once.";
+}
+
+for (var i = 0; i < 20000; ++i) {
+ postInc();
+ postDec();
+}
Modified: trunk/Source/_javascript_Core/ChangeLog (251370 => 251371)
--- trunk/Source/_javascript_Core/ChangeLog 2019-10-21 18:59:22 UTC (rev 251370)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-10-21 19:06:48 UTC (rev 251371)
@@ -1,3 +1,17 @@
+2019-10-21 Robin Morisset <[email protected]>
+
+ Post increment/decrement should only call ToNumber once
+ https://bugs.webkit.org/show_bug.cgi?id=202711
+
+ Reviewed by Saam Barati.
+
+ 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):
+
2019-10-18 Yusuke Suzuki <[email protected]>
[JSC] DFG::CommonData modification by DFG reallyAdd should be guarded by CodeBlock's lock
Modified: trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp (251370 => 251371)
--- trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2019-10-21 18:59:22 UTC (rev 251370)
+++ trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2019-10-21 19:06:48 UTC (rev 251371)
@@ -1784,8 +1784,11 @@
{
if (dst == srcDst)
return generator.emitToNumber(generator.finalDestination(dst), srcDst);
- RefPtr<RegisterID> tmp = generator.emitToNumber(generator.tempDestination(dst), srcDst);
- emitIncOrDec(generator, srcDst, oper);
+ RefPtr<RegisterID> tmp = generator.emitToNumber(generator.newTemporary(), srcDst);
+ RefPtr<RegisterID> result = generator.tempDestination(srcDst);
+ generator.move(result.get(), tmp.get());
+ emitIncOrDec(generator, result.get(), oper);
+ generator.move(srcDst, result.get());
return generator.move(dst, tmp.get());
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes