X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/2d39b0e377c0896910ee49ae70082ba665faf986..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/tests/stress/for-in-delete-during-iteration.js diff --git a/tests/stress/for-in-delete-during-iteration.js b/tests/stress/for-in-delete-during-iteration.js new file mode 100644 index 0000000..5ad3566 --- /dev/null +++ b/tests/stress/for-in-delete-during-iteration.js @@ -0,0 +1,69 @@ +(function() { + // Remove a yet-to-be-visited indexed property during iteration. + var foo = function() { + var a = [1, 2, 3, 4, 5]; + var result = ""; + for (var p in a) { + if (p == 2) + delete a[3]; + result += a[p]; + } + return result; + }; + noInline(foo); + for (var i = 0; i < 10000; ++i) { + if (foo() !== "1235") + throw new Error("bad result"); + } + foo(null); +})(); +(function() { + // Remove a yet-to-be-visited non-indexed property during iteration. + var foo = function() { + var o = {}; + o.x = "x"; + o.y = "y"; + o.z = "z"; + var result = ""; + for (var p in o) { + if (p == "x") { + delete o.y; + o.a = "a"; + } + result += o[p]; + } + return result; + }; + noInline(foo); + for (var i = 0; i < 10000; ++i) { + if (foo() !== "xz") + throw new Error("bad result"); + } +})(); +(function() { + // Remove then re-add a property during iteration. + var foo = function() { + var A = function() {}; + A.prototype.x = "A.x"; + A.prototype.y = "A.y"; + var o = new A(); + o.z = "o.z"; + o.y = "o.y"; + o.x = "o.x"; + var result = ""; + for (var p in o) { + if (p == "z") + delete o.x; + if (p == "y") + o.x = "o.x"; + result += o[p]; + } + return result; + }; + noInline(foo); + for (var i = 0; i < 10000; ++i) { + if (foo() !== "o.zo.yo.x") + throw new Error("bad result"); + } + foo(null); +})();