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(SERVICE_WORKER) |
24 | |
25 | #include "JSServiceWorkerClients.h" |
26 | |
27 | #include "JSDOMBinding.h" |
28 | #include "JSDOMConstructorNotConstructable.h" |
29 | #include "JSDOMConvertBoolean.h" |
30 | #include "JSDOMConvertEnumeration.h" |
31 | #include "JSDOMConvertStrings.h" |
32 | #include "JSDOMExceptionHandling.h" |
33 | #include "JSDOMOperation.h" |
34 | #include "JSDOMOperationReturningPromise.h" |
35 | #include "JSDOMWrapperCache.h" |
36 | #include "JSServiceWorkerClientType.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 | |
46 | namespace WebCore { |
47 | using namespace JSC; |
48 | |
49 | template<> ServiceWorkerClients::ClientQueryOptions convertDictionary<ServiceWorkerClients::ClientQueryOptions>(ExecState& state, JSValue value) |
50 | { |
51 | VM& vm = state.vm(); |
52 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
53 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
54 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
55 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
56 | throwTypeError(&state, throwScope); |
57 | return { }; |
58 | } |
59 | ServiceWorkerClients::ClientQueryOptions result; |
60 | JSValue includeUncontrolledValue; |
61 | if (isNullOrUndefined) |
62 | includeUncontrolledValue = jsUndefined(); |
63 | else { |
64 | includeUncontrolledValue = object->get(&state, Identifier::fromString(&state, "includeUncontrolled" )); |
65 | RETURN_IF_EXCEPTION(throwScope, { }); |
66 | } |
67 | if (!includeUncontrolledValue.isUndefined()) { |
68 | result.includeUncontrolled = convert<IDLBoolean>(state, includeUncontrolledValue); |
69 | RETURN_IF_EXCEPTION(throwScope, { }); |
70 | } else |
71 | result.includeUncontrolled = false; |
72 | JSValue typeValue; |
73 | if (isNullOrUndefined) |
74 | typeValue = jsUndefined(); |
75 | else { |
76 | typeValue = object->get(&state, Identifier::fromString(&state, "type" )); |
77 | RETURN_IF_EXCEPTION(throwScope, { }); |
78 | } |
79 | if (!typeValue.isUndefined()) { |
80 | result.type = convert<IDLEnumeration<ServiceWorkerClientType>>(state, typeValue); |
81 | RETURN_IF_EXCEPTION(throwScope, { }); |
82 | } else |
83 | result.type = ServiceWorkerClientType::Window; |
84 | return result; |
85 | } |
86 | |
87 | // Functions |
88 | |
89 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerClientsPrototypeFunctionGet(JSC::ExecState*); |
90 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerClientsPrototypeFunctionMatchAll(JSC::ExecState*); |
91 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerClientsPrototypeFunctionOpenWindow(JSC::ExecState*); |
92 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerClientsPrototypeFunctionClaim(JSC::ExecState*); |
93 | |
94 | // Attributes |
95 | |
96 | JSC::EncodedJSValue jsServiceWorkerClientsConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
97 | bool setJSServiceWorkerClientsConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
98 | |
99 | class JSServiceWorkerClientsPrototype : public JSC::JSNonFinalObject { |
100 | public: |
101 | using Base = JSC::JSNonFinalObject; |
102 | static JSServiceWorkerClientsPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
103 | { |
104 | JSServiceWorkerClientsPrototype* ptr = new (NotNull, JSC::allocateCell<JSServiceWorkerClientsPrototype>(vm.heap)) JSServiceWorkerClientsPrototype(vm, globalObject, structure); |
105 | ptr->finishCreation(vm); |
106 | return ptr; |
107 | } |
108 | |
109 | DECLARE_INFO; |
110 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
111 | { |
112 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
113 | } |
114 | |
115 | private: |
116 | JSServiceWorkerClientsPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
117 | : JSC::JSNonFinalObject(vm, structure) |
118 | { |
119 | } |
120 | |
121 | void finishCreation(JSC::VM&); |
122 | }; |
123 | |
124 | using JSServiceWorkerClientsConstructor = JSDOMConstructorNotConstructable<JSServiceWorkerClients>; |
125 | |
126 | template<> JSValue JSServiceWorkerClientsConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
127 | { |
128 | UNUSED_PARAM(vm); |
129 | return globalObject.functionPrototype(); |
130 | } |
131 | |
132 | template<> void JSServiceWorkerClientsConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
133 | { |
134 | putDirect(vm, vm.propertyNames->prototype, JSServiceWorkerClients::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
135 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Clients"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
136 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
137 | } |
138 | |
139 | template<> const ClassInfo JSServiceWorkerClientsConstructor::s_info = { "Clients" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerClientsConstructor) }; |
140 | |
141 | /* Hash table for prototype */ |
142 | |
143 | static const HashTableValue JSServiceWorkerClientsPrototypeTableValues[] = |
144 | { |
145 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerClientsConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSServiceWorkerClientsConstructor) } }, |
146 | { "get" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerClientsPrototypeFunctionGet), (intptr_t) (1) } }, |
147 | { "matchAll" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerClientsPrototypeFunctionMatchAll), (intptr_t) (0) } }, |
148 | { "openWindow" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerClientsPrototypeFunctionOpenWindow), (intptr_t) (1) } }, |
149 | { "claim" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerClientsPrototypeFunctionClaim), (intptr_t) (0) } }, |
150 | }; |
151 | |
152 | const ClassInfo JSServiceWorkerClientsPrototype::s_info = { "ClientsPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerClientsPrototype) }; |
153 | |
154 | void JSServiceWorkerClientsPrototype::finishCreation(VM& vm) |
155 | { |
156 | Base::finishCreation(vm); |
157 | reifyStaticProperties(vm, JSServiceWorkerClients::info(), JSServiceWorkerClientsPrototypeTableValues, *this); |
158 | } |
159 | |
160 | const ClassInfo JSServiceWorkerClients::s_info = { "Clients" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerClients) }; |
161 | |
162 | JSServiceWorkerClients::JSServiceWorkerClients(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ServiceWorkerClients>&& impl) |
163 | : JSDOMWrapper<ServiceWorkerClients>(structure, globalObject, WTFMove(impl)) |
164 | { |
165 | } |
166 | |
167 | void JSServiceWorkerClients::finishCreation(VM& vm) |
168 | { |
169 | Base::finishCreation(vm); |
170 | ASSERT(inherits(vm, info())); |
171 | |
172 | } |
173 | |
174 | JSObject* JSServiceWorkerClients::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
175 | { |
176 | return JSServiceWorkerClientsPrototype::create(vm, &globalObject, JSServiceWorkerClientsPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
177 | } |
178 | |
179 | JSObject* JSServiceWorkerClients::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
180 | { |
181 | return getDOMPrototype<JSServiceWorkerClients>(vm, globalObject); |
182 | } |
183 | |
184 | JSValue JSServiceWorkerClients::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
185 | { |
186 | return getDOMConstructor<JSServiceWorkerClientsConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
187 | } |
188 | |
189 | void JSServiceWorkerClients::destroy(JSC::JSCell* cell) |
190 | { |
191 | JSServiceWorkerClients* thisObject = static_cast<JSServiceWorkerClients*>(cell); |
192 | thisObject->JSServiceWorkerClients::~JSServiceWorkerClients(); |
193 | } |
194 | |
195 | template<> inline JSServiceWorkerClients* IDLOperation<JSServiceWorkerClients>::cast(ExecState& state) |
196 | { |
197 | return jsDynamicCast<JSServiceWorkerClients*>(state.vm(), state.thisValue()); |
198 | } |
199 | |
200 | EncodedJSValue jsServiceWorkerClientsConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
201 | { |
202 | VM& vm = state->vm(); |
203 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
204 | auto* prototype = jsDynamicCast<JSServiceWorkerClientsPrototype*>(vm, JSValue::decode(thisValue)); |
205 | if (UNLIKELY(!prototype)) |
206 | return throwVMTypeError(state, throwScope); |
207 | return JSValue::encode(JSServiceWorkerClients::getConstructor(state->vm(), prototype->globalObject())); |
208 | } |
209 | |
210 | bool setJSServiceWorkerClientsConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
211 | { |
212 | VM& vm = state->vm(); |
213 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
214 | auto* prototype = jsDynamicCast<JSServiceWorkerClientsPrototype*>(vm, JSValue::decode(thisValue)); |
215 | if (UNLIKELY(!prototype)) { |
216 | throwVMTypeError(state, throwScope); |
217 | return false; |
218 | } |
219 | // Shadowing a built-in constructor |
220 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
221 | } |
222 | |
223 | static inline JSC::EncodedJSValue jsServiceWorkerClientsPrototypeFunctionGetBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSServiceWorkerClients>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
224 | { |
225 | UNUSED_PARAM(state); |
226 | UNUSED_PARAM(throwScope); |
227 | auto& impl = castedThis->wrapped(); |
228 | if (UNLIKELY(state->argumentCount() < 1)) |
229 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
230 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
231 | if (UNLIKELY(!context)) |
232 | return JSValue::encode(jsUndefined()); |
233 | auto id = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
234 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
235 | impl.get(*context, WTFMove(id), WTFMove(promise)); |
236 | return JSValue::encode(jsUndefined()); |
237 | } |
238 | |
239 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerClientsPrototypeFunctionGet(ExecState* state) |
240 | { |
241 | return IDLOperationReturningPromise<JSServiceWorkerClients>::call<jsServiceWorkerClientsPrototypeFunctionGetBody, PromiseExecutionScope::WindowOrWorker>(*state, "get" ); |
242 | } |
243 | |
244 | static inline JSC::EncodedJSValue jsServiceWorkerClientsPrototypeFunctionMatchAllBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSServiceWorkerClients>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
245 | { |
246 | UNUSED_PARAM(state); |
247 | UNUSED_PARAM(throwScope); |
248 | auto& impl = castedThis->wrapped(); |
249 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
250 | if (UNLIKELY(!context)) |
251 | return JSValue::encode(jsUndefined()); |
252 | auto options = convert<IDLDictionary<ServiceWorkerClients::ClientQueryOptions>>(*state, state->argument(0)); |
253 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
254 | impl.matchAll(*context, WTFMove(options), WTFMove(promise)); |
255 | return JSValue::encode(jsUndefined()); |
256 | } |
257 | |
258 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerClientsPrototypeFunctionMatchAll(ExecState* state) |
259 | { |
260 | return IDLOperationReturningPromise<JSServiceWorkerClients>::call<jsServiceWorkerClientsPrototypeFunctionMatchAllBody, PromiseExecutionScope::WindowOrWorker>(*state, "matchAll" ); |
261 | } |
262 | |
263 | static inline JSC::EncodedJSValue jsServiceWorkerClientsPrototypeFunctionOpenWindowBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSServiceWorkerClients>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
264 | { |
265 | UNUSED_PARAM(state); |
266 | UNUSED_PARAM(throwScope); |
267 | auto& impl = castedThis->wrapped(); |
268 | if (UNLIKELY(state->argumentCount() < 1)) |
269 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
270 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
271 | if (UNLIKELY(!context)) |
272 | return JSValue::encode(jsUndefined()); |
273 | auto url = convert<IDLUSVString>(*state, state->uncheckedArgument(0)); |
274 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
275 | impl.openWindow(*context, WTFMove(url), WTFMove(promise)); |
276 | return JSValue::encode(jsUndefined()); |
277 | } |
278 | |
279 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerClientsPrototypeFunctionOpenWindow(ExecState* state) |
280 | { |
281 | return IDLOperationReturningPromise<JSServiceWorkerClients>::call<jsServiceWorkerClientsPrototypeFunctionOpenWindowBody, PromiseExecutionScope::WindowOrWorker>(*state, "openWindow" ); |
282 | } |
283 | |
284 | static inline JSC::EncodedJSValue jsServiceWorkerClientsPrototypeFunctionClaimBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSServiceWorkerClients>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
285 | { |
286 | UNUSED_PARAM(state); |
287 | UNUSED_PARAM(throwScope); |
288 | auto& impl = castedThis->wrapped(); |
289 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
290 | if (UNLIKELY(!context)) |
291 | return JSValue::encode(jsUndefined()); |
292 | impl.claim(*context, WTFMove(promise)); |
293 | return JSValue::encode(jsUndefined()); |
294 | } |
295 | |
296 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerClientsPrototypeFunctionClaim(ExecState* state) |
297 | { |
298 | return IDLOperationReturningPromise<JSServiceWorkerClients>::call<jsServiceWorkerClientsPrototypeFunctionClaimBody, PromiseExecutionScope::WindowOrWorker>(*state, "claim" ); |
299 | } |
300 | |
301 | void JSServiceWorkerClients::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
302 | { |
303 | auto* thisObject = jsCast<JSServiceWorkerClients*>(cell); |
304 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
305 | if (thisObject->scriptExecutionContext()) |
306 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
307 | Base::heapSnapshot(cell, builder); |
308 | } |
309 | |
310 | bool JSServiceWorkerClientsOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
311 | { |
312 | auto* jsServiceWorkerClients = jsCast<JSServiceWorkerClients*>(handle.slot()->asCell()); |
313 | ServiceWorkerClients* root = &jsServiceWorkerClients->wrapped(); |
314 | if (UNLIKELY(reason)) |
315 | *reason = "Reachable from ServiceWorkerClients" ; |
316 | return visitor.containsOpaqueRoot(root); |
317 | } |
318 | |
319 | void JSServiceWorkerClientsOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
320 | { |
321 | auto* jsServiceWorkerClients = static_cast<JSServiceWorkerClients*>(handle.slot()->asCell()); |
322 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
323 | uncacheWrapper(world, &jsServiceWorkerClients->wrapped(), jsServiceWorkerClients); |
324 | } |
325 | |
326 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<ServiceWorkerClients>&& impl) |
327 | { |
328 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
329 | // attribute. You should remove that attribute. If the class has subclasses |
330 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
331 | // attribute to ServiceWorkerClients. |
332 | static_assert(!std::is_polymorphic<ServiceWorkerClients>::value, "ServiceWorkerClients is polymorphic but the IDL claims it is not" ); |
333 | return createWrapper<ServiceWorkerClients>(globalObject, WTFMove(impl)); |
334 | } |
335 | |
336 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ServiceWorkerClients& impl) |
337 | { |
338 | return wrap(state, globalObject, impl); |
339 | } |
340 | |
341 | ServiceWorkerClients* JSServiceWorkerClients::toWrapped(JSC::VM& vm, JSC::JSValue value) |
342 | { |
343 | if (auto* wrapper = jsDynamicCast<JSServiceWorkerClients*>(vm, value)) |
344 | return &wrapper->wrapped(); |
345 | return nullptr; |
346 | } |
347 | |
348 | } |
349 | |
350 | #endif // ENABLE(SERVICE_WORKER) |
351 | |