OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-proxies |
| 6 |
| 7 "use strict"; |
| 8 |
| 9 |
| 10 var global = this; |
| 11 |
| 12 |
| 13 (function TestGlobalReceiver() { |
| 14 class A { |
| 15 s() { |
| 16 super.bla = 10; |
| 17 } |
| 18 } |
| 19 new A().s.call(global); |
| 20 assertEquals(10, global.bla); |
| 21 })(); |
| 22 |
| 23 |
| 24 (function TestProxyProto() { |
| 25 var calls = 0; |
| 26 var handler = { |
| 27 getPropertyDescriptor: function(name) { |
| 28 calls++; |
| 29 return undefined; |
| 30 } |
| 31 }; |
| 32 |
| 33 var proto = {}; |
| 34 var proxy = Proxy.create(handler, proto); |
| 35 var object = { |
| 36 __proto__: proxy, |
| 37 setX(v) { |
| 38 super.x = v; |
| 39 }, |
| 40 setSymbol(sym, v) { |
| 41 super[sym] = v; |
| 42 } |
| 43 }; |
| 44 |
| 45 object.setX(1); |
| 46 assertEquals(1, Object.getOwnPropertyDescriptor(object, 'x').value); |
| 47 assertEquals(1, calls); |
| 48 |
| 49 var sym = Symbol(); |
| 50 object.setSymbol.call(global, sym, 2); |
| 51 assertEquals(2, Object.getOwnPropertyDescriptor(global, sym).value); |
| 52 // We currently do not invoke proxy traps for symbols |
| 53 assertEquals(1, calls); |
| 54 })(); |
| 55 |
| 56 |
| 57 (function TestProxyReceiver() { |
| 58 var object = { |
| 59 setY(v) { |
| 60 super.y = v; |
| 61 } |
| 62 }; |
| 63 |
| 64 var calls = 0; |
| 65 var handler = { |
| 66 getPropertyDescriptor(name) { |
| 67 assertUnreachable(); |
| 68 }, |
| 69 set(receiver, name, value) { |
| 70 calls++; |
| 71 assertEquals(proxy, receiver); |
| 72 assertEquals('y', name); |
| 73 assertEquals(3, value); |
| 74 } |
| 75 }; |
| 76 |
| 77 var proxy = Proxy.create(handler); |
| 78 object.setY.call(proxy, 3); |
| 79 assertEquals(1, calls); |
| 80 })(); |
OLD | NEW |