Debian Codegraph @

js/src/tests/non262/ShadowRealms/function-copy-name-and-length-fails-error-realm.js

raw
1 // |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell)
2
3 var sr = new ShadowRealm();
4
5 var id = sr.evaluate(`x => x()`);
6
7 // |id| is a Function from the current realm and _not_ from ShadowRealm.
8 assertEq(id instanceof Function, true);
9
10 function f() {
11 return 1;
12 }
13
14 // Smoke test: Ensure calling |f| through the ShadowRealm works correctly.
15 assertEq(id(f), 1);
16
17 // Add an accessor for "name" which throws. This will lead to throwing an
18 // exception in CopyNameAndLength. The thrown exception should be from the
19 // realm of |id|, i.e. the current realm.
20 Object.defineProperty(f, "name", {
21 get() { throw new Error; }
22 });
23
24 assertThrowsInstanceOf(() => id(f), TypeError);
25
26 if (typeof reportCompare === 'function')
27 reportCompare(true, true);