зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1515214 - Add CallbackObject::GetDescription. r=bzbarsky
This allows us to create profiler markers whose description contains the name of the function and its file / line number. This allows the profiler UI to match up setTimeout callbacks for multiple instances of the same page load, in order to create meaningful profile comparisons based on markers. Differential Revision: https://phabricator.services.mozilla.com/D19192 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
f77093e6a4
Коммит
18e5146459
|
@ -126,6 +126,63 @@ JSObject* CallbackObject::Callback(JSContext* aCx) {
|
|||
return callback;
|
||||
}
|
||||
|
||||
void CallbackObject::GetDescription(nsACString& aOutString) {
|
||||
JSObject* wrappedCallback = CallbackOrNull();
|
||||
if (!wrappedCallback) {
|
||||
aOutString.Append("<callback from a nuked compartment>");
|
||||
return;
|
||||
}
|
||||
|
||||
JSObject* unwrappedCallback = js::CheckedUnwrapStatic(wrappedCallback);
|
||||
if (!unwrappedCallback) {
|
||||
aOutString.Append("<not a function>");
|
||||
return;
|
||||
}
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init();
|
||||
JSContext* cx = jsapi.cx();
|
||||
|
||||
JS::RootedObject rootedCallback(cx, unwrappedCallback);
|
||||
JSAutoRealm ar(cx, rootedCallback);
|
||||
|
||||
JS::Rooted<JSFunction*> rootedFunction(cx,
|
||||
JS_GetObjectFunction(rootedCallback));
|
||||
if (!rootedFunction) {
|
||||
aOutString.Append("<not a function>");
|
||||
return;
|
||||
}
|
||||
|
||||
JS::Rooted<JSString*> displayId(cx, JS_GetFunctionDisplayId(rootedFunction));
|
||||
if (displayId) {
|
||||
nsAutoJSString funcNameStr;
|
||||
if (funcNameStr.init(cx, displayId)) {
|
||||
if (funcNameStr.IsEmpty()) {
|
||||
aOutString.Append("<empty name>");
|
||||
} else {
|
||||
AppendUTF16toUTF8(funcNameStr, aOutString);
|
||||
}
|
||||
} else {
|
||||
aOutString.Append("<function name string failed to materialize>");
|
||||
jsapi.ClearException();
|
||||
}
|
||||
} else {
|
||||
aOutString.Append("<anonymous>");
|
||||
}
|
||||
|
||||
JS::Rooted<JSScript*> rootedScript(cx,
|
||||
JS_GetFunctionScript(cx, rootedFunction));
|
||||
if (!rootedScript) {
|
||||
return;
|
||||
}
|
||||
|
||||
aOutString.Append(" (");
|
||||
aOutString.Append(JS_GetScriptFilename(rootedScript));
|
||||
aOutString.Append(":");
|
||||
aOutString.AppendInt(JS_GetScriptBaseLineNumber(cx, rootedScript));
|
||||
aOutString.Append(")");
|
||||
}
|
||||
|
||||
CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
|
||||
ErrorResult& aRv,
|
||||
const char* aExecutionReason,
|
||||
|
|
|
@ -158,6 +158,13 @@ class CallbackObject : public nsISupports {
|
|||
eRethrowExceptions
|
||||
};
|
||||
|
||||
// Append a UTF-8 string to aOutString that describes the callback function,
|
||||
// for use in logging or profiler markers.
|
||||
// The string contains the function name and its source location, if
|
||||
// available, in the following format:
|
||||
// "<functionName> (<sourceURL>:<lineNumber>)"
|
||||
void GetDescription(nsACString& aOutString);
|
||||
|
||||
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
|
||||
return aMallocSizeOf(this);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче