toStringAll.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 test(func) {
  6. console.log(func.toString());
  7. try {
  8. var result = func();
  9. if (result && result.next) {
  10. result.next();
  11. }
  12. } catch (e) {
  13. // Ignore
  14. }
  15. }
  16. function testFunctions() {
  17. function/*ß*/ a/*ß*/()/*ß*/ { console.log('a'); }
  18. test(a);
  19. var b = /*ß*/(/*ß*/)/*ß*/ => { console.log('b'); }
  20. test(b);
  21. async/*ß*/ function/*ß*/ c/*ß*/()/*ß*/ { console.log('c'); }
  22. test(c);
  23. function/*ß*/ */*ß*/d/*ß*/(/*ß*/)/*ß*/ { console.log('d'); }
  24. test(d);
  25. }
  26. testFunctions();
  27. var objectMemberTest = {
  28. a/*ß*/() /*ß*/{ console.log('a'); },
  29. b: /*ß*/()/*ß*/ => { console.log('b'); },
  30. async/*ß*/ c/*ß*/()/*ß*/ { console.log('c'); },
  31. */*ß*/ d/*ß*/()/*ß*/ { console.log('d'); },
  32. ['e']/*ß*/()/*ß*/ { console.log('e'); },
  33. async/*ß*/ ['f']/*ß*/()/*ß*/ { console.log('f'); },
  34. */*ß*/ ['g']/*ß*/()/*ß*/ { console.log('g'); },
  35. get/*ß*/()/*ß*/ { console.log('get'); },
  36. set/*ß*/()/*ß*/ { console.log('set'); },
  37. [/]/.exec(']')]/*ß*/()/*ß*/ { console.log('regex'); },
  38. [(function () { return 'h'})()]/*ß*/()/*ß*/ { console.log('function'); },
  39. }
  40. for (var i of Object.keys(objectMemberTest)) {
  41. test(objectMemberTest[i]);
  42. }
  43. var objectAccessorTest = {
  44. get/*ß*/ a/*ß*/()/*ß*/ { console.log('getter'); },
  45. set /*ß*/a/*ß*/(x)/*ß*/ { console.log('setter'); },
  46. }
  47. var d = Object.getOwnPropertyDescriptor(objectAccessorTest, 'a');
  48. console.log(d.get.toString())
  49. d.get();
  50. console.log(d.set.toString())
  51. d.set(0);
  52. class ClassTest {
  53. constructor/*ß*/()/*ß*/ {}
  54. static /*ß*/a/*ß*/()/*ß*/ {}
  55. static /*ß*/async/*ß*/ b()/*ß*/ {}
  56. static /*ß*/*/*ß*/ c/*ß*/()/*ß*/ {}
  57. static /*ß*/['d']/*ß*/()/*ß*/ {}
  58. static /*ß*/async /*ß*/['e']/*ß*/()/*ß*/ {}
  59. static /*ß*/* /*ß*/['f']/*ß*/()/*ß*/ {}
  60. g/*ß*/()/*ß*/ {}
  61. async/*ß*/ h/*ß*/()/*ß*/ {}
  62. */*ß*/ i/*ß*/()/*ß*/ {}
  63. ['j']/*ß*/()/*ß*/ {}
  64. async/*ß*/ ['k']/*ß*/()/*ß*/ {}
  65. * /*ß*/['l']/*ß*/()/*ß*/ {}
  66. }
  67. var classInstance = new ClassTest();
  68. for(var i of ['a', 'b', 'c', 'd', 'e', 'f']) {
  69. test(ClassTest[i]);
  70. }
  71. for(var i of ['g', 'h', 'i', 'j', 'k', 'l']) {
  72. test(classInstance[i]);
  73. }
  74. test(classInstance.constructor)
  75. async function awaitTests() {
  76. return {
  77. [await 'a']/*ß*/()/*ß*/ { console.log("await a"); }
  78. }
  79. }
  80. awaitTests().then(o => {
  81. for (var i of Object.keys(o)) {
  82. test(o[i]);
  83. }
  84. });
  85. function * yieldTests() {
  86. return {
  87. [yield 'a']/*ß*/()/*ß*/ { console.log("yield a"); }
  88. }
  89. }
  90. var it = yieldTests();
  91. var last;
  92. do {
  93. last = it.next();
  94. } while (!last.done);
  95. for (var i of Object.keys(last.value)) {
  96. test(last.value[i]);
  97. }