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
23#if ENABLE(INDEXED_DATABASE)
24
25#include "JSIDBCursor.h"
26
27#include "JSDOMAttribute.h"
28#include "JSDOMBinding.h"
29#include "JSDOMConstructorNotConstructable.h"
30#include "JSDOMConvertAny.h"
31#include "JSDOMConvertEnumeration.h"
32#include "JSDOMConvertInterface.h"
33#include "JSDOMConvertNumbers.h"
34#include "JSDOMConvertUnion.h"
35#include "JSDOMExceptionHandling.h"
36#include "JSDOMGlobalObject.h"
37#include "JSDOMOperation.h"
38#include "JSDOMWrapperCache.h"
39#include "JSIDBCursorDirection.h"
40#include "JSIDBIndex.h"
41#include "JSIDBObjectStore.h"
42#include "JSIDBRequest.h"
43#include "ScriptExecutionContext.h"
44#include <JavaScriptCore/FunctionPrototype.h>
45#include <JavaScriptCore/HeapSnapshotBuilder.h>
46#include <JavaScriptCore/JSCInlines.h>
47#include <wtf/GetPtr.h>
48#include <wtf/PointerPreparations.h>
49#include <wtf/URL.h>
50#include <wtf/Variant.h>
51
52
53namespace WebCore {
54using namespace JSC;
55
56// Functions
57
58JSC::EncodedJSValue JSC_HOST_CALL jsIDBCursorPrototypeFunctionUpdate(JSC::ExecState*);
59JSC::EncodedJSValue JSC_HOST_CALL jsIDBCursorPrototypeFunctionAdvance(JSC::ExecState*);
60JSC::EncodedJSValue JSC_HOST_CALL jsIDBCursorPrototypeFunctionContinue(JSC::ExecState*);
61JSC::EncodedJSValue JSC_HOST_CALL jsIDBCursorPrototypeFunctionContinuePrimaryKey(JSC::ExecState*);
62JSC::EncodedJSValue JSC_HOST_CALL jsIDBCursorPrototypeFunctionDelete(JSC::ExecState*);
63
64// Attributes
65
66JSC::EncodedJSValue jsIDBCursorConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
67bool setJSIDBCursorConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
68JSC::EncodedJSValue jsIDBCursorSource(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
69JSC::EncodedJSValue jsIDBCursorDirection(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
70JSC::EncodedJSValue jsIDBCursorKey(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
71JSC::EncodedJSValue jsIDBCursorPrimaryKey(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
72
73class JSIDBCursorPrototype : public JSC::JSNonFinalObject {
74public:
75 using Base = JSC::JSNonFinalObject;
76 static JSIDBCursorPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
77 {
78 JSIDBCursorPrototype* ptr = new (NotNull, JSC::allocateCell<JSIDBCursorPrototype>(vm.heap)) JSIDBCursorPrototype(vm, globalObject, structure);
79 ptr->finishCreation(vm);
80 return ptr;
81 }
82
83 DECLARE_INFO;
84 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
85 {
86 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
87 }
88
89private:
90 JSIDBCursorPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
91 : JSC::JSNonFinalObject(vm, structure)
92 {
93 }
94
95 void finishCreation(JSC::VM&);
96};
97
98using JSIDBCursorConstructor = JSDOMConstructorNotConstructable<JSIDBCursor>;
99
100template<> JSValue JSIDBCursorConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
101{
102 UNUSED_PARAM(vm);
103 return globalObject.functionPrototype();
104}
105
106template<> void JSIDBCursorConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
107{
108 putDirect(vm, vm.propertyNames->prototype, JSIDBCursor::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
109 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("IDBCursor"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
110 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
111}
112
113template<> const ClassInfo JSIDBCursorConstructor::s_info = { "IDBCursor", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSIDBCursorConstructor) };
114
115/* Hash table for prototype */
116
117static const HashTableValue JSIDBCursorPrototypeTableValues[] =
118{
119 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBCursorConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSIDBCursorConstructor) } },
120 { "source", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBCursorSource), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
121 { "direction", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBCursorDirection), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
122 { "key", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBCursorKey), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
123 { "primaryKey", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBCursorPrimaryKey), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
124 { "update", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsIDBCursorPrototypeFunctionUpdate), (intptr_t) (1) } },
125 { "advance", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsIDBCursorPrototypeFunctionAdvance), (intptr_t) (1) } },
126 { "continue", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsIDBCursorPrototypeFunctionContinue), (intptr_t) (0) } },
127 { "continuePrimaryKey", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsIDBCursorPrototypeFunctionContinuePrimaryKey), (intptr_t) (2) } },
128 { "delete", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsIDBCursorPrototypeFunctionDelete), (intptr_t) (0) } },
129};
130
131const ClassInfo JSIDBCursorPrototype::s_info = { "IDBCursorPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSIDBCursorPrototype) };
132
133void JSIDBCursorPrototype::finishCreation(VM& vm)
134{
135 Base::finishCreation(vm);
136 reifyStaticProperties(vm, JSIDBCursor::info(), JSIDBCursorPrototypeTableValues, *this);
137}
138
139const ClassInfo JSIDBCursor::s_info = { "IDBCursor", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSIDBCursor) };
140
141JSIDBCursor::JSIDBCursor(Structure* structure, JSDOMGlobalObject& globalObject, Ref<IDBCursor>&& impl)
142 : JSDOMWrapper<IDBCursor>(structure, globalObject, WTFMove(impl))
143{
144}
145
146void JSIDBCursor::finishCreation(VM& vm)
147{
148 Base::finishCreation(vm);
149 ASSERT(inherits(vm, info()));
150
151}
152
153JSObject* JSIDBCursor::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
154{
155 return JSIDBCursorPrototype::create(vm, &globalObject, JSIDBCursorPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
156}
157
158JSObject* JSIDBCursor::prototype(VM& vm, JSDOMGlobalObject& globalObject)
159{
160 return getDOMPrototype<JSIDBCursor>(vm, globalObject);
161}
162
163JSValue JSIDBCursor::getConstructor(VM& vm, const JSGlobalObject* globalObject)
164{
165 return getDOMConstructor<JSIDBCursorConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
166}
167
168void JSIDBCursor::destroy(JSC::JSCell* cell)
169{
170 JSIDBCursor* thisObject = static_cast<JSIDBCursor*>(cell);
171 thisObject->JSIDBCursor::~JSIDBCursor();
172}
173
174template<> inline JSIDBCursor* IDLAttribute<JSIDBCursor>::cast(ExecState& state, EncodedJSValue thisValue)
175{
176 return jsDynamicCast<JSIDBCursor*>(state.vm(), JSValue::decode(thisValue));
177}
178
179template<> inline JSIDBCursor* IDLOperation<JSIDBCursor>::cast(ExecState& state)
180{
181 return jsDynamicCast<JSIDBCursor*>(state.vm(), state.thisValue());
182}
183
184EncodedJSValue jsIDBCursorConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
185{
186 VM& vm = state->vm();
187 auto throwScope = DECLARE_THROW_SCOPE(vm);
188 auto* prototype = jsDynamicCast<JSIDBCursorPrototype*>(vm, JSValue::decode(thisValue));
189 if (UNLIKELY(!prototype))
190 return throwVMTypeError(state, throwScope);
191 return JSValue::encode(JSIDBCursor::getConstructor(state->vm(), prototype->globalObject()));
192}
193
194bool setJSIDBCursorConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
195{
196 VM& vm = state->vm();
197 auto throwScope = DECLARE_THROW_SCOPE(vm);
198 auto* prototype = jsDynamicCast<JSIDBCursorPrototype*>(vm, JSValue::decode(thisValue));
199 if (UNLIKELY(!prototype)) {
200 throwVMTypeError(state, throwScope);
201 return false;
202 }
203 // Shadowing a built-in constructor
204 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
205}
206
207static inline JSValue jsIDBCursorSourceGetter(ExecState& state, JSIDBCursor& thisObject, ThrowScope& throwScope)
208{
209 UNUSED_PARAM(throwScope);
210 UNUSED_PARAM(state);
211 auto& impl = thisObject.wrapped();
212 JSValue result = toJS<IDLUnion<IDLInterface<IDBObjectStore>, IDLInterface<IDBIndex>>>(state, *thisObject.globalObject(), throwScope, impl.source());
213 return result;
214}
215
216EncodedJSValue jsIDBCursorSource(ExecState* state, EncodedJSValue thisValue, PropertyName)
217{
218 return IDLAttribute<JSIDBCursor>::get<jsIDBCursorSourceGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "source");
219}
220
221static inline JSValue jsIDBCursorDirectionGetter(ExecState& state, JSIDBCursor& thisObject, ThrowScope& throwScope)
222{
223 UNUSED_PARAM(throwScope);
224 UNUSED_PARAM(state);
225 auto& impl = thisObject.wrapped();
226 JSValue result = toJS<IDLEnumeration<IDBCursorDirection>>(state, throwScope, impl.direction());
227 return result;
228}
229
230EncodedJSValue jsIDBCursorDirection(ExecState* state, EncodedJSValue thisValue, PropertyName)
231{
232 return IDLAttribute<JSIDBCursor>::get<jsIDBCursorDirectionGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "direction");
233}
234
235static inline JSValue jsIDBCursorKeyGetter(ExecState& state, JSIDBCursor& thisObject, ThrowScope& throwScope)
236{
237 UNUSED_PARAM(throwScope);
238 UNUSED_PARAM(state);
239 return thisObject.key(state);
240}
241
242EncodedJSValue jsIDBCursorKey(ExecState* state, EncodedJSValue thisValue, PropertyName)
243{
244 return IDLAttribute<JSIDBCursor>::get<jsIDBCursorKeyGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "key");
245}
246
247static inline JSValue jsIDBCursorPrimaryKeyGetter(ExecState& state, JSIDBCursor& thisObject, ThrowScope& throwScope)
248{
249 UNUSED_PARAM(throwScope);
250 UNUSED_PARAM(state);
251 return thisObject.primaryKey(state);
252}
253
254EncodedJSValue jsIDBCursorPrimaryKey(ExecState* state, EncodedJSValue thisValue, PropertyName)
255{
256 return IDLAttribute<JSIDBCursor>::get<jsIDBCursorPrimaryKeyGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "primaryKey");
257}
258
259static inline JSC::EncodedJSValue jsIDBCursorPrototypeFunctionUpdateBody(JSC::ExecState* state, typename IDLOperation<JSIDBCursor>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
260{
261 UNUSED_PARAM(state);
262 UNUSED_PARAM(throwScope);
263 auto& impl = castedThis->wrapped();
264 if (UNLIKELY(state->argumentCount() < 1))
265 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
266 auto value = convert<IDLAny>(*state, state->uncheckedArgument(0));
267 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
268 return JSValue::encode(toJS<IDLInterface<IDBRequest>>(*state, *castedThis->globalObject(), throwScope, impl.update(*state, WTFMove(value))));
269}
270
271EncodedJSValue JSC_HOST_CALL jsIDBCursorPrototypeFunctionUpdate(ExecState* state)
272{
273 return IDLOperation<JSIDBCursor>::call<jsIDBCursorPrototypeFunctionUpdateBody>(*state, "update");
274}
275
276static inline JSC::EncodedJSValue jsIDBCursorPrototypeFunctionAdvanceBody(JSC::ExecState* state, typename IDLOperation<JSIDBCursor>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
277{
278 UNUSED_PARAM(state);
279 UNUSED_PARAM(throwScope);
280 auto& impl = castedThis->wrapped();
281 if (UNLIKELY(state->argumentCount() < 1))
282 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
283 auto count = convert<IDLEnforceRangeAdaptor<IDLUnsignedLong>>(*state, state->uncheckedArgument(0));
284 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
285 propagateException(*state, throwScope, impl.advance(WTFMove(count)));
286 return JSValue::encode(jsUndefined());
287}
288
289EncodedJSValue JSC_HOST_CALL jsIDBCursorPrototypeFunctionAdvance(ExecState* state)
290{
291 return IDLOperation<JSIDBCursor>::call<jsIDBCursorPrototypeFunctionAdvanceBody>(*state, "advance");
292}
293
294static inline JSC::EncodedJSValue jsIDBCursorPrototypeFunctionContinueBody(JSC::ExecState* state, typename IDLOperation<JSIDBCursor>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
295{
296 UNUSED_PARAM(state);
297 UNUSED_PARAM(throwScope);
298 auto& impl = castedThis->wrapped();
299 auto key = convert<IDLAny>(*state, state->argument(0));
300 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
301 propagateException(*state, throwScope, impl.continueFunction(*state, WTFMove(key)));
302 return JSValue::encode(jsUndefined());
303}
304
305EncodedJSValue JSC_HOST_CALL jsIDBCursorPrototypeFunctionContinue(ExecState* state)
306{
307 return IDLOperation<JSIDBCursor>::call<jsIDBCursorPrototypeFunctionContinueBody>(*state, "continue");
308}
309
310static inline JSC::EncodedJSValue jsIDBCursorPrototypeFunctionContinuePrimaryKeyBody(JSC::ExecState* state, typename IDLOperation<JSIDBCursor>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
311{
312 UNUSED_PARAM(state);
313 UNUSED_PARAM(throwScope);
314 auto& impl = castedThis->wrapped();
315 if (UNLIKELY(state->argumentCount() < 2))
316 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
317 auto key = convert<IDLAny>(*state, state->uncheckedArgument(0));
318 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
319 auto primaryKey = convert<IDLAny>(*state, state->uncheckedArgument(1));
320 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
321 propagateException(*state, throwScope, impl.continuePrimaryKey(*state, WTFMove(key), WTFMove(primaryKey)));
322 return JSValue::encode(jsUndefined());
323}
324
325EncodedJSValue JSC_HOST_CALL jsIDBCursorPrototypeFunctionContinuePrimaryKey(ExecState* state)
326{
327 return IDLOperation<JSIDBCursor>::call<jsIDBCursorPrototypeFunctionContinuePrimaryKeyBody>(*state, "continuePrimaryKey");
328}
329
330static inline JSC::EncodedJSValue jsIDBCursorPrototypeFunctionDeleteBody(JSC::ExecState* state, typename IDLOperation<JSIDBCursor>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
331{
332 UNUSED_PARAM(state);
333 UNUSED_PARAM(throwScope);
334 auto& impl = castedThis->wrapped();
335 return JSValue::encode(toJS<IDLInterface<IDBRequest>>(*state, *castedThis->globalObject(), throwScope, impl.deleteFunction(*state)));
336}
337
338EncodedJSValue JSC_HOST_CALL jsIDBCursorPrototypeFunctionDelete(ExecState* state)
339{
340 return IDLOperation<JSIDBCursor>::call<jsIDBCursorPrototypeFunctionDeleteBody>(*state, "delete");
341}
342
343void JSIDBCursor::visitChildren(JSCell* cell, SlotVisitor& visitor)
344{
345 auto* thisObject = jsCast<JSIDBCursor*>(cell);
346 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
347 Base::visitChildren(thisObject, visitor);
348 thisObject->visitAdditionalChildren(visitor);
349}
350
351void JSIDBCursor::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor)
352{
353 auto* thisObject = jsCast<JSIDBCursor*>(cell);
354 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
355 Base::visitOutputConstraints(thisObject, visitor);
356 thisObject->visitAdditionalChildren(visitor);
357}
358
359void JSIDBCursor::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
360{
361 auto* thisObject = jsCast<JSIDBCursor*>(cell);
362 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
363 if (thisObject->scriptExecutionContext())
364 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
365 Base::heapSnapshot(cell, builder);
366}
367
368bool JSIDBCursorOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
369{
370 UNUSED_PARAM(handle);
371 UNUSED_PARAM(visitor);
372 UNUSED_PARAM(reason);
373 return false;
374}
375
376void JSIDBCursorOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
377{
378 auto* jsIDBCursor = static_cast<JSIDBCursor*>(handle.slot()->asCell());
379 auto& world = *static_cast<DOMWrapperWorld*>(context);
380 uncacheWrapper(world, &jsIDBCursor->wrapped(), jsIDBCursor);
381}
382
383IDBCursor* JSIDBCursor::toWrapped(JSC::VM& vm, JSC::JSValue value)
384{
385 if (auto* wrapper = jsDynamicCast<JSIDBCursor*>(vm, value))
386 return &wrapper->wrapped();
387 return nullptr;
388}
389
390}
391
392#endif // ENABLE(INDEXED_DATABASE)
393