@@ -47,21 +47,21 @@ void HTMLFormElement::visit_edges(Cell::Visitor& visitor)
47
47
visitor.visit (element.ptr ());
48
48
}
49
49
50
- void HTMLFormElement::submit_form (JS::GCPtr<HTMLElement> submitter, bool from_submit_binding)
50
+ ErrorOr< void > HTMLFormElement::submit_form (JS::GCPtr<HTMLElement> submitter, bool from_submit_binding)
51
51
{
52
52
if (cannot_navigate ())
53
- return ;
53
+ return {} ;
54
54
55
55
if (action ().is_null ()) {
56
56
dbgln (" Unsupported form action ''" );
57
- return ;
57
+ return {} ;
58
58
}
59
59
60
60
auto effective_method = method ().to_lowercase ();
61
61
62
62
if (effective_method == " dialog" ) {
63
63
dbgln (" Failed to submit form: Unsupported form method '{}'" , method ());
64
- return ;
64
+ return {} ;
65
65
}
66
66
67
67
if (effective_method != " get" && effective_method != " post" ) {
@@ -70,7 +70,7 @@ void HTMLFormElement::submit_form(JS::GCPtr<HTMLElement> submitter, bool from_su
70
70
71
71
if (!from_submit_binding) {
72
72
if (m_firing_submission_events)
73
- return ;
73
+ return {} ;
74
74
75
75
m_firing_submission_events = true ;
76
76
@@ -91,58 +91,65 @@ void HTMLFormElement::submit_form(JS::GCPtr<HTMLElement> submitter, bool from_su
91
91
m_firing_submission_events = false ;
92
92
93
93
if (!continue_)
94
- return ;
94
+ return {} ;
95
95
96
96
// This is checked again because arbitrary JS may have run when handling submit,
97
97
// which may have changed the result.
98
98
if (cannot_navigate ())
99
- return ;
99
+ return {} ;
100
100
}
101
101
102
102
AK::URL url (document ().parse_url (action ()));
103
103
104
104
if (!url.is_valid ()) {
105
105
dbgln (" Failed to submit form: Invalid URL: {}" , action ());
106
- return ;
106
+ return {} ;
107
107
}
108
108
109
109
if (url.scheme () == " file" ) {
110
110
if (document ().url ().scheme () != " file" ) {
111
111
dbgln (" Failed to submit form: Security violation: {} may not submit to {}" , document ().url (), url);
112
- return ;
112
+ return {} ;
113
113
}
114
114
if (effective_method != " get" ) {
115
115
dbgln (" Failed to submit form: Unsupported form method '{}' for URL: {}" , method (), url);
116
- return ;
116
+ return {} ;
117
117
}
118
118
} else if (url.scheme () != " http" && url.scheme () != " https" ) {
119
119
dbgln (" Failed to submit form: Unsupported protocol for URL: {}" , url);
120
- return ;
120
+ return {} ;
121
121
}
122
122
123
123
Vector<URL::QueryParam> parameters;
124
124
125
125
for_each_in_inclusive_subtree_of_type<HTMLInputElement>([&](auto & input) {
126
- if (!input.name ().is_null () && (input.type () != " submit" || &input == submitter))
127
- parameters.append ({ input.name (), input.value () });
126
+ if (!input.name ().is_null () && (input.type () != " submit" || &input == submitter)) {
127
+ auto name = String::from_deprecated_string (input.name ()).release_value_but_fixme_should_propagate_errors ();
128
+ auto value = String::from_deprecated_string (input.value ()).release_value_but_fixme_should_propagate_errors ();
129
+ parameters.append ({ move (name), move (value) });
130
+ }
128
131
return IterationDecision::Continue;
129
132
});
130
133
131
134
if (effective_method == " get" ) {
132
- url.set_query (url_encode (parameters, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded));
135
+ auto url_encoded_parameters = TRY (url_encode (parameters, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded)).to_deprecated_string ();
136
+ url.set_query (move (url_encoded_parameters));
133
137
}
134
138
135
139
LoadRequest request = LoadRequest::create_for_url_on_page (url, document ().page ());
136
140
137
141
if (effective_method == " post" ) {
138
- auto body = url_encode (parameters, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded).to_byte_buffer ();
142
+ auto url_encoded_parameters_as_bytes = TRY (url_encode (parameters, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded)).bytes ();
143
+ auto body = TRY (ByteBuffer::copy (url_encoded_parameters_as_bytes));
139
144
request.set_method (" POST" );
140
145
request.set_header (" Content-Type" , " application/x-www-form-urlencoded" );
141
146
request.set_body (move (body));
142
147
}
143
148
144
149
if (auto * page = document ().page ())
145
150
page->load (request);
151
+
152
+ return {};
146
153
}
147
154
148
155
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#resetting-a-form
@@ -166,9 +173,12 @@ void HTMLFormElement::reset_form()
166
173
}
167
174
}
168
175
169
- void HTMLFormElement::submit ()
176
+ WebIDL::ExceptionOr< void > HTMLFormElement::submit ()
170
177
{
171
- submit_form (this , true );
178
+ auto & vm = realm ().vm ();
179
+
180
+ TRY_OR_THROW_OOM (vm, submit_form (this , true ));
181
+ return {};
172
182
}
173
183
174
184
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-reset
0 commit comments