summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/ShadowRealms/function-copy-name-and-length-fails-error-realm.js
blob: 23040c9fb3ae175fcf7f20f24de64d2e9ccb4c61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell)

var sr = new ShadowRealm();

var id = sr.evaluate(`x => x()`);

// |id| is a Function from the current realm and _not_ from ShadowRealm.
assertEq(id instanceof Function, true);

function f() {
  return 1;
}

// Smoke test: Ensure calling |f| through the ShadowRealm works correctly.
assertEq(id(f), 1);

// Add an accessor for "name" which throws. This will lead to throwing an
// exception in CopyNameAndLength. The thrown exception should be from the
// realm of |id|, i.e. the current realm.
Object.defineProperty(f, "name", {
  get() { throw new Error; }
});

assertThrowsInstanceOf(() => id(f), TypeError);

if (typeof reportCompare === 'function')
  reportCompare(true, true);