InlineCallbacks.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // Test inlining of callback.
  6. function Dispatch(f) { f(); }
  7. function Foo() { WScript.Echo("foo"); }
  8. function DispatchFoo() { Dispatch(Foo); }
  9. // make Dispatch megamorphic
  10. Dispatch(function(){})
  11. Dispatch(function(){})
  12. Dispatch(function(){})
  13. Dispatch(function(){})
  14. Dispatch(function(){})
  15. DispatchFoo();
  16. DispatchFoo();
  17. DispatchFoo();
  18. // Test inlining of a callback function with a callback.
  19. function Bar() { WScript.Echo("bar"); }
  20. function DispatchBar() { Dispatch(Bar); }
  21. function NestedDispatch() { Dispatch(DispatchBar) };
  22. NestedDispatch();
  23. NestedDispatch();
  24. NestedDispatch();
  25. // Test inlining of callback with argument
  26. function Dispatch2(f, arg) { f(arg); }
  27. function Blah(arg) { WScript.Echo(arg); }
  28. function DispatchBlah(arg) { Dispatch2(Blah, arg) }
  29. // make dispatch2 polymorphic.
  30. Dispatch2(function(){})
  31. Dispatch2(function(){})
  32. DispatchBlah("blah");
  33. DispatchBlah("blah");
  34. DispatchBlah("blah");
  35. // This will fail to inline the callback because currently we track at most one callback arg per callsite
  36. function Dispatch3(a, b) { a(); b(); }
  37. function DispatchFooBar() { Dispatch3(Foo, Bar); }
  38. Dispatch3(function(){}, function(){});
  39. Dispatch3(function(){}, function(){});
  40. DispatchFooBar();
  41. DispatchFooBar();
  42. DispatchFooBar();
  43. // test inlining of callback.call
  44. function DispatchCall(callback, thisArg) { callback.call(thisArg); }
  45. function DispatchFooCall() { DispatchCall(Foo, {}); }
  46. DispatchCall(function(){});
  47. DispatchCall(function(){}, []);
  48. DispatchFooCall();
  49. DispatchFooCall();
  50. DispatchFooCall();
  51. // test inlining of callback.apply
  52. function DispatchApply(callback, thisArg) { callback.apply(thisArg); }
  53. function DispatchBarApply() { DispatchApply(Bar, {}); }
  54. DispatchApply(function(){});
  55. DispatchApply(function(){}, []);
  56. DispatchBarApply();
  57. DispatchBarApply();
  58. DispatchBarApply();