Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / dom / performance / PerformanceMeasure.cpp
blobd276162b42c1db657065bf8fedf9cb15c629c804
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/. */
7 #include "PerformanceMeasure.h"
8 #include "MainThreadUtils.h"
9 #include "mozilla/dom/PerformanceMeasureBinding.h"
11 using namespace mozilla::dom;
13 PerformanceMeasure::PerformanceMeasure(nsISupports* aParent,
14 const nsAString& aName,
15 DOMHighResTimeStamp aStartTime,
16 DOMHighResTimeStamp aEndTime,
17 const JS::Handle<JS::Value>& aDetail)
18 : PerformanceEntry(aParent, aName, u"measure"_ns),
19 mStartTime(aStartTime),
20 mDuration(aEndTime - aStartTime),
21 mDetail(aDetail) {
22 mozilla::HoldJSObjects(this);
25 PerformanceMeasure::~PerformanceMeasure() { mozilla::DropJSObjects(this); }
27 NS_IMPL_CYCLE_COLLECTION_CLASS(PerformanceMeasure)
28 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PerformanceMeasure,
29 PerformanceEntry)
30 tmp->mDetail.setUndefined();
31 mozilla::DropJSObjects(tmp);
32 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
33 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PerformanceMeasure,
34 PerformanceEntry)
35 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
37 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(PerformanceMeasure,
38 PerformanceEntry)
39 NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mDetail)
40 NS_IMPL_CYCLE_COLLECTION_TRACE_END
42 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(PerformanceMeasure,
43 PerformanceEntry)
45 JSObject* PerformanceMeasure::WrapObject(JSContext* aCx,
46 JS::Handle<JSObject*> aGivenProto) {
47 return PerformanceMeasure_Binding::Wrap(aCx, this, aGivenProto);
50 void PerformanceMeasure::GetDetail(JSContext* aCx,
51 JS::MutableHandle<JS::Value> aRetval) {
52 // Return a copy so that this method always returns the value it is set to
53 // (i.e. it'll return the same value even if the caller assigns to it). Note
54 // that if detail is an object, its contents can be mutated and this is
55 // expected.
56 aRetval.set(mDetail);
59 size_t PerformanceMeasure::SizeOfIncludingThis(
60 mozilla::MallocSizeOf aMallocSizeOf) const {
61 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);