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

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

Issue 1481383003: [runtime] [proxy] Adding [[SetPrototypeOf]] trap. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: using new proxy method 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/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 assertThrows(function() { Object.setPrototypeOf(proxy, undefined) }, TypeError);
15 assertThrows(function() { Object.setPrototypeOf(proxy, 1) }, TypeError);
16
17 var prototype = [1];
18 assertSame(proxy, Object.setPrototypeOf(proxy, prototype));
19 assertSame(prototype, Object.getPrototypeOf(proxy));
20 assertSame(prototype, Object.getPrototypeOf(target));
21
22 handler.setPrototypeOf = function(target, proto) {
23 return false;
24 };
25 assertThrows(function() { Object.setPrototypeOf(proxy, {a:1}) }, TypeError);
26
27 handler.setPrototypeOf = function(target, proto) {
28 return undefined;
29 };
30 assertThrows(function() { Object.setPrototypeOf(proxy, {a:2}) }, TypeError);
31
32 handler.setPrototypeOf = function(proto) {};
33 assertThrows(function() { Object.setPrototypeOf(proxy, {a:3}) }, TypeError);
34
35 handler.setPrototypeOf = function(target, proto) {
36 throw Error();
37 };
38 assertThrows(function() { Object.setPrototypeOf(proxy, {a:4}) }, Error);
39
40 var seen_prototype;
41 var seen_target;
42 handler.setPrototypeOf = function(target, proto) {
43 seen_target = target;
44 seen_prototype = proto;
45 return true;
46 }
47 assertSame(Object.setPrototypeOf(proxy, {a:5}), proxy);
48 assertSame(target, seen_target);
49 assertEquals({a:5}, seen_prototype);
50
51 // Target is a Proxy:
52 var target2 = new Proxy(target, {});
53 var proxy2 = new Proxy(target2, {});
54 assertSame(Object.getPrototypeOf(proxy2), target.__proto__ );
55
56 prototype = [2,3];
57 assertSame(proxy2, Object.setPrototypeOf(proxy2, prototype));
58 assertSame(prototype, Object.getPrototypeOf(proxy2));
59 assertSame(prototype, Object.getPrototypeOf(target));
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698