blob: 14bc383c69688a6c0f20f796934298548870e671 [file] [log] [blame]
sbarati@apple.come12031e2016-03-11 00:43:46 +00001function assert(b) {
2 if (!b)
3 throw new Error("Bad assertion");
4}
5
6function test(f) {
7 for (let i = 0; i < 1000; i++)
8 f();
9}
10
11let constructors = [Error, String, RegExp, function() {}, class C {}];
12
13for (let constructor of constructors) {
14 test(function() {
15 let proxy = new Proxy(constructor, {});
16 assert(new constructor instanceof proxy);
17 });
18}
19
20test(function() {
21 let called = false;
22 let proxy = new Proxy(function(){ called = true; }, {});
23 assert(new proxy instanceof proxy);
24 assert(called);
25});
26
27test(function() {
28 let called = false;
29 let handler = {
30 get: function(target, prop) {
31 if (prop === "prototype")
32 return {};
33 return target[prop];
34 }
35 };
36 let proxy = new Proxy(function(){ called = true; }, handler);
37 assert(!(new proxy instanceof proxy));
38 assert(called);
39});