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 "JSServiceWorkerInternals.h" |
26 | |
27 | #include "JSDOMAttribute.h" |
28 | #include "JSDOMBinding.h" |
29 | #include "JSDOMConvertBoolean.h" |
30 | #include "JSDOMConvertInterface.h" |
31 | #include "JSDOMConvertSequences.h" |
32 | #include "JSDOMConvertStrings.h" |
33 | #include "JSDOMExceptionHandling.h" |
34 | #include "JSDOMGlobalObject.h" |
35 | #include "JSDOMOperation.h" |
36 | #include "JSDOMOperationReturningPromise.h" |
37 | #include "JSDOMWrapperCache.h" |
38 | #include "JSFetchEvent.h" |
39 | #include "JSFetchResponse.h" |
40 | #include "ScriptExecutionContext.h" |
41 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
42 | #include <JavaScriptCore/JSArray.h> |
43 | #include <JavaScriptCore/JSCInlines.h> |
44 | #include <wtf/GetPtr.h> |
45 | #include <wtf/PointerPreparations.h> |
46 | #include <wtf/URL.h> |
47 | |
48 | |
49 | namespace WebCore { |
50 | using namespace JSC; |
51 | |
52 | // Functions |
53 | |
54 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerInternalsPrototypeFunctionSetOnline(JSC::ExecState*); |
55 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerInternalsPrototypeFunctionWaitForFetchEventToFinish(JSC::ExecState*); |
56 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerInternalsPrototypeFunctionCreateBeingDispatchedFetchEvent(JSC::ExecState*); |
57 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerInternalsPrototypeFunctionCreateOpaqueWithBlobBodyResponse(JSC::ExecState*); |
58 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerInternalsPrototypeFunctionFetchResponseHeaderList(JSC::ExecState*); |
59 | |
60 | // Attributes |
61 | |
62 | JSC::EncodedJSValue jsServiceWorkerInternalsProcessName(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
63 | JSC::EncodedJSValue jsServiceWorkerInternalsIsThrottleable(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
64 | |
65 | class JSServiceWorkerInternalsPrototype : public JSC::JSNonFinalObject { |
66 | public: |
67 | using Base = JSC::JSNonFinalObject; |
68 | static JSServiceWorkerInternalsPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
69 | { |
70 | JSServiceWorkerInternalsPrototype* ptr = new (NotNull, JSC::allocateCell<JSServiceWorkerInternalsPrototype>(vm.heap)) JSServiceWorkerInternalsPrototype(vm, globalObject, structure); |
71 | ptr->finishCreation(vm); |
72 | return ptr; |
73 | } |
74 | |
75 | DECLARE_INFO; |
76 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
77 | { |
78 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
79 | } |
80 | |
81 | private: |
82 | JSServiceWorkerInternalsPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
83 | : JSC::JSNonFinalObject(vm, structure) |
84 | { |
85 | } |
86 | |
87 | void finishCreation(JSC::VM&); |
88 | }; |
89 | |
90 | /* Hash table for prototype */ |
91 | |
92 | static const HashTableValue JSServiceWorkerInternalsPrototypeTableValues[] = |
93 | { |
94 | { "processName" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerInternalsProcessName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
95 | { "isThrottleable" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerInternalsIsThrottleable), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
96 | { "setOnline" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerInternalsPrototypeFunctionSetOnline), (intptr_t) (1) } }, |
97 | { "waitForFetchEventToFinish" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerInternalsPrototypeFunctionWaitForFetchEventToFinish), (intptr_t) (1) } }, |
98 | { "createBeingDispatchedFetchEvent" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerInternalsPrototypeFunctionCreateBeingDispatchedFetchEvent), (intptr_t) (0) } }, |
99 | { "createOpaqueWithBlobBodyResponse" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerInternalsPrototypeFunctionCreateOpaqueWithBlobBodyResponse), (intptr_t) (0) } }, |
100 | { "fetchResponseHeaderList" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerInternalsPrototypeFunctionFetchResponseHeaderList), (intptr_t) (1) } }, |
101 | }; |
102 | |
103 | const ClassInfo JSServiceWorkerInternalsPrototype::s_info = { "ServiceWorkerInternalsPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerInternalsPrototype) }; |
104 | |
105 | void JSServiceWorkerInternalsPrototype::finishCreation(VM& vm) |
106 | { |
107 | Base::finishCreation(vm); |
108 | reifyStaticProperties(vm, JSServiceWorkerInternals::info(), JSServiceWorkerInternalsPrototypeTableValues, *this); |
109 | } |
110 | |
111 | const ClassInfo JSServiceWorkerInternals::s_info = { "ServiceWorkerInternals" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerInternals) }; |
112 | |
113 | JSServiceWorkerInternals::JSServiceWorkerInternals(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ServiceWorkerInternals>&& impl) |
114 | : JSDOMWrapper<ServiceWorkerInternals>(structure, globalObject, WTFMove(impl)) |
115 | { |
116 | } |
117 | |
118 | void JSServiceWorkerInternals::finishCreation(VM& vm) |
119 | { |
120 | Base::finishCreation(vm); |
121 | ASSERT(inherits(vm, info())); |
122 | |
123 | } |
124 | |
125 | JSObject* JSServiceWorkerInternals::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
126 | { |
127 | return JSServiceWorkerInternalsPrototype::create(vm, &globalObject, JSServiceWorkerInternalsPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
128 | } |
129 | |
130 | JSObject* JSServiceWorkerInternals::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
131 | { |
132 | return getDOMPrototype<JSServiceWorkerInternals>(vm, globalObject); |
133 | } |
134 | |
135 | void JSServiceWorkerInternals::destroy(JSC::JSCell* cell) |
136 | { |
137 | JSServiceWorkerInternals* thisObject = static_cast<JSServiceWorkerInternals*>(cell); |
138 | thisObject->JSServiceWorkerInternals::~JSServiceWorkerInternals(); |
139 | } |
140 | |
141 | template<> inline JSServiceWorkerInternals* IDLAttribute<JSServiceWorkerInternals>::cast(ExecState& state, EncodedJSValue thisValue) |
142 | { |
143 | return jsDynamicCast<JSServiceWorkerInternals*>(state.vm(), JSValue::decode(thisValue)); |
144 | } |
145 | |
146 | template<> inline JSServiceWorkerInternals* IDLOperation<JSServiceWorkerInternals>::cast(ExecState& state) |
147 | { |
148 | return jsDynamicCast<JSServiceWorkerInternals*>(state.vm(), state.thisValue()); |
149 | } |
150 | |
151 | static inline JSValue jsServiceWorkerInternalsProcessNameGetter(ExecState& state, JSServiceWorkerInternals& thisObject, ThrowScope& throwScope) |
152 | { |
153 | UNUSED_PARAM(throwScope); |
154 | UNUSED_PARAM(state); |
155 | auto& impl = thisObject.wrapped(); |
156 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.processName()); |
157 | return result; |
158 | } |
159 | |
160 | EncodedJSValue jsServiceWorkerInternalsProcessName(ExecState* state, EncodedJSValue thisValue, PropertyName) |
161 | { |
162 | return IDLAttribute<JSServiceWorkerInternals>::get<jsServiceWorkerInternalsProcessNameGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "processName" ); |
163 | } |
164 | |
165 | static inline JSValue jsServiceWorkerInternalsIsThrottleableGetter(ExecState& state, JSServiceWorkerInternals& thisObject, ThrowScope& throwScope) |
166 | { |
167 | UNUSED_PARAM(throwScope); |
168 | UNUSED_PARAM(state); |
169 | auto& impl = thisObject.wrapped(); |
170 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.isThrottleable()); |
171 | return result; |
172 | } |
173 | |
174 | EncodedJSValue jsServiceWorkerInternalsIsThrottleable(ExecState* state, EncodedJSValue thisValue, PropertyName) |
175 | { |
176 | return IDLAttribute<JSServiceWorkerInternals>::get<jsServiceWorkerInternalsIsThrottleableGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "isThrottleable" ); |
177 | } |
178 | |
179 | static inline JSC::EncodedJSValue jsServiceWorkerInternalsPrototypeFunctionSetOnlineBody(JSC::ExecState* state, typename IDLOperation<JSServiceWorkerInternals>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
180 | { |
181 | UNUSED_PARAM(state); |
182 | UNUSED_PARAM(throwScope); |
183 | auto& impl = castedThis->wrapped(); |
184 | if (UNLIKELY(state->argumentCount() < 1)) |
185 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
186 | auto isOnline = convert<IDLBoolean>(*state, state->uncheckedArgument(0)); |
187 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
188 | impl.setOnline(WTFMove(isOnline)); |
189 | return JSValue::encode(jsUndefined()); |
190 | } |
191 | |
192 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerInternalsPrototypeFunctionSetOnline(ExecState* state) |
193 | { |
194 | return IDLOperation<JSServiceWorkerInternals>::call<jsServiceWorkerInternalsPrototypeFunctionSetOnlineBody>(*state, "setOnline" ); |
195 | } |
196 | |
197 | static inline JSC::EncodedJSValue jsServiceWorkerInternalsPrototypeFunctionWaitForFetchEventToFinishBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSServiceWorkerInternals>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
198 | { |
199 | UNUSED_PARAM(state); |
200 | UNUSED_PARAM(throwScope); |
201 | auto& impl = castedThis->wrapped(); |
202 | if (UNLIKELY(state->argumentCount() < 1)) |
203 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
204 | auto event = convert<IDLInterface<FetchEvent>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "event" , "ServiceWorkerInternals" , "waitForFetchEventToFinish" , "FetchEvent" ); }); |
205 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
206 | impl.waitForFetchEventToFinish(*event, WTFMove(promise)); |
207 | return JSValue::encode(jsUndefined()); |
208 | } |
209 | |
210 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerInternalsPrototypeFunctionWaitForFetchEventToFinish(ExecState* state) |
211 | { |
212 | return IDLOperationReturningPromise<JSServiceWorkerInternals>::call<jsServiceWorkerInternalsPrototypeFunctionWaitForFetchEventToFinishBody, PromiseExecutionScope::WindowOnly>(*state, "waitForFetchEventToFinish" ); |
213 | } |
214 | |
215 | static inline JSC::EncodedJSValue jsServiceWorkerInternalsPrototypeFunctionCreateBeingDispatchedFetchEventBody(JSC::ExecState* state, typename IDLOperation<JSServiceWorkerInternals>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
216 | { |
217 | UNUSED_PARAM(state); |
218 | UNUSED_PARAM(throwScope); |
219 | auto& impl = castedThis->wrapped(); |
220 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
221 | if (UNLIKELY(!context)) |
222 | return JSValue::encode(jsUndefined()); |
223 | return JSValue::encode(toJS<IDLInterface<FetchEvent>>(*state, *castedThis->globalObject(), impl.createBeingDispatchedFetchEvent(*context))); |
224 | } |
225 | |
226 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerInternalsPrototypeFunctionCreateBeingDispatchedFetchEvent(ExecState* state) |
227 | { |
228 | return IDLOperation<JSServiceWorkerInternals>::call<jsServiceWorkerInternalsPrototypeFunctionCreateBeingDispatchedFetchEventBody>(*state, "createBeingDispatchedFetchEvent" ); |
229 | } |
230 | |
231 | static inline JSC::EncodedJSValue jsServiceWorkerInternalsPrototypeFunctionCreateOpaqueWithBlobBodyResponseBody(JSC::ExecState* state, typename IDLOperation<JSServiceWorkerInternals>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
232 | { |
233 | UNUSED_PARAM(state); |
234 | UNUSED_PARAM(throwScope); |
235 | auto& impl = castedThis->wrapped(); |
236 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
237 | if (UNLIKELY(!context)) |
238 | return JSValue::encode(jsUndefined()); |
239 | return JSValue::encode(toJS<IDLInterface<FetchResponse>>(*state, *castedThis->globalObject(), impl.createOpaqueWithBlobBodyResponse(*context))); |
240 | } |
241 | |
242 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerInternalsPrototypeFunctionCreateOpaqueWithBlobBodyResponse(ExecState* state) |
243 | { |
244 | return IDLOperation<JSServiceWorkerInternals>::call<jsServiceWorkerInternalsPrototypeFunctionCreateOpaqueWithBlobBodyResponseBody>(*state, "createOpaqueWithBlobBodyResponse" ); |
245 | } |
246 | |
247 | static inline JSC::EncodedJSValue jsServiceWorkerInternalsPrototypeFunctionFetchResponseHeaderListBody(JSC::ExecState* state, typename IDLOperation<JSServiceWorkerInternals>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
248 | { |
249 | UNUSED_PARAM(state); |
250 | UNUSED_PARAM(throwScope); |
251 | auto& impl = castedThis->wrapped(); |
252 | if (UNLIKELY(state->argumentCount() < 1)) |
253 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
254 | auto response = convert<IDLInterface<FetchResponse>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "response" , "ServiceWorkerInternals" , "fetchResponseHeaderList" , "FetchResponse" ); }); |
255 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
256 | return JSValue::encode(toJS<IDLSequence<IDLByteString>>(*state, *castedThis->globalObject(), impl.fetchResponseHeaderList(*response))); |
257 | } |
258 | |
259 | EncodedJSValue JSC_HOST_CALL (ExecState* state) |
260 | { |
261 | return IDLOperation<JSServiceWorkerInternals>::call<jsServiceWorkerInternalsPrototypeFunctionFetchResponseHeaderListBody>(*state, "fetchResponseHeaderList" ); |
262 | } |
263 | |
264 | void JSServiceWorkerInternals::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
265 | { |
266 | auto* thisObject = jsCast<JSServiceWorkerInternals*>(cell); |
267 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
268 | if (thisObject->scriptExecutionContext()) |
269 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
270 | Base::heapSnapshot(cell, builder); |
271 | } |
272 | |
273 | bool JSServiceWorkerInternalsOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
274 | { |
275 | UNUSED_PARAM(handle); |
276 | UNUSED_PARAM(visitor); |
277 | UNUSED_PARAM(reason); |
278 | return false; |
279 | } |
280 | |
281 | void JSServiceWorkerInternalsOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
282 | { |
283 | auto* jsServiceWorkerInternals = static_cast<JSServiceWorkerInternals*>(handle.slot()->asCell()); |
284 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
285 | uncacheWrapper(world, &jsServiceWorkerInternals->wrapped(), jsServiceWorkerInternals); |
286 | } |
287 | |
288 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<ServiceWorkerInternals>&& impl) |
289 | { |
290 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
291 | // attribute. You should remove that attribute. If the class has subclasses |
292 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
293 | // attribute to ServiceWorkerInternals. |
294 | static_assert(!std::is_polymorphic<ServiceWorkerInternals>::value, "ServiceWorkerInternals is polymorphic but the IDL claims it is not" ); |
295 | return createWrapper<ServiceWorkerInternals>(globalObject, WTFMove(impl)); |
296 | } |
297 | |
298 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ServiceWorkerInternals& impl) |
299 | { |
300 | return wrap(state, globalObject, impl); |
301 | } |
302 | |
303 | ServiceWorkerInternals* JSServiceWorkerInternals::toWrapped(JSC::VM& vm, JSC::JSValue value) |
304 | { |
305 | if (auto* wrapper = jsDynamicCast<JSServiceWorkerInternals*>(vm, value)) |
306 | return &wrapper->wrapped(); |
307 | return nullptr; |
308 | } |
309 | |
310 | } |
311 | |
312 | #endif // ENABLE(SERVICE_WORKER) |
313 | |