tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PerformanceMeasure.cpp (2694B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "PerformanceMeasure.h"
      8 
      9 #include "MainThreadUtils.h"
     10 #include "mozilla/dom/PerformanceMeasureBinding.h"
     11 #include "nsGkAtoms.h"
     12 
     13 using namespace mozilla::dom;
     14 
     15 PerformanceMeasure::PerformanceMeasure(nsISupports* aParent,
     16                                       const nsAString& aName,
     17                                       DOMHighResTimeStamp aStartTime,
     18                                       DOMHighResTimeStamp aEndTime,
     19                                       const JS::Handle<JS::Value>& aDetail)
     20    : PerformanceEntry(aParent, aName, nsGkAtoms::measure),
     21      mStartTime(aStartTime),
     22      mDuration(aEndTime - aStartTime),
     23      mDetail(aDetail) {
     24  mozilla::HoldJSObjects(this);
     25 }
     26 
     27 PerformanceMeasure::~PerformanceMeasure() { mozilla::DropJSObjects(this); }
     28 
     29 NS_IMPL_CYCLE_COLLECTION_CLASS(PerformanceMeasure)
     30 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PerformanceMeasure,
     31                                                PerformanceEntry)
     32  tmp->mDetail.setUndefined();
     33  mozilla::DropJSObjects(tmp);
     34 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
     35 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PerformanceMeasure,
     36                                                  PerformanceEntry)
     37 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
     38 
     39 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(PerformanceMeasure,
     40                                               PerformanceEntry)
     41  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mDetail)
     42 NS_IMPL_CYCLE_COLLECTION_TRACE_END
     43 
     44 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(PerformanceMeasure,
     45                                               PerformanceEntry)
     46 
     47 JSObject* PerformanceMeasure::WrapObject(JSContext* aCx,
     48                                         JS::Handle<JSObject*> aGivenProto) {
     49  return PerformanceMeasure_Binding::Wrap(aCx, this, aGivenProto);
     50 }
     51 
     52 void PerformanceMeasure::GetDetail(JSContext* aCx,
     53                                   JS::MutableHandle<JS::Value> aRetval) {
     54  // Return a copy so that this method always returns the value it is set to
     55  // (i.e. it'll return the same value even if the caller assigns to it). Note
     56  // that if detail is an object, its contents can be mutated and this is
     57  // expected.
     58  aRetval.set(mDetail);
     59 }
     60 
     61 size_t PerformanceMeasure::SizeOfIncludingThis(
     62    mozilla::MallocSizeOf aMallocSizeOf) const {
     63  return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
     64 }