11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<meta charset="utf-8"> 31cb0ef41Sopenharmony_ci<title>WebAssembly JS API: Default [[Prototype]] value is from NewTarget's Realm</title> 41cb0ef41Sopenharmony_ci<link rel="help" href="https://webidl.spec.whatwg.org/#internally-create-a-new-object-implementing-the-interface"> 51cb0ef41Sopenharmony_ci<link rel="help" href="https://tc39.es/ecma262/#sec-nativeerror"> 61cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 71cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 81cb0ef41Sopenharmony_ci<script src="wasm-module-builder.js"></script> 91cb0ef41Sopenharmony_ci<body> 101cb0ef41Sopenharmony_ci<iframe id="constructor-iframe" hidden></iframe> 111cb0ef41Sopenharmony_ci<iframe id="new-target-iframe" hidden></iframe> 121cb0ef41Sopenharmony_ci<iframe id="other-iframe" hidden></iframe> 131cb0ef41Sopenharmony_ci<script> 141cb0ef41Sopenharmony_ci"use strict"; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst constructorRealm = document.querySelector("#constructor-iframe").contentWindow; 171cb0ef41Sopenharmony_ciconst newTargetRealm = document.querySelector("#new-target-iframe").contentWindow; 181cb0ef41Sopenharmony_ciconst otherRealm = document.querySelector("#other-iframe").contentWindow; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciconst emptyModuleBinary = new WasmModuleBuilder().toBuffer(); 211cb0ef41Sopenharmony_ciconst interfaces = [ 221cb0ef41Sopenharmony_ci ["Module", emptyModuleBinary], 231cb0ef41Sopenharmony_ci ["Instance", new WebAssembly.Module(emptyModuleBinary)], 241cb0ef41Sopenharmony_ci ["Memory", {initial: 0}], 251cb0ef41Sopenharmony_ci ["Table", {element: "anyfunc", initial: 0}], 261cb0ef41Sopenharmony_ci ["Global", {value: "i32"}], 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci // See step 2 of https://tc39.es/ecma262/#sec-nativeerror 291cb0ef41Sopenharmony_ci ["CompileError"], 301cb0ef41Sopenharmony_ci ["LinkError"], 311cb0ef41Sopenharmony_ci ["RuntimeError"], 321cb0ef41Sopenharmony_ci]; 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ciconst primitives = [ 351cb0ef41Sopenharmony_ci undefined, 361cb0ef41Sopenharmony_ci null, 371cb0ef41Sopenharmony_ci false, 381cb0ef41Sopenharmony_ci true, 391cb0ef41Sopenharmony_ci 0, 401cb0ef41Sopenharmony_ci -1, 411cb0ef41Sopenharmony_ci "", 421cb0ef41Sopenharmony_ci "str", 431cb0ef41Sopenharmony_ci Symbol(), 441cb0ef41Sopenharmony_ci]; 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ciconst getNewTargets = function* (realm) { 471cb0ef41Sopenharmony_ci for (const primitive of primitives) { 481cb0ef41Sopenharmony_ci const newTarget = new realm.Function(); 491cb0ef41Sopenharmony_ci newTarget.prototype = primitive; 501cb0ef41Sopenharmony_ci yield [newTarget, "cross-realm NewTarget with `" + format_value(primitive) + "` prototype"]; 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci // GetFunctionRealm (https://tc39.es/ecma262/#sec-getfunctionrealm) coverage: 541cb0ef41Sopenharmony_ci const bindOther = otherRealm.Function.prototype.bind; 551cb0ef41Sopenharmony_ci const ProxyOther = otherRealm.Proxy; 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci const bound = new realm.Function(); 581cb0ef41Sopenharmony_ci bound.prototype = undefined; 591cb0ef41Sopenharmony_ci yield [bindOther.call(bound), "bound cross-realm NewTarget with `undefined` prototype"]; 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci const boundBound = new realm.Function(); 621cb0ef41Sopenharmony_ci boundBound.prototype = null; 631cb0ef41Sopenharmony_ci yield [bindOther.call(bindOther.call(boundBound)), "bound bound cross-realm NewTarget with `null` prototype"]; 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci const boundProxy = new realm.Function(); 661cb0ef41Sopenharmony_ci boundProxy.prototype = false; 671cb0ef41Sopenharmony_ci yield [bindOther.call(new ProxyOther(boundProxy, {})), "bound Proxy of cross-realm NewTarget with `false` prototype"]; 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci const proxy = new realm.Function(); 701cb0ef41Sopenharmony_ci proxy.prototype = true; 711cb0ef41Sopenharmony_ci yield [new ProxyOther(proxy, {}), "Proxy of cross-realm NewTarget with `true` prototype"]; 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci const proxyProxy = new realm.Function(); 741cb0ef41Sopenharmony_ci proxyProxy.prototype = -0; 751cb0ef41Sopenharmony_ci yield [new ProxyOther(new ProxyOther(proxyProxy, {}), {}), "Proxy of Proxy of cross-realm NewTarget with `-0` prototype"]; 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci const proxyBound = new realm.Function(); 781cb0ef41Sopenharmony_ci proxyBound.prototype = NaN; 791cb0ef41Sopenharmony_ci yield [new ProxyOther(bindOther.call(proxyBound), {}), "Proxy of bound cross-realm NewTarget with `NaN` prototype"]; 801cb0ef41Sopenharmony_ci}; 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_cifor (const [interfaceName, constructorArg] of interfaces) { 831cb0ef41Sopenharmony_ci for (const [newTarget, testDescription] of getNewTargets(newTargetRealm)) { 841cb0ef41Sopenharmony_ci test(() => { 851cb0ef41Sopenharmony_ci const Constructor = constructorRealm.WebAssembly[interfaceName]; 861cb0ef41Sopenharmony_ci const object = Reflect.construct(Constructor, [constructorArg], newTarget); 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci const NewTargetConstructor = newTargetRealm.WebAssembly[interfaceName]; 891cb0ef41Sopenharmony_ci assert_true(object instanceof NewTargetConstructor); 901cb0ef41Sopenharmony_ci assert_equals(Object.getPrototypeOf(object), NewTargetConstructor.prototype); 911cb0ef41Sopenharmony_ci }, `WebAssembly.${interfaceName}: ${testDescription}`); 921cb0ef41Sopenharmony_ci } 931cb0ef41Sopenharmony_ci} 941cb0ef41Sopenharmony_ci</script> 951cb0ef41Sopenharmony_ci</body> 96