PerformanceMark.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/PerformanceTimeline/PerformanceEntry.h>
  8. namespace Web::UserTiming {
  9. // https://w3c.github.io/user-timing/#ref-for-dom-performancemarkoptions-1
  10. struct PerformanceMarkOptions {
  11. JS::Value detail { JS::js_null() };
  12. Optional<HighResolutionTime::DOMHighResTimeStamp> start_time;
  13. };
  14. // https://w3c.github.io/user-timing/#dom-performancemark
  15. class PerformanceMark final : public PerformanceTimeline::PerformanceEntry {
  16. WEB_PLATFORM_OBJECT(PerformanceMark, PerformanceTimeline::PerformanceEntry);
  17. public:
  18. virtual ~PerformanceMark();
  19. static WebIDL::ExceptionOr<JS::NonnullGCPtr<PerformanceMark>> construct_impl(JS::Realm&, String const& mark_name, PerformanceMarkOptions const& mark_options = {});
  20. // NOTE: These three functions are answered by the registry for the given entry type.
  21. // https://w3c.github.io/timing-entrytypes-registry/#registry
  22. // https://w3c.github.io/timing-entrytypes-registry/#dfn-availablefromtimeline
  23. static PerformanceTimeline::AvailableFromTimeline available_from_timeline() { return PerformanceTimeline::AvailableFromTimeline::Yes; }
  24. // https://w3c.github.io/timing-entrytypes-registry/#dfn-maxbuffersize
  25. // NOTE: The empty state represents Infinite size.
  26. static Optional<u64> max_buffer_size() { return OptionalNone {}; }
  27. // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
  28. virtual PerformanceTimeline::ShouldAddEntry should_add_entry() const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
  29. virtual FlyString const& entry_type() const override;
  30. JS::Value detail() const { return m_detail; }
  31. private:
  32. PerformanceMark(JS::Realm&, String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail);
  33. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  34. virtual void visit_edges(JS::Cell::Visitor&) override;
  35. // https://w3c.github.io/user-timing/#dom-performancemark-detail
  36. JS::Value m_detail { JS::js_null() };
  37. };
  38. }