1function assert_equal_to_array(table, expected, message) { 2 assert_equals(table.length, expected.length, `${message}: length`); 3 // The argument check in get() happens before the range check, and negative numbers 4 // are illegal, hence will throw TypeError per spec. 5 assert_throws_js(TypeError, () => table.get(-1), `${message}: table.get(-1)`); 6 for (let i = 0; i < expected.length; ++i) { 7 assert_equals(table.get(i), expected[i], `${message}: table.get(${i} of ${expected.length})`); 8 } 9 assert_throws_js(RangeError, () => table.get(expected.length), 10 `${message}: table.get(${expected.length} of ${expected.length})`); 11 assert_throws_js(RangeError, () => table.get(expected.length + 1), 12 `${message}: table.get(${expected.length + 1} of ${expected.length})`); 13} 14 15function assert_Table(actual, expected) { 16 assert_equals(Object.getPrototypeOf(actual), WebAssembly.Table.prototype, 17 "prototype"); 18 assert_true(Object.isExtensible(actual), "extensible"); 19 20 assert_equals(actual.length, expected.length, "length"); 21 for (let i = 0; i < expected.length; ++i) { 22 assert_equals(actual.get(i), null, `actual.get(${i})`); 23 } 24} 25