summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-arguments-are-wrapped-into-the-inner-realm-extended.js
blob: 08fab52be91570bc54bde71155e0ddc0272ff36e (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options
// Copyright (C) 2021 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-shadowrealm.prototype.evaluate
description: >
  ShadowRealm.prototype.evaluate wrapped function arguments are wrapped into the inner realm, extended.
features: [ShadowRealm]
---*/

assert.sameValue(
  typeof ShadowRealm.prototype.evaluate,
  'function',
  'This test must fail if ShadowRealm.prototype.evaluate is not a function'
);

const r = new ShadowRealm();
const blueFn = (x, y) => x + y;

const redWrappedFn = r.evaluate(`
    function fn(wrapped1, wrapped2, wrapped3) {
        if (wrapped1.x) {
            return 1;
        }
        if (wrapped2.x) {
            return 2;
        }
        if (wrapped3.x) {
            // Not unwrapped
            return 3;
        }
        if (wrapped1 === wrapped2) {
            // Always a new wrapped function
            return 4;
        }

        // No unwrapping
        if (wrapped3 === fn) {
            return 5;
        };

        return true;
    }
    fn.x = 'secret';
    fn;
`);
assert.sameValue(redWrappedFn(blueFn, blueFn, redWrappedFn), true);

reportCompare(0, 0);