PerformanceMark.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. JS_DECLARE_ALLOCATOR(PerformanceMark);
  18. public:
  19. virtual ~PerformanceMark();
  20. static WebIDL::ExceptionOr<JS::NonnullGCPtr<PerformanceMark>> construct_impl(JS::Realm&, String const& mark_name, PerformanceMarkOptions const& mark_options = {});
  21. // NOTE: These three functions are answered by the registry for the given entry type.
  22. // https://w3c.github.io/timing-entrytypes-registry/#registry
  23. // https://w3c.github.io/timing-entrytypes-registry/#dfn-availablefromtimeline
  24. static PerformanceTimeline::AvailableFromTimeline available_from_timeline() { return PerformanceTimeline::AvailableFromTimeline::Yes; }
  25. // https://w3c.github.io/timing-entrytypes-registry/#dfn-maxbuffersize
  26. // NOTE: The empty state represents Infinite size.
  27. static Optional<u64> max_buffer_size() { return OptionalNone {}; }
  28. // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
  29. virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
  30. virtual FlyString const& entry_type() const override;
  31. JS::Value detail() const { return m_detail; }
  32. private:
  33. PerformanceMark(JS::Realm&, String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail);
  34. virtual void initialize(JS::Realm&) override;
  35. virtual void visit_edges(JS::Cell::Visitor&) override;
  36. // https://w3c.github.io/user-timing/#dom-performancemark-detail
  37. JS::Value m_detail { JS::js_null() };
  38. };
  39. }