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 "JSServiceWorkerContainer.h" |
26 | |
27 | #include "DOMPromiseProxy.h" |
28 | #include "EventNames.h" |
29 | #include "JSDOMAttribute.h" |
30 | #include "JSDOMBinding.h" |
31 | #include "JSDOMConstructorNotConstructable.h" |
32 | #include "JSDOMConvertEnumeration.h" |
33 | #include "JSDOMConvertInterface.h" |
34 | #include "JSDOMConvertNullable.h" |
35 | #include "JSDOMConvertPromise.h" |
36 | #include "JSDOMConvertStrings.h" |
37 | #include "JSDOMExceptionHandling.h" |
38 | #include "JSDOMGlobalObject.h" |
39 | #include "JSDOMOperation.h" |
40 | #include "JSDOMOperationReturningPromise.h" |
41 | #include "JSDOMWrapperCache.h" |
42 | #include "JSEventListener.h" |
43 | #include "JSServiceWorker.h" |
44 | #include "JSServiceWorkerRegistration.h" |
45 | #include "JSServiceWorkerUpdateViaCache.h" |
46 | #include "JSWorkerType.h" |
47 | #include "ScriptExecutionContext.h" |
48 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
49 | #include <JavaScriptCore/JSCInlines.h> |
50 | #include <wtf/GetPtr.h> |
51 | #include <wtf/PointerPreparations.h> |
52 | #include <wtf/URL.h> |
53 | |
54 | |
55 | namespace WebCore { |
56 | using namespace JSC; |
57 | |
58 | template<> ServiceWorkerContainer::RegistrationOptions convertDictionary<ServiceWorkerContainer::RegistrationOptions>(ExecState& state, JSValue value) |
59 | { |
60 | VM& vm = state.vm(); |
61 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
62 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
63 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
64 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
65 | throwTypeError(&state, throwScope); |
66 | return { }; |
67 | } |
68 | ServiceWorkerContainer::RegistrationOptions result; |
69 | JSValue scopeValue; |
70 | if (isNullOrUndefined) |
71 | scopeValue = jsUndefined(); |
72 | else { |
73 | scopeValue = object->get(&state, Identifier::fromString(&state, "scope" )); |
74 | RETURN_IF_EXCEPTION(throwScope, { }); |
75 | } |
76 | if (!scopeValue.isUndefined()) { |
77 | result.scope = convert<IDLUSVString>(state, scopeValue); |
78 | RETURN_IF_EXCEPTION(throwScope, { }); |
79 | } |
80 | JSValue typeValue; |
81 | if (isNullOrUndefined) |
82 | typeValue = jsUndefined(); |
83 | else { |
84 | typeValue = object->get(&state, Identifier::fromString(&state, "type" )); |
85 | RETURN_IF_EXCEPTION(throwScope, { }); |
86 | } |
87 | if (!typeValue.isUndefined()) { |
88 | result.type = convert<IDLEnumeration<WorkerType>>(state, typeValue); |
89 | RETURN_IF_EXCEPTION(throwScope, { }); |
90 | } else |
91 | result.type = WorkerType::Classic; |
92 | JSValue updateViaCacheValue; |
93 | if (isNullOrUndefined) |
94 | updateViaCacheValue = jsUndefined(); |
95 | else { |
96 | updateViaCacheValue = object->get(&state, Identifier::fromString(&state, "updateViaCache" )); |
97 | RETURN_IF_EXCEPTION(throwScope, { }); |
98 | } |
99 | if (!updateViaCacheValue.isUndefined()) { |
100 | result.updateViaCache = convert<IDLEnumeration<ServiceWorkerUpdateViaCache>>(state, updateViaCacheValue); |
101 | RETURN_IF_EXCEPTION(throwScope, { }); |
102 | } else |
103 | result.updateViaCache = ServiceWorkerUpdateViaCache::Imports; |
104 | return result; |
105 | } |
106 | |
107 | // Functions |
108 | |
109 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerContainerPrototypeFunctionRegister(JSC::ExecState*); |
110 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerContainerPrototypeFunctionGetRegistration(JSC::ExecState*); |
111 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerContainerPrototypeFunctionGetRegistrations(JSC::ExecState*); |
112 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerContainerPrototypeFunctionStartMessages(JSC::ExecState*); |
113 | |
114 | // Attributes |
115 | |
116 | JSC::EncodedJSValue jsServiceWorkerContainerConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
117 | bool setJSServiceWorkerContainerConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
118 | JSC::EncodedJSValue jsServiceWorkerContainerController(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
119 | JSC::EncodedJSValue jsServiceWorkerContainerReady(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
120 | JSC::EncodedJSValue jsServiceWorkerContainerOncontrollerchange(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
121 | bool setJSServiceWorkerContainerOncontrollerchange(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
122 | JSC::EncodedJSValue jsServiceWorkerContainerOnmessage(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
123 | bool setJSServiceWorkerContainerOnmessage(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
124 | JSC::EncodedJSValue jsServiceWorkerContainerOnmessageerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
125 | bool setJSServiceWorkerContainerOnmessageerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
126 | |
127 | class JSServiceWorkerContainerPrototype : public JSC::JSNonFinalObject { |
128 | public: |
129 | using Base = JSC::JSNonFinalObject; |
130 | static JSServiceWorkerContainerPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
131 | { |
132 | JSServiceWorkerContainerPrototype* ptr = new (NotNull, JSC::allocateCell<JSServiceWorkerContainerPrototype>(vm.heap)) JSServiceWorkerContainerPrototype(vm, globalObject, structure); |
133 | ptr->finishCreation(vm); |
134 | return ptr; |
135 | } |
136 | |
137 | DECLARE_INFO; |
138 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
139 | { |
140 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
141 | } |
142 | |
143 | private: |
144 | JSServiceWorkerContainerPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
145 | : JSC::JSNonFinalObject(vm, structure) |
146 | { |
147 | } |
148 | |
149 | void finishCreation(JSC::VM&); |
150 | }; |
151 | |
152 | using JSServiceWorkerContainerConstructor = JSDOMConstructorNotConstructable<JSServiceWorkerContainer>; |
153 | |
154 | template<> JSValue JSServiceWorkerContainerConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
155 | { |
156 | return JSEventTarget::getConstructor(vm, &globalObject); |
157 | } |
158 | |
159 | template<> void JSServiceWorkerContainerConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
160 | { |
161 | putDirect(vm, vm.propertyNames->prototype, JSServiceWorkerContainer::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
162 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("ServiceWorkerContainer"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
163 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
164 | } |
165 | |
166 | template<> const ClassInfo JSServiceWorkerContainerConstructor::s_info = { "ServiceWorkerContainer" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerContainerConstructor) }; |
167 | |
168 | /* Hash table for prototype */ |
169 | |
170 | static const HashTableValue JSServiceWorkerContainerPrototypeTableValues[] = |
171 | { |
172 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerContainerConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSServiceWorkerContainerConstructor) } }, |
173 | { "controller" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerContainerController), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
174 | { "ready" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerContainerReady), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
175 | { "oncontrollerchange" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerContainerOncontrollerchange), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSServiceWorkerContainerOncontrollerchange) } }, |
176 | { "onmessage" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerContainerOnmessage), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSServiceWorkerContainerOnmessage) } }, |
177 | { "onmessageerror" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerContainerOnmessageerror), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSServiceWorkerContainerOnmessageerror) } }, |
178 | { "register" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerContainerPrototypeFunctionRegister), (intptr_t) (1) } }, |
179 | { "getRegistration" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerContainerPrototypeFunctionGetRegistration), (intptr_t) (0) } }, |
180 | { "getRegistrations" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerContainerPrototypeFunctionGetRegistrations), (intptr_t) (0) } }, |
181 | { "startMessages" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerContainerPrototypeFunctionStartMessages), (intptr_t) (0) } }, |
182 | }; |
183 | |
184 | const ClassInfo JSServiceWorkerContainerPrototype::s_info = { "ServiceWorkerContainerPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerContainerPrototype) }; |
185 | |
186 | void JSServiceWorkerContainerPrototype::finishCreation(VM& vm) |
187 | { |
188 | Base::finishCreation(vm); |
189 | reifyStaticProperties(vm, JSServiceWorkerContainer::info(), JSServiceWorkerContainerPrototypeTableValues, *this); |
190 | } |
191 | |
192 | const ClassInfo JSServiceWorkerContainer::s_info = { "ServiceWorkerContainer" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerContainer) }; |
193 | |
194 | JSServiceWorkerContainer::JSServiceWorkerContainer(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ServiceWorkerContainer>&& impl) |
195 | : JSEventTarget(structure, globalObject, WTFMove(impl)) |
196 | { |
197 | } |
198 | |
199 | void JSServiceWorkerContainer::finishCreation(VM& vm) |
200 | { |
201 | Base::finishCreation(vm); |
202 | ASSERT(inherits(vm, info())); |
203 | |
204 | } |
205 | |
206 | JSObject* JSServiceWorkerContainer::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
207 | { |
208 | return JSServiceWorkerContainerPrototype::create(vm, &globalObject, JSServiceWorkerContainerPrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject))); |
209 | } |
210 | |
211 | JSObject* JSServiceWorkerContainer::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
212 | { |
213 | return getDOMPrototype<JSServiceWorkerContainer>(vm, globalObject); |
214 | } |
215 | |
216 | JSValue JSServiceWorkerContainer::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
217 | { |
218 | return getDOMConstructor<JSServiceWorkerContainerConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
219 | } |
220 | |
221 | template<> inline JSServiceWorkerContainer* IDLAttribute<JSServiceWorkerContainer>::cast(ExecState& state, EncodedJSValue thisValue) |
222 | { |
223 | return jsDynamicCast<JSServiceWorkerContainer*>(state.vm(), JSValue::decode(thisValue)); |
224 | } |
225 | |
226 | template<> inline JSServiceWorkerContainer* IDLOperation<JSServiceWorkerContainer>::cast(ExecState& state) |
227 | { |
228 | return jsDynamicCast<JSServiceWorkerContainer*>(state.vm(), state.thisValue()); |
229 | } |
230 | |
231 | EncodedJSValue jsServiceWorkerContainerConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
232 | { |
233 | VM& vm = state->vm(); |
234 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
235 | auto* prototype = jsDynamicCast<JSServiceWorkerContainerPrototype*>(vm, JSValue::decode(thisValue)); |
236 | if (UNLIKELY(!prototype)) |
237 | return throwVMTypeError(state, throwScope); |
238 | return JSValue::encode(JSServiceWorkerContainer::getConstructor(state->vm(), prototype->globalObject())); |
239 | } |
240 | |
241 | bool setJSServiceWorkerContainerConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
242 | { |
243 | VM& vm = state->vm(); |
244 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
245 | auto* prototype = jsDynamicCast<JSServiceWorkerContainerPrototype*>(vm, JSValue::decode(thisValue)); |
246 | if (UNLIKELY(!prototype)) { |
247 | throwVMTypeError(state, throwScope); |
248 | return false; |
249 | } |
250 | // Shadowing a built-in constructor |
251 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
252 | } |
253 | |
254 | static inline JSValue jsServiceWorkerContainerControllerGetter(ExecState& state, JSServiceWorkerContainer& thisObject, ThrowScope& throwScope) |
255 | { |
256 | UNUSED_PARAM(throwScope); |
257 | UNUSED_PARAM(state); |
258 | auto& impl = thisObject.wrapped(); |
259 | JSValue result = toJS<IDLNullable<IDLInterface<ServiceWorker>>>(state, *thisObject.globalObject(), throwScope, impl.controller()); |
260 | return result; |
261 | } |
262 | |
263 | EncodedJSValue jsServiceWorkerContainerController(ExecState* state, EncodedJSValue thisValue, PropertyName) |
264 | { |
265 | return IDLAttribute<JSServiceWorkerContainer>::get<jsServiceWorkerContainerControllerGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "controller" ); |
266 | } |
267 | |
268 | static inline JSValue jsServiceWorkerContainerReadyGetter(ExecState& state, JSServiceWorkerContainer& thisObject, ThrowScope& throwScope) |
269 | { |
270 | UNUSED_PARAM(throwScope); |
271 | UNUSED_PARAM(state); |
272 | auto& impl = thisObject.wrapped(); |
273 | JSValue result = toJS<IDLPromise<IDLInterface<ServiceWorkerRegistration>>>(state, *thisObject.globalObject(), throwScope, impl.ready()); |
274 | return result; |
275 | } |
276 | |
277 | EncodedJSValue jsServiceWorkerContainerReady(ExecState* state, EncodedJSValue thisValue, PropertyName) |
278 | { |
279 | return IDLAttribute<JSServiceWorkerContainer>::get<jsServiceWorkerContainerReadyGetter, CastedThisErrorBehavior::RejectPromise>(*state, thisValue, "ready" ); |
280 | } |
281 | |
282 | static inline JSValue jsServiceWorkerContainerOncontrollerchangeGetter(ExecState& state, JSServiceWorkerContainer& thisObject, ThrowScope& throwScope) |
283 | { |
284 | UNUSED_PARAM(throwScope); |
285 | UNUSED_PARAM(state); |
286 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().controllerchangeEvent, worldForDOMObject(thisObject)); |
287 | } |
288 | |
289 | EncodedJSValue jsServiceWorkerContainerOncontrollerchange(ExecState* state, EncodedJSValue thisValue, PropertyName) |
290 | { |
291 | return IDLAttribute<JSServiceWorkerContainer>::get<jsServiceWorkerContainerOncontrollerchangeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "oncontrollerchange" ); |
292 | } |
293 | |
294 | static inline bool setJSServiceWorkerContainerOncontrollerchangeSetter(ExecState& state, JSServiceWorkerContainer& thisObject, JSValue value, ThrowScope& throwScope) |
295 | { |
296 | UNUSED_PARAM(throwScope); |
297 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().controllerchangeEvent, value); |
298 | return true; |
299 | } |
300 | |
301 | bool setJSServiceWorkerContainerOncontrollerchange(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
302 | { |
303 | return IDLAttribute<JSServiceWorkerContainer>::set<setJSServiceWorkerContainerOncontrollerchangeSetter>(*state, thisValue, encodedValue, "oncontrollerchange" ); |
304 | } |
305 | |
306 | static inline JSValue jsServiceWorkerContainerOnmessageGetter(ExecState& state, JSServiceWorkerContainer& thisObject, ThrowScope& throwScope) |
307 | { |
308 | UNUSED_PARAM(throwScope); |
309 | UNUSED_PARAM(state); |
310 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().messageEvent, worldForDOMObject(thisObject)); |
311 | } |
312 | |
313 | EncodedJSValue jsServiceWorkerContainerOnmessage(ExecState* state, EncodedJSValue thisValue, PropertyName) |
314 | { |
315 | return IDLAttribute<JSServiceWorkerContainer>::get<jsServiceWorkerContainerOnmessageGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onmessage" ); |
316 | } |
317 | |
318 | static inline bool setJSServiceWorkerContainerOnmessageSetter(ExecState& state, JSServiceWorkerContainer& thisObject, JSValue value, ThrowScope& throwScope) |
319 | { |
320 | UNUSED_PARAM(throwScope); |
321 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().messageEvent, value); |
322 | return true; |
323 | } |
324 | |
325 | bool setJSServiceWorkerContainerOnmessage(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
326 | { |
327 | return IDLAttribute<JSServiceWorkerContainer>::set<setJSServiceWorkerContainerOnmessageSetter>(*state, thisValue, encodedValue, "onmessage" ); |
328 | } |
329 | |
330 | static inline JSValue jsServiceWorkerContainerOnmessageerrorGetter(ExecState& state, JSServiceWorkerContainer& thisObject, ThrowScope& throwScope) |
331 | { |
332 | UNUSED_PARAM(throwScope); |
333 | UNUSED_PARAM(state); |
334 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().messageerrorEvent, worldForDOMObject(thisObject)); |
335 | } |
336 | |
337 | EncodedJSValue jsServiceWorkerContainerOnmessageerror(ExecState* state, EncodedJSValue thisValue, PropertyName) |
338 | { |
339 | return IDLAttribute<JSServiceWorkerContainer>::get<jsServiceWorkerContainerOnmessageerrorGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onmessageerror" ); |
340 | } |
341 | |
342 | static inline bool setJSServiceWorkerContainerOnmessageerrorSetter(ExecState& state, JSServiceWorkerContainer& thisObject, JSValue value, ThrowScope& throwScope) |
343 | { |
344 | UNUSED_PARAM(throwScope); |
345 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().messageerrorEvent, value); |
346 | return true; |
347 | } |
348 | |
349 | bool setJSServiceWorkerContainerOnmessageerror(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
350 | { |
351 | return IDLAttribute<JSServiceWorkerContainer>::set<setJSServiceWorkerContainerOnmessageerrorSetter>(*state, thisValue, encodedValue, "onmessageerror" ); |
352 | } |
353 | |
354 | static inline JSC::EncodedJSValue jsServiceWorkerContainerPrototypeFunctionRegisterBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSServiceWorkerContainer>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
355 | { |
356 | UNUSED_PARAM(state); |
357 | UNUSED_PARAM(throwScope); |
358 | auto& impl = castedThis->wrapped(); |
359 | if (UNLIKELY(state->argumentCount() < 1)) |
360 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
361 | auto scriptURL = convert<IDLUSVString>(*state, state->uncheckedArgument(0)); |
362 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
363 | auto options = convert<IDLDictionary<ServiceWorkerContainer::RegistrationOptions>>(*state, state->argument(1)); |
364 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
365 | impl.addRegistration(WTFMove(scriptURL), WTFMove(options), WTFMove(promise)); |
366 | return JSValue::encode(jsUndefined()); |
367 | } |
368 | |
369 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerContainerPrototypeFunctionRegister(ExecState* state) |
370 | { |
371 | return IDLOperationReturningPromise<JSServiceWorkerContainer>::call<jsServiceWorkerContainerPrototypeFunctionRegisterBody, PromiseExecutionScope::WindowOrWorker>(*state, "register" ); |
372 | } |
373 | |
374 | static inline JSC::EncodedJSValue jsServiceWorkerContainerPrototypeFunctionGetRegistrationBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSServiceWorkerContainer>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
375 | { |
376 | UNUSED_PARAM(state); |
377 | UNUSED_PARAM(throwScope); |
378 | auto& impl = castedThis->wrapped(); |
379 | auto clientURL = state->argument(0).isUndefined() ? emptyString() : convert<IDLUSVString>(*state, state->uncheckedArgument(0)); |
380 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
381 | impl.getRegistration(WTFMove(clientURL), WTFMove(promise)); |
382 | return JSValue::encode(jsUndefined()); |
383 | } |
384 | |
385 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerContainerPrototypeFunctionGetRegistration(ExecState* state) |
386 | { |
387 | return IDLOperationReturningPromise<JSServiceWorkerContainer>::call<jsServiceWorkerContainerPrototypeFunctionGetRegistrationBody, PromiseExecutionScope::WindowOrWorker>(*state, "getRegistration" ); |
388 | } |
389 | |
390 | static inline JSC::EncodedJSValue jsServiceWorkerContainerPrototypeFunctionGetRegistrationsBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSServiceWorkerContainer>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
391 | { |
392 | UNUSED_PARAM(state); |
393 | UNUSED_PARAM(throwScope); |
394 | auto& impl = castedThis->wrapped(); |
395 | impl.getRegistrations(WTFMove(promise)); |
396 | return JSValue::encode(jsUndefined()); |
397 | } |
398 | |
399 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerContainerPrototypeFunctionGetRegistrations(ExecState* state) |
400 | { |
401 | return IDLOperationReturningPromise<JSServiceWorkerContainer>::call<jsServiceWorkerContainerPrototypeFunctionGetRegistrationsBody, PromiseExecutionScope::WindowOrWorker>(*state, "getRegistrations" ); |
402 | } |
403 | |
404 | static inline JSC::EncodedJSValue jsServiceWorkerContainerPrototypeFunctionStartMessagesBody(JSC::ExecState* state, typename IDLOperation<JSServiceWorkerContainer>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
405 | { |
406 | UNUSED_PARAM(state); |
407 | UNUSED_PARAM(throwScope); |
408 | auto& impl = castedThis->wrapped(); |
409 | impl.startMessages(); |
410 | return JSValue::encode(jsUndefined()); |
411 | } |
412 | |
413 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerContainerPrototypeFunctionStartMessages(ExecState* state) |
414 | { |
415 | return IDLOperation<JSServiceWorkerContainer>::call<jsServiceWorkerContainerPrototypeFunctionStartMessagesBody>(*state, "startMessages" ); |
416 | } |
417 | |
418 | void JSServiceWorkerContainer::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
419 | { |
420 | auto* thisObject = jsCast<JSServiceWorkerContainer*>(cell); |
421 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
422 | if (thisObject->scriptExecutionContext()) |
423 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
424 | Base::heapSnapshot(cell, builder); |
425 | } |
426 | |
427 | bool JSServiceWorkerContainerOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
428 | { |
429 | auto* jsServiceWorkerContainer = jsCast<JSServiceWorkerContainer*>(handle.slot()->asCell()); |
430 | if (jsServiceWorkerContainer->wrapped().isFiringEventListeners()) { |
431 | if (UNLIKELY(reason)) |
432 | *reason = "EventTarget firing event listeners" ; |
433 | return true; |
434 | } |
435 | ServiceWorkerContainer* root = &jsServiceWorkerContainer->wrapped(); |
436 | if (UNLIKELY(reason)) |
437 | *reason = "Reachable from ServiceWorkerContainer" ; |
438 | return visitor.containsOpaqueRoot(root); |
439 | } |
440 | |
441 | void JSServiceWorkerContainerOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
442 | { |
443 | auto* jsServiceWorkerContainer = static_cast<JSServiceWorkerContainer*>(handle.slot()->asCell()); |
444 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
445 | uncacheWrapper(world, &jsServiceWorkerContainer->wrapped(), jsServiceWorkerContainer); |
446 | } |
447 | |
448 | #if ENABLE(BINDING_INTEGRITY) |
449 | #if PLATFORM(WIN) |
450 | #pragma warning(disable: 4483) |
451 | extern "C" { extern void (*const __identifier("??_7ServiceWorkerContainer@WebCore@@6B@" )[])(); } |
452 | #else |
453 | extern "C" { extern void* _ZTVN7WebCore22ServiceWorkerContainerE[]; } |
454 | #endif |
455 | #endif |
456 | |
457 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<ServiceWorkerContainer>&& impl) |
458 | { |
459 | |
460 | #if ENABLE(BINDING_INTEGRITY) |
461 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
462 | #if PLATFORM(WIN) |
463 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7ServiceWorkerContainer@WebCore@@6B@" )); |
464 | #else |
465 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore22ServiceWorkerContainerE[2]); |
466 | #endif |
467 | |
468 | // If this fails ServiceWorkerContainer does not have a vtable, so you need to add the |
469 | // ImplementationLacksVTable attribute to the interface definition |
470 | static_assert(std::is_polymorphic<ServiceWorkerContainer>::value, "ServiceWorkerContainer is not polymorphic" ); |
471 | |
472 | // If you hit this assertion you either have a use after free bug, or |
473 | // ServiceWorkerContainer has subclasses. If ServiceWorkerContainer has subclasses that get passed |
474 | // to toJS() we currently require ServiceWorkerContainer you to opt out of binding hardening |
475 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
476 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
477 | #endif |
478 | return createWrapper<ServiceWorkerContainer>(globalObject, WTFMove(impl)); |
479 | } |
480 | |
481 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ServiceWorkerContainer& impl) |
482 | { |
483 | return wrap(state, globalObject, impl); |
484 | } |
485 | |
486 | ServiceWorkerContainer* JSServiceWorkerContainer::toWrapped(JSC::VM& vm, JSC::JSValue value) |
487 | { |
488 | if (auto* wrapper = jsDynamicCast<JSServiceWorkerContainer*>(vm, value)) |
489 | return &wrapper->wrapped(); |
490 | return nullptr; |
491 | } |
492 | |
493 | } |
494 | |
495 | #endif // ENABLE(SERVICE_WORKER) |
496 | |