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 = { preventExtensions: 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 = { preventExtensions: 42 }; 43 var proxy = new Proxy(target, handler); 44 45 assertThrows(() => {Reflect.preventExtensions(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 // Trap returns falsish. 65 66 var target = {}; 67 var handler = { preventExtensions() {return 0} }; 68 var proxy = new Proxy(target, handler); 69 70 assertFalse(Reflect.preventExtensions(proxy)); 71 Reflect.preventExtensions(target); 72 assertFalse(Reflect.preventExtensions(proxy)); 73 })(); 74 75 76 (function () { 77 var target = {}; 78 var handler = { preventExtensions() {return Symbol()} }; 79 var proxy = new Proxy(target, handler); 80 81 // Trap returns trueish but target is extensible. 82 assertThrows(() => {Reflect.preventExtensions(proxy)}, TypeError); 83 84 // Trap returns trueish and target is not extensible. 85 Reflect.preventExtensions(target); 86 assertTrue(Reflect.preventExtensions(proxy)); 87 })(); 88