LibWeb: Use correct IDL for HTTPFormElement's method attribute

Removed the custom getter and updated the idl so that the attribute
is Reflected and Enumerated.
This commit is contained in:
samu698 2024-10-20 18:24:24 +02:00 committed by Andrew Kaster
parent ebe89a3207
commit 6892482755
Notes: github-actions[bot] 2024-10-21 21:42:12 +00:00
5 changed files with 83 additions and 19 deletions

View file

@ -0,0 +1,51 @@
form: unset
form.getAttribute('method') == 'null'
form.method == 'get'
form.setAttribute('method', '')
form.getAttribute('method') == ''
form.method == 'get'
form.setAttribute('method', 'undefined')
form.getAttribute('method') == 'undefined'
form.method == 'get'
form.setAttribute('method', 'null')
form.getAttribute('method') == 'null'
form.method == 'get'
form.setAttribute('method', 'get')
form.getAttribute('method') == 'get'
form.method == 'get'
form.setAttribute('method', 'post')
form.getAttribute('method') == 'post'
form.method == 'post'
form.setAttribute('method', 'dialog')
form.getAttribute('method') == 'dialog'
form.method == 'dialog'
form.setAttribute('method', 'GeT')
form.getAttribute('method') == 'GeT'
form.method == 'get'
form.setAttribute('method', 'POST')
form.getAttribute('method') == 'POST'
form.method == 'post'
form.setAttribute('method', 'DIAlog')
form.getAttribute('method') == 'DIAlog'
form.method == 'dialog'
form.setAttribute('method', 'foo')
form.getAttribute('method') == 'foo'
form.method == 'get'
form.setAttribute('method', 'xpost')
form.getAttribute('method') == 'xpost'
form.method == 'get'
form.setAttribute('method', '5%')
form.getAttribute('method') == '5%'
form.method == 'get'

View file

@ -0,0 +1,23 @@
<script src="./include.js"></script>
<script>
test(() => {
const form = document.createElement('form');
const values = [
'', undefined, null,
'get', 'post', 'dialog',
'GeT', 'POST', 'DIAlog',
'foo', 'xpost', '5%'
];
println('form: unset');
println(`form.getAttribute('method') == '${form.getAttribute('method')}'`);
println(`form.method == '${form.method}'`);
for (value of values) {
form.setAttribute('method', value);
println('');
println(`form.setAttribute('method', '${value}')`);
println(`form.getAttribute('method') == '${form.getAttribute('method')}'`);
println(`form.method == '${form.method}'`);
}
});
</script>

View file

@ -565,23 +565,6 @@ Vector<JS::NonnullGCPtr<DOM::Element>> HTMLFormElement::get_submittable_elements
return submittable_elements; return submittable_elements;
} }
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-method
StringView HTMLFormElement::method() const
{
// The method and enctype IDL attributes must reflect the respective content attributes of the same name, limited to only known values.
// FIXME: This should probably be `Reflect` in the IDL.
auto method_state = method_state_from_form_element(*this);
switch (method_state) {
case MethodAttributeState::GET:
return "get"sv;
case MethodAttributeState::POST:
return "post"sv;
case MethodAttributeState::Dialog:
return "dialog"sv;
}
VERIFY_NOT_REACHED();
}
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-rellist // https://html.spec.whatwg.org/multipage/forms.html#dom-form-rellist
JS::NonnullGCPtr<DOM::DOMTokenList> HTMLFormElement::rel_list() JS::NonnullGCPtr<DOM::DOMTokenList> HTMLFormElement::rel_list()
{ {

View file

@ -88,7 +88,6 @@ public:
bool constructing_entry_list() const { return m_constructing_entry_list; } bool constructing_entry_list() const { return m_constructing_entry_list; }
void set_constructing_entry_list(bool value) { m_constructing_entry_list = value; } void set_constructing_entry_list(bool value) { m_constructing_entry_list = value; }
StringView method() const;
WebIDL::ExceptionOr<void> set_method(String const&); WebIDL::ExceptionOr<void> set_method(String const&);
JS::NonnullGCPtr<DOM::DOMTokenList> rel_list(); JS::NonnullGCPtr<DOM::DOMTokenList> rel_list();

View file

@ -16,6 +16,14 @@ enum EnctypeAttribute {
"text/plain" "text/plain"
}; };
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-method
[MissingValueDefault=get, InvalidValueDefault=get]
enum MethodAttribute {
"get",
"post",
"dialog"
};
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#selectionmode // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#selectionmode
enum SelectionMode { enum SelectionMode {
"select", "select",
@ -35,7 +43,7 @@ interface HTMLFormElement : HTMLElement {
[CEReactions, Enumerated=Autocomplete, Reflect] attribute DOMString autocomplete; [CEReactions, Enumerated=Autocomplete, Reflect] attribute DOMString autocomplete;
[CEReactions, Enumerated=EnctypeAttribute, Reflect] attribute DOMString enctype; [CEReactions, Enumerated=EnctypeAttribute, Reflect] attribute DOMString enctype;
[CEReactions, Enumerated=EnctypeAttribute, Reflect=enctype] attribute DOMString encoding; [CEReactions, Enumerated=EnctypeAttribute, Reflect=enctype] attribute DOMString encoding;
[CEReactions] attribute DOMString method; [CEReactions, Enumerated=MethodAttribute, Reflect] attribute DOMString method;
[CEReactions, Reflect] attribute DOMString name; [CEReactions, Reflect] attribute DOMString name;
[CEReactions, Reflect=novalidate] attribute boolean noValidate; [CEReactions, Reflect=novalidate] attribute boolean noValidate;
[CEReactions, Reflect] attribute DOMString target; [CEReactions, Reflect] attribute DOMString target;