(instance, expected_exports)
| 33 | globalThis.assert_exported_function = assert_exported_function; |
| 34 | |
| 35 | function assert_Instance(instance, expected_exports) { |
| 36 | assert_equals(Object.getPrototypeOf(instance), WebAssembly.Instance.prototype, |
| 37 | "prototype"); |
| 38 | assert_true(Object.isExtensible(instance), "extensible"); |
| 39 | |
| 40 | assert_equals(instance.exports, instance.exports, "exports should be idempotent"); |
| 41 | const exports = instance.exports; |
| 42 | |
| 43 | assert_equals(Object.getPrototypeOf(exports), null, "exports prototype"); |
| 44 | assert_false(Object.isExtensible(exports), "extensible exports"); |
| 45 | assert_array_equals(Object.keys(exports), Object.keys(expected_exports), "matching export keys"); |
| 46 | for (const [key, expected] of Object.entries(expected_exports)) { |
| 47 | const property = Object.getOwnPropertyDescriptor(exports, key); |
| 48 | assert_equals(typeof property, "object", `${key} should be present`); |
| 49 | assert_false(property.writable, `${key}: writable`); |
| 50 | assert_true(property.enumerable, `${key}: enumerable`); |
| 51 | assert_false(property.configurable, `${key}: configurable`); |
| 52 | const actual = property.value; |
| 53 | assert_true(Object.isExtensible(actual), `${key}: extensible`); |
| 54 | |
| 55 | switch (expected.kind) { |
| 56 | case "function": |
| 57 | assert_exported_function(actual, expected, `value of ${key}`); |
| 58 | break; |
| 59 | case "global": |
| 60 | assert_equals(Object.getPrototypeOf(actual), WebAssembly.Global.prototype, |
| 61 | `value of ${key}: prototype`); |
| 62 | assert_equals(actual.value, expected.value, `value of ${key}: value`); |
| 63 | assert_equals(actual.valueOf(), expected.value, `value of ${key}: valueOf()`); |
| 64 | break; |
| 65 | case "memory": |
| 66 | assert_equals(Object.getPrototypeOf(actual), WebAssembly.Memory.prototype, |
| 67 | `value of ${key}: prototype`); |
| 68 | assert_equals(Object.getPrototypeOf(actual.buffer), ArrayBuffer.prototype, |
| 69 | `value of ${key}: prototype of buffer`); |
| 70 | assert_equals(actual.buffer.byteLength, 0x10000 * expected.size, `value of ${key}: size of buffer`); |
| 71 | const array = new Uint8Array(actual.buffer); |
| 72 | assert_equals(array[0], 0, `value of ${key}: first element of buffer`); |
| 73 | assert_equals(array[array.byteLength - 1], 0, `value of ${key}: last element of buffer`); |
| 74 | break; |
| 75 | case "table": |
| 76 | assert_equals(Object.getPrototypeOf(actual), WebAssembly.Table.prototype, |
| 77 | `value of ${key}: prototype`); |
| 78 | assert_equals(actual.length, expected.length, `value of ${key}: length of table`); |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | globalThis.assert_Instance = assert_Instance; |
| 84 | |
| 85 | function assert_WebAssemblyInstantiatedSource(actual, expected_exports={}) { |
no test coverage detected