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

Side by Side Diff: test/mjsunit/harmony/reflect.js

Issue 1379313002: [es6] Implement parts of the Reflect object. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase and use strict Created 5 years, 2 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
« no previous file with comments | « src/objects.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-reflect
6
7 // TODO(neis): Test with proxies.
8
9
10
11 ////////////////////////////////////////////////////////////////////////////////
12 // (Auxiliaries)
13
14
15 "use strict";
16
17 var global = this;
18
19 var sym = Symbol("gaga");
20
21 var objects = [
22 {},
23 [],
24 function() {},
25 function() {
26 return arguments;
27 }(),
28 function() {
29 'use strict';
30 return arguments;
31 }(),
32 Object(1),
33 Object(true),
34 Object('bla'),
35 new Date,
36 new RegExp,
37 new Set,
38 new Map,
39 new WeakMap,
40 new WeakSet,
41 new ArrayBuffer(10),
42 new Int32Array(5),
43 Object,
44 Function,
45 Date,
46 RegExp,
47 global
48 ];
49
50 function prepare(tgt) {
51 tgt["bla"] = true;
52 tgt[4] = 42;
53 tgt[sym] = "foo";
54 tgt["noconf"] = 43;
55 Object.defineProperty(tgt, "noconf", {configurable: false});
56 }
57
58
59
60 ////////////////////////////////////////////////////////////////////////////////
61 // Reflect.get
62
63
64 (function testReflectGetArity() {
65 assertEquals(3, Reflect.get.length);
66 })();
67
68
69 (function testReflectGetOnNonObject() {
70 assertThrows(function() { Reflect.get(); }, TypeError);
71 assertThrows(function() { Reflect.get(42, "bla"); }, TypeError);
72 assertThrows(function() { Reflect.get(null, "bla"); }, TypeError);
73 })();
74
75
76 (function testReflectGetKeyConversion() {
77 var tgt = {bla: 42};
78 var a = { [Symbol.toPrimitive]: function() { return "bla" } };
79 var b = { [Symbol.toPrimitive]: function() { throw "gaga" } };
80 assertEquals(42, Reflect.get(tgt, a));
81 assertThrows(function() { Reflect.get(tgt, b); }, "gaga");
82 })();
83
84
85 (function testReflectGetOnObject() {
86 for (let tgt of objects) {
87 prepare(tgt);
88 assertEquals(true, Reflect.get(tgt, "bla"));
89 assertEquals(42, Reflect.get(tgt, 4));
90 assertEquals(42, Reflect.get(tgt, "4"));
91 assertEquals("foo", Reflect.get(tgt, sym));
92 assertEquals(undefined, Reflect.get(tgt, "doesnotexist"));
93 assertEquals(undefined, Reflect.get(tgt, 666));
94 }
95 })();
96
97
98
99 ////////////////////////////////////////////////////////////////////////////////
100 // Reflect.has
101
102
103 (function testReflectHasArity() {
104 assertEquals(2, Reflect.has.length);
105 })();
106
107
108 (function testReflectHasOnNonObject() {
109 assertThrows(function() { Reflect.has(); }, TypeError);
110 assertThrows(function() { Reflect.has(42, "bla"); }, TypeError);
111 assertThrows(function() { Reflect.has(null, "bla"); }, TypeError);
112 })();
113
114
115 (function testReflectHasKeyConversion() {
116 var tgt = {bla: 42};
117 var a = { [Symbol.toPrimitive]: function() { return "bla" } };
118 var b = { [Symbol.toPrimitive]: function() { throw "gaga" } };
119 assertTrue(Reflect.has(tgt, a));
120 assertThrows(function() { Reflect.has(tgt, b); }, "gaga");
121 })();
122
123
124 (function testReflectHasOnObject() {
125 for (let tgt of objects) {
126 prepare(tgt);
127 assertTrue(Reflect.has(tgt, "bla"));
128 assertTrue(Reflect.has(tgt, 4));
129 assertTrue(Reflect.has(tgt, "4"));
130 assertTrue(Reflect.has(tgt, sym));
131 assertFalse(Reflect.has(tgt, "doesnotexist"));
132 assertFalse(Reflect.has(tgt, 666));
133 }
134 })();
135
136
137
138 ////////////////////////////////////////////////////////////////////////////////
139 // Reflect.deleteProperty
140
141
142 (function testReflectDeletePropertyArity() {
143 assertEquals(2, Reflect.deleteProperty.length);
144 })();
145
146
147 (function testReflectDeletePropertyOnNonObject() {
148 assertThrows(function() { Reflect.deleteProperty(); }, TypeError);
149 assertThrows(function() { Reflect.deleteProperty(42, "bla"); }, TypeError);
150 assertThrows(function() { Reflect.deleteProperty(null, "bla"); }, TypeError);
151 })();
152
153
154 (function testReflectDeletePropertyKeyConversion() {
155 var tgt = {bla: 42};
156 var a = { [Symbol.toPrimitive]: function() { return "bla" } };
157 var b = { [Symbol.toPrimitive]: function() { throw "gaga" } };
158 assertTrue(Reflect.deleteProperty(tgt, a));
159 assertThrows(function() { Reflect.deleteProperty(tgt, b); }, "gaga");
160 })();
161
162
163 (function testReflectDeletePropertyOnObject() {
164 for (let tgt of objects) {
165 prepare(tgt);
166 assertTrue(Reflect.deleteProperty(tgt, "bla"));
167 assertEquals(undefined, Object.getOwnPropertyDescriptor(tgt, "bla"));
168 if (tgt instanceof Int32Array) {
169 assertFalse(Reflect.deleteProperty(tgt, 4));
170 } else {
171 assertTrue(Reflect.deleteProperty(tgt, 4));
172 assertEquals(undefined, Object.getOwnPropertyDescriptor(tgt, 4));
173 }
174 assertTrue(Reflect.deleteProperty(tgt, sym));
175 assertEquals(undefined, Object.getOwnPropertyDescriptor(tgt, sym));
176 assertTrue(Reflect.deleteProperty(tgt, "doesnotexist"));
177 assertTrue(Reflect.deleteProperty(tgt, 666));
178 assertFalse(Reflect.deleteProperty(tgt, "noconf"));
179 assertEquals(43, tgt.noconf);
180 }
181 })();
182
183
184
185 ////////////////////////////////////////////////////////////////////////////////
186 // Reflect.isExtensible
187
188
189 (function testReflectIsExtensibleArity() {
190 assertEquals(1, Reflect.isExtensible.length);
191 })();
192
193
194 (function testReflectIsExtensibleOnNonObject() {
195 assertThrows(function() { Reflect.isExtensible(); }, TypeError);
196 assertThrows(function() { Reflect.isExtensible(42); }, TypeError);
197 assertThrows(function() { Reflect.isExtensible(null); }, TypeError);
198 })();
199
200
201 (function testReflectIsExtensibleOnObject() {
202 // This should be the last test as it modifies the objects irreversibly.
203 for (let tgt of objects) {
204 prepare(tgt);
205 if (tgt instanceof Int32Array) continue; // issue v8:4460
206 assertTrue(Reflect.isExtensible(tgt));
207 Object.preventExtensions(tgt);
208 assertFalse(Reflect.isExtensible(tgt));
209 }
210 })();
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698