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