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 "JSDOMCacheStorage.h"
23
24#include "JSCacheQueryOptions.h"
25#include "JSDOMBinding.h"
26#include "JSDOMConstructorNotConstructable.h"
27#include "JSDOMConvertDictionary.h"
28#include "JSDOMConvertInterface.h"
29#include "JSDOMConvertStrings.h"
30#include "JSDOMConvertUnion.h"
31#include "JSDOMExceptionHandling.h"
32#include "JSDOMOperation.h"
33#include "JSDOMOperationReturningPromise.h"
34#include "JSDOMWrapperCache.h"
35#include "JSFetchRequest.h"
36#include "ScriptExecutionContext.h"
37#include <JavaScriptCore/FunctionPrototype.h>
38#include <JavaScriptCore/HeapSnapshotBuilder.h>
39#include <JavaScriptCore/JSCInlines.h>
40#include <wtf/GetPtr.h>
41#include <wtf/PointerPreparations.h>
42#include <wtf/URL.h>
43#include <wtf/Variant.h>
44
45
46namespace WebCore {
47using namespace JSC;
48
49// Functions
50
51JSC::EncodedJSValue JSC_HOST_CALL jsDOMCacheStoragePrototypeFunctionMatch(JSC::ExecState*);
52JSC::EncodedJSValue JSC_HOST_CALL jsDOMCacheStoragePrototypeFunctionHas(JSC::ExecState*);
53JSC::EncodedJSValue JSC_HOST_CALL jsDOMCacheStoragePrototypeFunctionOpen(JSC::ExecState*);
54JSC::EncodedJSValue JSC_HOST_CALL jsDOMCacheStoragePrototypeFunctionDelete(JSC::ExecState*);
55JSC::EncodedJSValue JSC_HOST_CALL jsDOMCacheStoragePrototypeFunctionKeys(JSC::ExecState*);
56
57// Attributes
58
59JSC::EncodedJSValue jsDOMCacheStorageConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
60bool setJSDOMCacheStorageConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
61
62class JSDOMCacheStoragePrototype : public JSC::JSNonFinalObject {
63public:
64 using Base = JSC::JSNonFinalObject;
65 static JSDOMCacheStoragePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
66 {
67 JSDOMCacheStoragePrototype* ptr = new (NotNull, JSC::allocateCell<JSDOMCacheStoragePrototype>(vm.heap)) JSDOMCacheStoragePrototype(vm, globalObject, structure);
68 ptr->finishCreation(vm);
69 return ptr;
70 }
71
72 DECLARE_INFO;
73 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
74 {
75 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
76 }
77
78private:
79 JSDOMCacheStoragePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
80 : JSC::JSNonFinalObject(vm, structure)
81 {
82 }
83
84 void finishCreation(JSC::VM&);
85};
86
87using JSDOMCacheStorageConstructor = JSDOMConstructorNotConstructable<JSDOMCacheStorage>;
88
89template<> JSValue JSDOMCacheStorageConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
90{
91 UNUSED_PARAM(vm);
92 return globalObject.functionPrototype();
93}
94
95template<> void JSDOMCacheStorageConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
96{
97 putDirect(vm, vm.propertyNames->prototype, JSDOMCacheStorage::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
98 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("CacheStorage"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
99 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
100}
101
102template<> const ClassInfo JSDOMCacheStorageConstructor::s_info = { "CacheStorage", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMCacheStorageConstructor) };
103
104/* Hash table for prototype */
105
106static const HashTableValue JSDOMCacheStoragePrototypeTableValues[] =
107{
108 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMCacheStorageConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMCacheStorageConstructor) } },
109 { "match", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMCacheStoragePrototypeFunctionMatch), (intptr_t) (1) } },
110 { "has", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMCacheStoragePrototypeFunctionHas), (intptr_t) (1) } },
111 { "open", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMCacheStoragePrototypeFunctionOpen), (intptr_t) (1) } },
112 { "delete", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMCacheStoragePrototypeFunctionDelete), (intptr_t) (1) } },
113 { "keys", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMCacheStoragePrototypeFunctionKeys), (intptr_t) (0) } },
114};
115
116const ClassInfo JSDOMCacheStoragePrototype::s_info = { "CacheStoragePrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMCacheStoragePrototype) };
117
118void JSDOMCacheStoragePrototype::finishCreation(VM& vm)
119{
120 Base::finishCreation(vm);
121 reifyStaticProperties(vm, JSDOMCacheStorage::info(), JSDOMCacheStoragePrototypeTableValues, *this);
122}
123
124const ClassInfo JSDOMCacheStorage::s_info = { "CacheStorage", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMCacheStorage) };
125
126JSDOMCacheStorage::JSDOMCacheStorage(Structure* structure, JSDOMGlobalObject& globalObject, Ref<DOMCacheStorage>&& impl)
127 : JSDOMWrapper<DOMCacheStorage>(structure, globalObject, WTFMove(impl))
128{
129}
130
131void JSDOMCacheStorage::finishCreation(VM& vm)
132{
133 Base::finishCreation(vm);
134 ASSERT(inherits(vm, info()));
135
136}
137
138JSObject* JSDOMCacheStorage::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
139{
140 return JSDOMCacheStoragePrototype::create(vm, &globalObject, JSDOMCacheStoragePrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
141}
142
143JSObject* JSDOMCacheStorage::prototype(VM& vm, JSDOMGlobalObject& globalObject)
144{
145 return getDOMPrototype<JSDOMCacheStorage>(vm, globalObject);
146}
147
148JSValue JSDOMCacheStorage::getConstructor(VM& vm, const JSGlobalObject* globalObject)
149{
150 return getDOMConstructor<JSDOMCacheStorageConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
151}
152
153void JSDOMCacheStorage::destroy(JSC::JSCell* cell)
154{
155 JSDOMCacheStorage* thisObject = static_cast<JSDOMCacheStorage*>(cell);
156 thisObject->JSDOMCacheStorage::~JSDOMCacheStorage();
157}
158
159template<> inline JSDOMCacheStorage* IDLOperation<JSDOMCacheStorage>::cast(ExecState& state)
160{
161 return jsDynamicCast<JSDOMCacheStorage*>(state.vm(), state.thisValue());
162}
163
164EncodedJSValue jsDOMCacheStorageConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
165{
166 VM& vm = state->vm();
167 auto throwScope = DECLARE_THROW_SCOPE(vm);
168 auto* prototype = jsDynamicCast<JSDOMCacheStoragePrototype*>(vm, JSValue::decode(thisValue));
169 if (UNLIKELY(!prototype))
170 return throwVMTypeError(state, throwScope);
171 return JSValue::encode(JSDOMCacheStorage::getConstructor(state->vm(), prototype->globalObject()));
172}
173
174bool setJSDOMCacheStorageConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
175{
176 VM& vm = state->vm();
177 auto throwScope = DECLARE_THROW_SCOPE(vm);
178 auto* prototype = jsDynamicCast<JSDOMCacheStoragePrototype*>(vm, JSValue::decode(thisValue));
179 if (UNLIKELY(!prototype)) {
180 throwVMTypeError(state, throwScope);
181 return false;
182 }
183 // Shadowing a built-in constructor
184 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
185}
186
187static inline JSC::EncodedJSValue jsDOMCacheStoragePrototypeFunctionMatchBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSDOMCacheStorage>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
188{
189 UNUSED_PARAM(state);
190 UNUSED_PARAM(throwScope);
191 auto& impl = castedThis->wrapped();
192 if (UNLIKELY(state->argumentCount() < 1))
193 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
194 auto request = convert<IDLUnion<IDLInterface<FetchRequest>, IDLUSVString>>(*state, state->uncheckedArgument(0));
195 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
196 auto options = convert<IDLDictionary<CacheQueryOptions>>(*state, state->argument(1));
197 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
198 impl.match(WTFMove(request), WTFMove(options), WTFMove(promise));
199 return JSValue::encode(jsUndefined());
200}
201
202EncodedJSValue JSC_HOST_CALL jsDOMCacheStoragePrototypeFunctionMatch(ExecState* state)
203{
204 return IDLOperationReturningPromise<JSDOMCacheStorage>::call<jsDOMCacheStoragePrototypeFunctionMatchBody, PromiseExecutionScope::WindowOrWorker>(*state, "match");
205}
206
207static inline JSC::EncodedJSValue jsDOMCacheStoragePrototypeFunctionHasBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSDOMCacheStorage>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
208{
209 UNUSED_PARAM(state);
210 UNUSED_PARAM(throwScope);
211 auto& impl = castedThis->wrapped();
212 if (UNLIKELY(state->argumentCount() < 1))
213 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
214 auto cacheName = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
215 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
216 impl.has(WTFMove(cacheName), WTFMove(promise));
217 return JSValue::encode(jsUndefined());
218}
219
220EncodedJSValue JSC_HOST_CALL jsDOMCacheStoragePrototypeFunctionHas(ExecState* state)
221{
222 return IDLOperationReturningPromise<JSDOMCacheStorage>::call<jsDOMCacheStoragePrototypeFunctionHasBody, PromiseExecutionScope::WindowOrWorker>(*state, "has");
223}
224
225static inline JSC::EncodedJSValue jsDOMCacheStoragePrototypeFunctionOpenBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSDOMCacheStorage>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
226{
227 UNUSED_PARAM(state);
228 UNUSED_PARAM(throwScope);
229 auto& impl = castedThis->wrapped();
230 if (UNLIKELY(state->argumentCount() < 1))
231 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
232 auto cacheName = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
233 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
234 impl.open(WTFMove(cacheName), WTFMove(promise));
235 return JSValue::encode(jsUndefined());
236}
237
238EncodedJSValue JSC_HOST_CALL jsDOMCacheStoragePrototypeFunctionOpen(ExecState* state)
239{
240 return IDLOperationReturningPromise<JSDOMCacheStorage>::call<jsDOMCacheStoragePrototypeFunctionOpenBody, PromiseExecutionScope::WindowOrWorker>(*state, "open");
241}
242
243static inline JSC::EncodedJSValue jsDOMCacheStoragePrototypeFunctionDeleteBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSDOMCacheStorage>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
244{
245 UNUSED_PARAM(state);
246 UNUSED_PARAM(throwScope);
247 auto& impl = castedThis->wrapped();
248 if (UNLIKELY(state->argumentCount() < 1))
249 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
250 auto cacheName = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
251 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
252 impl.remove(WTFMove(cacheName), WTFMove(promise));
253 return JSValue::encode(jsUndefined());
254}
255
256EncodedJSValue JSC_HOST_CALL jsDOMCacheStoragePrototypeFunctionDelete(ExecState* state)
257{
258 return IDLOperationReturningPromise<JSDOMCacheStorage>::call<jsDOMCacheStoragePrototypeFunctionDeleteBody, PromiseExecutionScope::WindowOrWorker>(*state, "delete");
259}
260
261static inline JSC::EncodedJSValue jsDOMCacheStoragePrototypeFunctionKeysBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSDOMCacheStorage>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
262{
263 UNUSED_PARAM(state);
264 UNUSED_PARAM(throwScope);
265 auto& impl = castedThis->wrapped();
266 impl.keys(WTFMove(promise));
267 return JSValue::encode(jsUndefined());
268}
269
270EncodedJSValue JSC_HOST_CALL jsDOMCacheStoragePrototypeFunctionKeys(ExecState* state)
271{
272 return IDLOperationReturningPromise<JSDOMCacheStorage>::call<jsDOMCacheStoragePrototypeFunctionKeysBody, PromiseExecutionScope::WindowOrWorker>(*state, "keys");
273}
274
275void JSDOMCacheStorage::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
276{
277 auto* thisObject = jsCast<JSDOMCacheStorage*>(cell);
278 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
279 if (thisObject->scriptExecutionContext())
280 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
281 Base::heapSnapshot(cell, builder);
282}
283
284bool JSDOMCacheStorageOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
285{
286 UNUSED_PARAM(handle);
287 UNUSED_PARAM(visitor);
288 UNUSED_PARAM(reason);
289 return false;
290}
291
292void JSDOMCacheStorageOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
293{
294 auto* jsDOMCacheStorage = static_cast<JSDOMCacheStorage*>(handle.slot()->asCell());
295 auto& world = *static_cast<DOMWrapperWorld*>(context);
296 uncacheWrapper(world, &jsDOMCacheStorage->wrapped(), jsDOMCacheStorage);
297}
298
299#if ENABLE(BINDING_INTEGRITY)
300#if PLATFORM(WIN)
301#pragma warning(disable: 4483)
302extern "C" { extern void (*const __identifier("??_7DOMCacheStorage@WebCore@@6B@")[])(); }
303#else
304extern "C" { extern void* _ZTVN7WebCore15DOMCacheStorageE[]; }
305#endif
306#endif
307
308JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<DOMCacheStorage>&& impl)
309{
310
311#if ENABLE(BINDING_INTEGRITY)
312 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
313#if PLATFORM(WIN)
314 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7DOMCacheStorage@WebCore@@6B@"));
315#else
316 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore15DOMCacheStorageE[2]);
317#endif
318
319 // If this fails DOMCacheStorage does not have a vtable, so you need to add the
320 // ImplementationLacksVTable attribute to the interface definition
321 static_assert(std::is_polymorphic<DOMCacheStorage>::value, "DOMCacheStorage is not polymorphic");
322
323 // If you hit this assertion you either have a use after free bug, or
324 // DOMCacheStorage has subclasses. If DOMCacheStorage has subclasses that get passed
325 // to toJS() we currently require DOMCacheStorage you to opt out of binding hardening
326 // by adding the SkipVTableValidation attribute to the interface IDL definition
327 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
328#endif
329 return createWrapper<DOMCacheStorage>(globalObject, WTFMove(impl));
330}
331
332JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, DOMCacheStorage& impl)
333{
334 return wrap(state, globalObject, impl);
335}
336
337DOMCacheStorage* JSDOMCacheStorage::toWrapped(JSC::VM& vm, JSC::JSValue value)
338{
339 if (auto* wrapper = jsDynamicCast<JSDOMCacheStorage*>(vm, value))
340 return &wrapper->wrapped();
341 return nullptr;
342}
343
344}
345