Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(668)

Side by Side Diff: test/mjsunit/harmony/proxies-define-property.js

Issue 1517463002: [runtime] [proxies] adding tests for uncovered branches (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: dropping mips changes Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/harmony/proxies-enumerate.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --harmony-proxies 5 // Flags: --harmony-proxies
6 6
7 // Check basic call to trap. 7 // Check basic call to trap.
8 8
9 var g_target, g_name, g_desc; 9 var g_target, g_name, g_desc;
10 var handler = { 10 var handler = {
11 defineProperty: function(target, name, desc) { 11 defineProperty: function(target, name, desc) {
12 g_target = target; 12 g_target = target;
13 g_name = name; 13 g_name = name;
14 g_desc = desc; 14 g_desc = desc;
15 return true; 15 return true;
16 } 16 }
17 } 17 }
18 var target = {} 18 var target = {}
19 var proxy = new Proxy(target, handler); 19 var proxy = new Proxy(target, handler);
20 var desc = { value: 1, writable: true, configurable: true, enumerable: true }; 20 var desc = { value: 1, writable: true, configurable: true, enumerable: true };
21 Object.defineProperty(proxy, "foo", desc); 21 Object.defineProperty(proxy, "foo", desc);
22 assertSame(target, g_target); 22 assertSame(target, g_target);
23 assertEquals("foo", g_name); 23 assertEquals("foo", g_name);
24 assertEquals(desc, g_desc); 24 assertEquals(desc, g_desc);
25 25
26 // Check specific steps in the spec: 26 // Check specific steps in the spec
27
28 // Step 4: revoked handler
29 var pair = Proxy.revocable(target, handler);
30 Object.defineProperty(proxy, "foo2", desc);
31 assertSame(target, g_target);
32 assertEquals("foo2", g_name);
33 assertEquals(desc, g_desc);
34 pair.revoke();
35 assertThrows('Object.defineProperty(pair.proxy, "bar", desc);', TypeError);
27 36
28 // Step 6: Trap isn't callable. 37 // Step 6: Trap isn't callable.
29 handler.defineProperty = 1; 38 handler.defineProperty = 1;
30 assertThrows("Object.defineProperty(proxy, 'foo', {value: 2})", TypeError); 39 assertThrows("Object.defineProperty(proxy, 'foo', {value: 2})", TypeError);
31 40
32 // Step 7: Trap is undefined. 41 // Step 7: Trap is undefined.
33 handler.defineProperty = undefined; 42 handler.defineProperty = undefined;
34 Object.defineProperty(proxy, "prop1", desc); 43 Object.defineProperty(proxy, "prop1", desc);
35 assertEquals(desc, Object.getOwnPropertyDescriptor(target, "prop1")); 44 assertEquals(desc, Object.getOwnPropertyDescriptor(target, "prop1"));
36 var target2 = {}; 45 var target2 = {};
(...skipping 29 matching lines...) Expand all
66 // Step 16a: Trap returns true for non-compatible property descriptor. 75 // Step 16a: Trap returns true for non-compatible property descriptor.
67 Object.defineProperty(target, "foo", 76 Object.defineProperty(target, "foo",
68 {value: 1, writable: false, configurable: false}); 77 {value: 1, writable: false, configurable: false});
69 assertThrows("Object.defineProperty(proxy, 'foo', {value: 2})", TypeError); 78 assertThrows("Object.defineProperty(proxy, 'foo', {value: 2})", TypeError);
70 79
71 // Step 16b: Trap returns true for overwriting a configurable property 80 // Step 16b: Trap returns true for overwriting a configurable property
72 // with a non-configurable descriptor. 81 // with a non-configurable descriptor.
73 target.bar = "baz"; 82 target.bar = "baz";
74 assertThrows("Object.defineProperty(proxy, 'bar', {configurable: false})", 83 assertThrows("Object.defineProperty(proxy, 'bar', {configurable: false})",
75 TypeError); 84 TypeError);
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/harmony/proxies-enumerate.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698