1/*
2 This file is part of the WebKit open source project.
3 This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22#include "JSHTMLOptionsCollection.h"
23
24#include "CustomElementReactionQueue.h"
25#include "Element.h"
26#include "JSDOMAbstractOperations.h"
27#include "JSDOMAttribute.h"
28#include "JSDOMBinding.h"
29#include "JSDOMConstructorNotConstructable.h"
30#include "JSDOMConvertInterface.h"
31#include "JSDOMConvertNullable.h"
32#include "JSDOMConvertNumbers.h"
33#include "JSDOMConvertStrings.h"
34#include "JSDOMConvertUnion.h"
35#include "JSDOMExceptionHandling.h"
36#include "JSDOMGlobalObject.h"
37#include "JSDOMOperation.h"
38#include "JSDOMWrapperCache.h"
39#include "JSHTMLElement.h"
40#include "JSHTMLOptGroupElement.h"
41#include "JSHTMLOptionElement.h"
42#include "JSNode.h"
43#include "JSNodeCustom.h"
44#include "Node.h"
45#include "ScriptExecutionContext.h"
46#include <JavaScriptCore/ArrayPrototype.h>
47#include <JavaScriptCore/BuiltinNames.h>
48#include <JavaScriptCore/HeapSnapshotBuilder.h>
49#include <JavaScriptCore/JSCInlines.h>
50#include <JavaScriptCore/PropertyNameArray.h>
51#include <wtf/GetPtr.h>
52#include <wtf/PointerPreparations.h>
53#include <wtf/URL.h>
54#include <wtf/Variant.h>
55
56
57namespace WebCore {
58using namespace JSC;
59
60// Functions
61
62JSC::EncodedJSValue JSC_HOST_CALL jsHTMLOptionsCollectionPrototypeFunctionAdd(JSC::ExecState*);
63JSC::EncodedJSValue JSC_HOST_CALL jsHTMLOptionsCollectionPrototypeFunctionRemove(JSC::ExecState*);
64JSC::EncodedJSValue JSC_HOST_CALL jsHTMLOptionsCollectionPrototypeFunctionItem(JSC::ExecState*);
65JSC::EncodedJSValue JSC_HOST_CALL jsHTMLOptionsCollectionPrototypeFunctionNamedItem(JSC::ExecState*);
66
67// Attributes
68
69JSC::EncodedJSValue jsHTMLOptionsCollectionConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
70bool setJSHTMLOptionsCollectionConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
71JSC::EncodedJSValue jsHTMLOptionsCollectionLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
72bool setJSHTMLOptionsCollectionLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
73JSC::EncodedJSValue jsHTMLOptionsCollectionSelectedIndex(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
74bool setJSHTMLOptionsCollectionSelectedIndex(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
75
76class JSHTMLOptionsCollectionPrototype : public JSC::JSNonFinalObject {
77public:
78 using Base = JSC::JSNonFinalObject;
79 static JSHTMLOptionsCollectionPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
80 {
81 JSHTMLOptionsCollectionPrototype* ptr = new (NotNull, JSC::allocateCell<JSHTMLOptionsCollectionPrototype>(vm.heap)) JSHTMLOptionsCollectionPrototype(vm, globalObject, structure);
82 ptr->finishCreation(vm);
83 return ptr;
84 }
85
86 DECLARE_INFO;
87 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
88 {
89 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
90 }
91
92private:
93 JSHTMLOptionsCollectionPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
94 : JSC::JSNonFinalObject(vm, structure)
95 {
96 }
97
98 void finishCreation(JSC::VM&);
99};
100
101using JSHTMLOptionsCollectionConstructor = JSDOMConstructorNotConstructable<JSHTMLOptionsCollection>;
102
103template<> JSValue JSHTMLOptionsCollectionConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
104{
105 return JSHTMLCollection::getConstructor(vm, &globalObject);
106}
107
108template<> void JSHTMLOptionsCollectionConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
109{
110 putDirect(vm, vm.propertyNames->prototype, JSHTMLOptionsCollection::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
111 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("HTMLOptionsCollection"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
112 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
113}
114
115template<> const ClassInfo JSHTMLOptionsCollectionConstructor::s_info = { "HTMLOptionsCollection", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLOptionsCollectionConstructor) };
116
117/* Hash table for prototype */
118
119static const HashTableValue JSHTMLOptionsCollectionPrototypeTableValues[] =
120{
121 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLOptionsCollectionConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSHTMLOptionsCollectionConstructor) } },
122 { "length", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLOptionsCollectionLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSHTMLOptionsCollectionLength) } },
123 { "selectedIndex", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLOptionsCollectionSelectedIndex), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSHTMLOptionsCollectionSelectedIndex) } },
124 { "add", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsHTMLOptionsCollectionPrototypeFunctionAdd), (intptr_t) (1) } },
125 { "remove", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsHTMLOptionsCollectionPrototypeFunctionRemove), (intptr_t) (1) } },
126 { "item", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsHTMLOptionsCollectionPrototypeFunctionItem), (intptr_t) (1) } },
127 { "namedItem", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsHTMLOptionsCollectionPrototypeFunctionNamedItem), (intptr_t) (1) } },
128};
129
130const ClassInfo JSHTMLOptionsCollectionPrototype::s_info = { "HTMLOptionsCollectionPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLOptionsCollectionPrototype) };
131
132void JSHTMLOptionsCollectionPrototype::finishCreation(VM& vm)
133{
134 Base::finishCreation(vm);
135 reifyStaticProperties(vm, JSHTMLOptionsCollection::info(), JSHTMLOptionsCollectionPrototypeTableValues, *this);
136 putDirect(vm, vm.propertyNames->iteratorSymbol, globalObject()->arrayPrototype()->getDirect(vm, vm.propertyNames->builtinNames().valuesPrivateName()), static_cast<unsigned>(JSC::PropertyAttribute::DontEnum));
137}
138
139const ClassInfo JSHTMLOptionsCollection::s_info = { "HTMLOptionsCollection", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLOptionsCollection) };
140
141JSHTMLOptionsCollection::JSHTMLOptionsCollection(Structure* structure, JSDOMGlobalObject& globalObject, Ref<HTMLOptionsCollection>&& impl)
142 : JSHTMLCollection(structure, globalObject, WTFMove(impl))
143{
144}
145
146void JSHTMLOptionsCollection::finishCreation(VM& vm)
147{
148 Base::finishCreation(vm);
149 ASSERT(inherits(vm, info()));
150
151}
152
153JSObject* JSHTMLOptionsCollection::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
154{
155 return JSHTMLOptionsCollectionPrototype::create(vm, &globalObject, JSHTMLOptionsCollectionPrototype::createStructure(vm, &globalObject, JSHTMLCollection::prototype(vm, globalObject)));
156}
157
158JSObject* JSHTMLOptionsCollection::prototype(VM& vm, JSDOMGlobalObject& globalObject)
159{
160 return getDOMPrototype<JSHTMLOptionsCollection>(vm, globalObject);
161}
162
163JSValue JSHTMLOptionsCollection::getConstructor(VM& vm, const JSGlobalObject* globalObject)
164{
165 return getDOMConstructor<JSHTMLOptionsCollectionConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
166}
167
168bool JSHTMLOptionsCollection::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
169{
170 auto* thisObject = jsCast<JSHTMLOptionsCollection*>(object);
171 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
172 if (auto index = parseIndex(propertyName)) {
173 if (index.value() < thisObject->wrapped().length()) {
174 auto value = toJS<IDLNullable<IDLInterface<HTMLOptionElement>>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index.value()));
175 slot.setValue(thisObject, static_cast<unsigned>(0), value);
176 return true;
177 }
178 return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
179 }
180 using GetterIDLType = IDLInterface<HTMLOptionElement>;
181 auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
182 auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
183 if (!GetterIDLType::isNullValue(result))
184 return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
185 return WTF::nullopt;
186 };
187 if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
188 auto value = toJS<IDLNullable<IDLInterface<HTMLOptionElement>>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value()));
189 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
190 return true;
191 }
192 return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
193}
194
195bool JSHTMLOptionsCollection::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
196{
197 auto* thisObject = jsCast<JSHTMLOptionsCollection*>(object);
198 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
199 if (LIKELY(index <= MAX_ARRAY_INDEX)) {
200 if (index < thisObject->wrapped().length()) {
201 auto value = toJS<IDLNullable<IDLInterface<HTMLOptionElement>>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index));
202 slot.setValue(thisObject, static_cast<unsigned>(0), value);
203 return true;
204 }
205 return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
206 }
207 auto propertyName = Identifier::from(state, index);
208 using GetterIDLType = IDLInterface<HTMLOptionElement>;
209 auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
210 auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
211 if (!GetterIDLType::isNullValue(result))
212 return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
213 return WTF::nullopt;
214 };
215 if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
216 auto value = toJS<IDLNullable<IDLInterface<HTMLOptionElement>>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value()));
217 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
218 return true;
219 }
220 return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
221}
222
223void JSHTMLOptionsCollection::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
224{
225 auto* thisObject = jsCast<JSHTMLOptionsCollection*>(object);
226 ASSERT_GC_OBJECT_INHERITS(object, info());
227 for (unsigned i = 0, count = thisObject->wrapped().length(); i < count; ++i)
228 propertyNames.add(Identifier::from(state, i));
229 for (auto& propertyName : thisObject->wrapped().supportedPropertyNames())
230 propertyNames.add(Identifier::fromString(state, propertyName));
231 JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
232}
233
234bool JSHTMLOptionsCollection::put(JSCell* cell, ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot& putPropertySlot)
235{
236 auto* thisObject = jsCast<JSHTMLOptionsCollection*>(cell);
237 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
238
239 CustomElementReactionStack customElementReactionStack(*state);
240 if (auto index = parseIndex(propertyName)) {
241 auto throwScope = DECLARE_THROW_SCOPE(state->vm());
242 auto nativeValue = convert<IDLNullable<IDLInterface<HTMLOptionElement>>>(*state, value);
243 RETURN_IF_EXCEPTION(throwScope, true);
244 thisObject->wrapped().setItem(index.value(), WTFMove(nativeValue));
245 return true;
246 }
247
248 return JSObject::put(thisObject, state, propertyName, value, putPropertySlot);
249}
250
251bool JSHTMLOptionsCollection::putByIndex(JSCell* cell, ExecState* state, unsigned index, JSValue value, bool shouldThrow)
252{
253 auto* thisObject = jsCast<JSHTMLOptionsCollection*>(cell);
254 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
255
256 CustomElementReactionStack customElementReactionStack(*state);
257 if (LIKELY(index <= MAX_ARRAY_INDEX)) {
258 auto throwScope = DECLARE_THROW_SCOPE(state->vm());
259 auto nativeValue = convert<IDLNullable<IDLInterface<HTMLOptionElement>>>(*state, value);
260 RETURN_IF_EXCEPTION(throwScope, true);
261 thisObject->wrapped().setItem(index, WTFMove(nativeValue));
262 return true;
263 }
264
265 return JSObject::putByIndex(cell, state, index, value, shouldThrow);
266}
267
268bool JSHTMLOptionsCollection::defineOwnProperty(JSObject* object, ExecState* state, PropertyName propertyName, const PropertyDescriptor& propertyDescriptor, bool shouldThrow)
269{
270 auto* thisObject = jsCast<JSHTMLOptionsCollection*>(object);
271 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
272
273 CustomElementReactionStack customElementReactionStack(*state);
274 if (auto index = parseIndex(propertyName)) {
275 if (!propertyDescriptor.isDataDescriptor())
276 return false;
277 auto throwScope = DECLARE_THROW_SCOPE(state->vm());
278 auto nativeValue = convert<IDLNullable<IDLInterface<HTMLOptionElement>>>(*state, propertyDescriptor.value());
279 RETURN_IF_EXCEPTION(throwScope, true);
280 thisObject->wrapped().setItem(index.value(), WTFMove(nativeValue));
281 return true;
282 }
283
284 if (!propertyName.isSymbol()) {
285 PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
286 if (!JSObject::getOwnPropertySlot(thisObject, state, propertyName, slot)) {
287 if (thisObject->wrapped().isSupportedPropertyName(propertyNameToString(propertyName)))
288 return false;
289 }
290 }
291
292 PropertyDescriptor newPropertyDescriptor = propertyDescriptor;
293 newPropertyDescriptor.setConfigurable(true);
294 return JSObject::defineOwnProperty(object, state, propertyName, newPropertyDescriptor, shouldThrow);
295}
296
297template<> inline JSHTMLOptionsCollection* IDLAttribute<JSHTMLOptionsCollection>::cast(ExecState& state, EncodedJSValue thisValue)
298{
299 return jsDynamicCast<JSHTMLOptionsCollection*>(state.vm(), JSValue::decode(thisValue));
300}
301
302template<> inline JSHTMLOptionsCollection* IDLOperation<JSHTMLOptionsCollection>::cast(ExecState& state)
303{
304 return jsDynamicCast<JSHTMLOptionsCollection*>(state.vm(), state.thisValue());
305}
306
307EncodedJSValue jsHTMLOptionsCollectionConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
308{
309 VM& vm = state->vm();
310 auto throwScope = DECLARE_THROW_SCOPE(vm);
311 auto* prototype = jsDynamicCast<JSHTMLOptionsCollectionPrototype*>(vm, JSValue::decode(thisValue));
312 if (UNLIKELY(!prototype))
313 return throwVMTypeError(state, throwScope);
314 return JSValue::encode(JSHTMLOptionsCollection::getConstructor(state->vm(), prototype->globalObject()));
315}
316
317bool setJSHTMLOptionsCollectionConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
318{
319 VM& vm = state->vm();
320 auto throwScope = DECLARE_THROW_SCOPE(vm);
321 auto* prototype = jsDynamicCast<JSHTMLOptionsCollectionPrototype*>(vm, JSValue::decode(thisValue));
322 if (UNLIKELY(!prototype)) {
323 throwVMTypeError(state, throwScope);
324 return false;
325 }
326 // Shadowing a built-in constructor
327 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
328}
329
330static inline JSValue jsHTMLOptionsCollectionLengthGetter(ExecState& state, JSHTMLOptionsCollection& thisObject, ThrowScope& throwScope)
331{
332 UNUSED_PARAM(throwScope);
333 UNUSED_PARAM(state);
334 auto& impl = thisObject.wrapped();
335 JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.length());
336 return result;
337}
338
339EncodedJSValue jsHTMLOptionsCollectionLength(ExecState* state, EncodedJSValue thisValue, PropertyName)
340{
341 return IDLAttribute<JSHTMLOptionsCollection>::get<jsHTMLOptionsCollectionLengthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "length");
342}
343
344static inline bool setJSHTMLOptionsCollectionLengthSetter(ExecState& state, JSHTMLOptionsCollection& thisObject, JSValue value, ThrowScope& throwScope)
345{
346 UNUSED_PARAM(throwScope);
347 CustomElementReactionStack customElementReactionStack(state);
348 auto& impl = thisObject.wrapped();
349 auto nativeValue = convert<IDLUnsignedLong>(state, value);
350 RETURN_IF_EXCEPTION(throwScope, false);
351 AttributeSetter::call(state, throwScope, [&] {
352 return impl.setLength(WTFMove(nativeValue));
353 });
354 return true;
355}
356
357bool setJSHTMLOptionsCollectionLength(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
358{
359 return IDLAttribute<JSHTMLOptionsCollection>::set<setJSHTMLOptionsCollectionLengthSetter>(*state, thisValue, encodedValue, "length");
360}
361
362static inline JSValue jsHTMLOptionsCollectionSelectedIndexGetter(ExecState& state, JSHTMLOptionsCollection& thisObject, ThrowScope& throwScope)
363{
364 UNUSED_PARAM(throwScope);
365 UNUSED_PARAM(state);
366 auto& impl = thisObject.wrapped();
367 JSValue result = toJS<IDLLong>(state, throwScope, impl.selectedIndex());
368 return result;
369}
370
371EncodedJSValue jsHTMLOptionsCollectionSelectedIndex(ExecState* state, EncodedJSValue thisValue, PropertyName)
372{
373 return IDLAttribute<JSHTMLOptionsCollection>::get<jsHTMLOptionsCollectionSelectedIndexGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "selectedIndex");
374}
375
376static inline bool setJSHTMLOptionsCollectionSelectedIndexSetter(ExecState& state, JSHTMLOptionsCollection& thisObject, JSValue value, ThrowScope& throwScope)
377{
378 UNUSED_PARAM(throwScope);
379 auto& impl = thisObject.wrapped();
380 auto nativeValue = convert<IDLLong>(state, value);
381 RETURN_IF_EXCEPTION(throwScope, false);
382 AttributeSetter::call(state, throwScope, [&] {
383 return impl.setSelectedIndex(WTFMove(nativeValue));
384 });
385 return true;
386}
387
388bool setJSHTMLOptionsCollectionSelectedIndex(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
389{
390 return IDLAttribute<JSHTMLOptionsCollection>::set<setJSHTMLOptionsCollectionSelectedIndexSetter>(*state, thisValue, encodedValue, "selectedIndex");
391}
392
393static inline JSC::EncodedJSValue jsHTMLOptionsCollectionPrototypeFunctionAddBody(JSC::ExecState* state, typename IDLOperation<JSHTMLOptionsCollection>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
394{
395 UNUSED_PARAM(state);
396 UNUSED_PARAM(throwScope);
397 CustomElementReactionStack customElementReactionStack(*state);
398 auto& impl = castedThis->wrapped();
399 if (UNLIKELY(state->argumentCount() < 1))
400 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
401 auto element = convert<IDLUnion<IDLInterface<HTMLOptionElement>, IDLInterface<HTMLOptGroupElement>>>(*state, state->uncheckedArgument(0));
402 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
403 auto before = state->argument(1).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLUnion<IDLInterface<HTMLElement>, IDLLong>>>(*state, state->uncheckedArgument(1));
404 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
405 propagateException(*state, throwScope, impl.add(WTFMove(element), WTFMove(before)));
406 return JSValue::encode(jsUndefined());
407}
408
409EncodedJSValue JSC_HOST_CALL jsHTMLOptionsCollectionPrototypeFunctionAdd(ExecState* state)
410{
411 return IDLOperation<JSHTMLOptionsCollection>::call<jsHTMLOptionsCollectionPrototypeFunctionAddBody>(*state, "add");
412}
413
414static inline JSC::EncodedJSValue jsHTMLOptionsCollectionPrototypeFunctionRemoveBody(JSC::ExecState* state, typename IDLOperation<JSHTMLOptionsCollection>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
415{
416 UNUSED_PARAM(state);
417 UNUSED_PARAM(throwScope);
418 CustomElementReactionStack customElementReactionStack(*state);
419 auto& impl = castedThis->wrapped();
420 if (UNLIKELY(state->argumentCount() < 1))
421 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
422 auto index = convert<IDLLong>(*state, state->uncheckedArgument(0));
423 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
424 impl.remove(WTFMove(index));
425 return JSValue::encode(jsUndefined());
426}
427
428EncodedJSValue JSC_HOST_CALL jsHTMLOptionsCollectionPrototypeFunctionRemove(ExecState* state)
429{
430 return IDLOperation<JSHTMLOptionsCollection>::call<jsHTMLOptionsCollectionPrototypeFunctionRemoveBody>(*state, "remove");
431}
432
433static inline JSC::EncodedJSValue jsHTMLOptionsCollectionPrototypeFunctionItemBody(JSC::ExecState* state, typename IDLOperation<JSHTMLOptionsCollection>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
434{
435 UNUSED_PARAM(state);
436 UNUSED_PARAM(throwScope);
437 auto& impl = castedThis->wrapped();
438 if (UNLIKELY(state->argumentCount() < 1))
439 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
440 auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0));
441 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
442 return JSValue::encode(toJS<IDLNullable<IDLInterface<HTMLOptionElement>>>(*state, *castedThis->globalObject(), impl.item(WTFMove(index))));
443}
444
445EncodedJSValue JSC_HOST_CALL jsHTMLOptionsCollectionPrototypeFunctionItem(ExecState* state)
446{
447 return IDLOperation<JSHTMLOptionsCollection>::call<jsHTMLOptionsCollectionPrototypeFunctionItemBody>(*state, "item");
448}
449
450static inline JSC::EncodedJSValue jsHTMLOptionsCollectionPrototypeFunctionNamedItemBody(JSC::ExecState* state, typename IDLOperation<JSHTMLOptionsCollection>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
451{
452 UNUSED_PARAM(state);
453 UNUSED_PARAM(throwScope);
454 auto& impl = castedThis->wrapped();
455 if (UNLIKELY(state->argumentCount() < 1))
456 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
457 auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
458 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
459 return JSValue::encode(toJS<IDLNullable<IDLInterface<HTMLOptionElement>>>(*state, *castedThis->globalObject(), impl.namedItem(WTFMove(name))));
460}
461
462EncodedJSValue JSC_HOST_CALL jsHTMLOptionsCollectionPrototypeFunctionNamedItem(ExecState* state)
463{
464 return IDLOperation<JSHTMLOptionsCollection>::call<jsHTMLOptionsCollectionPrototypeFunctionNamedItemBody>(*state, "namedItem");
465}
466
467void JSHTMLOptionsCollection::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
468{
469 auto* thisObject = jsCast<JSHTMLOptionsCollection*>(cell);
470 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
471 if (thisObject->scriptExecutionContext())
472 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
473 Base::heapSnapshot(cell, builder);
474}
475
476bool JSHTMLOptionsCollectionOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
477{
478 auto* jsHTMLOptionsCollection = jsCast<JSHTMLOptionsCollection*>(handle.slot()->asCell());
479 void* root = WebCore::root(jsHTMLOptionsCollection->wrapped().ownerNode());
480 if (UNLIKELY(reason))
481 *reason = "Reachable from HTMLOptionsCollection ownerNode";
482 return visitor.containsOpaqueRoot(root);
483}
484
485void JSHTMLOptionsCollectionOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
486{
487 auto* jsHTMLOptionsCollection = static_cast<JSHTMLOptionsCollection*>(handle.slot()->asCell());
488 auto& world = *static_cast<DOMWrapperWorld*>(context);
489 uncacheWrapper(world, &jsHTMLOptionsCollection->wrapped(), jsHTMLOptionsCollection);
490}
491
492HTMLOptionsCollection* JSHTMLOptionsCollection::toWrapped(JSC::VM& vm, JSC::JSValue value)
493{
494 if (auto* wrapper = jsDynamicCast<JSHTMLOptionsCollection*>(vm, value))
495 return &wrapper->wrapped();
496 return nullptr;
497}
498
499}
500