concatmulti.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. var tests = [
  6. function (str)
  7. {
  8. // Can't optimize
  9. return "<start> " + str + " <end>";
  10. },
  11. function(str, str2)
  12. {
  13. // Can't optimize because the first two might not be string
  14. return str + str2 + " something";
  15. },
  16. function(str, str2)
  17. {
  18. // Can't optimize, side effect ordering
  19. return str + " something " + str2;
  20. },
  21. function(str, str2)
  22. {
  23. // Can't optimize, side effect ordering
  24. return str + (" something " + str2);
  25. },
  26. function(str)
  27. {
  28. return ("<start> " + str)
  29. + (str + " <end>");
  30. },
  31. function(str)
  32. {
  33. return "<start> " + str + str + (str += "<extra>") + " <end>";
  34. },
  35. function(str)
  36. {
  37. return "<start> " + str + str;
  38. }
  39. ];
  40. function test(func, str, str2)
  41. {
  42. WScript.Echo("------------------------------------------");
  43. WScript.Echo(func(str, str2));
  44. WScript.Echo(func(str, str2));
  45. }
  46. function alltest(str, str2)
  47. {
  48. WScript.Echo("==========================================");
  49. WScript.Echo("Input : " + str + " | " + str2);
  50. WScript.Echo("==========================================");
  51. for (var i = 0; i < tests.length; i++)
  52. {
  53. test(tests[i], str, str2);
  54. }
  55. }
  56. alltest("x");
  57. alltest(12);
  58. alltest(true);
  59. function A() {};
  60. function B() {};
  61. A.prototype.toString = function() { WScript.Echo("A.toString"); return "A"; }
  62. B.prototype.toString = function() { WScript.Echo("B.toString"); return "B"; }
  63. alltest(new A(), new B());