VerifySkipNestedDeferred.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. // Following lines generate a baseline with flags:
  6. // -UseParserStateCache -ParserStateCache -ForceDeferParse -Trace:SkipNestedDeferred
  7. function assertEqual(left, right, msg) {
  8. if (left != right) {
  9. console.log(`Fail: ${msg} ('${left}' != '${right}')`);
  10. return false;
  11. }
  12. console.log(`Pass: ${msg}`);
  13. return true;
  14. }
  15. var promiseToString ='[object Promise]';
  16. var x = 'something'
  17. function bar() {
  18. function foo() {
  19. function baz() {
  20. function onemorefoo() {
  21. return x;
  22. }
  23. return onemorefoo();
  24. }
  25. return baz();
  26. }
  27. return foo();
  28. }
  29. assertEqual(x, bar(), 'A few nested functions');
  30. function foo() {
  31. var n = (function() {
  32. var x = 'x';
  33. var l = () => {
  34. var x = 'y';
  35. return function() {
  36. return x;
  37. }
  38. }
  39. return l;
  40. })()
  41. return n()();
  42. }
  43. assertEqual('y', foo(), 'Nested unnamed function expression');
  44. function f1() {
  45. async function a1() {
  46. async function a2() {
  47. return x;
  48. }
  49. return a2();
  50. }
  51. return a1();
  52. }
  53. assertEqual(promiseToString, f1(), 'Function with nested async functions');
  54. function f2() {
  55. function* g1() {
  56. function* g2() {
  57. yield x;
  58. }
  59. yield g2().next().value;
  60. }
  61. return g1().next().value;
  62. }
  63. assertEqual(x, f2(), 'Function with nested generator functions');
  64. function f3() {
  65. var l1 = (s) => x;
  66. return l1()
  67. }
  68. assertEqual(x, f3(), 'Nested concise-body lambda');
  69. function f4() {
  70. var l1 = (s) => { return x }
  71. return l1()
  72. }
  73. assertEqual(x, f4(), 'Simple nested lambda');
  74. function f5() {
  75. var l1 = s => { return x }
  76. return l1()
  77. }
  78. assertEqual(x, f5(), 'Nested concise-argument list lambda');
  79. function f52() {
  80. var l5 = s => { return s => { return x; } };
  81. return l5();
  82. }
  83. assertEqual(x, f52()(), 'Couple of nested lambda');
  84. function f6() {
  85. var o = {
  86. method(s) { return x; },
  87. get method2() { return x; },
  88. ['method3'](arg) { return x; },
  89. get ['method4']() { return x; },
  90. async method5(s) { return x; },
  91. *method6(s) { yield x; },
  92. *['method7'](s) { yield x; },
  93. async ['method8'](s) { return x; },
  94. f8: function() { return x; },
  95. f9: () => { return x; }
  96. }
  97. return assertEqual(x, o.method(), 'Simple method') &&
  98. assertEqual(x, o.method2, 'Simple getter') &&
  99. assertEqual(x, o.method3(), 'Computed-property named method') &&
  100. assertEqual(x, o.method4, 'Computed-property named getter') &&
  101. assertEqual(promiseToString, o.method5(), 'Async method') &&
  102. assertEqual(x, o.method6().next().value, 'Generator method') &&
  103. assertEqual(x, o.method7().next().value, 'Generator method with computed-property name') &&
  104. assertEqual(promiseToString, o.method8(), 'Async method with computed-property name') &&
  105. assertEqual(x, o.f8(), 'Function stored in object literal property') &&
  106. assertEqual(x, o.f9(), 'Lambda stored in object literal property');
  107. }
  108. assertEqual(true, f6(), 'Several object literal methods');
  109. function f7() {
  110. eval('function f5(s) { return x; }');
  111. return f5();
  112. }
  113. assertEqual(x, f7(), 'Simple function defined in eval');
  114. function f8() {
  115. eval('function f7(r) { function f9() { return x; }; return f9(); }');
  116. return f7();
  117. }
  118. assertEqual(x, f8(), 'Nested eval functions');