5 #include "jsobjinlines.h"
7 #ifdef MOZ_TRACE_JSCALLS
10 static int enters
= 0;
11 static int leaves
= 0;
12 static int interpreted
= 0;
15 funcTransition(const JSFunction
*,
30 static JSBool called2
= false;
33 funcTransition2(const JSFunction
*, const JSScript
*, const JSContext
*, int)
38 static int overlays
= 0;
39 static JSFunctionCallback innerCallback
= NULL
;
41 funcTransitionOverlay(const JSFunction
*fun
,
42 const JSScript
*script
,
46 (*innerCallback
)(fun
, script
, cx
, entering
);
51 BEGIN_TEST(testFuncCallback_bug507012
)
53 #ifdef MOZ_TRACE_JSCALLS
54 // Call funcTransition() whenever a Javascript method is invoked
55 JS_SetFunctionCallback(cx
, funcTransition
);
57 EXEC("x = 0; function f (n) { if (n > 1) { f(n - 1); } }");
58 interpreted
= enters
= leaves
= depth
= 0;
60 // Check whether JS_Execute() tracking works
62 CHECK_EQUAL(enters
, 1);
63 CHECK_EQUAL(leaves
, 1);
64 CHECK_EQUAL(depth
, 0);
65 interpreted
= enters
= leaves
= depth
= 0;
67 // Check whether the basic function tracking works
69 CHECK_EQUAL(enters
, 1+1);
70 CHECK_EQUAL(leaves
, 1+1);
71 CHECK_EQUAL(depth
, 0);
73 // Can we switch to a different callback?
75 JS_SetFunctionCallback(cx
, funcTransition2
);
78 CHECK_EQUAL(enters
, 777);
80 // Check whether we can turn off function tracing
81 JS_SetFunctionCallback(cx
, NULL
);
83 CHECK_EQUAL(enters
, 777);
84 interpreted
= enters
= leaves
= depth
= 0;
86 // Check nested invocations
87 JS_SetFunctionCallback(cx
, funcTransition
);
88 enters
= leaves
= depth
= 0;
90 CHECK_EQUAL(enters
, 1+3);
91 CHECK_EQUAL(leaves
, 1+3);
92 CHECK_EQUAL(depth
, 0);
93 interpreted
= enters
= leaves
= depth
= 0;
95 // Check calls invoked while running on trace -- or now, perhaps on
96 // IonMonkey's equivalent, if it ever starts to exist?
97 EXEC("function g () { ++x; }");
98 interpreted
= enters
= leaves
= depth
= 0;
99 EXEC("for (i = 0; i < 5000; ++i) { g(); }");
100 CHECK_EQUAL(enters
, 1+5000);
101 CHECK_EQUAL(leaves
, 1+5000);
102 CHECK_EQUAL(depth
, 0);
104 // Test nesting callbacks via JS_GetFunctionCallback()
105 JS_SetFunctionCallback(cx
, funcTransition
);
106 innerCallback
= JS_GetFunctionCallback(cx
);
107 JS_SetFunctionCallback(cx
, funcTransitionOverlay
);
109 EXEC("x = 0; function f (n) { if (n > 1) { f(n - 1); } }");
110 interpreted
= enters
= leaves
= depth
= overlays
= 0;
113 CHECK_EQUAL(enters
, 1);
114 CHECK_EQUAL(leaves
, 1);
115 CHECK_EQUAL(depth
, 0);
116 CHECK_EQUAL(overlays
, enters
+ leaves
);
117 interpreted
= enters
= leaves
= depth
= overlays
= 0;
120 // Uncomment this to validate whether you're hitting all runmodes (interp,
121 // mjit, ...?) Unfortunately, that still doesn't cover all
122 // transitions between the various runmodes, but it's a start.
123 //JS_DumpAllProfiles(cx);
128 // Make sure that the method jit is enabled.
129 // We'll probably want to test in all modes.
131 JSContext
*createContext()
133 JSContext
*cx
= JSAPITest::createContext();
135 JS_SetOptions(cx
, JS_GetOptions(cx
) | JSOPTION_METHODJIT
| JSOPTION_PCCOUNT
);
139 END_TEST(testFuncCallback_bug507012
)