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 "JSDOMStringList.h"
23
24#include "JSDOMAttribute.h"
25#include "JSDOMBinding.h"
26#include "JSDOMConstructorNotConstructable.h"
27#include "JSDOMConvertBoolean.h"
28#include "JSDOMConvertNullable.h"
29#include "JSDOMConvertNumbers.h"
30#include "JSDOMConvertStrings.h"
31#include "JSDOMExceptionHandling.h"
32#include "JSDOMOperation.h"
33#include "JSDOMWrapperCache.h"
34#include "ScriptExecutionContext.h"
35#include <JavaScriptCore/ArrayPrototype.h>
36#include <JavaScriptCore/BuiltinNames.h>
37#include <JavaScriptCore/FunctionPrototype.h>
38#include <JavaScriptCore/HeapSnapshotBuilder.h>
39#include <JavaScriptCore/JSCInlines.h>
40#include <JavaScriptCore/PropertyNameArray.h>
41#include <wtf/GetPtr.h>
42#include <wtf/PointerPreparations.h>
43#include <wtf/URL.h>
44
45
46namespace WebCore {
47using namespace JSC;
48
49// Functions
50
51JSC::EncodedJSValue JSC_HOST_CALL jsDOMStringListPrototypeFunctionItem(JSC::ExecState*);
52JSC::EncodedJSValue JSC_HOST_CALL jsDOMStringListPrototypeFunctionContains(JSC::ExecState*);
53
54// Attributes
55
56JSC::EncodedJSValue jsDOMStringListConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
57bool setJSDOMStringListConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
58JSC::EncodedJSValue jsDOMStringListLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
59
60class JSDOMStringListPrototype : public JSC::JSNonFinalObject {
61public:
62 using Base = JSC::JSNonFinalObject;
63 static JSDOMStringListPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
64 {
65 JSDOMStringListPrototype* ptr = new (NotNull, JSC::allocateCell<JSDOMStringListPrototype>(vm.heap)) JSDOMStringListPrototype(vm, globalObject, structure);
66 ptr->finishCreation(vm);
67 return ptr;
68 }
69
70 DECLARE_INFO;
71 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
72 {
73 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
74 }
75
76private:
77 JSDOMStringListPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
78 : JSC::JSNonFinalObject(vm, structure)
79 {
80 }
81
82 void finishCreation(JSC::VM&);
83};
84
85using JSDOMStringListConstructor = JSDOMConstructorNotConstructable<JSDOMStringList>;
86
87template<> JSValue JSDOMStringListConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
88{
89 UNUSED_PARAM(vm);
90 return globalObject.functionPrototype();
91}
92
93template<> void JSDOMStringListConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
94{
95 putDirect(vm, vm.propertyNames->prototype, JSDOMStringList::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
96 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("DOMStringList"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
97 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
98}
99
100template<> const ClassInfo JSDOMStringListConstructor::s_info = { "DOMStringList", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMStringListConstructor) };
101
102/* Hash table for prototype */
103
104static const HashTableValue JSDOMStringListPrototypeTableValues[] =
105{
106 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMStringListConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMStringListConstructor) } },
107 { "length", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMStringListLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
108 { "item", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMStringListPrototypeFunctionItem), (intptr_t) (1) } },
109 { "contains", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMStringListPrototypeFunctionContains), (intptr_t) (1) } },
110};
111
112const ClassInfo JSDOMStringListPrototype::s_info = { "DOMStringListPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMStringListPrototype) };
113
114void JSDOMStringListPrototype::finishCreation(VM& vm)
115{
116 Base::finishCreation(vm);
117 reifyStaticProperties(vm, JSDOMStringList::info(), JSDOMStringListPrototypeTableValues, *this);
118 putDirect(vm, vm.propertyNames->iteratorSymbol, globalObject()->arrayPrototype()->getDirect(vm, vm.propertyNames->builtinNames().valuesPrivateName()), static_cast<unsigned>(JSC::PropertyAttribute::DontEnum));
119}
120
121const ClassInfo JSDOMStringList::s_info = { "DOMStringList", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMStringList) };
122
123JSDOMStringList::JSDOMStringList(Structure* structure, JSDOMGlobalObject& globalObject, Ref<DOMStringList>&& impl)
124 : JSDOMWrapper<DOMStringList>(structure, globalObject, WTFMove(impl))
125{
126}
127
128void JSDOMStringList::finishCreation(VM& vm)
129{
130 Base::finishCreation(vm);
131 ASSERT(inherits(vm, info()));
132
133}
134
135JSObject* JSDOMStringList::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
136{
137 return JSDOMStringListPrototype::create(vm, &globalObject, JSDOMStringListPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
138}
139
140JSObject* JSDOMStringList::prototype(VM& vm, JSDOMGlobalObject& globalObject)
141{
142 return getDOMPrototype<JSDOMStringList>(vm, globalObject);
143}
144
145JSValue JSDOMStringList::getConstructor(VM& vm, const JSGlobalObject* globalObject)
146{
147 return getDOMConstructor<JSDOMStringListConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
148}
149
150void JSDOMStringList::destroy(JSC::JSCell* cell)
151{
152 JSDOMStringList* thisObject = static_cast<JSDOMStringList*>(cell);
153 thisObject->JSDOMStringList::~JSDOMStringList();
154}
155
156bool JSDOMStringList::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
157{
158 auto* thisObject = jsCast<JSDOMStringList*>(object);
159 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
160 if (auto index = parseIndex(propertyName)) {
161 if (index.value() < thisObject->wrapped().length()) {
162 auto value = toJS<IDLNullable<IDLDOMString>>(*state, thisObject->wrapped().item(index.value()));
163 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
164 return true;
165 }
166 }
167 return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
168}
169
170bool JSDOMStringList::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
171{
172 auto* thisObject = jsCast<JSDOMStringList*>(object);
173 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
174 if (LIKELY(index <= MAX_ARRAY_INDEX)) {
175 if (index < thisObject->wrapped().length()) {
176 auto value = toJS<IDLNullable<IDLDOMString>>(*state, thisObject->wrapped().item(index));
177 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
178 return true;
179 }
180 }
181 return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
182}
183
184void JSDOMStringList::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
185{
186 auto* thisObject = jsCast<JSDOMStringList*>(object);
187 ASSERT_GC_OBJECT_INHERITS(object, info());
188 for (unsigned i = 0, count = thisObject->wrapped().length(); i < count; ++i)
189 propertyNames.add(Identifier::from(state, i));
190 JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
191}
192
193template<> inline JSDOMStringList* IDLAttribute<JSDOMStringList>::cast(ExecState& state, EncodedJSValue thisValue)
194{
195 return jsDynamicCast<JSDOMStringList*>(state.vm(), JSValue::decode(thisValue));
196}
197
198template<> inline JSDOMStringList* IDLOperation<JSDOMStringList>::cast(ExecState& state)
199{
200 return jsDynamicCast<JSDOMStringList*>(state.vm(), state.thisValue());
201}
202
203EncodedJSValue jsDOMStringListConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
204{
205 VM& vm = state->vm();
206 auto throwScope = DECLARE_THROW_SCOPE(vm);
207 auto* prototype = jsDynamicCast<JSDOMStringListPrototype*>(vm, JSValue::decode(thisValue));
208 if (UNLIKELY(!prototype))
209 return throwVMTypeError(state, throwScope);
210 return JSValue::encode(JSDOMStringList::getConstructor(state->vm(), prototype->globalObject()));
211}
212
213bool setJSDOMStringListConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
214{
215 VM& vm = state->vm();
216 auto throwScope = DECLARE_THROW_SCOPE(vm);
217 auto* prototype = jsDynamicCast<JSDOMStringListPrototype*>(vm, JSValue::decode(thisValue));
218 if (UNLIKELY(!prototype)) {
219 throwVMTypeError(state, throwScope);
220 return false;
221 }
222 // Shadowing a built-in constructor
223 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
224}
225
226static inline JSValue jsDOMStringListLengthGetter(ExecState& state, JSDOMStringList& thisObject, ThrowScope& throwScope)
227{
228 UNUSED_PARAM(throwScope);
229 UNUSED_PARAM(state);
230 auto& impl = thisObject.wrapped();
231 JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.length());
232 return result;
233}
234
235EncodedJSValue jsDOMStringListLength(ExecState* state, EncodedJSValue thisValue, PropertyName)
236{
237 return IDLAttribute<JSDOMStringList>::get<jsDOMStringListLengthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "length");
238}
239
240static inline JSC::EncodedJSValue jsDOMStringListPrototypeFunctionItemBody(JSC::ExecState* state, typename IDLOperation<JSDOMStringList>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
241{
242 UNUSED_PARAM(state);
243 UNUSED_PARAM(throwScope);
244 auto& impl = castedThis->wrapped();
245 if (UNLIKELY(state->argumentCount() < 1))
246 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
247 auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0));
248 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
249 return JSValue::encode(toJS<IDLNullable<IDLDOMString>>(*state, impl.item(WTFMove(index))));
250}
251
252EncodedJSValue JSC_HOST_CALL jsDOMStringListPrototypeFunctionItem(ExecState* state)
253{
254 return IDLOperation<JSDOMStringList>::call<jsDOMStringListPrototypeFunctionItemBody>(*state, "item");
255}
256
257static inline JSC::EncodedJSValue jsDOMStringListPrototypeFunctionContainsBody(JSC::ExecState* state, typename IDLOperation<JSDOMStringList>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
258{
259 UNUSED_PARAM(state);
260 UNUSED_PARAM(throwScope);
261 auto& impl = castedThis->wrapped();
262 if (UNLIKELY(state->argumentCount() < 1))
263 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
264 auto string = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
265 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
266 return JSValue::encode(toJS<IDLBoolean>(impl.contains(WTFMove(string))));
267}
268
269EncodedJSValue JSC_HOST_CALL jsDOMStringListPrototypeFunctionContains(ExecState* state)
270{
271 return IDLOperation<JSDOMStringList>::call<jsDOMStringListPrototypeFunctionContainsBody>(*state, "contains");
272}
273
274void JSDOMStringList::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
275{
276 auto* thisObject = jsCast<JSDOMStringList*>(cell);
277 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
278 if (thisObject->scriptExecutionContext())
279 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
280 Base::heapSnapshot(cell, builder);
281}
282
283bool JSDOMStringListOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
284{
285 UNUSED_PARAM(handle);
286 UNUSED_PARAM(visitor);
287 UNUSED_PARAM(reason);
288 return false;
289}
290
291void JSDOMStringListOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
292{
293 auto* jsDOMStringList = static_cast<JSDOMStringList*>(handle.slot()->asCell());
294 auto& world = *static_cast<DOMWrapperWorld*>(context);
295 uncacheWrapper(world, &jsDOMStringList->wrapped(), jsDOMStringList);
296}
297
298JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<DOMStringList>&& impl)
299{
300 // If you hit this failure the interface definition has the ImplementationLacksVTable
301 // attribute. You should remove that attribute. If the class has subclasses
302 // that may be passed through this toJS() function you should use the SkipVTableValidation
303 // attribute to DOMStringList.
304 static_assert(!std::is_polymorphic<DOMStringList>::value, "DOMStringList is polymorphic but the IDL claims it is not");
305 return createWrapper<DOMStringList>(globalObject, WTFMove(impl));
306}
307
308JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, DOMStringList& impl)
309{
310 return wrap(state, globalObject, impl);
311}
312
313DOMStringList* JSDOMStringList::toWrapped(JSC::VM& vm, JSC::JSValue value)
314{
315 if (auto* wrapper = jsDynamicCast<JSDOMStringList*>(vm, value))
316 return &wrapper->wrapped();
317 return nullptr;
318}
319
320}
321