mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-09 09:18:42 +09:00
Issue #2053 - Part 3: Update PerformanceMark to User Timing L3
There are a few minor differences between this and Mozilla's implementation: (a) The type error messages were not hardcoded to the Performance class and were moved to Errors.msg or domerr.msg instead. (b) Resist fingerprinting-pref changes were skipped. Partially based on https://bugzilla.mozilla.org/show_bug.cgi?id=1724645
This commit is contained in:
parent
23519e0c22
commit
3b57ba1415
8 changed files with 197 additions and 19 deletions
|
|
@ -26,6 +26,7 @@
|
|||
#include "mozilla/TimerClamping.h"
|
||||
#include "WorkerPrivate.h"
|
||||
#include "WorkerRunnable.h"
|
||||
#include "WorkerScope.h"
|
||||
|
||||
#define PERFLOG(msg, ...) printf_stderr(msg, ##__VA_ARGS__)
|
||||
|
||||
|
|
@ -105,6 +106,27 @@ Performance::CreateForWorker(workers::WorkerPrivate* aWorkerPrivate)
|
|||
return performance.forget();
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<Performance> Performance::Get(JSContext* aCx,
|
||||
nsIGlobalObject* aGlobal) {
|
||||
RefPtr<Performance> performance;
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
|
||||
if (window) {
|
||||
performance = window->GetPerformance();
|
||||
} else {
|
||||
const WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
||||
if (!workerPrivate) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
|
||||
MOZ_ASSERT(scope);
|
||||
performance = scope->GetPerformance();
|
||||
}
|
||||
|
||||
return performance.forget();
|
||||
}
|
||||
|
||||
Performance::Performance()
|
||||
: mResourceTimingBufferSize(kDefaultResourceTimingBufferSize)
|
||||
, mPendingNotificationObserversTask(false)
|
||||
|
|
@ -234,27 +256,42 @@ Performance::RoundTime(double aTime) const
|
|||
return floor(aTime / maxResolutionMs) * maxResolutionMs;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Performance::Mark(const nsAString& aName, ErrorResult& aRv)
|
||||
already_AddRefed<PerformanceMark> Performance::Mark(
|
||||
JSContext* aCx,
|
||||
const nsAString& aName,
|
||||
const PerformanceMarkOptions& aMarkOptions,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
// Don't add the entry if the buffer is full. XXX should be removed by bug 1159003.
|
||||
if (mUserEntries.Length() >= mResourceTimingBufferSize) {
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (IsPerformanceTimingAttribute(aName)) {
|
||||
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
||||
return;
|
||||
nsCOMPtr<nsIGlobalObject> parent = GetParentObject();
|
||||
if (!parent || parent->IsDying() || !parent->GetGlobalJSObject()) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GlobalObject global(aCx, parent->GetGlobalJSObject());
|
||||
if (global.Failed()) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<PerformanceMark> performanceMark =
|
||||
new PerformanceMark(GetAsISupports(), aName, Now());
|
||||
PerformanceMark::Constructor(global, aName, aMarkOptions, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
InsertUserEntry(performanceMark);
|
||||
|
||||
if (profiler_is_active()) {
|
||||
PROFILER_MARKER(NS_ConvertUTF16toUTF8(aName).get());
|
||||
}
|
||||
|
||||
return performanceMark.forget();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue