summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/PrivateName/proxy-ccw.js
blob: 94778489b602040a3c75470390874cc14f082117 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// |reftest| 

// Validate CCWs and proxies
class Base {
  constructor(o) {
    return o;
  }
}

class A extends Base {
  x1 = 12;
  #x = 10;
  static gx(o) {
    return o.#x;
  }
  static sx(o, x) {
    o.#x = x;
  }
  static hasx(o) {
    try {
      o.#x;
      return true;
    } catch {
      return false;
    }
  }
}


var g = newGlobal({newCompartment: true});
g.A = A;

// cross_compartment_target is a cross compartment wrapper to an empty object.
var cross_compartment_target = g.eval('this.x = {}; this.x');

// #x gets stamped into the target of the CCW.
new A(cross_compartment_target);
assertEq(A.hasx(cross_compartment_target), true);

// Can we update and read from this compartment?
assertEq(A.gx(cross_compartment_target), 10);
var o = {test: 12};
A.sx(cross_compartment_target, o);
assertEq(A.gx(cross_compartment_target), o);

// Can we read and update from the other compartment?
assertEq(g.eval('this.A.gx(this.x)'), o);
var y = g.eval('this.y = {test: 13}; this.A.sx(this.x, this.y); this.y');
assertEq(g.eval('this.A.gx(this.x)'), y);
assertEq(A.gx(cross_compartment_target), y);


if (typeof nukeCCW === 'function') {
  // Nuke the CCW. Now things should throw.
  nukeCCW(cross_compartment_target);
  var threw = true;
  try {
    A.gx(cross_compartment_target);
    threw = false;
  } catch (e) {
  }
  assertEq(threw, true);
}


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