OLD | NEW |
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 |
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([1, 2, ...[3, 4], 5])); |
49 // assertTrue(%IsStrong([])); | 111 assertTrue(%IsStrong([[[]]])); |
50 // assertTrue(%IsStrong([1, 2, 3])); | 112 assertTrue(%IsStrong([[1], {}, [[3]]])); |
51 })(0); // TODO(arv): drop dummy | 113 assertTrue(%IsStrong([[1], {}, [[3]]][0])); |
| 114 assertTrue(%IsStrong([[1], {}, [[3]]][1])); |
| 115 assertTrue(%IsStrong([[1], {}, [[3]]][2])); |
| 116 assertTrue(%IsStrong([[1], {}, [[3]]][2][0])); |
| 117 })(); |
52 | 118 |
53 (function WeakFunctionLiterals() { | 119 (function WeakFunctionLiterals() { |
54 function f() {} | 120 function f() {} |
55 assertTrue(!%IsStrong(f)); | 121 assertTrue(!%IsStrong(f)); |
56 assertTrue(!%IsStrong(function(){})); | 122 assertTrue(!%IsStrong(function(){})); |
| 123 assertTrue(!%IsStrong(function f(){})); |
57 assertTrue(!%IsStrong(() => {})); | 124 assertTrue(!%IsStrong(() => {})); |
58 assertTrue(!%IsStrong(x => x)); | 125 assertTrue(!%IsStrong(x => x)); |
59 })(); | 126 assertTrue(!%IsStrong({m(){}}.m)); |
60 | 127 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
61 (function StrongFunctionLiterals(g) { | 128 {get a(){}}, 'a').get)); |
| 129 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
| 130 {set a(x){}}, 'a').set)); |
| 131 assertTrue(!%IsStrong((class {static m(){}}).m)); |
| 132 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
| 133 class {static get a(){}}, 'a').get)); |
| 134 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
| 135 class {static set a(x){}}, 'a').set)); |
| 136 assertTrue(!%IsStrong((new class {m(){}}).m)); |
| 137 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
| 138 (class {get a(){}}).prototype, 'a').get)); |
| 139 assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
| 140 (class {set a(x){}}).prototype, 'a').set)); |
| 141 })(); |
| 142 |
| 143 (function StrongFunctionLiterals() { |
62 'use strong'; | 144 'use strong'; |
63 function f() {} | 145 function f() {} |
64 assertTrue(%IsStrong(f)); | 146 assertTrue(%IsStrong(f)); |
65 assertTrue(%IsStrong(g)); | |
66 assertTrue(%IsStrong(function(){})); | 147 assertTrue(%IsStrong(function(){})); |
| 148 assertTrue(%IsStrong(function f(){})); |
67 assertTrue(%IsStrong(() => {})); | 149 assertTrue(%IsStrong(() => {})); |
68 assertTrue(%IsStrong(x => x)); | 150 assertTrue(%IsStrong(x => x)); |
69 })(function() { 'use strong' }); | 151 assertTrue(%IsStrong({m(){}}.m)); |
| 152 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 153 {get a(){}}, 'a').get)); |
| 154 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 155 {set a(x){}}, 'a').set)); |
| 156 assertTrue(%IsStrong((class {static m(){}}).m)); |
| 157 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 158 class {static get a(){}}, 'a').get)); |
| 159 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 160 class {static set a(x){}}, 'a').set)); |
| 161 assertTrue(%IsStrong((new class {m(){}}).m)); |
| 162 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 163 (class {get a(){}}).prototype, 'a').get)); |
| 164 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 165 (class {set a(x){}}).prototype, 'a').set)); |
| 166 })(); |
| 167 |
| 168 (function SelfStrongFunctionLiterals() { |
| 169 function f() {'use strong'} |
| 170 assertTrue(%IsStrong(f)); |
| 171 assertTrue(%IsStrong(function(){'use strong'})); |
| 172 assertTrue(%IsStrong(function f(){'use strong'})); |
| 173 assertTrue(%IsStrong(() => {'use strong'})); |
| 174 assertTrue(%IsStrong(x => {'use strong'})); |
| 175 assertTrue(%IsStrong({m(){'use strong'}}.m)); |
| 176 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 177 {get a(){'use strong'}}, 'a').get)); |
| 178 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 179 {set a(x){'use strong'}}, 'a').set)); |
| 180 assertTrue(%IsStrong((class {static m(){'use strong'}}).m)); |
| 181 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 182 class {static get a(){'use strong'}}, 'a').get)); |
| 183 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 184 class {static set a(x){'use strong'}}, 'a').set)); |
| 185 assertTrue(%IsStrong((new class {m(){'use strong'}}).m)); |
| 186 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 187 (class {get a(){'use strong'}}).prototype, 'a').get)); |
| 188 assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
| 189 (class {set a(x){'use strong'}}).prototype, 'a').set)); |
| 190 })(); |
| 191 |
| 192 (function WeakGeneratorLiterals() { |
| 193 function* g() {} |
| 194 assertTrue(!%IsStrong(g)); |
| 195 assertTrue(!%IsStrong(function*(){})); |
| 196 assertTrue(!%IsStrong(function* g(){})); |
| 197 assertTrue(!%IsStrong({*m(){}}.m)); |
| 198 assertTrue(!%IsStrong((class {static *m(){}}).m)); |
| 199 assertTrue(!%IsStrong((new class {*m(){}}).m)); |
| 200 })(); |
| 201 |
| 202 (function StrongGeneratorLiterals() { |
| 203 'use strong'; |
| 204 function* g() {} |
| 205 assertTrue(%IsStrong(g)); |
| 206 assertTrue(%IsStrong(function*(){})); |
| 207 assertTrue(%IsStrong(function* g(){})); |
| 208 assertTrue(%IsStrong({*m(){}}.m)); |
| 209 assertTrue(%IsStrong((class {static *m(){}}).m)); |
| 210 assertTrue(%IsStrong((new class {*m(){}}).m)); |
| 211 })(); |
| 212 |
| 213 (function SelfStrongGeneratorLiterals() { |
| 214 function* g() {'use strong'} |
| 215 assertTrue(%IsStrong(g)); |
| 216 assertTrue(%IsStrong(function*(){'use strong'})); |
| 217 assertTrue(%IsStrong(function* g(){'use strong'})); |
| 218 assertTrue(%IsStrong({*m(){'use strong'}}.m)); |
| 219 assertTrue(%IsStrong((class {static *m(){'use strong'}}).m)); |
| 220 assertTrue(%IsStrong((new class {*m(){'use strong'}}).m)); |
| 221 })(); |
| 222 |
| 223 (function WeakClassLiterals() { |
| 224 function assertWeakClass(C) { |
| 225 assertTrue(!%IsStrong(C)); |
| 226 assertTrue(!%IsStrong(C.prototype)); |
| 227 } |
| 228 class C {}; |
| 229 class D extends C {}; |
| 230 class E extends Object {}; |
| 231 class F extends null {}; |
| 232 const S = (() => {'use strong'; return class {}})(); |
| 233 class G extends S {}; |
| 234 assertWeakClass(C); |
| 235 assertWeakClass(D); |
| 236 assertWeakClass(E); |
| 237 assertWeakClass(F); |
| 238 assertWeakClass(G); |
| 239 assertWeakClass(class {}); |
| 240 assertWeakClass(class extends Object {}); |
| 241 assertWeakClass(class extends null {}); |
| 242 assertWeakClass(class extends C {}); |
| 243 assertWeakClass(class extends S {}); |
| 244 assertWeakClass(class extends class {} {}); |
| 245 assertWeakClass(class C {}); |
| 246 assertWeakClass(class D extends Object {}); |
| 247 assertWeakClass(class D extends null {}); |
| 248 assertWeakClass(class D extends C {}); |
| 249 assertWeakClass(class D extends S {}); |
| 250 assertWeakClass(class D extends class {} {}); |
| 251 })(); |
| 252 |
| 253 (function StrongClassLiterals() { |
| 254 'use strong'; |
| 255 function assertStrongClass(C) { |
| 256 assertTrue(%IsStrong(C)); |
| 257 // TODO(rossberg): prototype object is not yet strongified |
| 258 // assertTrue(%IsStrong(C.prototype)); |
| 259 } |
| 260 class C {}; |
| 261 class D extends C {}; |
| 262 class E extends Object {}; |
| 263 class F extends null {}; |
| 264 const W = (1, eval)(() => {'use strict'; return class {}})(); |
| 265 class G extends W {}; |
| 266 assertStrongClass(C); |
| 267 assertStrongClass(D); |
| 268 assertStrongClass(E); |
| 269 assertStrongClass(F); |
| 270 assertStrongClass(G); |
| 271 assertStrongClass(class {}); |
| 272 assertStrongClass(class extends Object {}); |
| 273 assertStrongClass(class extends null {}); |
| 274 assertStrongClass(class extends C {}); |
| 275 assertStrongClass(class extends W {}); |
| 276 assertStrongClass(class extends class {} {}); |
| 277 assertStrongClass(class C {}); |
| 278 assertStrongClass(class D extends Object {}); |
| 279 assertStrongClass(class D extends null {}); |
| 280 assertStrongClass(class D extends C {}); |
| 281 assertStrongClass(class D extends W {}); |
| 282 assertStrongClass(class D extends class {} {}); |
| 283 })(); |
70 | 284 |
71 (function WeakRegExpLiterals() { | 285 (function WeakRegExpLiterals() { |
72 assertTrue(!%IsStrong(/abc/)); | 286 assertTrue(!%IsStrong(/abc/)); |
73 })(); | 287 })(); |
74 | 288 |
75 (function StrongRegExpLiterals() { | 289 (function StrongRegExpLiterals() { |
76 'use strong'; | 290 'use strong'; |
77 // TODO(rossberg): implement strong regexp literals | 291 // TODO(rossberg): implement strong regexp literals |
78 // assertTrue(%IsStrong(/abc/)); | 292 // assertTrue(%IsStrong(/abc/)); |
79 })(); | 293 })(); |
OLD | NEW |