]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - tests/stress/for-in-delete-during-iteration.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / 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 (file)
index 0000000..5ad3566
--- /dev/null
@@ -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);
+})();