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