LibWeb: Add stub for ValidityState

This fixes https://html5test.com/ as previously an exception was being
thrown after trying to access this attribute which would then result in
a popup about the test failing (and none of the test results being
shown).
This commit is contained in:
Shannon Booth 2024-06-09 15:13:38 +12:00 committed by Andreas Kling
parent 0ec0e92b10
commit e0bbbc729b
Notes: sideshowbarker 2024-07-17 03:25:24 +09:00
9 changed files with 87 additions and 1 deletions

View file

@ -448,6 +448,7 @@ set(SOURCES
HTML/WorkerGlobalScope.cpp HTML/WorkerGlobalScope.cpp
HTML/WorkerLocation.cpp HTML/WorkerLocation.cpp
HTML/WorkerNavigator.cpp HTML/WorkerNavigator.cpp
HTML/ValidityState.cpp
HighResolutionTime/Performance.cpp HighResolutionTime/Performance.cpp
HighResolutionTime/TimeOrigin.cpp HighResolutionTime/TimeOrigin.cpp
Infra/Base64.cpp Infra/Base64.cpp

View file

@ -467,6 +467,7 @@ class TrackEvent;
struct TransferDataHolder; struct TransferDataHolder;
class TraversableNavigable; class TraversableNavigable;
class UserActivation; class UserActivation;
class ValidityState;
class VideoTrack; class VideoTrack;
class VideoTrackList; class VideoTrackList;
class Window; class Window;

View file

@ -27,6 +27,7 @@
#include <LibWeb/HTML/HTMLDivElement.h> #include <LibWeb/HTML/HTMLDivElement.h>
#include <LibWeb/HTML/HTMLFormElement.h> #include <LibWeb/HTML/HTMLFormElement.h>
#include <LibWeb/HTML/HTMLInputElement.h> #include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/HTML/ValidityState.h>
#include <LibWeb/HTML/Numbers.h> #include <LibWeb/HTML/Numbers.h>
#include <LibWeb/HTML/Parser/HTMLParser.h> #include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/HTML/Scripting/Environments.h> #include <LibWeb/HTML/Scripting/Environments.h>
@ -82,6 +83,17 @@ void HTMLInputElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_image_request); visitor.visit(m_image_request);
} }
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-validity
JS::NonnullGCPtr<ValidityState const> HTMLInputElement::validity() const
{
auto& vm = this->vm();
auto& realm = this->realm();
dbgln("FIXME: Implement validity attribute getter");
return vm.heap().allocate<ValidityState>(realm, realm);
}
JS::GCPtr<Layout::Node> HTMLInputElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style) JS::GCPtr<Layout::Node> HTMLInputElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
{ {
if (type_state() == TypeAttributeState::Hidden) if (type_state() == TypeAttributeState::Hidden)

View file

@ -174,6 +174,8 @@ public:
virtual void form_associated_element_was_removed(DOM::Node*) override; virtual void form_associated_element_was_removed(DOM::Node*) override;
virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&) override; virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&) override;
JS::NonnullGCPtr<ValidityState const> validity() const;
// ^HTMLElement // ^HTMLElement
// https://html.spec.whatwg.org/multipage/forms.html#category-label // https://html.spec.whatwg.org/multipage/forms.html#category-label
virtual bool is_labelable() const override { return type_state() != TypeAttributeState::Hidden; } virtual bool is_labelable() const override { return type_state() != TypeAttributeState::Hidden; }

View file

@ -1,5 +1,6 @@
#import <HTML/HTMLElement.idl> #import <HTML/HTMLElement.idl>
#import <HTML/HTMLFormElement.idl> #import <HTML/HTMLFormElement.idl>
#import <HTML/ValidityState.idl>
#import <FileAPI/FileList.idl> #import <FileAPI/FileList.idl>
// https://html.spec.whatwg.org/multipage/input.html#htmlinputelement // https://html.spec.whatwg.org/multipage/input.html#htmlinputelement
@ -48,7 +49,7 @@ interface HTMLInputElement : HTMLElement {
undefined stepDown(optional long n = 1); undefined stepDown(optional long n = 1);
[FIXME] readonly attribute boolean willValidate; [FIXME] readonly attribute boolean willValidate;
[FIXME] readonly attribute ValidityState validity; readonly attribute ValidityState validity;
[FIXME] readonly attribute DOMString validationMessage; [FIXME] readonly attribute DOMString validationMessage;
boolean checkValidity(); boolean checkValidity();
boolean reportValidity(); boolean reportValidity();

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/ValidityState.h>
#include <LibWeb/Bindings/ValidityStatePrototype.h>
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(ValidityState);
ValidityState::ValidityState(JS::Realm& realm)
: PlatformObject(realm)
{
}
void ValidityState::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(ValidityState);
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#validitystate
class ValidityState final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(ValidityState, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(ValidityState);
public:
virtual ~ValidityState() override = default;
private:
ValidityState(JS::Realm&);
virtual void initialize(JS::Realm&) override;
};
}

View file

@ -0,0 +1,15 @@
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#validitystate
[Exposed=Window]
interface ValidityState {
[FIXME] readonly attribute boolean valueMissing;
[FIXME] readonly attribute boolean typeMismatch;
[FIXME] readonly attribute boolean patternMismatch;
[FIXME] readonly attribute boolean tooLong;
[FIXME] readonly attribute boolean tooShort;
[FIXME] readonly attribute boolean rangeUnderflow;
[FIXME] readonly attribute boolean rangeOverflow;
[FIXME] readonly attribute boolean stepMismatch;
[FIXME] readonly attribute boolean badInput;
[FIXME] readonly attribute boolean customError;
[FIXME] readonly attribute boolean valid;
};

View file

@ -210,6 +210,7 @@ libweb_js_bindings(HTML/TimeRanges)
libweb_js_bindings(HTML/ToggleEvent) libweb_js_bindings(HTML/ToggleEvent)
libweb_js_bindings(HTML/TrackEvent) libweb_js_bindings(HTML/TrackEvent)
libweb_js_bindings(HTML/UserActivation) libweb_js_bindings(HTML/UserActivation)
libweb_js_bindings(HTML/ValidityState)
libweb_js_bindings(HTML/VideoTrack) libweb_js_bindings(HTML/VideoTrack)
libweb_js_bindings(HTML/VideoTrackList) libweb_js_bindings(HTML/VideoTrackList)
libweb_js_bindings(HTML/Window GLOBAL) libweb_js_bindings(HTML/Window GLOBAL)