InlineCallbacks.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 Dispatch(f) { f(); }
  6. function Foo() { WScript.Echo("foo"); }
  7. function DispatchFoo() { Dispatch(Foo); }
  8. // make Dispatch megamorphic
  9. Dispatch(function(){})
  10. Dispatch(function(){})
  11. Dispatch(function(){})
  12. Dispatch(function(){})
  13. Dispatch(function(){})
  14. DispatchFoo();
  15. DispatchFoo();
  16. DispatchFoo();
  17. function Bar() { WScript.Echo("bar"); }
  18. function DispatchBar() { Dispatch(Bar); }
  19. function NestedDispatch() { Dispatch(DispatchBar) };
  20. NestedDispatch();
  21. NestedDispatch();
  22. NestedDispatch();
  23. function Dispatch2(f, arg) { f(arg); }
  24. function Blah(arg) { WScript.Echo(arg); }
  25. function DispatchBlah(arg) { Dispatch2(Blah, arg) }
  26. // make dispatch2 polymorphic.
  27. Dispatch2(function(){})
  28. Dispatch2(function(){})
  29. DispatchBlah("blah");
  30. DispatchBlah("blah");
  31. DispatchBlah("blah");
  32. // This will fail to inline the callback because currently we track at most one callback arg per callsite
  33. function Dispatch3(a, b) { a(); b(); }
  34. function DispatchFooBar() { Dispatch3(Foo, Bar); }
  35. Dispatch3(function(){}, function(){});
  36. Dispatch3(function(){}, function(){});
  37. DispatchFooBar();
  38. DispatchFooBar();
  39. DispatchFooBar();