| 129 | } |
| 130 | |
| 131 | function VerifyBoundsCheck(func, memtype_size) { |
| 132 | const kPageSize = 65536; |
| 133 | // Test out of bounds at boundary |
| 134 | for (let i = memory.buffer.byteLength - memtype_size + 1; |
| 135 | i < memory.buffer.byteLength + memtype_size + 4; i++) { |
| 136 | assertTrapsOneOf( |
| 137 | // If an underlying platform uses traps for a bounds check, |
| 138 | // kTrapUnalignedAccess will be thrown before kTrapMemOutOfBounds. |
| 139 | // Otherwise, kTrapMemOutOfBounds will be first. |
| 140 | [kTrapMemOutOfBounds, kTrapUnalignedAccess], |
| 141 | () => func(i, 5, 10) |
| 142 | ); |
| 143 | } |
| 144 | // Test out of bounds at maximum + 1 |
| 145 | assertTraps(kTrapMemOutOfBounds, () => func((maxSize + 1) * kPageSize, 5, 1)); |
| 146 | } |
| 147 | |
| 148 | // Test many elements in the small range, make bigger steps later. This is still |
| 149 | // O(2^n), but takes 213 steps to reach 2^32. |