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

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

Issue 1509603005: [runtime] [proxy] implement [[Construct]] (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2015-12-03_JSProxy_Call_1499593003
Patch Set: use add instruction on ia32 + x87 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
« src/runtime/runtime-proxy.cc ('K') | « src/x87/builtins-x87.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 --harmony-reflect
6
7 (function testNonConstructable() {
8 var proxy = new Proxy({},{});
9 assertThrows(function(){ new proxy() }, TypeError);
10
11 var proxy2 = new Proxy(proxy, {});
12 assertThrows(function(){ proxy2() }, TypeError);
13 })();
14
15 (function testFailingConstructRevoked() {
16 var pair = Proxy.revocable(Array, {});
17 var instance = new pair.proxy();
18 pair.revoke();
19 assertThrows(function(){ new pair.proxy() }, TypeError);
20 })();
21
22 (function testFailingGetTrap() {
23 var handler = {
24 get: function() {
25 throw TypeError();
26 }
27 }
28 var proxy = new Proxy({},{});
29 var proxy2 = new Proxy({}, proxy);
30 assertThrows(function(){ new proxy2() }, TypeError);
31 })();
32
33 (function testConstructFallback() {
34 var called = false;
35 function Target() {
36 called = true;
37 this.property1 = 'value1';
38 };
39 Target.prototype = {};
40 var proxy = new Proxy(Target, {});
41
42 assertFalse(called);
43 var instance = new proxy();
44 assertTrue(called);
45 assertEquals('value1', instance.property1);
46 assertSame(Target.prototype, Reflect.getPrototypeOf(instance));
47
48 var proxy2 = new Proxy(proxy, {});
49 called = false;
50 var instance2 = new proxy2();
51 assertTrue(called);
52 assertEquals('value1', instance2.property1);
53 assertSame(Target.prototype, Reflect.getPrototypeOf(instance));
54 })();
55
56 (function testConstructTrapDirectReturn() {
57 function Target(a, b) {
58 this.sum = a + b;
59 };
60 var handler = {
61 construct: function(t, c, args) {
62 return { sum: 42 };
63 }
64 };
65 var proxy = new Proxy(Target, handler);
66 assertEquals(42, (new proxy(1, 2)).sum);
67 })();
68
69 (function testConstructTrap() {
70 function Target(arg1, arg2) {
71 this.arg1 = arg1;
72 this.arg2 = arg2;
73 }
74 var seend_target, seen_arguments, seen_new_target;
Toon Verwaest 2015/12/08 20:27:22 seend? :)
Camillo Bruni 2015/12/09 12:15:44 see, seen, seend, isn't that obivous?
75 var handler = {
76 construct: function(target, args, new_target) {
77 seen_target = target;
78 seen_arguments = args;
79 seen_new_target = new_target;
80 return Reflect.construct(target, args, new_target);
81 }
82 }
83 var proxy = new Proxy(Target, handler);
84 var instance = new proxy('a', 'b');
85 assertEquals(Target, seen_target);
86 assertEquals(['a','b'], seen_arguments);
87 assertEquals(proxy, seen_new_target);
88 assertEquals('a', instance.arg1);
89 assertEquals('b', instance.arg2);
90
91 var instance2 = Reflect.construct(proxy, ['a1', 'b1'], Array);
92 assertEquals(Target, seen_target);
93 assertEquals(['a1', 'b1'], seen_arguments);
94 assertEquals(Array, seen_new_target);
95 assertEquals('a1', instance2.arg1);
96 assertEquals('b1', instance2.arg2);
97 })()
OLDNEW
« src/runtime/runtime-proxy.cc ('K') | « src/x87/builtins-x87.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698