e3fd353459eb4e634c9db31401ce53026e546d98
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMHTMLSelectElement.cpp
1 /*
2  *  This file is part of the WebKit open source project.
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Library General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2 of the License, or (at your option) any later version.
8  *
9  *  This library is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *  Library General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Library General Public License
15  *  along with this library; see the file COPYING.LIB.  If not, write to
16  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  *  Boston, MA 02110-1301, USA.
18  */
19
20 #include "config.h"
21 #include "WebKitDOMHTMLSelectElement.h"
22
23 #include <WebCore/CSSImportRule.h>
24 #include "DOMObjectCache.h"
25 #include <WebCore/Document.h>
26 #include <WebCore/ExceptionCode.h>
27 #include <WebCore/ExceptionCodeDescription.h>
28 #include "GObjectEventListener.h"
29 #include <WebCore/HTMLNames.h>
30 #include <WebCore/HTMLOptGroupElement.h>
31 #include <WebCore/JSMainThreadExecState.h>
32 #include "WebKitDOMEventPrivate.h"
33 #include "WebKitDOMEventTarget.h"
34 #include "WebKitDOMHTMLCollectionPrivate.h"
35 #include "WebKitDOMHTMLElementPrivate.h"
36 #include "WebKitDOMHTMLFormElementPrivate.h"
37 #include "WebKitDOMHTMLOptionsCollectionPrivate.h"
38 #include "WebKitDOMHTMLSelectElementPrivate.h"
39 #include "WebKitDOMNodeListPrivate.h"
40 #include "WebKitDOMNodePrivate.h"
41 #include "WebKitDOMPrivate.h"
42 #include "ConvertToUTF8String.h"
43 #include <wtf/GetPtr.h>
44 #include <wtf/RefPtr.h>
45
46 namespace WebKit {
47
48 WebKitDOMHTMLSelectElement* kit(WebCore::HTMLSelectElement* obj)
49 {
50     return WEBKIT_DOM_HTML_SELECT_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
51 }
52
53 WebCore::HTMLSelectElement* core(WebKitDOMHTMLSelectElement* request)
54 {
55     return request ? static_cast<WebCore::HTMLSelectElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
56 }
57
58 WebKitDOMHTMLSelectElement* wrapHTMLSelectElement(WebCore::HTMLSelectElement* coreObject)
59 {
60     ASSERT(coreObject);
61     return WEBKIT_DOM_HTML_SELECT_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_SELECT_ELEMENT, "core-object", coreObject, nullptr));
62 }
63
64 } // namespace WebKit
65
66 static gboolean webkit_dom_html_select_element_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
67 {
68     WebCore::Event* coreEvent = WebKit::core(event);
69     if (!coreEvent)
70         return false;
71     WebCore::HTMLSelectElement* coreTarget = static_cast<WebCore::HTMLSelectElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
72
73     auto result = coreTarget->dispatchEventForBindings(*coreEvent);
74     if (result.hasException()) {
75         WebCore::ExceptionCodeDescription description(result.releaseException().code());
76         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.code, description.name);
77         return false;
78     }
79     return result.releaseReturnValue();
80 }
81
82 static gboolean webkit_dom_html_select_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
83 {
84     WebCore::HTMLSelectElement* coreTarget = static_cast<WebCore::HTMLSelectElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
85     return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
86 }
87
88 static gboolean webkit_dom_html_select_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
89 {
90     WebCore::HTMLSelectElement* coreTarget = static_cast<WebCore::HTMLSelectElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
91     return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
92 }
93
94 static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface)
95 {
96     iface->dispatch_event = webkit_dom_html_select_element_dispatch_event;
97     iface->add_event_listener = webkit_dom_html_select_element_add_event_listener;
98     iface->remove_event_listener = webkit_dom_html_select_element_remove_event_listener;
99 }
100
101 G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLSelectElement, webkit_dom_html_select_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_event_target_init))
102
103 enum {
104     PROP_0,
105     PROP_AUTOFOCUS,
106     PROP_DISABLED,
107     PROP_FORM,
108     PROP_MULTIPLE,
109     PROP_NAME,
110     PROP_SIZE,
111     PROP_TYPE,
112     PROP_OPTIONS,
113     PROP_LENGTH,
114     PROP_SELECTED_INDEX,
115     PROP_VALUE,
116     PROP_WILL_VALIDATE,
117 };
118
119 static void webkit_dom_html_select_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
120 {
121     WebKitDOMHTMLSelectElement* self = WEBKIT_DOM_HTML_SELECT_ELEMENT(object);
122
123     switch (propertyId) {
124     case PROP_AUTOFOCUS:
125         webkit_dom_html_select_element_set_autofocus(self, g_value_get_boolean(value));
126         break;
127     case PROP_DISABLED:
128         webkit_dom_html_select_element_set_disabled(self, g_value_get_boolean(value));
129         break;
130     case PROP_MULTIPLE:
131         webkit_dom_html_select_element_set_multiple(self, g_value_get_boolean(value));
132         break;
133     case PROP_NAME:
134         webkit_dom_html_select_element_set_name(self, g_value_get_string(value));
135         break;
136     case PROP_SIZE:
137         webkit_dom_html_select_element_set_size(self, g_value_get_long(value));
138         break;
139     case PROP_LENGTH:
140         webkit_dom_html_select_element_set_length(self, g_value_get_ulong(value), nullptr);
141         break;
142     case PROP_SELECTED_INDEX:
143         webkit_dom_html_select_element_set_selected_index(self, g_value_get_long(value));
144         break;
145     case PROP_VALUE:
146         webkit_dom_html_select_element_set_value(self, g_value_get_string(value));
147         break;
148     default:
149         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
150         break;
151     }
152 }
153
154 static void webkit_dom_html_select_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
155 {
156     WebKitDOMHTMLSelectElement* self = WEBKIT_DOM_HTML_SELECT_ELEMENT(object);
157
158     switch (propertyId) {
159     case PROP_AUTOFOCUS:
160         g_value_set_boolean(value, webkit_dom_html_select_element_get_autofocus(self));
161         break;
162     case PROP_DISABLED:
163         g_value_set_boolean(value, webkit_dom_html_select_element_get_disabled(self));
164         break;
165     case PROP_FORM:
166         g_value_set_object(value, webkit_dom_html_select_element_get_form(self));
167         break;
168     case PROP_MULTIPLE:
169         g_value_set_boolean(value, webkit_dom_html_select_element_get_multiple(self));
170         break;
171     case PROP_NAME:
172         g_value_take_string(value, webkit_dom_html_select_element_get_name(self));
173         break;
174     case PROP_SIZE:
175         g_value_set_long(value, webkit_dom_html_select_element_get_size(self));
176         break;
177     case PROP_TYPE:
178         g_value_take_string(value, webkit_dom_html_select_element_get_select_type(self));
179         break;
180     case PROP_OPTIONS:
181         g_value_set_object(value, webkit_dom_html_select_element_get_options(self));
182         break;
183     case PROP_LENGTH:
184         g_value_set_ulong(value, webkit_dom_html_select_element_get_length(self));
185         break;
186     case PROP_SELECTED_INDEX:
187         g_value_set_long(value, webkit_dom_html_select_element_get_selected_index(self));
188         break;
189     case PROP_VALUE:
190         g_value_take_string(value, webkit_dom_html_select_element_get_value(self));
191         break;
192     case PROP_WILL_VALIDATE:
193         g_value_set_boolean(value, webkit_dom_html_select_element_get_will_validate(self));
194         break;
195     default:
196         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
197         break;
198     }
199 }
200
201 static void webkit_dom_html_select_element_class_init(WebKitDOMHTMLSelectElementClass* requestClass)
202 {
203     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
204     gobjectClass->set_property = webkit_dom_html_select_element_set_property;
205     gobjectClass->get_property = webkit_dom_html_select_element_get_property;
206
207     g_object_class_install_property(
208         gobjectClass,
209         PROP_AUTOFOCUS,
210         g_param_spec_boolean(
211             "autofocus",
212             "HTMLSelectElement:autofocus",
213             "read-write gboolean HTMLSelectElement:autofocus",
214             FALSE,
215             WEBKIT_PARAM_READWRITE));
216
217     g_object_class_install_property(
218         gobjectClass,
219         PROP_DISABLED,
220         g_param_spec_boolean(
221             "disabled",
222             "HTMLSelectElement:disabled",
223             "read-write gboolean HTMLSelectElement:disabled",
224             FALSE,
225             WEBKIT_PARAM_READWRITE));
226
227     g_object_class_install_property(
228         gobjectClass,
229         PROP_FORM,
230         g_param_spec_object(
231             "form",
232             "HTMLSelectElement:form",
233             "read-only WebKitDOMHTMLFormElement* HTMLSelectElement:form",
234             WEBKIT_DOM_TYPE_HTML_FORM_ELEMENT,
235             WEBKIT_PARAM_READABLE));
236
237     g_object_class_install_property(
238         gobjectClass,
239         PROP_MULTIPLE,
240         g_param_spec_boolean(
241             "multiple",
242             "HTMLSelectElement:multiple",
243             "read-write gboolean HTMLSelectElement:multiple",
244             FALSE,
245             WEBKIT_PARAM_READWRITE));
246
247     g_object_class_install_property(
248         gobjectClass,
249         PROP_NAME,
250         g_param_spec_string(
251             "name",
252             "HTMLSelectElement:name",
253             "read-write gchar* HTMLSelectElement:name",
254             "",
255             WEBKIT_PARAM_READWRITE));
256
257     g_object_class_install_property(
258         gobjectClass,
259         PROP_SIZE,
260         g_param_spec_long(
261             "size",
262             "HTMLSelectElement:size",
263             "read-write glong HTMLSelectElement:size",
264             G_MINLONG, G_MAXLONG, 0,
265             WEBKIT_PARAM_READWRITE));
266
267     g_object_class_install_property(
268         gobjectClass,
269         PROP_TYPE,
270         g_param_spec_string(
271             "type",
272             "HTMLSelectElement:type",
273             "read-only gchar* HTMLSelectElement:type",
274             "",
275             WEBKIT_PARAM_READABLE));
276
277     g_object_class_install_property(
278         gobjectClass,
279         PROP_OPTIONS,
280         g_param_spec_object(
281             "options",
282             "HTMLSelectElement:options",
283             "read-only WebKitDOMHTMLOptionsCollection* HTMLSelectElement:options",
284             WEBKIT_DOM_TYPE_HTML_OPTIONS_COLLECTION,
285             WEBKIT_PARAM_READABLE));
286
287     g_object_class_install_property(
288         gobjectClass,
289         PROP_LENGTH,
290         g_param_spec_ulong(
291             "length",
292             "HTMLSelectElement:length",
293             "read-write gulong HTMLSelectElement:length",
294             0, G_MAXULONG, 0,
295             WEBKIT_PARAM_READWRITE));
296
297     g_object_class_install_property(
298         gobjectClass,
299         PROP_SELECTED_INDEX,
300         g_param_spec_long(
301             "selected-index",
302             "HTMLSelectElement:selected-index",
303             "read-write glong HTMLSelectElement:selected-index",
304             G_MINLONG, G_MAXLONG, 0,
305             WEBKIT_PARAM_READWRITE));
306
307     g_object_class_install_property(
308         gobjectClass,
309         PROP_VALUE,
310         g_param_spec_string(
311             "value",
312             "HTMLSelectElement:value",
313             "read-write gchar* HTMLSelectElement:value",
314             "",
315             WEBKIT_PARAM_READWRITE));
316
317     g_object_class_install_property(
318         gobjectClass,
319         PROP_WILL_VALIDATE,
320         g_param_spec_boolean(
321             "will-validate",
322             "HTMLSelectElement:will-validate",
323             "read-only gboolean HTMLSelectElement:will-validate",
324             FALSE,
325             WEBKIT_PARAM_READABLE));
326 }
327
328 static void webkit_dom_html_select_element_init(WebKitDOMHTMLSelectElement* request)
329 {
330     UNUSED_PARAM(request);
331 }
332
333 WebKitDOMNode* webkit_dom_html_select_element_item(WebKitDOMHTMLSelectElement* self, gulong index)
334 {
335     WebCore::JSMainThreadNullState state;
336     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
337     WebCore::HTMLSelectElement* item = WebKit::core(self);
338     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->item(index));
339     return WebKit::kit(gobjectResult.get());
340 }
341
342 WebKitDOMNode* webkit_dom_html_select_element_named_item(WebKitDOMHTMLSelectElement* self, const gchar* name)
343 {
344     WebCore::JSMainThreadNullState state;
345     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
346     g_return_val_if_fail(name, 0);
347     WebCore::HTMLSelectElement* item = WebKit::core(self);
348     WTF::String convertedName = WTF::String::fromUTF8(name);
349     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->namedItem(convertedName));
350     return WebKit::kit(gobjectResult.get());
351 }
352
353 void webkit_dom_html_select_element_add(WebKitDOMHTMLSelectElement* self, WebKitDOMHTMLElement* element, WebKitDOMHTMLElement* before, GError** error)
354 {
355     WebCore::JSMainThreadNullState state;
356     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
357     g_return_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(element));
358     g_return_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(before));
359     g_return_if_fail(!error || !*error);
360     WebCore::HTMLSelectElement* item = WebKit::core(self);
361     WebCore::HTMLElement* convertedElement = WebKit::core(element);
362     WebCore::HTMLElement* convertedBefore = WebKit::core(before);
363     Variant<RefPtr<WebCore::HTMLOptionElement>, RefPtr<WebCore::HTMLOptGroupElement>> variantElement;
364     if (is<WebCore::HTMLOptionElement>(convertedElement))
365         variantElement = &downcast<WebCore::HTMLOptionElement>(*convertedElement);
366     else if (is<WebCore::HTMLOptGroupElement>(convertedElement))
367         variantElement = &downcast<WebCore::HTMLOptGroupElement>(*convertedElement);
368     else {
369         WebCore::ExceptionCodeDescription ecdesc(WebCore::TypeError);
370         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
371         return;
372     }
373
374     auto exception = item->add(WTFMove(variantElement), WebCore::HTMLSelectElement::HTMLElementOrInt(convertedBefore));
375     if (exception.hasException()) {
376         WebCore::ExceptionCodeDescription ecdesc(exception.releaseException().code());
377         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
378     }
379 }
380
381 void webkit_dom_html_select_element_remove(WebKitDOMHTMLSelectElement* self, glong index)
382 {
383     WebCore::JSMainThreadNullState state;
384     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
385     WebCore::HTMLSelectElement* item = WebKit::core(self);
386     item->remove(index);
387 }
388
389 gboolean webkit_dom_html_select_element_get_autofocus(WebKitDOMHTMLSelectElement* self)
390 {
391     WebCore::JSMainThreadNullState state;
392     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), FALSE);
393     WebCore::HTMLSelectElement* item = WebKit::core(self);
394     gboolean result = item->hasAttributeWithoutSynchronization(WebCore::HTMLNames::autofocusAttr);
395     return result;
396 }
397
398 void webkit_dom_html_select_element_set_autofocus(WebKitDOMHTMLSelectElement* self, gboolean value)
399 {
400     WebCore::JSMainThreadNullState state;
401     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
402     WebCore::HTMLSelectElement* item = WebKit::core(self);
403     item->setBooleanAttribute(WebCore::HTMLNames::autofocusAttr, value);
404 }
405
406 gboolean webkit_dom_html_select_element_get_disabled(WebKitDOMHTMLSelectElement* self)
407 {
408     WebCore::JSMainThreadNullState state;
409     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), FALSE);
410     WebCore::HTMLSelectElement* item = WebKit::core(self);
411     gboolean result = item->hasAttributeWithoutSynchronization(WebCore::HTMLNames::disabledAttr);
412     return result;
413 }
414
415 void webkit_dom_html_select_element_set_disabled(WebKitDOMHTMLSelectElement* self, gboolean value)
416 {
417     WebCore::JSMainThreadNullState state;
418     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
419     WebCore::HTMLSelectElement* item = WebKit::core(self);
420     item->setBooleanAttribute(WebCore::HTMLNames::disabledAttr, value);
421 }
422
423 WebKitDOMHTMLFormElement* webkit_dom_html_select_element_get_form(WebKitDOMHTMLSelectElement* self)
424 {
425     WebCore::JSMainThreadNullState state;
426     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
427     WebCore::HTMLSelectElement* item = WebKit::core(self);
428     RefPtr<WebCore::HTMLFormElement> gobjectResult = WTF::getPtr(item->form());
429     return WebKit::kit(gobjectResult.get());
430 }
431
432 gboolean webkit_dom_html_select_element_get_multiple(WebKitDOMHTMLSelectElement* self)
433 {
434     WebCore::JSMainThreadNullState state;
435     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), FALSE);
436     WebCore::HTMLSelectElement* item = WebKit::core(self);
437     gboolean result = item->multiple();
438     return result;
439 }
440
441 void webkit_dom_html_select_element_set_multiple(WebKitDOMHTMLSelectElement* self, gboolean value)
442 {
443     WebCore::JSMainThreadNullState state;
444     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
445     WebCore::HTMLSelectElement* item = WebKit::core(self);
446     item->setMultiple(value);
447 }
448
449 gchar* webkit_dom_html_select_element_get_name(WebKitDOMHTMLSelectElement* self)
450 {
451     WebCore::JSMainThreadNullState state;
452     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
453     WebCore::HTMLSelectElement* item = WebKit::core(self);
454     gchar* result = convertToUTF8String(item->getNameAttribute());
455     return result;
456 }
457
458 void webkit_dom_html_select_element_set_name(WebKitDOMHTMLSelectElement* self, const gchar* value)
459 {
460     WebCore::JSMainThreadNullState state;
461     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
462     g_return_if_fail(value);
463     WebCore::HTMLSelectElement* item = WebKit::core(self);
464     WTF::String convertedValue = WTF::String::fromUTF8(value);
465     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::nameAttr, convertedValue);
466 }
467
468 glong webkit_dom_html_select_element_get_size(WebKitDOMHTMLSelectElement* self)
469 {
470     WebCore::JSMainThreadNullState state;
471     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
472     WebCore::HTMLSelectElement* item = WebKit::core(self);
473     glong result = item->size();
474     return result;
475 }
476
477 void webkit_dom_html_select_element_set_size(WebKitDOMHTMLSelectElement* self, glong value)
478 {
479     WebCore::JSMainThreadNullState state;
480     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
481     WebCore::HTMLSelectElement* item = WebKit::core(self);
482     item->setSize(value);
483 }
484
485 gchar* webkit_dom_html_select_element_get_select_type(WebKitDOMHTMLSelectElement* self)
486 {
487     WebCore::JSMainThreadNullState state;
488     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
489     WebCore::HTMLSelectElement* item = WebKit::core(self);
490     gchar* result = convertToUTF8String(item->type());
491     return result;
492 }
493
494 WebKitDOMHTMLOptionsCollection* webkit_dom_html_select_element_get_options(WebKitDOMHTMLSelectElement* self)
495 {
496     WebCore::JSMainThreadNullState state;
497     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
498     WebCore::HTMLSelectElement* item = WebKit::core(self);
499     RefPtr<WebCore::HTMLOptionsCollection> gobjectResult = WTF::getPtr(item->options());
500     return WebKit::kit(gobjectResult.get());
501 }
502
503 gulong webkit_dom_html_select_element_get_length(WebKitDOMHTMLSelectElement* self)
504 {
505     WebCore::JSMainThreadNullState state;
506     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
507     WebCore::HTMLSelectElement* item = WebKit::core(self);
508     gulong result = item->length();
509     return result;
510 }
511
512 void webkit_dom_html_select_element_set_length(WebKitDOMHTMLSelectElement* self, gulong value, GError** error)
513 {
514     WebCore::JSMainThreadNullState state;
515     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
516     g_return_if_fail(!error || !*error);
517     WebCore::HTMLSelectElement* item = WebKit::core(self);
518     auto result = item->setLength(value);
519     if (result.hasException()) {
520         WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
521         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
522     }
523 }
524
525 glong webkit_dom_html_select_element_get_selected_index(WebKitDOMHTMLSelectElement* self)
526 {
527     WebCore::JSMainThreadNullState state;
528     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
529     WebCore::HTMLSelectElement* item = WebKit::core(self);
530     glong result = item->selectedIndex();
531     return result;
532 }
533
534 void webkit_dom_html_select_element_set_selected_index(WebKitDOMHTMLSelectElement* self, glong value)
535 {
536     WebCore::JSMainThreadNullState state;
537     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
538     WebCore::HTMLSelectElement* item = WebKit::core(self);
539     item->setSelectedIndex(value);
540 }
541
542 gchar* webkit_dom_html_select_element_get_value(WebKitDOMHTMLSelectElement* self)
543 {
544     WebCore::JSMainThreadNullState state;
545     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
546     WebCore::HTMLSelectElement* item = WebKit::core(self);
547     gchar* result = convertToUTF8String(item->value());
548     return result;
549 }
550
551 void webkit_dom_html_select_element_set_value(WebKitDOMHTMLSelectElement* self, const gchar* value)
552 {
553     WebCore::JSMainThreadNullState state;
554     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
555     g_return_if_fail(value);
556     WebCore::HTMLSelectElement* item = WebKit::core(self);
557     WTF::String convertedValue = WTF::String::fromUTF8(value);
558     item->setValue(convertedValue);
559 }
560
561 gboolean webkit_dom_html_select_element_get_will_validate(WebKitDOMHTMLSelectElement* self)
562 {
563     WebCore::JSMainThreadNullState state;
564     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), FALSE);
565     WebCore::HTMLSelectElement* item = WebKit::core(self);
566     gboolean result = item->willValidate();
567     return result;
568 }