(helper, oobThrows)
| 1160 | }()); |
| 1161 | |
| 1162 | function TestFill(helper, oobThrows) { |
| 1163 | for (let ctor of ctors) { |
| 1164 | const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, |
| 1165 | 8 * ctor.BYTES_PER_ELEMENT); |
| 1166 | const fixedLength = new ctor(rab, 0, 4); |
| 1167 | const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); |
| 1168 | const lengthTracking = new ctor(rab, 0); |
| 1169 | const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); |
| 1170 | |
| 1171 | assertEquals([0, 0, 0, 0], ReadDataFromBuffer(rab, ctor)); |
| 1172 | |
| 1173 | helper(fixedLength, 1); |
| 1174 | assertEquals([1, 1, 1, 1], ReadDataFromBuffer(rab, ctor)); |
| 1175 | |
| 1176 | helper(fixedLengthWithOffset, 2); |
| 1177 | assertEquals([1, 1, 2, 2], ReadDataFromBuffer(rab, ctor)); |
| 1178 | |
| 1179 | helper(lengthTracking, 3); |
| 1180 | assertEquals([3, 3, 3, 3], ReadDataFromBuffer(rab, ctor)); |
| 1181 | |
| 1182 | helper(lengthTrackingWithOffset, 4); |
| 1183 | assertEquals([3, 3, 4, 4], ReadDataFromBuffer(rab, ctor)); |
| 1184 | |
| 1185 | // Shrink so that fixed length TAs go out of bounds. |
| 1186 | rab.resize(3 * ctor.BYTES_PER_ELEMENT); |
| 1187 | |
| 1188 | if (oobThrows) { |
| 1189 | assertThrows(() => helper(fixedLength, 5), TypeError); |
| 1190 | assertThrows(() => helper(fixedLengthWithOffset, 6), TypeError); |
| 1191 | } else { |
| 1192 | helper(fixedLength, 5); |
| 1193 | helper(fixedLengthWithOffset, 6); |
| 1194 | // We'll check below that these were no-op. |
| 1195 | } |
| 1196 | assertEquals([3, 3, 4], ReadDataFromBuffer(rab, ctor)); |
| 1197 | |
| 1198 | helper(lengthTracking, 7); |
| 1199 | assertEquals([7, 7, 7], ReadDataFromBuffer(rab, ctor)); |
| 1200 | |
| 1201 | helper(lengthTrackingWithOffset, 8); |
| 1202 | assertEquals([7, 7, 8], ReadDataFromBuffer(rab, ctor)); |
| 1203 | |
| 1204 | // Shrink so that the TAs with offset go out of bounds. |
| 1205 | rab.resize(1 * ctor.BYTES_PER_ELEMENT); |
| 1206 | |
| 1207 | if (oobThrows) { |
| 1208 | assertThrows(() => helper(fixedLength, 9), TypeError); |
| 1209 | assertThrows(() => helper(fixedLengthWithOffset, 10), TypeError); |
| 1210 | assertThrows(() => helper(lengthTrackingWithOffset, 11), TypeError); |
| 1211 | } else { |
| 1212 | // We'll check below that these were no-op. |
| 1213 | helper(fixedLength, 9); |
| 1214 | helper(fixedLengthWithOffset, 10); |
| 1215 | helper(lengthTrackingWithOffset, 11); |
| 1216 | } |
| 1217 | assertEquals([7], ReadDataFromBuffer(rab, ctor)); |
| 1218 | |
| 1219 | helper(lengthTracking, 12); |
no test coverage detected
searching dependent graphs…