-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathInlineCallbacks.js
66 lines (58 loc) · 2.17 KB
/
InlineCallbacks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
// Test inlining of callback.
function Dispatch(f) { f(); }
function Foo() { WScript.Echo("foo"); }
function DispatchFoo() { Dispatch(Foo); }
// make Dispatch megamorphic
Dispatch(function(){})
Dispatch(function(){})
Dispatch(function(){})
Dispatch(function(){})
Dispatch(function(){})
DispatchFoo();
DispatchFoo();
DispatchFoo();
// Test inlining of a callback function with a callback.
function Bar() { WScript.Echo("bar"); }
function DispatchBar() { Dispatch(Bar); }
function NestedDispatch() { Dispatch(DispatchBar) };
NestedDispatch();
NestedDispatch();
NestedDispatch();
// Test inlining of callback with argument
function Dispatch2(f, arg) { f(arg); }
function Blah(arg) { WScript.Echo(arg); }
function DispatchBlah(arg) { Dispatch2(Blah, arg) }
// make dispatch2 polymorphic.
Dispatch2(function(){})
Dispatch2(function(){})
DispatchBlah("blah");
DispatchBlah("blah");
DispatchBlah("blah");
// This will fail to inline the callback because currently we track at most one callback arg per callsite
function Dispatch3(a, b) { a(); b(); }
function DispatchFooBar() { Dispatch3(Foo, Bar); }
Dispatch3(function(){}, function(){});
Dispatch3(function(){}, function(){});
DispatchFooBar();
DispatchFooBar();
DispatchFooBar();
// test inlining of callback.call
function DispatchCall(callback, thisArg) { callback.call(thisArg); }
function DispatchFooCall() { DispatchCall(Foo, {}); }
DispatchCall(function(){});
DispatchCall(function(){}, []);
DispatchFooCall();
DispatchFooCall();
DispatchFooCall();
// test inlining of callback.apply
function DispatchApply(callback, thisArg) { callback.apply(thisArg); }
function DispatchBarApply() { DispatchApply(Bar, {}); }
DispatchApply(function(){});
DispatchApply(function(){}, []);
DispatchBarApply();
DispatchBarApply();
DispatchBarApply();