SVGLength.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/SVG/SVGLength.h>
  8. namespace Web::SVG {
  9. WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGLength>> SVGLength::create(JS::Realm& realm, u8 unit_type, float value)
  10. {
  11. return MUST_OR_THROW_OOM(realm.heap().allocate<SVGLength>(realm, realm, unit_type, value));
  12. }
  13. SVGLength::SVGLength(JS::Realm& realm, u8 unit_type, float value)
  14. : PlatformObject(realm)
  15. , m_unit_type(unit_type)
  16. , m_value(value)
  17. {
  18. }
  19. JS::ThrowCompletionOr<void> SVGLength::initialize(JS::Realm& realm)
  20. {
  21. MUST_OR_THROW_OOM(Base::initialize(realm));
  22. set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGLengthPrototype>(realm, "SVGLength"));
  23. return {};
  24. }
  25. SVGLength::~SVGLength() = default;
  26. // https://www.w3.org/TR/SVG11/types.html#__svg__SVGLength__value
  27. WebIDL::ExceptionOr<void> SVGLength::set_value(float value)
  28. {
  29. // FIXME: Raise an exception if this <length> is read-only.
  30. m_value = value;
  31. return {};
  32. }
  33. }