/work/obj-fuzz/dom/bindings/ServiceWorkerRegistrationBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM ServiceWorkerRegistration.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "EventHandlerBinding.h" |
4 | | #include "EventTargetBinding.h" |
5 | | #include "NotificationBinding.h" |
6 | | #include "ServiceWorkerRegistrationBinding.h" |
7 | | #include "WrapperFactory.h" |
8 | | #include "jsapi.h" |
9 | | #include "mozilla/OwningNonNull.h" |
10 | | #include "mozilla/dom/BindingUtils.h" |
11 | | #include "mozilla/dom/DOMJSClass.h" |
12 | | #include "mozilla/dom/DOMPrefs.h" |
13 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
14 | | #include "mozilla/dom/Nullable.h" |
15 | | #include "mozilla/dom/Promise.h" |
16 | | #include "mozilla/dom/PushManager.h" |
17 | | #include "mozilla/dom/ServiceWorker.h" |
18 | | #include "mozilla/dom/ServiceWorkerRegistration.h" |
19 | | #include "mozilla/dom/ToJSValue.h" |
20 | | #include "mozilla/dom/XrayExpandoClass.h" |
21 | | |
22 | | namespace mozilla { |
23 | | namespace dom { |
24 | | |
25 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
26 | | using namespace mozilla::dom::binding_detail; |
27 | | |
28 | | |
29 | | namespace ServiceWorkerUpdateViaCacheValues { |
30 | | extern const EnumEntry strings[4] = { |
31 | | {"imports", 7}, |
32 | | {"all", 3}, |
33 | | {"none", 4}, |
34 | | { nullptr, 0 } |
35 | | }; |
36 | | } // namespace ServiceWorkerUpdateViaCacheValues |
37 | | |
38 | | bool |
39 | | ToJSValue(JSContext* aCx, ServiceWorkerUpdateViaCache aArgument, JS::MutableHandle<JS::Value> aValue) |
40 | 0 | { |
41 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(ServiceWorkerUpdateViaCacheValues::strings)); |
42 | 0 | JSString* resultStr = |
43 | 0 | JS_NewStringCopyN(aCx, ServiceWorkerUpdateViaCacheValues::strings[uint32_t(aArgument)].value, |
44 | 0 | ServiceWorkerUpdateViaCacheValues::strings[uint32_t(aArgument)].length); |
45 | 0 | if (!resultStr) { |
46 | 0 | return false; |
47 | 0 | } |
48 | 0 | aValue.setString(resultStr); |
49 | 0 | return true; |
50 | 0 | } |
51 | | |
52 | | |
53 | | namespace ServiceWorkerRegistration_Binding { |
54 | | |
55 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
56 | | "Can't inherit from an interface with a different ownership model."); |
57 | | |
58 | | MOZ_CAN_RUN_SCRIPT static bool |
59 | | get_installing(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, JSJitGetterCallArgs args) |
60 | 0 | { |
61 | 0 | AUTO_PROFILER_LABEL_FAST("get ServiceWorkerRegistration.installing", DOM, cx); |
62 | 0 |
|
63 | 0 | auto result(StrongOrRawPtr<mozilla::dom::ServiceWorker>(self->GetInstalling())); |
64 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
65 | 0 | if (!result) { |
66 | 0 | args.rval().setNull(); |
67 | 0 | return true; |
68 | 0 | } |
69 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
70 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
71 | 0 | return false; |
72 | 0 | } |
73 | 0 | return true; |
74 | 0 | } |
75 | | |
76 | | static const JSJitInfo installing_getterinfo = { |
77 | | { (JSJitGetterOp)get_installing }, |
78 | | { prototypes::id::ServiceWorkerRegistration }, |
79 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
80 | | JSJitInfo::Getter, |
81 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
82 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
83 | | false, /* isInfallible. False in setters. */ |
84 | | false, /* isMovable. Not relevant for setters. */ |
85 | | false, /* isEliminatable. Not relevant for setters. */ |
86 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
87 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
88 | | false, /* isTypedMethod. Only relevant for methods. */ |
89 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
90 | | }; |
91 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
92 | | static_assert(0 < 1, "There is no slot for us"); |
93 | | |
94 | | MOZ_CAN_RUN_SCRIPT static bool |
95 | | get_waiting(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, JSJitGetterCallArgs args) |
96 | 0 | { |
97 | 0 | AUTO_PROFILER_LABEL_FAST("get ServiceWorkerRegistration.waiting", DOM, cx); |
98 | 0 |
|
99 | 0 | auto result(StrongOrRawPtr<mozilla::dom::ServiceWorker>(self->GetWaiting())); |
100 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
101 | 0 | if (!result) { |
102 | 0 | args.rval().setNull(); |
103 | 0 | return true; |
104 | 0 | } |
105 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
106 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
107 | 0 | return false; |
108 | 0 | } |
109 | 0 | return true; |
110 | 0 | } |
111 | | |
112 | | static const JSJitInfo waiting_getterinfo = { |
113 | | { (JSJitGetterOp)get_waiting }, |
114 | | { prototypes::id::ServiceWorkerRegistration }, |
115 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
116 | | JSJitInfo::Getter, |
117 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
118 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
119 | | false, /* isInfallible. False in setters. */ |
120 | | false, /* isMovable. Not relevant for setters. */ |
121 | | false, /* isEliminatable. Not relevant for setters. */ |
122 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
123 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
124 | | false, /* isTypedMethod. Only relevant for methods. */ |
125 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
126 | | }; |
127 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
128 | | static_assert(0 < 1, "There is no slot for us"); |
129 | | |
130 | | MOZ_CAN_RUN_SCRIPT static bool |
131 | | get_active(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, JSJitGetterCallArgs args) |
132 | 0 | { |
133 | 0 | AUTO_PROFILER_LABEL_FAST("get ServiceWorkerRegistration.active", DOM, cx); |
134 | 0 |
|
135 | 0 | auto result(StrongOrRawPtr<mozilla::dom::ServiceWorker>(self->GetActive())); |
136 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
137 | 0 | if (!result) { |
138 | 0 | args.rval().setNull(); |
139 | 0 | return true; |
140 | 0 | } |
141 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
142 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
143 | 0 | return false; |
144 | 0 | } |
145 | 0 | return true; |
146 | 0 | } |
147 | | |
148 | | static const JSJitInfo active_getterinfo = { |
149 | | { (JSJitGetterOp)get_active }, |
150 | | { prototypes::id::ServiceWorkerRegistration }, |
151 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
152 | | JSJitInfo::Getter, |
153 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
154 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
155 | | false, /* isInfallible. False in setters. */ |
156 | | false, /* isMovable. Not relevant for setters. */ |
157 | | false, /* isEliminatable. Not relevant for setters. */ |
158 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
159 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
160 | | false, /* isTypedMethod. Only relevant for methods. */ |
161 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
162 | | }; |
163 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
164 | | static_assert(0 < 1, "There is no slot for us"); |
165 | | |
166 | | MOZ_CAN_RUN_SCRIPT static bool |
167 | | get_scope(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, JSJitGetterCallArgs args) |
168 | 0 | { |
169 | 0 | AUTO_PROFILER_LABEL_FAST("get ServiceWorkerRegistration.scope", DOM, cx); |
170 | 0 |
|
171 | 0 | DOMString result; |
172 | 0 | self->GetScope(result); |
173 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
174 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
175 | 0 | return false; |
176 | 0 | } |
177 | 0 | return true; |
178 | 0 | } |
179 | | |
180 | | static const JSJitInfo scope_getterinfo = { |
181 | | { (JSJitGetterOp)get_scope }, |
182 | | { prototypes::id::ServiceWorkerRegistration }, |
183 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
184 | | JSJitInfo::Getter, |
185 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
186 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
187 | | false, /* isInfallible. False in setters. */ |
188 | | false, /* isMovable. Not relevant for setters. */ |
189 | | false, /* isEliminatable. Not relevant for setters. */ |
190 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
191 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
192 | | false, /* isTypedMethod. Only relevant for methods. */ |
193 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
194 | | }; |
195 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
196 | | static_assert(0 < 1, "There is no slot for us"); |
197 | | |
198 | | MOZ_CAN_RUN_SCRIPT static bool |
199 | | get_updateViaCache(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, JSJitGetterCallArgs args) |
200 | 0 | { |
201 | 0 | AUTO_PROFILER_LABEL_FAST("get ServiceWorkerRegistration.updateViaCache", DOM, cx); |
202 | 0 |
|
203 | 0 | FastErrorResult rv; |
204 | 0 | ServiceWorkerUpdateViaCache result(self->GetUpdateViaCache(rv)); |
205 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
206 | 0 | return false; |
207 | 0 | } |
208 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
209 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
210 | 0 | return false; |
211 | 0 | } |
212 | 0 | return true; |
213 | 0 | } |
214 | | |
215 | | static const JSJitInfo updateViaCache_getterinfo = { |
216 | | { (JSJitGetterOp)get_updateViaCache }, |
217 | | { prototypes::id::ServiceWorkerRegistration }, |
218 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
219 | | JSJitInfo::Getter, |
220 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
221 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
222 | | false, /* isInfallible. False in setters. */ |
223 | | false, /* isMovable. Not relevant for setters. */ |
224 | | false, /* isEliminatable. Not relevant for setters. */ |
225 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
226 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
227 | | false, /* isTypedMethod. Only relevant for methods. */ |
228 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
229 | | }; |
230 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
231 | | static_assert(0 < 1, "There is no slot for us"); |
232 | | |
233 | | MOZ_CAN_RUN_SCRIPT static bool |
234 | | update(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, const JSJitMethodCallArgs& args) |
235 | 0 | { |
236 | 0 | AUTO_PROFILER_LABEL_FAST("ServiceWorkerRegistration.update", DOM, cx); |
237 | 0 |
|
238 | 0 | FastErrorResult rv; |
239 | 0 | auto result(StrongOrRawPtr<Promise>(self->Update(rv))); |
240 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
241 | 0 | return false; |
242 | 0 | } |
243 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
244 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
245 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
246 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
247 | 0 | return false; |
248 | 0 | } |
249 | 0 | return true; |
250 | 0 | } |
251 | | |
252 | | MOZ_CAN_RUN_SCRIPT static bool |
253 | | update_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, const JSJitMethodCallArgs& args) |
254 | 0 | { |
255 | 0 | bool ok = update(cx, obj, self, args); |
256 | 0 | if (ok) { |
257 | 0 | return true; |
258 | 0 | } |
259 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
260 | 0 | } |
261 | | |
262 | | static const JSJitInfo update_methodinfo = { |
263 | | { (JSJitGetterOp)update_promiseWrapper }, |
264 | | { prototypes::id::ServiceWorkerRegistration }, |
265 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
266 | | JSJitInfo::Method, |
267 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
268 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
269 | | false, /* isInfallible. False in setters. */ |
270 | | false, /* isMovable. Not relevant for setters. */ |
271 | | false, /* isEliminatable. Not relevant for setters. */ |
272 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
273 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
274 | | false, /* isTypedMethod. Only relevant for methods. */ |
275 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
276 | | }; |
277 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
278 | | static_assert(0 < 1, "There is no slot for us"); |
279 | | |
280 | | MOZ_CAN_RUN_SCRIPT static bool |
281 | | unregister(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, const JSJitMethodCallArgs& args) |
282 | 0 | { |
283 | 0 | AUTO_PROFILER_LABEL_FAST("ServiceWorkerRegistration.unregister", DOM, cx); |
284 | 0 |
|
285 | 0 | FastErrorResult rv; |
286 | 0 | auto result(StrongOrRawPtr<Promise>(self->Unregister(rv))); |
287 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
288 | 0 | return false; |
289 | 0 | } |
290 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
291 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
292 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
293 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
294 | 0 | return false; |
295 | 0 | } |
296 | 0 | return true; |
297 | 0 | } |
298 | | |
299 | | MOZ_CAN_RUN_SCRIPT static bool |
300 | | unregister_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, const JSJitMethodCallArgs& args) |
301 | 0 | { |
302 | 0 | bool ok = unregister(cx, obj, self, args); |
303 | 0 | if (ok) { |
304 | 0 | return true; |
305 | 0 | } |
306 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
307 | 0 | } |
308 | | |
309 | | static const JSJitInfo unregister_methodinfo = { |
310 | | { (JSJitGetterOp)unregister_promiseWrapper }, |
311 | | { prototypes::id::ServiceWorkerRegistration }, |
312 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
313 | | JSJitInfo::Method, |
314 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
315 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
316 | | false, /* isInfallible. False in setters. */ |
317 | | false, /* isMovable. Not relevant for setters. */ |
318 | | false, /* isEliminatable. Not relevant for setters. */ |
319 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
320 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
321 | | false, /* isTypedMethod. Only relevant for methods. */ |
322 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
323 | | }; |
324 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
325 | | static_assert(0 < 1, "There is no slot for us"); |
326 | | |
327 | | MOZ_CAN_RUN_SCRIPT static bool |
328 | | get_onupdatefound(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, JSJitGetterCallArgs args) |
329 | 0 | { |
330 | 0 | AUTO_PROFILER_LABEL_FAST("get ServiceWorkerRegistration.onupdatefound", DOM, cx); |
331 | 0 |
|
332 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnupdatefound()); |
333 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
334 | 0 | if (result) { |
335 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
336 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
337 | 0 | return false; |
338 | 0 | } |
339 | 0 | return true; |
340 | 0 | } else { |
341 | 0 | args.rval().setNull(); |
342 | 0 | return true; |
343 | 0 | } |
344 | 0 | } |
345 | | |
346 | | MOZ_CAN_RUN_SCRIPT static bool |
347 | | set_onupdatefound(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, JSJitSetterCallArgs args) |
348 | 0 | { |
349 | 0 | AUTO_PROFILER_LABEL_FAST("set ServiceWorkerRegistration.onupdatefound", DOM, cx); |
350 | 0 |
|
351 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
352 | 0 | if (args[0].isObject()) { |
353 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
354 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
355 | 0 | } |
356 | 0 | } else { |
357 | 0 | arg0 = nullptr; |
358 | 0 | } |
359 | 0 | self->SetOnupdatefound(Constify(arg0)); |
360 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
361 | 0 |
|
362 | 0 | return true; |
363 | 0 | } |
364 | | |
365 | | static const JSJitInfo onupdatefound_getterinfo = { |
366 | | { (JSJitGetterOp)get_onupdatefound }, |
367 | | { prototypes::id::ServiceWorkerRegistration }, |
368 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
369 | | JSJitInfo::Getter, |
370 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
371 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
372 | | false, /* isInfallible. False in setters. */ |
373 | | false, /* isMovable. Not relevant for setters. */ |
374 | | false, /* isEliminatable. Not relevant for setters. */ |
375 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
376 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
377 | | false, /* isTypedMethod. Only relevant for methods. */ |
378 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
379 | | }; |
380 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
381 | | static_assert(0 < 1, "There is no slot for us"); |
382 | | static const JSJitInfo onupdatefound_setterinfo = { |
383 | | { (JSJitGetterOp)set_onupdatefound }, |
384 | | { prototypes::id::ServiceWorkerRegistration }, |
385 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
386 | | JSJitInfo::Setter, |
387 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
388 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
389 | | false, /* isInfallible. False in setters. */ |
390 | | false, /* isMovable. Not relevant for setters. */ |
391 | | false, /* isEliminatable. Not relevant for setters. */ |
392 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
393 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
394 | | false, /* isTypedMethod. Only relevant for methods. */ |
395 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
396 | | }; |
397 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
398 | | static_assert(0 < 1, "There is no slot for us"); |
399 | | |
400 | | MOZ_CAN_RUN_SCRIPT static bool |
401 | | get_pushManager(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, JSJitGetterCallArgs args) |
402 | 0 | { |
403 | 0 | AUTO_PROFILER_LABEL_FAST("get ServiceWorkerRegistration.pushManager", DOM, cx); |
404 | 0 |
|
405 | 0 | FastErrorResult rv; |
406 | 0 | auto result(StrongOrRawPtr<mozilla::dom::PushManager>(self->GetPushManager(cx, rv))); |
407 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
408 | 0 | return false; |
409 | 0 | } |
410 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
411 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
412 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
413 | 0 | return false; |
414 | 0 | } |
415 | 0 | return true; |
416 | 0 | } |
417 | | |
418 | | static const JSJitInfo pushManager_getterinfo = { |
419 | | { (JSJitGetterOp)get_pushManager }, |
420 | | { prototypes::id::ServiceWorkerRegistration }, |
421 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
422 | | JSJitInfo::Getter, |
423 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
424 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
425 | | false, /* isInfallible. False in setters. */ |
426 | | false, /* isMovable. Not relevant for setters. */ |
427 | | false, /* isEliminatable. Not relevant for setters. */ |
428 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
429 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
430 | | false, /* isTypedMethod. Only relevant for methods. */ |
431 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
432 | | }; |
433 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
434 | | static_assert(0 < 1, "There is no slot for us"); |
435 | | |
436 | | MOZ_CAN_RUN_SCRIPT static bool |
437 | | showNotification(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, const JSJitMethodCallArgs& args) |
438 | 0 | { |
439 | 0 | AUTO_PROFILER_LABEL_FAST("ServiceWorkerRegistration.showNotification", DOM, cx); |
440 | 0 |
|
441 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
442 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ServiceWorkerRegistration.showNotification"); |
443 | 0 | } |
444 | 0 | binding_detail::FakeString arg0; |
445 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
446 | 0 | return false; |
447 | 0 | } |
448 | 0 | RootedDictionary<binding_detail::FastNotificationOptions> arg1(cx); |
449 | 0 | if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of ServiceWorkerRegistration.showNotification", false)) { |
450 | 0 | return false; |
451 | 0 | } |
452 | 0 | FastErrorResult rv; |
453 | 0 | auto result(StrongOrRawPtr<Promise>(self->ShowNotification(cx, NonNullHelper(Constify(arg0)), Constify(arg1), rv))); |
454 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
455 | 0 | return false; |
456 | 0 | } |
457 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
458 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
459 | 0 | return false; |
460 | 0 | } |
461 | 0 | return true; |
462 | 0 | } |
463 | | |
464 | | MOZ_CAN_RUN_SCRIPT static bool |
465 | | showNotification_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, const JSJitMethodCallArgs& args) |
466 | 0 | { |
467 | 0 | bool ok = showNotification(cx, obj, self, args); |
468 | 0 | if (ok) { |
469 | 0 | return true; |
470 | 0 | } |
471 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
472 | 0 | } |
473 | | |
474 | | static const JSJitInfo showNotification_methodinfo = { |
475 | | { (JSJitGetterOp)showNotification_promiseWrapper }, |
476 | | { prototypes::id::ServiceWorkerRegistration }, |
477 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
478 | | JSJitInfo::Method, |
479 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
480 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
481 | | false, /* isInfallible. False in setters. */ |
482 | | false, /* isMovable. Not relevant for setters. */ |
483 | | false, /* isEliminatable. Not relevant for setters. */ |
484 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
485 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
486 | | false, /* isTypedMethod. Only relevant for methods. */ |
487 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
488 | | }; |
489 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
490 | | static_assert(0 < 1, "There is no slot for us"); |
491 | | |
492 | | MOZ_CAN_RUN_SCRIPT static bool |
493 | | getNotifications(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, const JSJitMethodCallArgs& args) |
494 | 0 | { |
495 | 0 | AUTO_PROFILER_LABEL_FAST("ServiceWorkerRegistration.getNotifications", DOM, cx); |
496 | 0 |
|
497 | 0 | binding_detail::FastGetNotificationOptions arg0; |
498 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of ServiceWorkerRegistration.getNotifications", false)) { |
499 | 0 | return false; |
500 | 0 | } |
501 | 0 | FastErrorResult rv; |
502 | 0 | auto result(StrongOrRawPtr<Promise>(self->GetNotifications(Constify(arg0), rv))); |
503 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
504 | 0 | return false; |
505 | 0 | } |
506 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
507 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
508 | 0 | return false; |
509 | 0 | } |
510 | 0 | return true; |
511 | 0 | } |
512 | | |
513 | | MOZ_CAN_RUN_SCRIPT static bool |
514 | | getNotifications_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerRegistration* self, const JSJitMethodCallArgs& args) |
515 | 0 | { |
516 | 0 | bool ok = getNotifications(cx, obj, self, args); |
517 | 0 | if (ok) { |
518 | 0 | return true; |
519 | 0 | } |
520 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
521 | 0 | } |
522 | | |
523 | | static const JSJitInfo getNotifications_methodinfo = { |
524 | | { (JSJitGetterOp)getNotifications_promiseWrapper }, |
525 | | { prototypes::id::ServiceWorkerRegistration }, |
526 | | { PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth }, |
527 | | JSJitInfo::Method, |
528 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
529 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
530 | | false, /* isInfallible. False in setters. */ |
531 | | false, /* isMovable. Not relevant for setters. */ |
532 | | false, /* isEliminatable. Not relevant for setters. */ |
533 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
534 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
535 | | false, /* isTypedMethod. Only relevant for methods. */ |
536 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
537 | | }; |
538 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
539 | | static_assert(0 < 1, "There is no slot for us"); |
540 | | |
541 | | static bool |
542 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
543 | 0 | { |
544 | 0 | mozilla::dom::ServiceWorkerRegistration* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorkerRegistration>(obj); |
545 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
546 | 0 | // obviously can't preserve if we're not initialized. |
547 | 0 | if (self && self->GetWrapperPreserveColor()) { |
548 | 0 | PreserveWrapper(self); |
549 | 0 | } |
550 | 0 | return true; |
551 | 0 | } |
552 | | |
553 | | static void |
554 | | _finalize(js::FreeOp* fop, JSObject* obj) |
555 | 0 | { |
556 | 0 | mozilla::dom::ServiceWorkerRegistration* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorkerRegistration>(obj); |
557 | 0 | if (self) { |
558 | 0 | ClearWrapper(self, self, obj); |
559 | 0 | AddForDeferredFinalization<mozilla::dom::ServiceWorkerRegistration>(self); |
560 | 0 | } |
561 | 0 | } |
562 | | |
563 | | static size_t |
564 | | _objectMoved(JSObject* obj, JSObject* old) |
565 | 0 | { |
566 | 0 | mozilla::dom::ServiceWorkerRegistration* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorkerRegistration>(obj); |
567 | 0 | if (self) { |
568 | 0 | UpdateWrapper(self, self, obj, old); |
569 | 0 | } |
570 | 0 |
|
571 | 0 | return 0; |
572 | 0 | } |
573 | | |
574 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
575 | | #if defined(__clang__) |
576 | | #pragma clang diagnostic push |
577 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
578 | | #endif |
579 | | static const JSFunctionSpec sMethods_specs[] = { |
580 | | JS_FNSPEC("update", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&update_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
581 | | JS_FNSPEC("unregister", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&unregister_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
582 | | JS_FS_END, |
583 | | JS_FNSPEC("showNotification", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&showNotification_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
584 | | JS_FNSPEC("getNotifications", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&getNotifications_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
585 | | JS_FS_END |
586 | | }; |
587 | | #if defined(__clang__) |
588 | | #pragma clang diagnostic pop |
589 | | #endif |
590 | | |
591 | | // Can't be const because the pref-enabled boolean needs to be writable |
592 | | static PrefableDisablers sMethods_disablers3 = { |
593 | | true, false, 0, &mozilla::dom::DOMPrefs::dom_webnotifications_serviceworker_enabled |
594 | | }; |
595 | | |
596 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
597 | | { nullptr, &sMethods_specs[0] }, |
598 | | { &sMethods_disablers3, &sMethods_specs[3] }, |
599 | | { nullptr, nullptr } |
600 | | }; |
601 | | |
602 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
603 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
604 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
605 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
606 | | |
607 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
608 | | #if defined(__clang__) |
609 | | #pragma clang diagnostic push |
610 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
611 | | #endif |
612 | | static const JSPropertySpec sAttributes_specs[] = { |
613 | | { "scope", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &scope_getterinfo, nullptr, nullptr }, |
614 | | { "updateViaCache", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &updateViaCache_getterinfo, nullptr, nullptr }, |
615 | | { "onupdatefound", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onupdatefound_getterinfo, GenericSetter<NormalThisPolicy>, &onupdatefound_setterinfo }, |
616 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr }, |
617 | | { "pushManager", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pushManager_getterinfo, nullptr, nullptr }, |
618 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
619 | | }; |
620 | | #if defined(__clang__) |
621 | | #pragma clang diagnostic pop |
622 | | #endif |
623 | | |
624 | | // Can't be const because the pref-enabled boolean needs to be writable |
625 | | static PrefableDisablers sAttributes_disablers4 = { |
626 | | true, false, 0, &mozilla::dom::DOMPrefs::dom_push_enabled |
627 | | }; |
628 | | |
629 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
630 | | { nullptr, &sAttributes_specs[0] }, |
631 | | { &sAttributes_disablers4, &sAttributes_specs[4] }, |
632 | | { nullptr, nullptr } |
633 | | }; |
634 | | |
635 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
636 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
637 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
638 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
639 | | |
640 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
641 | | #if defined(__clang__) |
642 | | #pragma clang diagnostic push |
643 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
644 | | #endif |
645 | | static const JSPropertySpec sUnforgeableAttributes_specs[] = { |
646 | | { "installing", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &installing_getterinfo, nullptr, nullptr }, |
647 | | { "waiting", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &waiting_getterinfo, nullptr, nullptr }, |
648 | | { "active", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &active_getterinfo, nullptr, nullptr }, |
649 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
650 | | }; |
651 | | #if defined(__clang__) |
652 | | #pragma clang diagnostic pop |
653 | | #endif |
654 | | |
655 | | |
656 | | static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = { |
657 | | { nullptr, &sUnforgeableAttributes_specs[0] }, |
658 | | { nullptr, nullptr } |
659 | | }; |
660 | | |
661 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
662 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
663 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
664 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
665 | | |
666 | | |
667 | | static uint16_t sNativeProperties_sortedPropertyIndices[11]; |
668 | | static PropertyInfo sNativeProperties_propertyInfos[11]; |
669 | | |
670 | | static const NativePropertiesN<3> sNativeProperties = { |
671 | | false, 0, |
672 | | false, 0, |
673 | | true, 0 /* sMethods */, |
674 | | true, 1 /* sAttributes */, |
675 | | false, 0, |
676 | | true, 2 /* sUnforgeableAttributes */, |
677 | | false, 0, |
678 | | -1, |
679 | | 11, |
680 | | sNativeProperties_sortedPropertyIndices, |
681 | | { |
682 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
683 | | { sAttributes, &sNativeProperties_propertyInfos[4] }, |
684 | | { sUnforgeableAttributes, &sNativeProperties_propertyInfos[8] } |
685 | | } |
686 | | }; |
687 | | static_assert(11 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
688 | | "We have a property info count that is oversized"); |
689 | | |
690 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
691 | | { |
692 | | "Function", |
693 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
694 | | &sBoringInterfaceObjectClassClassOps, |
695 | | JS_NULL_CLASS_SPEC, |
696 | | JS_NULL_CLASS_EXT, |
697 | | &sInterfaceObjectClassObjectOps |
698 | | }, |
699 | | eInterface, |
700 | | true, |
701 | | prototypes::id::ServiceWorkerRegistration, |
702 | | PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth, |
703 | | sNativePropertyHooks, |
704 | | "function ServiceWorkerRegistration() {\n [native code]\n}", |
705 | | EventTarget_Binding::GetConstructorObject |
706 | | }; |
707 | | |
708 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
709 | | { |
710 | | "ServiceWorkerRegistrationPrototype", |
711 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */), |
712 | | JS_NULL_CLASS_OPS, |
713 | | JS_NULL_CLASS_SPEC, |
714 | | JS_NULL_CLASS_EXT, |
715 | | JS_NULL_OBJECT_OPS |
716 | | }, |
717 | | eInterfacePrototype, |
718 | | false, |
719 | | prototypes::id::ServiceWorkerRegistration, |
720 | | PrototypeTraits<prototypes::id::ServiceWorkerRegistration>::Depth, |
721 | | sNativePropertyHooks, |
722 | | "[object ServiceWorkerRegistrationPrototype]", |
723 | | EventTarget_Binding::GetProtoObject |
724 | | }; |
725 | | |
726 | | bool |
727 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
728 | 0 | { |
729 | 0 | return mozilla::dom::DOMPrefs::dom_serviceWorkers_enabled(aCx, aObj); |
730 | 0 | } |
731 | | |
732 | | static const js::ClassOps sClassOps = { |
733 | | _addProperty, /* addProperty */ |
734 | | nullptr, /* delProperty */ |
735 | | nullptr, /* enumerate */ |
736 | | nullptr, /* newEnumerate */ |
737 | | nullptr, /* resolve */ |
738 | | nullptr, /* mayResolve */ |
739 | | _finalize, /* finalize */ |
740 | | nullptr, /* call */ |
741 | | nullptr, /* hasInstance */ |
742 | | nullptr, /* construct */ |
743 | | nullptr, /* trace */ |
744 | | }; |
745 | | |
746 | | static const js::ClassExtension sClassExtension = { |
747 | | nullptr, /* weakmapKeyDelegateOp */ |
748 | | _objectMoved /* objectMovedOp */ |
749 | | }; |
750 | | |
751 | | static const DOMJSClass sClass = { |
752 | | { "ServiceWorkerRegistration", |
753 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
754 | | &sClassOps, |
755 | | JS_NULL_CLASS_SPEC, |
756 | | &sClassExtension, |
757 | | JS_NULL_OBJECT_OPS |
758 | | }, |
759 | | { prototypes::id::EventTarget, prototypes::id::ServiceWorkerRegistration, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
760 | | IsBaseOf<nsISupports, mozilla::dom::ServiceWorkerRegistration >::value, |
761 | | sNativePropertyHooks, |
762 | | FindAssociatedGlobalForNative<mozilla::dom::ServiceWorkerRegistration>::Get, |
763 | | GetProtoObjectHandle, |
764 | | GetCCParticipant<mozilla::dom::ServiceWorkerRegistration>::Get() |
765 | | }; |
766 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
767 | | "Must have the right minimal number of reserved slots."); |
768 | | static_assert(1 >= 1, |
769 | | "Must have enough reserved slots."); |
770 | | |
771 | | const JSClass* |
772 | | GetJSClass() |
773 | 0 | { |
774 | 0 | return sClass.ToJSClass(); |
775 | 0 | } |
776 | | |
777 | | bool |
778 | | Wrap(JSContext* aCx, mozilla::dom::ServiceWorkerRegistration* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
779 | 0 | { |
780 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ServiceWorkerRegistration>::value, |
781 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
782 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ServiceWorkerRegistration*>(aObject) == |
783 | 0 | reinterpret_cast<mozilla::dom::ServiceWorkerRegistration*>(aObject), |
784 | 0 | "Multiple inheritance for mozilla::dom::ServiceWorkerRegistration is broken."); |
785 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
786 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
787 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
788 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
789 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
790 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
791 | 0 | "You should probably not be using Wrap() directly; use " |
792 | 0 | "GetOrCreateDOMReflector instead"); |
793 | 0 |
|
794 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
795 | 0 | "nsISupports must be on our primary inheritance chain"); |
796 | 0 |
|
797 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
798 | 0 | if (!global) { |
799 | 0 | return false; |
800 | 0 | } |
801 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
802 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
803 | 0 |
|
804 | 0 | // That might have ended up wrapping us already, due to the wonders |
805 | 0 | // of XBL. Check for that, and bail out as needed. |
806 | 0 | aReflector.set(aCache->GetWrapper()); |
807 | 0 | if (aReflector) { |
808 | | #ifdef DEBUG |
809 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
810 | | #endif // DEBUG |
811 | | return true; |
812 | 0 | } |
813 | 0 |
|
814 | 0 | JSAutoRealm ar(aCx, global); |
815 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
816 | 0 | if (!canonicalProto) { |
817 | 0 | return false; |
818 | 0 | } |
819 | 0 | JS::Rooted<JSObject*> proto(aCx); |
820 | 0 | if (aGivenProto) { |
821 | 0 | proto = aGivenProto; |
822 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
823 | 0 | // coming in, we changed compartments to that of "parent" so may need |
824 | 0 | // to wrap the proto here. |
825 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
826 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
827 | 0 | return false; |
828 | 0 | } |
829 | 0 | } |
830 | 0 | } else { |
831 | 0 | proto = canonicalProto; |
832 | 0 | } |
833 | 0 |
|
834 | 0 | BindingJSObjectCreator<mozilla::dom::ServiceWorkerRegistration> creator(aCx); |
835 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
836 | 0 | if (!aReflector) { |
837 | 0 | return false; |
838 | 0 | } |
839 | 0 | |
840 | 0 | aCache->SetWrapper(aReflector); |
841 | 0 |
|
842 | 0 | // Important: do unforgeable property setup after we have handed |
843 | 0 | // over ownership of the C++ object to obj as needed, so that if |
844 | 0 | // we fail and it ends up GCed it won't have problems in the |
845 | 0 | // finalizer trying to drop its ownership of the C++ object. |
846 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx, |
847 | 0 | &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject()); |
848 | 0 | if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) { |
849 | 0 | aCache->ReleaseWrapper(aObject); |
850 | 0 | aCache->ClearWrapper(); |
851 | 0 | return false; |
852 | 0 | } |
853 | 0 | creator.InitializationSucceeded(); |
854 | 0 |
|
855 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
856 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
857 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
858 | 0 | // otherwise we won't be able to properly recreate it later, since |
859 | 0 | // we won't know what proto to use. Note that we don't check |
860 | 0 | // aGivenProto here, since it's entirely possible (and even |
861 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
862 | 0 | // same as canonicalProto. |
863 | 0 | if (proto != canonicalProto) { |
864 | 0 | PreserveWrapper(aObject); |
865 | 0 | } |
866 | 0 |
|
867 | 0 | return true; |
868 | 0 | } |
869 | | |
870 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
871 | | nullptr, |
872 | | nullptr, |
873 | | nullptr, |
874 | | { sNativeProperties.Upcast(), nullptr }, |
875 | | prototypes::id::ServiceWorkerRegistration, |
876 | | constructors::id::ServiceWorkerRegistration, |
877 | | EventTarget_Binding::sNativePropertyHooks, |
878 | | &DefaultXrayExpandoObjectClass |
879 | | } }; |
880 | | |
881 | | void |
882 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
883 | 0 | { |
884 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
885 | 0 | if (!parentProto) { |
886 | 0 | return; |
887 | 0 | } |
888 | 0 | |
889 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
890 | 0 | if (!constructorProto) { |
891 | 0 | return; |
892 | 0 | } |
893 | 0 | |
894 | 0 | static bool sIdsInited = false; |
895 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
896 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
897 | 0 | return; |
898 | 0 | } |
899 | 0 | sIdsInited = true; |
900 | 0 | } |
901 | 0 |
|
902 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ServiceWorkerRegistration); |
903 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ServiceWorkerRegistration); |
904 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
905 | 0 | &sPrototypeClass.mBase, protoCache, |
906 | 0 | nullptr, |
907 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
908 | 0 | interfaceCache, |
909 | 0 | sNativeProperties.Upcast(), |
910 | 0 | nullptr, |
911 | 0 | "ServiceWorkerRegistration", aDefineOnGlobal, |
912 | 0 | nullptr, |
913 | 0 | false); |
914 | 0 |
|
915 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx); |
916 | 0 | { |
917 | 0 | JS::Rooted<JSObject*> holderProto(aCx, *protoCache); |
918 | 0 | unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto); |
919 | 0 | if (!unforgeableHolder) { |
920 | 0 | *protoCache = nullptr; |
921 | 0 | if (interfaceCache) { |
922 | 0 | *interfaceCache = nullptr; |
923 | 0 | } |
924 | 0 | return; |
925 | 0 | } |
926 | 0 | } |
927 | 0 |
|
928 | 0 | if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) { |
929 | 0 | *protoCache = nullptr; |
930 | 0 | if (interfaceCache) { |
931 | 0 | *interfaceCache = nullptr; |
932 | 0 | } |
933 | 0 | return; |
934 | 0 | } |
935 | 0 |
|
936 | 0 | if (*protoCache) { |
937 | 0 | js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE, |
938 | 0 | JS::ObjectValue(*unforgeableHolder)); |
939 | 0 | } |
940 | 0 | } |
941 | | |
942 | | JSObject* |
943 | | GetConstructorObject(JSContext* aCx) |
944 | 0 | { |
945 | 0 | return GetConstructorObjectHandle(aCx); |
946 | 0 | } |
947 | | |
948 | | } // namespace ServiceWorkerRegistration_Binding |
949 | | |
950 | | |
951 | | |
952 | | } // namespace dom |
953 | | } // namespace mozilla |