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: --strong-mode --allow-natives-syntax 6 7"use strict"; 8 9//****************************************************************************** 10// Number function declarations 11function inline_add_strong(x, y) { 12 "use strong"; 13 return x + y; 14} 15 16function inline_add_strong_outer(x, y) { 17 return inline_add_strong(x, y); 18} 19 20function inline_sub_strong(x, y) { 21 "use strong"; 22 return x - y; 23} 24 25function inline_sub_strong_outer(x, y) { 26 return inline_sub_strong(x, y); 27} 28 29function inline_mul_strong(x, y) { 30 "use strong"; 31 return x * y; 32} 33 34function inline_mul_strong_outer(x, y) { 35 return inline_mul_strong(x, y); 36} 37 38function inline_div_strong(x, y) { 39 "use strong"; 40 return x / y; 41} 42 43function inline_div_strong_outer(x, y) { 44 return inline_div_strong(x, y); 45} 46 47function inline_mod_strong(x, y) { 48 "use strong"; 49 return x % y; 50} 51 52function inline_mod_strong_outer(x, y) { 53 return inline_mod_strong(x, y); 54} 55 56function inline_or_strong(x, y) { 57 "use strong"; 58 return x | y; 59} 60 61function inline_or_strong_outer(x, y) { 62 return inline_or_strong(x, y); 63} 64 65function inline_and_strong(x, y) { 66 "use strong"; 67 return x & y; 68} 69 70function inline_and_strong_outer(x, y) { 71 return inline_and_strong(x, y); 72} 73 74function inline_xor_strong(x, y) { 75 "use strong"; 76 return x ^ y; 77} 78 79function inline_xor_strong_outer(x, y) { 80 return inline_xor_strong(x, y); 81} 82 83function inline_shl_strong(x, y) { 84 "use strong"; 85 return x << y; 86} 87 88function inline_shl_strong_outer(x, y) { 89 return inline_shl_strong(x, y); 90} 91 92function inline_shr_strong(x, y) { 93 "use strong"; 94 return x >> y; 95} 96 97function inline_shr_strong_outer(x, y) { 98 return inline_shr_strong(x, y); 99} 100 101function inline_sar_strong(x, y) { 102 "use strong"; 103 return x >>> y; 104} 105 106function inline_sar_strong_outer(x, y) { 107 return inline_sar_strong(x, y); 108} 109 110function inline_less_strong(x, y) { 111 "use strong"; 112 return x < y; 113} 114 115function inline_less_strong_outer(x, y) { 116 return inline_less_strong(x, y); 117} 118 119function inline_greater_strong(x, y) { 120 "use strong"; 121 return x > y; 122} 123 124function inline_greater_strong_outer(x, y) { 125 return inline_greater_strong(x, y); 126} 127 128function inline_less_equal_strong(x, y) { 129 "use strong"; 130 return x <= y; 131} 132 133function inline_less_equal_strong_outer(x, y) { 134 return inline_less_equal_strong(x, y); 135} 136 137function inline_greater_equal_strong(x, y) { 138 "use strong"; 139 return x >= y; 140} 141 142function inline_greater_equal_strong_outer(x, y) { 143 return inline_greater_equal_strong(x, y); 144} 145 146function inline_add(x, y) { 147 return x + y; 148} 149 150function inline_add_outer_strong(x, y) { 151 "use strong"; 152 return inline_add(x, y); 153} 154 155function inline_sub(x, y) { 156 return x - y; 157} 158 159function inline_sub_outer_strong(x, y) { 160 "use strong"; 161 return inline_sub(x, y); 162} 163 164function inline_mul(x, y) { 165 return x * y; 166} 167 168function inline_mul_outer_strong(x, y) { 169 "use strong"; 170 return inline_mul(x, y); 171} 172 173function inline_div(x, y) { 174 return x / y; 175} 176 177function inline_div_outer_strong(x, y) { 178 "use strong"; 179 return inline_div(x, y); 180} 181 182function inline_mod(x, y) { 183 return x % y; 184} 185 186function inline_mod_outer_strong(x, y) { 187 "use strong"; 188 return inline_mod(x, y); 189} 190 191function inline_or(x, y) { 192 return x | y; 193} 194 195function inline_or_outer_strong(x, y) { 196 "use strong"; 197 return inline_or(x, y); 198} 199 200function inline_and(x, y) { 201 return x & y; 202} 203 204function inline_and_outer_strong(x, y) { 205 "use strong"; 206 return inline_and(x, y); 207} 208 209function inline_xor(x, y) { 210 return x ^ y; 211} 212 213function inline_xor_outer_strong(x, y) { 214 "use strong"; 215 return inline_xor(x, y); 216} 217 218function inline_shl(x, y) { 219 return x << y; 220} 221 222function inline_shl_outer_strong(x, y) { 223 "use strong"; 224 return inline_shl(x, y); 225} 226 227function inline_shr(x, y) { 228 return x >> y; 229} 230 231function inline_shr_outer_strong(x, y) { 232 "use strong"; 233 return inline_shr(x, y); 234} 235 236function inline_sar(x, y) { 237 return x >>> y; 238} 239 240function inline_sar_outer_strong(x, y) { 241 "use strong"; 242 return inline_sar(x, y); 243} 244 245function inline_less(x, y) { 246 return x < y; 247} 248 249function inline_less_outer_strong(x, y) { 250 "use strong"; 251 return inline_less(x, y); 252} 253 254function inline_greater(x, y) { 255 return x > y; 256} 257 258function inline_greater_outer_strong(x, y) { 259 "use strong"; 260 return inline_greater(x, y); 261} 262 263function inline_less_equal(x, y) { 264 return x <= y; 265} 266 267function inline_less_equal_outer_strong(x, y) { 268 "use strong"; 269 return inline_less_equal(x, y); 270} 271 272function inline_greater_equal(x, y) { 273 return x >>> y; 274} 275 276function inline_greater_equal_outer_strong(x, y) { 277 "use strong"; 278 return inline_greater_equal(x, y); 279} 280 281//****************************************************************************** 282// String function declarations 283function inline_add_string_strong(x, y) { 284 "use strong"; 285 return x + y; 286} 287 288function inline_add_string_strong_outer(x, y) { 289 return inline_add_string_strong(x, y); 290} 291 292function inline_less_string_strong(x, y) { 293 "use strong"; 294 return x < y; 295} 296 297function inline_less_string_strong_outer(x, y) { 298 return inline_less_string_strong(x, y); 299} 300 301function inline_greater_string_strong(x, y) { 302 "use strong"; 303 return x > y; 304} 305 306function inline_greater_string_strong_outer(x, y) { 307 return inline_greater_string_strong(x, y); 308} 309 310function inline_less_equal_string_strong(x, y) { 311 "use strong"; 312 return x <= y; 313} 314 315function inline_less_equal_string_strong_outer(x, y) { 316 return inline_less_equal_string_strong(x, y); 317} 318 319function inline_greater_equal_string_strong(x, y) { 320 "use strong"; 321 return x >= y; 322} 323 324function inline_greater_equal_string_strong_outer(x, y) { 325 return inline_greater_equal_string_strong(x, y); 326} 327 328function inline_add_string(x, y) { 329 return x + y; 330} 331 332function inline_add_string_outer_strong(x, y) { 333 "use strong"; 334 return inline_add_string(x, y); 335} 336 337function inline_less_string(x, y) { 338 return x < y; 339} 340 341function inline_less_string_outer_strong(x, y) { 342 "use strong"; 343 return inline_less_string(x, y); 344} 345 346function inline_greater_string(x, y) { 347 return x > y; 348} 349 350function inline_greater_string_outer_strong(x, y) { 351 "use strong"; 352 return inline_greater_string(x, y); 353} 354 355function inline_less_equal_string(x, y) { 356 return x <= y; 357} 358 359function inline_less_equal_string_outer_strong(x, y) { 360 "use strong"; 361 return inline_less_equal_string(x, y); 362} 363 364function inline_greater_equal_string(x, y) { 365 return x >= y; 366} 367 368function 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 376let 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 386let 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 396let 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 402let 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 408for (let strong_inner_func of strong_inner_funcs_num) { 409 assertThrows(function(){strong_inner_func(1, {})}, TypeError); 410 for (var i = 0; i < 100; i++) { 411 strong_inner_func(1, 2); 412 } 413 %OptimizeFunctionOnNextCall(strong_inner_func); 414 assertThrows(function(){strong_inner_func(1, {})}, TypeError); 415} 416 417for (let strong_outer_func of strong_outer_funcs_num) { 418 assertDoesNotThrow(function(){strong_outer_func(1, {})}); 419 for (var i = 0; i < 100; i++) { 420 strong_outer_func(1, 2); 421 } 422 %OptimizeFunctionOnNextCall(strong_outer_func); 423 assertDoesNotThrow(function(){strong_outer_func(1, {})}); 424} 425 426for (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 435for (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} 443