ggaren@apple.com | c27acb4 | 2008-09-04 07:21:43 +0000 | [diff] [blame] | 1 | <p> |
| 2 | This page tests for correct behavior in the case of a prototype that transitions |
| 3 | to dictionary status. If the test passes, you'll see a series of PASS messages below. |
| 4 | </p> |
| 5 | |
| 6 | <pre id="console"></pre> |
| 7 | |
| 8 | <script> |
| 9 | (function() { |
rniwa@webkit.org | 03b9c6d | 2012-07-16 01:41:53 +0000 | [diff] [blame] | 10 | if (window.testRunner) |
| 11 | testRunner.dumpAsText(); |
ggaren@apple.com | c27acb4 | 2008-09-04 07:21:43 +0000 | [diff] [blame] | 12 | |
| 13 | function log(s) |
| 14 | { |
| 15 | if (this.document) |
| 16 | document.getElementById("console").appendChild(document.createTextNode(s + "\n")); |
| 17 | else |
| 18 | print(s + "\n"); |
| 19 | } |
| 20 | |
| 21 | function shouldBe(a, aDescription, b) |
| 22 | { |
| 23 | if (a === b) { |
| 24 | log("PASS: " + aDescription + " should be " + b + " and is."); |
| 25 | } else { |
| 26 | log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + "."); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | function getSlice(array) |
| 31 | { |
| 32 | return array.slice; |
| 33 | } |
| 34 | |
| 35 | var array = [ ]; |
| 36 | var slice = array.slice; |
| 37 | |
| 38 | // Transition the array prototype to dictionary mode. |
| 39 | for (var i = 0; i < 256; ++i) |
| 40 | Array.prototype["p" + i] = 1; |
| 41 | |
| 42 | // Try to cache access to an array prototype property (slice). |
| 43 | getSlice(array); |
| 44 | getSlice(array); |
| 45 | |
| 46 | // Force the array prototype to rehash its storage. |
| 47 | for (var i = 256; i < 512; ++i) |
| 48 | Array.prototype["p" + i] = 1; |
| 49 | |
| 50 | // Use previously cached access to slice. |
| 51 | shouldBe(slice === getSlice(array), "slice === getSlice(array)", true); |
| 52 | |
| 53 | // Try to cache access to an array prototype property (slice). |
| 54 | getSlice(array); |
| 55 | getSlice(array); |
| 56 | |
| 57 | shouldBe(slice === getSlice(array), "slice === getSlice(array)", true); |
| 58 | })(); |
| 59 | </script> |