Geremy Condra | c957189 | 2012-03-05 12:32:24 -0800 | [diff] [blame] | 1 | <p>This page tests for a crash when throwing an exception from a callback provided |
| 2 | to String.prototype.replace. |
| 3 | </p> |
| 4 | |
| 5 | <p>If the test passes, you'll see a series of PASS messages below. |
| 6 | </p> |
| 7 | |
| 8 | <pre id="console"></pre> |
| 9 | |
| 10 | <script> |
| 11 | function log(s) |
| 12 | { |
| 13 | document.getElementById("console").appendChild(document.createTextNode(s + "\n")); |
| 14 | } |
| 15 | |
| 16 | if (window.layoutTestController) |
| 17 | layoutTestController.dumpAsText(); |
| 18 | |
| 19 | // these should not crash |
| 20 | |
| 21 | try { |
| 22 | (function () { |
| 23 | "aa".replace(/a/g, function() { |
| 24 | var bogus; |
| 25 | bogus.property; |
| 26 | }); |
| 27 | })(); |
| 28 | } catch(e) { |
| 29 | log ("PASS: You didn't crash."); |
| 30 | } |
| 31 | |
| 32 | try { |
| 33 | (function () { |
| 34 | "aa".replace("a", function() { |
| 35 | ({})(); |
| 36 | }); |
| 37 | })(); |
| 38 | } catch(e) { |
| 39 | log ("PASS: You didn't crash."); |
| 40 | } |
| 41 | |
| 42 | // this should not continue execution after an exception |
| 43 | |
| 44 | var message = "PASS: String.prototype.replace did not continue executing after an exception was thrown."; |
| 45 | try { |
| 46 | (function () { |
| 47 | var count = 0; |
| 48 | "aa".replace(/a/g, function() { |
| 49 | if (++count > 1) |
| 50 | message = "FAIL: String.prototype.replace continued executing after an exception was thrown."; |
| 51 | |
| 52 | var bogus; |
| 53 | bogus.property; |
| 54 | }); |
| 55 | })(); |
| 56 | } catch(e) { |
| 57 | try { |
| 58 | (function x() { return 'blargh'.replace(/a/g, x) })() |
| 59 | } catch(e) { |
| 60 | log (message); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | </script> |