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