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 "JSDatabase.h"
23
24#include "JSDOMAttribute.h"
25#include "JSDOMBinding.h"
26#include "JSDOMConstructorNotConstructable.h"
27#include "JSDOMConvertCallbacks.h"
28#include "JSDOMConvertNullable.h"
29#include "JSDOMConvertStrings.h"
30#include "JSDOMExceptionHandling.h"
31#include "JSDOMGlobalObject.h"
32#include "JSDOMOperation.h"
33#include "JSDOMWrapperCache.h"
34#include "JSSQLTransactionCallback.h"
35#include "JSSQLTransactionErrorCallback.h"
36#include "JSVoidCallback.h"
37#include "ScriptExecutionContext.h"
38#include <JavaScriptCore/FunctionPrototype.h>
39#include <JavaScriptCore/HeapSnapshotBuilder.h>
40#include <JavaScriptCore/JSCInlines.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 jsDatabasePrototypeFunctionChangeVersion(JSC::ExecState*);
52JSC::EncodedJSValue JSC_HOST_CALL jsDatabasePrototypeFunctionTransaction(JSC::ExecState*);
53JSC::EncodedJSValue JSC_HOST_CALL jsDatabasePrototypeFunctionReadTransaction(JSC::ExecState*);
54
55// Attributes
56
57JSC::EncodedJSValue jsDatabaseConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
58bool setJSDatabaseConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
59JSC::EncodedJSValue jsDatabaseVersion(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
60
61class JSDatabasePrototype : public JSC::JSNonFinalObject {
62public:
63 using Base = JSC::JSNonFinalObject;
64 static JSDatabasePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
65 {
66 JSDatabasePrototype* ptr = new (NotNull, JSC::allocateCell<JSDatabasePrototype>(vm.heap)) JSDatabasePrototype(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 JSDatabasePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
79 : JSC::JSNonFinalObject(vm, structure)
80 {
81 }
82
83 void finishCreation(JSC::VM&);
84};
85
86using JSDatabaseConstructor = JSDOMConstructorNotConstructable<JSDatabase>;
87
88template<> JSValue JSDatabaseConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
89{
90 UNUSED_PARAM(vm);
91 return globalObject.functionPrototype();
92}
93
94template<> void JSDatabaseConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
95{
96 putDirect(vm, vm.propertyNames->prototype, JSDatabase::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
97 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Database"_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 JSDatabaseConstructor::s_info = { "Database", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDatabaseConstructor) };
102
103/* Hash table for prototype */
104
105static const HashTableValue JSDatabasePrototypeTableValues[] =
106{
107 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDatabaseConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDatabaseConstructor) } },
108 { "version", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDatabaseVersion), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
109 { "changeVersion", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDatabasePrototypeFunctionChangeVersion), (intptr_t) (2) } },
110 { "transaction", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDatabasePrototypeFunctionTransaction), (intptr_t) (1) } },
111 { "readTransaction", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDatabasePrototypeFunctionReadTransaction), (intptr_t) (1) } },
112};
113
114const ClassInfo JSDatabasePrototype::s_info = { "DatabasePrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDatabasePrototype) };
115
116void JSDatabasePrototype::finishCreation(VM& vm)
117{
118 Base::finishCreation(vm);
119 reifyStaticProperties(vm, JSDatabase::info(), JSDatabasePrototypeTableValues, *this);
120}
121
122const ClassInfo JSDatabase::s_info = { "Database", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDatabase) };
123
124JSDatabase::JSDatabase(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Database>&& impl)
125 : JSDOMWrapper<Database>(structure, globalObject, WTFMove(impl))
126{
127}
128
129void JSDatabase::finishCreation(VM& vm)
130{
131 Base::finishCreation(vm);
132 ASSERT(inherits(vm, info()));
133
134}
135
136JSObject* JSDatabase::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
137{
138 return JSDatabasePrototype::create(vm, &globalObject, JSDatabasePrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
139}
140
141JSObject* JSDatabase::prototype(VM& vm, JSDOMGlobalObject& globalObject)
142{
143 return getDOMPrototype<JSDatabase>(vm, globalObject);
144}
145
146JSValue JSDatabase::getConstructor(VM& vm, const JSGlobalObject* globalObject)
147{
148 return getDOMConstructor<JSDatabaseConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
149}
150
151void JSDatabase::destroy(JSC::JSCell* cell)
152{
153 JSDatabase* thisObject = static_cast<JSDatabase*>(cell);
154 thisObject->JSDatabase::~JSDatabase();
155}
156
157template<> inline JSDatabase* IDLAttribute<JSDatabase>::cast(ExecState& state, EncodedJSValue thisValue)
158{
159 return jsDynamicCast<JSDatabase*>(state.vm(), JSValue::decode(thisValue));
160}
161
162template<> inline JSDatabase* IDLOperation<JSDatabase>::cast(ExecState& state)
163{
164 return jsDynamicCast<JSDatabase*>(state.vm(), state.thisValue());
165}
166
167EncodedJSValue jsDatabaseConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
168{
169 VM& vm = state->vm();
170 auto throwScope = DECLARE_THROW_SCOPE(vm);
171 auto* prototype = jsDynamicCast<JSDatabasePrototype*>(vm, JSValue::decode(thisValue));
172 if (UNLIKELY(!prototype))
173 return throwVMTypeError(state, throwScope);
174 return JSValue::encode(JSDatabase::getConstructor(state->vm(), prototype->globalObject()));
175}
176
177bool setJSDatabaseConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
178{
179 VM& vm = state->vm();
180 auto throwScope = DECLARE_THROW_SCOPE(vm);
181 auto* prototype = jsDynamicCast<JSDatabasePrototype*>(vm, JSValue::decode(thisValue));
182 if (UNLIKELY(!prototype)) {
183 throwVMTypeError(state, throwScope);
184 return false;
185 }
186 // Shadowing a built-in constructor
187 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
188}
189
190static inline JSValue jsDatabaseVersionGetter(ExecState& state, JSDatabase& thisObject, ThrowScope& throwScope)
191{
192 UNUSED_PARAM(throwScope);
193 UNUSED_PARAM(state);
194 auto& impl = thisObject.wrapped();
195 JSValue result = toJS<IDLDOMString>(state, throwScope, impl.version());
196 return result;
197}
198
199EncodedJSValue jsDatabaseVersion(ExecState* state, EncodedJSValue thisValue, PropertyName)
200{
201 return IDLAttribute<JSDatabase>::get<jsDatabaseVersionGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "version");
202}
203
204static inline JSC::EncodedJSValue jsDatabasePrototypeFunctionChangeVersionBody(JSC::ExecState* state, typename IDLOperation<JSDatabase>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
205{
206 UNUSED_PARAM(state);
207 UNUSED_PARAM(throwScope);
208 auto& impl = castedThis->wrapped();
209 if (UNLIKELY(state->argumentCount() < 2))
210 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
211 auto oldVersion = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
212 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
213 auto newVersion = convert<IDLDOMString>(*state, state->uncheckedArgument(1));
214 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
215 auto callback = convert<IDLNullable<IDLCallbackFunction<JSSQLTransactionCallback>>>(*state, state->argument(2), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 2, "callback", "Database", "changeVersion"); });
216 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
217 auto errorCallback = convert<IDLNullable<IDLCallbackFunction<JSSQLTransactionErrorCallback>>>(*state, state->argument(3), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 3, "errorCallback", "Database", "changeVersion"); });
218 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
219 auto successCallback = convert<IDLNullable<IDLCallbackFunction<JSVoidCallback>>>(*state, state->argument(4), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 4, "successCallback", "Database", "changeVersion"); });
220 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
221 impl.changeVersion(WTFMove(oldVersion), WTFMove(newVersion), WTFMove(callback), WTFMove(errorCallback), WTFMove(successCallback));
222 return JSValue::encode(jsUndefined());
223}
224
225EncodedJSValue JSC_HOST_CALL jsDatabasePrototypeFunctionChangeVersion(ExecState* state)
226{
227 return IDLOperation<JSDatabase>::call<jsDatabasePrototypeFunctionChangeVersionBody>(*state, "changeVersion");
228}
229
230static inline JSC::EncodedJSValue jsDatabasePrototypeFunctionTransactionBody(JSC::ExecState* state, typename IDLOperation<JSDatabase>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
231{
232 UNUSED_PARAM(state);
233 UNUSED_PARAM(throwScope);
234 auto& impl = castedThis->wrapped();
235 if (UNLIKELY(state->argumentCount() < 1))
236 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
237 auto callback = convert<IDLCallbackFunction<JSSQLTransactionCallback>>(*state, state->uncheckedArgument(0), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 0, "callback", "Database", "transaction"); });
238 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
239 auto errorCallback = convert<IDLNullable<IDLCallbackFunction<JSSQLTransactionErrorCallback>>>(*state, state->argument(1), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 1, "errorCallback", "Database", "transaction"); });
240 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
241 auto successCallback = convert<IDLNullable<IDLCallbackFunction<JSVoidCallback>>>(*state, state->argument(2), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 2, "successCallback", "Database", "transaction"); });
242 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
243 impl.transaction(callback.releaseNonNull(), WTFMove(errorCallback), WTFMove(successCallback));
244 return JSValue::encode(jsUndefined());
245}
246
247EncodedJSValue JSC_HOST_CALL jsDatabasePrototypeFunctionTransaction(ExecState* state)
248{
249 return IDLOperation<JSDatabase>::call<jsDatabasePrototypeFunctionTransactionBody>(*state, "transaction");
250}
251
252static inline JSC::EncodedJSValue jsDatabasePrototypeFunctionReadTransactionBody(JSC::ExecState* state, typename IDLOperation<JSDatabase>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
253{
254 UNUSED_PARAM(state);
255 UNUSED_PARAM(throwScope);
256 auto& impl = castedThis->wrapped();
257 if (UNLIKELY(state->argumentCount() < 1))
258 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
259 auto callback = convert<IDLCallbackFunction<JSSQLTransactionCallback>>(*state, state->uncheckedArgument(0), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 0, "callback", "Database", "readTransaction"); });
260 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
261 auto errorCallback = convert<IDLNullable<IDLCallbackFunction<JSSQLTransactionErrorCallback>>>(*state, state->argument(1), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 1, "errorCallback", "Database", "readTransaction"); });
262 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
263 auto successCallback = convert<IDLNullable<IDLCallbackFunction<JSVoidCallback>>>(*state, state->argument(2), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 2, "successCallback", "Database", "readTransaction"); });
264 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
265 impl.readTransaction(callback.releaseNonNull(), WTFMove(errorCallback), WTFMove(successCallback));
266 return JSValue::encode(jsUndefined());
267}
268
269EncodedJSValue JSC_HOST_CALL jsDatabasePrototypeFunctionReadTransaction(ExecState* state)
270{
271 return IDLOperation<JSDatabase>::call<jsDatabasePrototypeFunctionReadTransactionBody>(*state, "readTransaction");
272}
273
274void JSDatabase::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
275{
276 auto* thisObject = jsCast<JSDatabase*>(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 JSDatabaseOwner::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 JSDatabaseOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
292{
293 auto* jsDatabase = static_cast<JSDatabase*>(handle.slot()->asCell());
294 auto& world = *static_cast<DOMWrapperWorld*>(context);
295 uncacheWrapper(world, &jsDatabase->wrapped(), jsDatabase);
296}
297
298JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<Database>&& 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 Database.
304 static_assert(!std::is_polymorphic<Database>::value, "Database is polymorphic but the IDL claims it is not");
305 return createWrapper<Database>(globalObject, WTFMove(impl));
306}
307
308JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, Database& impl)
309{
310 return wrap(state, globalObject, impl);
311}
312
313Database* JSDatabase::toWrapped(JSC::VM& vm, JSC::JSValue value)
314{
315 if (auto* wrapper = jsDynamicCast<JSDatabase*>(vm, value))
316 return &wrapper->wrapped();
317 return nullptr;
318}
319
320}
321