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 var target = { 8 "target_one": 1 9 }; 10 target.__proto__ = { 11 "target_two": 2 12 }; 13 var handler = { 14 has: function(target, name) { 15 return name == "present"; 16 } 17 } 18 19 var proxy = new Proxy(target, handler); 20 21 // Test simple cases. 22 assertTrue("present" in proxy); 23 assertFalse("nonpresent" in proxy); 24 25 // Test interesting algorithm steps: 26 27 // Step 7: Fall through to target if trap is undefined. 28 handler.has = undefined; 29 assertTrue("target_one" in proxy); 30 assertTrue("target_two" in proxy); 31 assertFalse("in_your_dreams" in proxy); 32 33 // Step 8: Result is converted to boolean. 34 var result = 1; 35 handler.has = function(t, n) { return result; } 36 assertTrue("foo" in proxy); 37 result = {}; 38 assertTrue("foo" in proxy); 39 result = undefined; 40 assertFalse("foo" in proxy); 41 result = "string"; 42 assertTrue("foo" in proxy); 43 44 // Step 9b i. Trap result must confirm presence of non-configurable properties 45 // of the target. 46 Object.defineProperty(target, "nonconf", {value: 1, configurable: false}); 47 result = false; 48 assertThrows("'nonconf' in proxy", TypeError); 49 50 // Step 9b iii. Trap result must confirm presence of all own properties of 51 // non-extensible targets. 52 Object.preventExtensions(target); 53 assertThrows("'nonconf' in proxy", TypeError); 54 assertThrows("'target_one' in proxy", TypeError); 55 assertFalse("target_two" in proxy); 56 assertFalse("in_your_dreams" in proxy); 57 58 // Regression test for crbug.com/570120 (stray JSObject::cast). 59 (function TestHasPropertyFastPath() { 60 var proxy = new Proxy({}, {}); 61 var object = Object.create(proxy); 62 object.hasOwnProperty(0); 63 })(); 64