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

Side by Side Diff: test/mjsunit/harmony/proxies-get-prototype-of.js

Issue 1815773002: Remove runtime flags for Proxy and Reflect (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 4 years, 9 months 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
OLDNEW
(Empty)
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 = { target: 1 };
8 target.__proto__ = {};
9 var handler = { handler: 1 };
10 var proxy = new Proxy(target, handler);
11
12 assertSame(Object.getPrototypeOf(proxy), target.__proto__ );
13
14 target.__proto__ = [];
15 assertSame(Object.getPrototypeOf(proxy), target.__proto__);
16
17 handler.getPrototypeOf = function() {
18 return 1;
19 }
20 assertThrows(function() { Object.getPrototypeOf(proxy) }, TypeError);
21
22 var target_prototype = {a:1, b:2};
23 handler.getPrototypeOf = function() {
24 return target_prototype ;
25 }
26 assertSame(Object.getPrototypeOf(proxy), target_prototype);
27
28 // Test with proxy target:
29 var proxy2 = new Proxy(proxy, {'handler':1});
30 assertSame(Object.getPrototypeOf(proxy2), target_prototype);
31
32 // Test with Proxy handler:
33 var proxy3_prototype = {'proto3':true};
34 var handler_proxy = new Proxy({
35 getPrototypeOf: function() { return proxy3_prototype }
36 }, {});
37 var proxy3 = new Proxy(target, handler_proxy);
38 assertSame(Object.getPrototypeOf(proxy3), proxy3_prototype);
39
40
41 // Some tests with Object.prototype.isPrototypeOf
42
43 (function () {
44 var object = {};
45 var handler = {};
46 var proto = new Proxy({}, handler);
47 object.__proto__ = proto;
48
49 assertTrue(proto.isPrototypeOf(object));
50 assertTrue(Object.prototype.isPrototypeOf.call(proto, object));
51
52 handler.getPrototypeOf = function () { return Object.prototype };
53 assertTrue(proto.isPrototypeOf(object));
54 assertTrue(Object.prototype.isPrototypeOf.call(proto, object));
55 assertTrue(Object.prototype.isPrototypeOf(object));
56 assertFalse(Object.prototype.isPrototypeOf.call(Array.prototype, object));
57 assertFalse(Array.prototype.isPrototypeOf(object));
58
59 handler.getPrototypeOf = function () { return object };
60 assertTrue(Object.prototype.isPrototypeOf.call(proto, object));
61 assertTrue(proto.isPrototypeOf(object));
62 assertTrue(Object.prototype.isPrototypeOf.call(object, object));
63 assertTrue(object.isPrototypeOf(object));
64
65 handler.getPrototypeOf = function () { throw "foo" };
66 assertTrue(proto.isPrototypeOf(object));
67 assertTrue(Object.prototype.isPrototypeOf.call(proto, object));
68 assertThrows(()=> Object.prototype.isPrototypeOf(object));
69 assertThrows(()=> Object.prototype.isPrototypeOf.call(Array.prototype, object) );
70 assertThrows(()=> Array.prototype.isPrototypeOf(object));
71 })();
72
73 (function () {
74 var handler = {};
75 var object = new Proxy({}, handler);
76 var proto = {};
77
78 assertFalse(Object.prototype.isPrototypeOf.call(object, object));
79 assertFalse(Object.prototype.isPrototypeOf.call(proto, object));
80 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, object));
81
82 handler.getPrototypeOf = function () { return proto };
83 assertTrue(Object.prototype.isPrototypeOf.call(proto, object));
84 assertFalse(Object.prototype.isPrototypeOf.call({}, object));
85 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, object));
86
87 handler.getPrototypeOf = function () { return object };
88 assertTrue(Object.prototype.isPrototypeOf.call(object, object));
89
90 handler.getPrototypeOf = function () { throw "foo" };
91 assertThrows(()=> Object.prototype.isPrototypeOf.call(object, object));
92 assertThrows(()=> Object.prototype.isPrototypeOf(object));
93 })();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/proxies-get-own-property-descriptor.js ('k') | test/mjsunit/harmony/proxies-global-reference.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698