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