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

Side by Side Diff: test/mjsunit/strong/literals.js

Issue 1145213005: [strong] cache strong object literal maps (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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/runtime/runtime-literals.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
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: --strong-mode --allow-natives-syntax 5 // Flags: --strong-mode --allow-natives-syntax
6 // Flags: --harmony-arrow-functions --harmony-rest-parameters 6 // Flags: --harmony-arrow-functions --harmony-rest-parameters
7 // Flags: --harmony-destructuring
7 8
9 'use strict';
8 10
9 (function WeakObjectLiterals() { 11 (function WeakObjectLiterals() {
10 assertTrue(!%IsStrong({})); 12 assertTrue(!%IsStrong({}));
11 assertTrue(!%IsStrong({a: 0, b: 0})); 13 assertTrue(!%IsStrong({a: 0, b: 0}));
14 assertTrue(!%IsStrong({a: [], b: {}}));
15 assertTrue(!%IsStrong({a: [], b: {}}.a));
16 assertTrue(!%IsStrong({a: [], b: {}}.b));
17 assertTrue(!%IsStrong({a: {b: {c: {}}}}.a));
18 assertTrue(!%IsStrong({a: {b: {c: {}}}}.a.b));
19 assertTrue(!%IsStrong({a: {b: {c: {}}}}.a.b.c));
12 assertTrue(!%IsStrong({f: function(){}})); 20 assertTrue(!%IsStrong({f: function(){}}));
13 assertTrue(!%IsStrong(Realm.eval(Realm.current(), 21 assertTrue(!%IsStrong(Realm.eval(Realm.current(),
14 "({f: function(){}})"))); 22 "({f: function(){}})")));
15 })(); 23 })();
16 24
17 (function StrongObjectLiterals() { 25 (function StrongObjectLiterals() {
18 'use strong'; 26 'use strong';
19 assertTrue(%IsStrong({})); 27 assertTrue(%IsStrong({}));
20 assertTrue(%IsStrong({a: 0, b: 0})); 28 assertTrue(%IsStrong({a: 0, b: 0}));
29 assertTrue(%IsStrong({a: [], b: {}}));
30 assertTrue(%IsStrong({a: [], b: {}}.a));
31 assertTrue(%IsStrong({a: [], b: {}}.b));
32 assertTrue(%IsStrong({a: {b: {c: {}}}}.a));
33 assertTrue(%IsStrong({a: {b: {c: {}}}}.a.b));
34 assertTrue(%IsStrong({a: {b: {c: {}}}}.a.b.c));
35 // Maps for literals with too many properties are not cached.
36 assertTrue(%IsStrong({
37 x001: 0, x002: 0, x003: 0, x004: 0, x005: 0,
38 x006: 0, x007: 0, x008: 0, x009: 0, x010: 0,
39 x011: 0, x012: 0, x013: 0, x014: 0, x015: 0,
40 x016: 0, x017: 0, x018: 0, x019: 0, x020: 0,
41 x021: 0, x022: 0, x023: 0, x024: 0, x025: 0,
42 x026: 0, x027: 0, x028: 0, x029: 0, x030: 0,
43 x031: 0, x032: 0, x033: 0, x034: 0, x035: 0,
44 x036: 0, x037: 0, x038: 0, x039: 0, x040: 0,
45 x041: 0, x042: 0, x043: 0, x044: 0, x045: 0,
46 x046: 0, x047: 0, x048: 0, x049: 0, x050: 0,
47 x051: 0, x052: 0, x053: 0, x054: 0, x055: 0,
48 x056: 0, x057: 0, x058: 0, x059: 0, x060: 0,
49 x061: 0, x062: 0, x063: 0, x064: 0, x065: 0,
50 x066: 0, x067: 0, x068: 0, x069: 0, x070: 0,
51 x071: 0, x072: 0, x073: 0, x074: 0, x075: 0,
52 x076: 0, x077: 0, x078: 0, x079: 0, x080: 0,
53 x081: 0, x082: 0, x083: 0, x084: 0, x085: 0,
54 x086: 0, x087: 0, x088: 0, x089: 0, x090: 0,
55 x091: 0, x092: 0, x093: 0, x094: 0, x095: 0,
56 x096: 0, x097: 0, x098: 0, x099: 0, x100: 0,
57 x101: 0, x102: 0, x103: 0, x104: 0, x105: 0,
58 x106: 0, x107: 0, x108: 0, x109: 0, x110: 0,
59 x111: 0, x112: 0, x113: 0, x114: 0, x115: 0,
60 x116: 0, x117: 0, x118: 0, x119: 0, x120: 0,
61 x121: 0, x122: 0, x123: 0, x124: 0, x125: 0,
62 x126: 0, x127: 0, x128: 0, x129: 0, x130: 0,
63 x131: 0, x132: 0, x133: 0, x134: 0, x135: 0,
64 x136: 0, x137: 0, x138: 0, x139: 0, x140: 0,
65 x141: 0, x142: 0, x143: 0, x144: 0, x145: 0,
66 x146: 0, x147: 0, x148: 0, x149: 0, x150: 0,
67 x151: 0, x152: 0, x153: 0, x154: 0, x155: 0,
68 x156: 0, x157: 0, x158: 0, x159: 0, x160: 0,
69 x161: 0, x162: 0, x163: 0, x164: 0, x165: 0,
70 x166: 0, x167: 0, x168: 0, x169: 0, x170: 0,
71 x171: 0, x172: 0, x173: 0, x174: 0, x175: 0,
72 x176: 0, x177: 0, x178: 0, x179: 0, x180: 0,
73 x181: 0, x182: 0, x183: 0, x184: 0, x185: 0,
74 x186: 0, x187: 0, x188: 0, x189: 0, x190: 0,
75 x191: 0, x192: 0, x193: 0, x194: 0, x195: 0,
76 x196: 0, x197: 0, x198: 0, x199: 0, x200: 0,
77 }));
21 assertTrue(%IsStrong({__proto__: {}, get a() {}, set b(x) {}})); 78 assertTrue(%IsStrong({__proto__: {}, get a() {}, set b(x) {}}));
22 assertTrue(%IsStrong({[Date() + ""]: 0, [Symbol()]: 0})); 79 assertTrue(%IsStrong({[Date() + ""]: 0, [Symbol()]: 0}));
23 // TODO(rossberg): super does not work yet 80 assertTrue(%IsStrong({m() { super.m() }}));
24 // assertTrue(%IsStrong({m() { super.m() }}));
25 // Object literals with constant functions are treated specially, 81 // Object literals with constant functions are treated specially,
26 // but currently only on the toplevel. 82 // but currently only on the toplevel (using Realm.eval to emulate that).
27 assertTrue(%IsStrong({f: function(){}})); 83 assertTrue(%IsStrong({f: function(){}}));
28 // TODO(rossberg): implement strong object literals with functions 84 assertTrue(%IsStrong(Realm.eval(Realm.current(),
29 // assertTrue(%IsStrong(Realm.eval(Realm.current(), 85 "'use strong'; ({f: function(){}})")));
30 // "'use strong'; ({f: function(){}})")));
31 })(); 86 })();
32 87
33 (function WeakArrayLiterals(...args) { 88 (function WeakArrayLiterals(...args) {
89 let [...r] = [];
34 assertTrue(!%IsStrong(args)); 90 assertTrue(!%IsStrong(args));
91 assertTrue(!%IsStrong(r));
35 assertTrue(!%IsStrong([])); 92 assertTrue(!%IsStrong([]));
36 assertTrue(!%IsStrong([1, 2, 3])); 93 assertTrue(!%IsStrong([1, 2, 3]));
37 Array.prototype = {} 94 assertTrue(!%IsStrong([[[]]]));
38 assertTrue(!%IsStrong([])); 95 assertTrue(!%IsStrong([[1], {}, [[3]]]));
39 assertTrue(!%IsStrong([1, 2, 3])); 96 assertTrue(!%IsStrong([[1], {}, [[3]]][0]));
97 assertTrue(!%IsStrong([[1], {}, [[3]]][1]));
98 assertTrue(!%IsStrong([[1], {}, [[3]]][2]));
99 assertTrue(!%IsStrong([[1], {}, [[3]]][2][0]));
40 })(); 100 })();
41 101
42 (function StrongArrayLiterals(...args) { 102 (function StrongArrayLiterals(...args) {
43 'use strong'; 103 'use strong';
44 // TODO(rossberg): implement strong array literals 104 let [...r] = [];
105 // TODO(rossberg): teach strongness to FastCloneShallowArrayStub
arv (Not doing code reviews) 2015/05/21 13:09:55 Also, spread in arrays literals. It will have the
rossberg 2015/05/21 17:05:09 Done.
45 // assertTrue(%IsStrong(args)); 106 // assertTrue(%IsStrong(args));
107 // assertTrue(%IsStrong(r));
46 // assertTrue(%IsStrong([])); 108 // assertTrue(%IsStrong([]));
47 // assertTrue(%IsStrong([1, 2, 3])); 109 // assertTrue(%IsStrong([1, 2, 3]));
48 // Array.prototype = {} 110 assertTrue(%IsStrong([[[]]]));
49 // assertTrue(%IsStrong([])); 111 assertTrue(%IsStrong([[1], {}, [[3]]]));
50 // assertTrue(%IsStrong([1, 2, 3])); 112 assertTrue(%IsStrong([[1], {}, [[3]]][0]));
51 })(0); // TODO(arv): drop dummy 113 assertTrue(%IsStrong([[1], {}, [[3]]][1]));
114 assertTrue(%IsStrong([[1], {}, [[3]]][2]));
115 assertTrue(%IsStrong([[1], {}, [[3]]][2][0]));
116 })();
52 117
53 (function WeakFunctionLiterals() { 118 (function WeakFunctionLiterals() {
54 function f() {} 119 function f() {}
55 assertTrue(!%IsStrong(f)); 120 assertTrue(!%IsStrong(f));
56 assertTrue(!%IsStrong(function(){})); 121 assertTrue(!%IsStrong(function(){}));
122 assertTrue(!%IsStrong(function f(){}));
57 assertTrue(!%IsStrong(() => {})); 123 assertTrue(!%IsStrong(() => {}));
58 assertTrue(!%IsStrong(x => x)); 124 assertTrue(!%IsStrong(x => x));
59 })(); 125 assertTrue(!%IsStrong({m(){}}.m));
60 126 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor(
61 (function StrongFunctionLiterals(g) { 127 {get a(){}}, 'a').get));
128 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor(
129 {set a(x){}}, 'a').set));
130 assertTrue(!%IsStrong((class {static m(){}}).m));
131 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor(
132 class {static get a(){}}, 'a').get));
133 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor(
134 class {static set a(x){}}, 'a').set));
135 assertTrue(!%IsStrong((new class {m(){}}).m));
136 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor(
137 (class {get a(){}}).prototype, 'a').get));
138 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor(
139 (class {set a(x){}}).prototype, 'a').set));
140 })();
141
142 (function StrongFunctionLiterals() {
62 'use strong'; 143 'use strong';
63 function f() {} 144 function f() {}
64 assertTrue(%IsStrong(f)); 145 assertTrue(%IsStrong(f));
65 assertTrue(%IsStrong(g));
66 assertTrue(%IsStrong(function(){})); 146 assertTrue(%IsStrong(function(){}));
147 assertTrue(%IsStrong(function f(){}));
67 assertTrue(%IsStrong(() => {})); 148 assertTrue(%IsStrong(() => {}));
68 assertTrue(%IsStrong(x => x)); 149 assertTrue(%IsStrong(x => x));
69 })(function() { 'use strong' }); 150 assertTrue(%IsStrong({m(){}}.m));
151 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
152 {get a(){}}, 'a').get));
153 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
154 {set a(x){}}, 'a').set));
155 assertTrue(%IsStrong((class {static m(){}}).m));
156 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
157 class {static get a(){}}, 'a').get));
158 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
159 class {static set a(x){}}, 'a').set));
160 assertTrue(%IsStrong((new class {m(){}}).m));
161 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
162 (class {get a(){}}).prototype, 'a').get));
163 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
164 (class {set a(x){}}).prototype, 'a').set));
165 })();
166
167 (function SelfStrongFunctionLiterals() {
168 function f() {'use strong'}
169 assertTrue(%IsStrong(f));
170 assertTrue(%IsStrong(function(){'use strong'}));
171 assertTrue(%IsStrong(function f(){'use strong'}));
172 assertTrue(%IsStrong(() => {'use strong'}));
173 assertTrue(%IsStrong(x => {'use strong'}));
174 assertTrue(%IsStrong({m(){'use strong'}}.m));
175 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
176 {get a(){'use strong'}}, 'a').get));
177 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
178 {set a(x){'use strong'}}, 'a').set));
179 assertTrue(%IsStrong((class {static m(){'use strong'}}).m));
180 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
181 class {static get a(){'use strong'}}, 'a').get));
182 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
183 class {static set a(x){'use strong'}}, 'a').set));
184 assertTrue(%IsStrong((new class {m(){'use strong'}}).m));
185 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
186 (class {get a(){'use strong'}}).prototype, 'a').get));
187 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor(
188 (class {set a(x){'use strong'}}).prototype, 'a').set));
189 })();
190
191 (function WeakGeneratorLiterals() {
192 function* g() {}
193 assertTrue(!%IsStrong(g));
194 assertTrue(!%IsStrong(function*(){}));
195 assertTrue(!%IsStrong(function* g(){}));
196 assertTrue(!%IsStrong({*m(){}}.m));
197 assertTrue(!%IsStrong((class {static *m(){}}).m));
198 assertTrue(!%IsStrong((new class {*m(){}}).m));
199 })();
200
201 (function StrongGeneratorLiterals() {
202 'use strong';
203 function* g() {}
204 assertTrue(%IsStrong(g));
205 assertTrue(%IsStrong(function*(){}));
206 assertTrue(%IsStrong(function* g(){}));
207 assertTrue(%IsStrong({*m(){}}.m));
208 assertTrue(%IsStrong((class {static *m(){}}).m));
209 assertTrue(%IsStrong((new class {*m(){}}).m));
210 })();
211
212 (function SelfStrongGeneratorLiterals() {
213 function* g() {'use strong'}
214 assertTrue(%IsStrong(g));
215 assertTrue(%IsStrong(function*(){'use strong'}));
216 assertTrue(%IsStrong(function* g(){'use strong'}));
217 assertTrue(%IsStrong({*m(){'use strong'}}.m));
218 assertTrue(%IsStrong((class {static *m(){'use strong'}}).m));
219 assertTrue(%IsStrong((new class {*m(){'use strong'}}).m));
220 })();
221
222 (function WeakClassLiterals() {
223 function assertWeakClass(C) {
224 assertTrue(!%IsStrong(C));
225 assertTrue(!%IsStrong(C.prototype));
226 }
227 class C {};
228 class D extends C {};
229 class E extends Object {};
230 class F extends null {};
231 const S = (() => {'use strong'; return class {}})();
232 class G extends S {};
233 assertWeakClass(C);
234 assertWeakClass(D);
235 assertWeakClass(E);
236 assertWeakClass(F);
237 assertWeakClass(G);
238 assertWeakClass(class {});
239 assertWeakClass(class extends Object {});
240 assertWeakClass(class extends null {});
241 assertWeakClass(class extends C {});
242 assertWeakClass(class extends S {});
243 assertWeakClass(class extends class {} {});
244 assertWeakClass(class C {});
245 assertWeakClass(class D extends Object {});
246 assertWeakClass(class D extends null {});
247 assertWeakClass(class D extends C {});
248 assertWeakClass(class D extends S {});
249 assertWeakClass(class D extends class {} {});
250 })();
251
252 (function StrongClassLiterals() {
253 'use strong';
254 function assertStrongClass(C) {
255 assertTrue(%IsStrong(C));
256 // TODO(rossberg): prototype object is not yet strongified
257 // assertTrue(%IsStrong(C.prototype));
258 }
259 class C {};
260 class D extends C {};
261 class E extends Object {};
262 class F extends null {};
263 const W = (1, eval)(() => {'use strict'; return class {}})();
264 class G extends W {};
265 assertStrongClass(C);
266 assertStrongClass(D);
267 assertStrongClass(E);
268 assertStrongClass(F);
269 assertStrongClass(G);
270 assertStrongClass(class {});
271 assertStrongClass(class extends Object {});
272 assertStrongClass(class extends null {});
273 assertStrongClass(class extends C {});
274 assertStrongClass(class extends W {});
275 assertStrongClass(class extends class {} {});
276 assertStrongClass(class C {});
277 assertStrongClass(class D extends Object {});
278 assertStrongClass(class D extends null {});
279 assertStrongClass(class D extends C {});
280 assertStrongClass(class D extends W {});
281 assertStrongClass(class D extends class {} {});
282 })();
70 283
71 (function WeakRegExpLiterals() { 284 (function WeakRegExpLiterals() {
72 assertTrue(!%IsStrong(/abc/)); 285 assertTrue(!%IsStrong(/abc/));
73 })(); 286 })();
74 287
75 (function StrongRegExpLiterals() { 288 (function StrongRegExpLiterals() {
76 'use strong'; 289 'use strong';
77 // TODO(rossberg): implement strong regexp literals 290 // TODO(rossberg): implement strong regexp literals
78 // assertTrue(%IsStrong(/abc/)); 291 // assertTrue(%IsStrong(/abc/));
79 })(); 292 })();
OLDNEW
« no previous file with comments | « src/runtime/runtime-literals.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698