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 --harmony-reflect |
| 6 |
| 7 |
| 8 (function () { |
| 9 // No trap. |
| 10 |
| 11 var target = {}; |
| 12 var handler = {}; |
| 13 var proxy = new Proxy(target, handler); |
| 14 |
| 15 assertTrue(Reflect.isExtensible(target)); |
| 16 assertTrue(Reflect.isExtensible(proxy)); |
| 17 assertTrue(Reflect.preventExtensions(proxy)); |
| 18 assertFalse(Reflect.isExtensible(target)); |
| 19 assertFalse(Reflect.isExtensible(proxy)); |
| 20 })(); |
| 21 |
| 22 |
| 23 (function () { |
| 24 // "Undefined" trap. |
| 25 |
| 26 var target = {}; |
| 27 var handler = { isExtensible: null }; |
| 28 var proxy = new Proxy(target, handler); |
| 29 |
| 30 assertTrue(Reflect.isExtensible(target)); |
| 31 assertTrue(Reflect.isExtensible(proxy)); |
| 32 assertTrue(Reflect.preventExtensions(proxy)); |
| 33 assertFalse(Reflect.isExtensible(target)); |
| 34 assertFalse(Reflect.isExtensible(proxy)); |
| 35 })(); |
| 36 |
| 37 |
| 38 (function () { |
| 39 // Invalid trap. |
| 40 |
| 41 var target = {}; |
| 42 var handler = { isExtensible: true }; |
| 43 var proxy = new Proxy(target, handler); |
| 44 |
| 45 assertThrows(() => {Reflect.isExtensible(proxy)}, TypeError); |
| 46 })(); |
| 47 |
| 48 |
| 49 (function () { |
| 50 var target = {}; |
| 51 var handler = { isExtensible() {return "bla"} }; |
| 52 var proxy = new Proxy(target, handler); |
| 53 |
| 54 // Trap returns trueish and target is extensible. |
| 55 assertTrue(Reflect.isExtensible(proxy)); |
| 56 |
| 57 // Trap returns trueish but target is not extensible. |
| 58 Reflect.preventExtensions(target); |
| 59 assertThrows(() => {Reflect.isExtensible(proxy)}, TypeError); |
| 60 })(); |
| 61 |
| 62 |
| 63 (function () { |
| 64 var target = {}; |
| 65 var handler = { isExtensible() {return 0} }; |
| 66 var proxy = new Proxy(target, handler); |
| 67 |
| 68 // Trap returns falsish but target is extensible. |
| 69 assertThrows(() => {Reflect.isExtensible(proxy)}, TypeError); |
| 70 |
| 71 // Trap returns falsish and target is not extensible. |
| 72 Reflect.preventExtensions(target); |
| 73 assertFalse(Reflect.isExtensible(proxy)); |
| 74 })(); |
OLD | NEW |