| 1 |
const constructors = [ |
| 2 |
Int8Array, |
| 3 |
Uint8Array, |
| 4 |
Uint8ClampedArray, |
| 5 |
Int16Array, |
| 6 |
Uint16Array, |
| 7 |
Int32Array, |
| 8 |
Uint32Array, |
| 9 |
Float16Array, |
| 10 |
Float32Array, |
| 11 |
Float64Array ]; |
| 12 |
|
| 13 |
function messWith(view, obj) { |
| 14 |
view[0] = 1; |
| 15 |
view[1] = 1; |
| 16 |
view[2] = 2; |
| 17 |
view[3] = 3; |
| 18 |
ensureNonInline(obj); |
| 19 |
assertEq(view[0], 1); |
| 20 |
assertEq(view[1], 1); |
| 21 |
assertEq(view[2], 2); |
| 22 |
assertEq(view[3], 3); |
| 23 |
} |
| 24 |
|
| 25 |
function test() { |
| 26 |
// Bufferless |
| 27 |
for (const ctor of constructors) { |
| 28 |
let small = new ctor(4); |
| 29 |
messWith(small, small); |
| 30 |
let big = new ctor(4000); |
| 31 |
messWith(big, big); |
| 32 |
} |
| 33 |
|
| 34 |
// With buffer, single view, operate on view |
| 35 |
for (const ctor of constructors) { |
| 36 |
let ab = new ArrayBuffer(96); |
| 37 |
const small = new ctor(ab); |
| 38 |
messWith(small, small); |
| 39 |
ab = new ArrayBuffer(4000); |
| 40 |
const big = new ctor(ab); |
| 41 |
messWith(big, big); |
| 42 |
} |
| 43 |
|
| 44 |
// With buffer, single view, operate on ArrayBuffer |
| 45 |
for (const ctor of constructors) { |
| 46 |
let ab = new ArrayBuffer(96); |
| 47 |
const small = new ctor(ab); |
| 48 |
messWith(small, ab); |
| 49 |
ab = new ArrayBuffer(4000); |
| 50 |
const big = new ctor(ab); |
| 51 |
messWith(big, ab); |
| 52 |
} |
| 53 |
|
| 54 |
// With buffer, dual view, operate on view |
| 55 |
for (const ctor of constructors) { |
| 56 |
let ab = new ArrayBuffer(96); |
| 57 |
let view0 = new Uint8Array(ab); |
| 58 |
const small = new ctor(ab); |
| 59 |
messWith(small, small); |
| 60 |
ab = new ArrayBuffer(4000); |
| 61 |
view0 = new Uint8Array(ab); |
| 62 |
const big = new ctor(ab); |
| 63 |
messWith(big, big); |
| 64 |
} |
| 65 |
|
| 66 |
// With buffer, dual view, operate on ArrayBuffer |
| 67 |
for (const ctor of constructors) { |
| 68 |
let ab = new ArrayBuffer(96); |
| 69 |
let view0 = new Uint8Array(ab); |
| 70 |
const small = new ctor(ab); |
| 71 |
messWith(small, ab); |
| 72 |
ab = new ArrayBuffer(4000); |
| 73 |
view0 = new Uint8Array(ab); |
| 74 |
const big = new ctor(ab); |
| 75 |
messWith(big, ab); |
| 76 |
} |
| 77 |
|
| 78 |
// With resizable buffer. |
| 79 |
for (const ctor of constructors) { |
| 80 |
let ab = new ArrayBuffer(32, {maxByteLength: 64}); |
| 81 |
const small = new ctor(ab); |
| 82 |
messWith(small, small); |
| 83 |
ab = new ArrayBuffer(4000, {maxByteLength: 4096}); |
| 84 |
const big = new ctor(ab); |
| 85 |
messWith(big, big); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
try { |
| 90 |
ensureNonInline(new Array(3)); |
| 91 |
assertEq(false, true); |
| 92 |
} catch (e) { |
| 93 |
assertEq(e.message.includes("unhandled type"), true); |
| 94 |
} |
| 95 |
|
| 96 |
test(); |