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 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
| 9 //****************************************************************************** |
| 10 // Number function declarations |
9 function inline_add_strong(x, y) { | 11 function inline_add_strong(x, y) { |
10 "use strong"; | 12 "use strong"; |
11 return x + y; | 13 return x + y; |
12 } | 14 } |
13 | 15 |
14 function inline_add_strong_outer(x, y) { | 16 function inline_add_strong_outer(x, y) { |
15 return inline_add_strong(x, y); | 17 return inline_add_strong(x, y); |
16 } | 18 } |
17 | 19 |
18 function inline_sub_strong(x, y) { | 20 function inline_sub_strong(x, y) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 100 |
99 function inline_sar_strong(x, y) { | 101 function inline_sar_strong(x, y) { |
100 "use strong"; | 102 "use strong"; |
101 return x >>> y; | 103 return x >>> y; |
102 } | 104 } |
103 | 105 |
104 function inline_sar_strong_outer(x, y) { | 106 function inline_sar_strong_outer(x, y) { |
105 return inline_sar_strong(x, y); | 107 return inline_sar_strong(x, y); |
106 } | 108 } |
107 | 109 |
| 110 function inline_less_strong(x, y) { |
| 111 "use strong"; |
| 112 return x < y; |
| 113 } |
| 114 |
| 115 function inline_less_strong_outer(x, y) { |
| 116 return inline_less_strong(x, y); |
| 117 } |
| 118 |
| 119 function inline_greater_strong(x, y) { |
| 120 "use strong"; |
| 121 return x > y; |
| 122 } |
| 123 |
| 124 function inline_greater_strong_outer(x, y) { |
| 125 return inline_greater_strong(x, y); |
| 126 } |
| 127 |
| 128 function inline_less_equal_strong(x, y) { |
| 129 "use strong"; |
| 130 return x <= y; |
| 131 } |
| 132 |
| 133 function inline_less_equal_strong_outer(x, y) { |
| 134 return inline_less_equal_strong(x, y); |
| 135 } |
| 136 |
| 137 function inline_greater_equal_strong(x, y) { |
| 138 "use strong"; |
| 139 return x >= y; |
| 140 } |
| 141 |
| 142 function inline_greater_equal_strong_outer(x, y) { |
| 143 return inline_greater_equal_strong(x, y); |
| 144 } |
| 145 |
108 function inline_add(x, y) { | 146 function inline_add(x, y) { |
109 return x + y; | 147 return x + y; |
110 } | 148 } |
111 | 149 |
112 function inline_add_outer_strong(x, y) { | 150 function inline_add_outer_strong(x, y) { |
113 "use strong"; | 151 "use strong"; |
114 return inline_add(x, y); | 152 return inline_add(x, y); |
115 } | 153 } |
116 | 154 |
117 function inline_sub(x, y) { | 155 function inline_sub(x, y) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 235 |
198 function inline_sar(x, y) { | 236 function inline_sar(x, y) { |
199 return x >>> y; | 237 return x >>> y; |
200 } | 238 } |
201 | 239 |
202 function inline_sar_outer_strong(x, y) { | 240 function inline_sar_outer_strong(x, y) { |
203 "use strong"; | 241 "use strong"; |
204 return inline_sar(x, y); | 242 return inline_sar(x, y); |
205 } | 243 } |
206 | 244 |
207 let strong_inner_funcs = [inline_add_strong_outer, inline_sub_strong_outer, | 245 function inline_less(x, y) { |
208 inline_mul_strong_outer, inline_div_strong_outer, | 246 return x < y; |
209 inline_mod_strong_outer, inline_or_strong_outer, | 247 } |
210 inline_and_strong_outer, inline_xor_strong_outer, | |
211 inline_shl_strong_outer, inline_shr_strong_outer]; | |
212 | 248 |
213 let strong_outer_funcs = [inline_add_outer_strong, inline_sub_outer_strong, | 249 function inline_less_outer_strong(x, y) { |
214 inline_mul_outer_strong, inline_div_outer_strong, | 250 "use strong"; |
215 inline_mod_outer_strong, inline_or_outer_strong, | 251 return inline_less(x, y); |
216 inline_and_outer_strong, inline_xor_outer_strong, | 252 } |
217 inline_shl_outer_strong, inline_shr_outer_strong]; | |
218 | 253 |
219 for (let strong_inner_func of strong_inner_funcs) { | 254 function inline_greater(x, y) { |
| 255 return x > y; |
| 256 } |
| 257 |
| 258 function inline_greater_outer_strong(x, y) { |
| 259 "use strong"; |
| 260 return inline_greater(x, y); |
| 261 } |
| 262 |
| 263 function inline_less_equal(x, y) { |
| 264 return x <= y; |
| 265 } |
| 266 |
| 267 function inline_less_equal_outer_strong(x, y) { |
| 268 "use strong"; |
| 269 return inline_less_equal(x, y); |
| 270 } |
| 271 |
| 272 function inline_greater_equal(x, y) { |
| 273 return x >>> y; |
| 274 } |
| 275 |
| 276 function inline_greater_equal_outer_strong(x, y) { |
| 277 "use strong"; |
| 278 return inline_greater_equal(x, y); |
| 279 } |
| 280 |
| 281 //****************************************************************************** |
| 282 // String function declarations |
| 283 function inline_add_string_strong(x, y) { |
| 284 "use strong"; |
| 285 return x + y; |
| 286 } |
| 287 |
| 288 function inline_add_string_strong_outer(x, y) { |
| 289 return inline_add_string_strong(x, y); |
| 290 } |
| 291 |
| 292 function inline_less_string_strong(x, y) { |
| 293 "use strong"; |
| 294 return x < y; |
| 295 } |
| 296 |
| 297 function inline_less_string_strong_outer(x, y) { |
| 298 return inline_less_string_strong(x, y); |
| 299 } |
| 300 |
| 301 function inline_greater_string_strong(x, y) { |
| 302 "use strong"; |
| 303 return x > y; |
| 304 } |
| 305 |
| 306 function inline_greater_string_strong_outer(x, y) { |
| 307 return inline_greater_string_strong(x, y); |
| 308 } |
| 309 |
| 310 function inline_less_equal_string_strong(x, y) { |
| 311 "use strong"; |
| 312 return x <= y; |
| 313 } |
| 314 |
| 315 function inline_less_equal_string_strong_outer(x, y) { |
| 316 return inline_less_equal_string_strong(x, y); |
| 317 } |
| 318 |
| 319 function inline_greater_equal_string_strong(x, y) { |
| 320 "use strong"; |
| 321 return x >= y; |
| 322 } |
| 323 |
| 324 function inline_greater_equal_string_strong_outer(x, y) { |
| 325 return inline_greater_equal_string_strong(x, y); |
| 326 } |
| 327 |
| 328 function inline_add_string(x, y) { |
| 329 return x + y; |
| 330 } |
| 331 |
| 332 function inline_add_string_outer_strong(x, y) { |
| 333 "use strong"; |
| 334 return inline_add_string(x, y); |
| 335 } |
| 336 |
| 337 function inline_less_string(x, y) { |
| 338 return x < y; |
| 339 } |
| 340 |
| 341 function inline_less_string_outer_strong(x, y) { |
| 342 "use strong"; |
| 343 return inline_less_string(x, y); |
| 344 } |
| 345 |
| 346 function inline_greater_string(x, y) { |
| 347 return x > y; |
| 348 } |
| 349 |
| 350 function inline_greater_string_outer_strong(x, y) { |
| 351 "use strong"; |
| 352 return inline_greater_string(x, y); |
| 353 } |
| 354 |
| 355 function inline_less_equal_string(x, y) { |
| 356 return x <= y; |
| 357 } |
| 358 |
| 359 function inline_less_equal_string_outer_strong(x, y) { |
| 360 "use strong"; |
| 361 return inline_less_equal_string(x, y); |
| 362 } |
| 363 |
| 364 function inline_greater_equal_string(x, y) { |
| 365 return x >= y; |
| 366 } |
| 367 |
| 368 function inline_greater_equal_string_outer_strong(x, y) { |
| 369 "use strong"; |
| 370 return inline_greater_equal_string(x, y); |
| 371 } |
| 372 |
| 373 |
| 374 //****************************************************************************** |
| 375 // Testing |
| 376 let strong_inner_funcs_num = [inline_add_strong_outer, inline_sub_strong_outer, |
| 377 inline_mul_strong_outer, inline_div_strong_outer, |
| 378 inline_mod_strong_outer, inline_or_strong_outer, |
| 379 inline_and_strong_outer, inline_xor_strong_outer, |
| 380 inline_shl_strong_outer, inline_shr_strong_outer, |
| 381 inline_less_strong_outer, |
| 382 inline_greater_strong_outer, |
| 383 inline_less_equal_strong_outer, |
| 384 inline_greater_equal_strong_outer]; |
| 385 |
| 386 let strong_outer_funcs_num = [inline_add_outer_strong, inline_sub_outer_strong, |
| 387 inline_mul_outer_strong, inline_div_outer_strong, |
| 388 inline_mod_outer_strong, inline_or_outer_strong, |
| 389 inline_and_outer_strong, inline_xor_outer_strong, |
| 390 inline_shl_outer_strong, inline_shr_outer_strong, |
| 391 inline_less_outer_strong, |
| 392 inline_greater_outer_strong, |
| 393 inline_less_equal_outer_strong, |
| 394 inline_greater_equal_outer_strong]; |
| 395 |
| 396 let strong_inner_funcs_string = [inline_add_string_strong_outer, |
| 397 inline_less_string_strong_outer, |
| 398 inline_greater_string_strong_outer, |
| 399 inline_less_equal_string_strong_outer, |
| 400 inline_greater_equal_string_strong_outer]; |
| 401 |
| 402 let strong_outer_funcs_string = [inline_add_string_outer_strong, |
| 403 inline_less_string_outer_strong, |
| 404 inline_greater_string_outer_strong, |
| 405 inline_less_equal_string_outer_strong, |
| 406 inline_greater_equal_string_outer_strong]; |
| 407 |
| 408 for (let strong_inner_func of strong_inner_funcs_num) { |
220 assertThrows(function(){strong_inner_func(1, {})}, TypeError); | 409 assertThrows(function(){strong_inner_func(1, {})}, TypeError); |
221 for (var i = 0; i < 100; i++) { | 410 for (var i = 0; i < 100; i++) { |
222 strong_inner_func(1, 2); | 411 strong_inner_func(1, 2); |
223 } | 412 } |
224 %OptimizeFunctionOnNextCall(strong_inner_func); | 413 %OptimizeFunctionOnNextCall(strong_inner_func); |
225 assertThrows(function(){strong_inner_func(1, {})}, TypeError); | 414 assertThrows(function(){strong_inner_func(1, {})}, TypeError); |
226 } | 415 } |
227 | 416 |
228 for (let strong_outer_func of strong_outer_funcs) { | 417 for (let strong_outer_func of strong_outer_funcs_num) { |
229 assertDoesNotThrow(function(){strong_outer_func(1, {})}); | 418 assertDoesNotThrow(function(){strong_outer_func(1, {})}); |
230 for (var i = 0; i < 100; i++) { | 419 for (var i = 0; i < 100; i++) { |
231 strong_outer_func(1, 2); | 420 strong_outer_func(1, 2); |
232 } | 421 } |
233 %OptimizeFunctionOnNextCall(strong_outer_func); | 422 %OptimizeFunctionOnNextCall(strong_outer_func); |
234 assertDoesNotThrow(function(){strong_outer_func(1, {})}); | 423 assertDoesNotThrow(function(){strong_outer_func(1, {})}); |
235 } | 424 } |
| 425 |
| 426 for (let strong_inner_func of strong_inner_funcs_string) { |
| 427 assertThrows(function(){strong_inner_func("foo", {})}, TypeError); |
| 428 for (var i = 0; i < 100; i++) { |
| 429 strong_inner_func("foo", "bar"); |
| 430 } |
| 431 %OptimizeFunctionOnNextCall(strong_inner_func); |
| 432 assertThrows(function(){strong_inner_func("foo", {})}, TypeError); |
| 433 } |
| 434 |
| 435 for (let strong_outer_func of strong_outer_funcs_string) { |
| 436 assertDoesNotThrow(function(){strong_outer_func("foo", {})}); |
| 437 for (var i = 0; i < 100; i++) { |
| 438 strong_outer_func("foo", "bar"); |
| 439 } |
| 440 %OptimizeFunctionOnNextCall(strong_outer_func); |
| 441 assertDoesNotThrow(function(){strong_outer_func("foo", {})}); |
| 442 } |
OLD | NEW |