#include "vm/Probes-inl.h"
#include "js/CharacterEncoding.h"
#include "vm/JSContext.h"
#ifdef INCLUDE_MOZILLA_DTRACE
# include "vm/JSScript-inl.h"
#endif
#define TYPEOF(cx, v) (v.isNull() ? JSTYPE_NULL : JS_TypeOfValue(cx, v))
using namespace js;
const char probes::nullName[] = "(null)";
const char probes::anonymousName[] = "(anonymous)";
bool probes::ProfilingActive = true;
#ifdef INCLUDE_MOZILLA_DTRACE
static const char* ScriptFilename(const JSScript* script) {
if (!script) {
return probes::nullName;
}
if (!script->filename()) {
return probes::anonymousName;
}
return script->filename();
}
static const char* FunctionName(JSContext* cx, JSFunction* fun,
UniqueChars* bytes) {
if (!fun) {
return probes::nullName;
}
if (!fun->displayAtom()) {
return probes::anonymousName;
}
*bytes = JS_EncodeStringToLatin1(cx, fun->displayAtom());
return *bytes ? bytes->get() : probes::nullName;
}
void probes::DTraceEnterJSFun(JSContext* cx, JSFunction* fun,
JSScript* script) {
UniqueChars funNameBytes;
JAVASCRIPT_FUNCTION_ENTRY(ScriptFilename(script), probes::nullName,
FunctionName(cx, fun, &funNameBytes));
}
void probes::DTraceExitJSFun(JSContext* cx, JSFunction* fun, JSScript* script) {
UniqueChars funNameBytes;
JAVASCRIPT_FUNCTION_RETURN(ScriptFilename(script), probes::nullName,
FunctionName(cx, fun, &funNameBytes));
}
#endif