summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/RegExp/constructor-constructor.js
blob: 528f4978c22dc3dbf83ff1760cbd2efa4b4ad49c (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
67
68
69
70
71
72
73
74
75
76
77
78
var BUGNUMBER = 1147817;
var summary = "RegExp constructor should check pattern.constructor.";

print(BUGNUMBER + ": " + summary);

var g = newGlobal();

var re = /foo/;
assertEq(RegExp(re), re);
re.constructor = 10;
assertEq(RegExp(re) === re, false);
assertEq(RegExp(re).toString(), re.toString());

// If pattern comes from different global, RegExp shouldn't return it.
re = g.eval(`var re = /foo/; re;`);
assertEq(RegExp(re) === re, false);
assertEq(RegExp(re).toString(), re.toString());
g.eval(`re.constructor = 10;`);
assertEq(RegExp(re) === re, false);
assertEq(RegExp(re).toString(), re.toString());


re = new Proxy(/a/, {
  get(that, name) {
    return that[name];
  }
});
assertEq(RegExp(re), re);
re = new Proxy(/a/, {
  get(that, name) {
    if (name == "constructor") {
      return function() {};
    }
    return that[name];
  }
});
assertEq(RegExp(re) === re, false);
re = new Proxy(/a/, {
  get(that, name) {
    if (name == Symbol.match) {
      return undefined;
    }
    return that[name];
  }
});
assertEq(RegExp(re) === re, false);

re = new Proxy(g.eval(`/a/`), {
  get(that, name) {
    return that[name];
  }
});
assertEq(RegExp(re) === re, false);

re = g.eval(`new Proxy(/a/, {
  get(that, name) {
    return that[name];
  }
});`);
assertEq(RegExp(re) === re, false);


var obj = { [Symbol.match]: true, source: "foo", flags: "gi" };
assertEq(RegExp(obj) === obj, false);
assertEq(RegExp(obj).toString(), "/foo/gi");
obj.constructor = RegExp;
assertEq(RegExp(obj), obj);

obj = g.eval(`var obj = { [Symbol.match]: true, source: "foo", flags: "gi" }; obj;`);
assertEq(RegExp(obj) === obj, false);
assertEq(RegExp(obj).toString(), "/foo/gi");
g.eval(`obj.constructor = RegExp`);
assertEq(RegExp(obj) === obj, false);
obj.constructor = RegExp;
assertEq(RegExp(obj), obj);

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