constructor.any.js (1470B)
1 // META: global=window,dedicatedworker,jsshell,shadowrealm 2 // META: script=/wasm/jsapi/wasm-module-builder.js 3 // META: script=/wasm/jsapi/assertions.js 4 // META: script=/wasm/jsapi/instanceTestFactory.js 5 6 let emptyModuleBinary; 7 setup(() => { 8 emptyModuleBinary = new WasmModuleBuilder().toBuffer(); 9 }); 10 11 test(() => { 12 assert_function_name(WebAssembly.Instance, "Instance", "WebAssembly.Instance"); 13 }, "name"); 14 15 test(() => { 16 assert_function_length(WebAssembly.Instance, 1, "WebAssembly.Instance"); 17 }, "length"); 18 19 test(() => { 20 assert_throws_js(TypeError, () => new WebAssembly.Instance()); 21 }, "No arguments"); 22 23 test(() => { 24 const invalidArguments = [ 25 undefined, 26 null, 27 true, 28 "", 29 Symbol(), 30 1, 31 {}, 32 WebAssembly.Module, 33 WebAssembly.Module.prototype, 34 ]; 35 for (const argument of invalidArguments) { 36 assert_throws_js(TypeError, () => new WebAssembly.Instance(argument), 37 `new Instance(${format_value(argument)})`); 38 } 39 }, "Non-Module arguments"); 40 41 test(() => { 42 const module = new WebAssembly.Module(emptyModuleBinary); 43 assert_throws_js(TypeError, () => WebAssembly.Instance(module)); 44 }, "Calling"); 45 46 for (const [name, fn] of instanceTestFactory) { 47 test(() => { 48 const { buffer, args, exports, verify } = fn(); 49 const module = new WebAssembly.Module(buffer); 50 const instance = new WebAssembly.Instance(module, ...args); 51 assert_Instance(instance, exports); 52 verify(instance); 53 }, name); 54 }