sbarati@apple.com | e12031e | 2016-03-11 00:43:46 +0000 | [diff] [blame] | 1 | function assert(b) { |
| 2 | if (!b) |
| 3 | throw new Error("Bad assertion"); |
| 4 | } |
| 5 | |
| 6 | function test(f) { |
| 7 | for (let i = 0; i < 1000; i++) |
| 8 | f(); |
| 9 | } |
| 10 | |
| 11 | let constructors = [Error, String, RegExp, function() {}, class C {}]; |
| 12 | |
| 13 | for (let constructor of constructors) { |
| 14 | test(function() { |
| 15 | let proxy = new Proxy(constructor, {}); |
| 16 | assert(new constructor instanceof proxy); |
| 17 | }); |
| 18 | } |
| 19 | |
| 20 | test(function() { |
| 21 | let called = false; |
| 22 | let proxy = new Proxy(function(){ called = true; }, {}); |
| 23 | assert(new proxy instanceof proxy); |
| 24 | assert(called); |
| 25 | }); |
| 26 | |
| 27 | test(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 | }); |