2015-05-03 12:32:37 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-08-29 16:50:06 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "Performance.h"
|
|
|
|
#include "mozilla/dom/PerformanceBinding.h"
|
|
|
|
|
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
Performance::Performance(WorkerPrivate* aWorkerPrivate)
|
|
|
|
: mWorkerPrivate(aWorkerPrivate)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
Performance::~Performance()
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
Performance::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-08-29 16:50:06 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return PerformanceBinding_workers::Wrap(aCx, this, aGivenProto);
|
2014-08-29 16:50:06 -07:00
|
|
|
}
|
|
|
|
|
2015-05-25 09:53:07 -07:00
|
|
|
DOMHighResTimeStamp
|
2014-08-29 16:50:06 -07:00
|
|
|
Performance::Now() const
|
|
|
|
{
|
|
|
|
TimeDuration duration =
|
|
|
|
TimeStamp::Now() - mWorkerPrivate->NowBaseTimeStamp();
|
2015-07-22 10:22:16 -07:00
|
|
|
double nowTime = duration.ToMilliseconds();
|
|
|
|
// Round down to the nearest 5us, because if the timer is too accurate people
|
|
|
|
// can do nasty timing attacks with it. See similar code in the non-worker
|
|
|
|
// Performance implementation.
|
|
|
|
const double maxResolutionMs = 0.005;
|
|
|
|
return floor(nowTime / maxResolutionMs) * maxResolutionMs;
|
2014-08-29 16:50:06 -07:00
|
|
|
}
|
|
|
|
|
2015-05-25 09:53:07 -07:00
|
|
|
// To be removed once bug 1124165 lands
|
|
|
|
bool
|
|
|
|
Performance::IsPerformanceTimingAttribute(const nsAString& aName)
|
|
|
|
{
|
|
|
|
// In workers we just support navigationStart.
|
|
|
|
return aName.EqualsASCII("navigationStart");
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
Performance::GetPerformanceTimingFromString(const nsAString& aProperty)
|
|
|
|
{
|
|
|
|
if (!IsPerformanceTimingAttribute(aProperty)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aProperty.EqualsLiteral("navigationStart")) {
|
|
|
|
return mWorkerPrivate->NowBaseTimeHighRes();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("IsPerformanceTimingAttribute and GetPerformanceTimingFromString are out of sync");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-28 09:33:37 -07:00
|
|
|
void
|
|
|
|
Performance::InsertUserEntry(PerformanceEntry* aEntry)
|
|
|
|
{
|
|
|
|
if (mWorkerPrivate->PerformanceLoggingEnabled()) {
|
2015-08-20 14:34:22 -07:00
|
|
|
nsAutoCString uri;
|
|
|
|
nsCOMPtr<nsIURI> scriptURI = mWorkerPrivate->GetResolvedScriptURI();
|
|
|
|
if (!scriptURI || NS_FAILED(scriptURI->GetHost(uri))) {
|
|
|
|
// If we have no URI, just put in "none".
|
|
|
|
uri.AssignLiteral("none");
|
|
|
|
}
|
|
|
|
PerformanceBase::LogEntry(aEntry, uri);
|
2015-07-28 09:33:37 -07:00
|
|
|
}
|
|
|
|
PerformanceBase::InsertUserEntry(aEntry);
|
|
|
|
}
|
|
|
|
|
2015-05-25 09:53:07 -07:00
|
|
|
DOMHighResTimeStamp
|
|
|
|
Performance::DeltaFromNavigationStart(DOMHighResTimeStamp aTime)
|
|
|
|
{
|
|
|
|
if (aTime == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aTime - mWorkerPrivate->NowBaseTimeHighRes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Performance::DispatchBufferFullEvent()
|
|
|
|
{
|
|
|
|
// This method is needed just for InsertResourceEntry, but this method is not
|
|
|
|
// exposed to workers.
|
|
|
|
MOZ_CRASH("This should not be called.");
|
|
|
|
}
|
|
|
|
|
2014-08-29 16:50:06 -07:00
|
|
|
END_WORKERS_NAMESPACE
|