ErrorEvent.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/HTML/ErrorEvent.h>
  8. namespace Web::HTML {
  9. WebIDL::ExceptionOr<JS::NonnullGCPtr<ErrorEvent>> ErrorEvent::create(JS::Realm& realm, FlyString const& event_name, ErrorEventInit const& event_init)
  10. {
  11. return MUST_OR_THROW_OOM(realm.heap().allocate<ErrorEvent>(realm, realm, event_name, event_init));
  12. }
  13. WebIDL::ExceptionOr<JS::NonnullGCPtr<ErrorEvent>> ErrorEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, ErrorEventInit const& event_init)
  14. {
  15. return create(realm, event_name, event_init);
  16. }
  17. ErrorEvent::ErrorEvent(JS::Realm& realm, FlyString const& event_name, ErrorEventInit const& event_init)
  18. : DOM::Event(realm, event_name)
  19. , m_message(event_init.message)
  20. , m_filename(event_init.filename)
  21. , m_lineno(event_init.lineno)
  22. , m_colno(event_init.colno)
  23. , m_error(event_init.error)
  24. {
  25. }
  26. ErrorEvent::~ErrorEvent() = default;
  27. JS::ThrowCompletionOr<void> ErrorEvent::initialize(JS::Realm& realm)
  28. {
  29. MUST_OR_THROW_OOM(Base::initialize(realm));
  30. set_prototype(&Bindings::ensure_web_prototype<Bindings::ErrorEventPrototype>(realm, "ErrorEvent"));
  31. return {};
  32. }
  33. void ErrorEvent::visit_edges(Cell::Visitor& visitor)
  34. {
  35. Base::visit_edges(visitor);
  36. visitor.visit(m_error);
  37. }
  38. }