MCPcopy Index your code
hub / github.com/nodejs/node / assert_Instance

Function assert_Instance

test/fixtures/wpt/wasm/jsapi/assertions.js:35–82  ·  view source on GitHub ↗
(instance, expected_exports)

Source from the content-addressed store, hash-verified

33globalThis.assert_exported_function = assert_exported_function;
34
35function 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}
83globalThis.assert_Instance = assert_Instance;
84
85function assert_WebAssemblyInstantiatedSource(actual, expected_exports={}) {

Callers 3

instantiate.any.jsFile · 0.85
constructor.any.jsFile · 0.85

Calls 7

assert_exported_functionFunction · 0.85
keysMethod · 0.65
assert_equalsFunction · 0.50
assert_trueFunction · 0.50
assert_falseFunction · 0.50
assert_array_equalsFunction · 0.50
entriesMethod · 0.45

Tested by

no test coverage detected