]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - tests/stress/get-by-id-throw-from-getter-through-optimized-code.js
JavaScriptCore-7600.1.4.9.tar.gz
[apple/javascriptcore.git] / tests / stress / get-by-id-throw-from-getter-through-optimized-code.js
diff --git a/tests/stress/get-by-id-throw-from-getter-through-optimized-code.js b/tests/stress/get-by-id-throw-from-getter-through-optimized-code.js
new file mode 100644 (file)
index 0000000..1b301d7
--- /dev/null
@@ -0,0 +1,37 @@
+function foo(o) {
+    return o.f + 1;
+}
+
+noInline(foo);
+
+var shouldThrow = false;
+
+function makeWithGetter() {
+    var o = {};
+    o.__defineGetter__("f", function() {
+        if (shouldThrow)
+            throw "hello";
+        return 42;
+    });
+    return o;
+}
+
+for (var i = 0; i < 100000; ++i) {
+    var result = foo({f:23});
+    if (result != 24)
+        throw "Error: bad result: " + result;
+    result = foo(makeWithGetter());
+    if (result != 43)
+        throw "Error: bad result: " + result;
+}
+
+var didThrow;
+try {
+    shouldThrow = true;
+    foo(makeWithGetter());
+} catch (e) {
+    didThrow = e;
+}
+
+if (didThrow != "hello")
+    throw "Error: didn't throw or threw wrong exception: " + didThrow;