pre1.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. function test1(o)
  6. {
  7. var count = 0;
  8. for(var i=0;i<10;i++)
  9. {
  10. count += o.x.y;
  11. count += o.x.y;
  12. count += o.x.w;
  13. count += o.z;
  14. }
  15. return count;
  16. }
  17. var o = {x:{y:2, w:3}, z:1};
  18. print("\ntest1");
  19. test1(o);
  20. test1(o);
  21. test1(o);
  22. function test2(o)
  23. {
  24. var a=0;var b =0;
  25. o.x;
  26. for(var i=0;i<10;i++)
  27. {
  28. o.x++
  29. }
  30. return b;
  31. }
  32. o.x=1;
  33. print("\ntest2");
  34. test2(o)
  35. test2(o)
  36. test2(o)
  37. var Direction = new Object();
  38. Direction.NONE = 0;
  39. Direction.FORWARD = 1;
  40. Direction.BACKWARD = -1;
  41. function inlinee(o)
  42. {
  43. o.count += Direction.FORWARD;
  44. return true;
  45. }
  46. function testInlined(o)
  47. {
  48. for(var i = 0; i < 1000; i++)
  49. {
  50. if(!inlinee(o))
  51. {
  52. o.count = 1;
  53. }
  54. inlinee(o);
  55. }
  56. }
  57. print("\ntestInlined");
  58. var obj = {count:0, dir:1};
  59. obj.count= 1;
  60. o.dir=1;
  61. testInlined(obj);
  62. print(o.count);
  63. obj.count = 1;
  64. obj.dir =2;
  65. testInlined(obj);
  66. print(obj.count);
  67. obj.count = 1;
  68. obj.dir =1;
  69. testInlined(obj);
  70. print(obj.count);
  71. function test3()
  72. {
  73. function OrderedCollection() {
  74. this.elms = new Array();
  75. }
  76. OrderedCollection.prototype.size = function() {
  77. return this.elms.length;
  78. }
  79. OrderedCollection.prototype.at = function (index) {
  80. return this.elms[index];
  81. }
  82. function Plan() {
  83. this.v = new OrderedCollection();
  84. }
  85. Plan.prototype.add = function(c){
  86. this.v.elms.push(c);
  87. }
  88. Plan.prototype.size = function () {
  89. return this.v.size();
  90. }
  91. Plan.prototype.constraintAt = function (index) {
  92. return this.v.at(index);
  93. }
  94. Plan.prototype.execute = function()
  95. {
  96. var count = 0;
  97. for (var i = 0; i < this.size(); i++) {
  98. this.constraintAt(i);
  99. count += Direction.FORWARD;
  100. }
  101. return count;
  102. }
  103. var plan = new Plan();
  104. for(var i = 0; i < 10; i++)
  105. {
  106. plan.add(1);
  107. }
  108. print(plan.execute());
  109. print(plan.execute());
  110. print(plan.execute());
  111. }
  112. print("\ntest3");
  113. test3();