Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM ServiceWorkerContainer.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "EventHandlerBinding.h"
5 : #include "EventTargetBinding.h"
6 : #include "ServiceWorkerContainer.h"
7 : #include "ServiceWorkerContainerBinding.h"
8 : #include "WrapperFactory.h"
9 : #include "mozilla/OwningNonNull.h"
10 : #include "mozilla/Preferences.h"
11 : #include "mozilla/dom/BindingUtils.h"
12 : #include "mozilla/dom/DOMJSClass.h"
13 : #include "mozilla/dom/NonRefcountedDOMObject.h"
14 : #include "mozilla/dom/Nullable.h"
15 : #include "mozilla/dom/Promise.h"
16 : #include "mozilla/dom/ScriptSettings.h"
17 : #include "mozilla/dom/ServiceWorkerContainer.h"
18 : #include "mozilla/dom/SimpleGlobalObject.h"
19 : #include "mozilla/dom/ToJSValue.h"
20 : #include "mozilla/dom/XrayExpandoClass.h"
21 : #include "mozilla/dom/workers/bindings/ServiceWorker.h"
22 :
23 : namespace mozilla {
24 : namespace dom {
25 :
26 :
27 0 : RegistrationOptions::RegistrationOptions()
28 : {
29 : // Safe to pass a null context if we pass a null value
30 0 : Init(nullptr, JS::NullHandleValue);
31 0 : }
32 :
33 :
34 :
35 : bool
36 0 : RegistrationOptions::InitIds(JSContext* cx, RegistrationOptionsAtoms* atomsCache)
37 : {
38 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
39 :
40 : // Initialize these in reverse order so that any failure leaves the first one
41 : // uninitialized.
42 0 : if (!atomsCache->scope_id.init(cx, "scope")) {
43 0 : return false;
44 : }
45 0 : return true;
46 : }
47 :
48 : bool
49 0 : RegistrationOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
50 : {
51 : // Passing a null JSContext is OK only if we're initing from null,
52 : // Since in that case we will not have to do any property gets
53 : // Also evaluate isNullOrUndefined in order to avoid false-positive
54 : // checkers by static analysis tools
55 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
56 0 : RegistrationOptionsAtoms* atomsCache = nullptr;
57 0 : if (cx) {
58 0 : atomsCache = GetAtomCache<RegistrationOptionsAtoms>(cx);
59 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
60 0 : return false;
61 : }
62 : }
63 :
64 0 : if (!IsConvertibleToDictionary(val)) {
65 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
66 : }
67 :
68 0 : bool isNull = val.isNullOrUndefined();
69 : // We only need these if !isNull, in which case we have |cx|.
70 0 : Maybe<JS::Rooted<JSObject *> > object;
71 0 : Maybe<JS::Rooted<JS::Value> > temp;
72 0 : if (!isNull) {
73 0 : MOZ_ASSERT(cx);
74 0 : object.emplace(cx, &val.toObject());
75 0 : temp.emplace(cx);
76 : }
77 0 : if (!isNull) {
78 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->scope_id, temp.ptr())) {
79 0 : return false;
80 : }
81 : }
82 0 : if (!isNull && !temp->isUndefined()) {
83 0 : mScope.Construct();
84 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mScope.Value()))) {
85 0 : return false;
86 : }
87 0 : NormalizeUSVString((mScope.Value()));
88 0 : mIsAnyMemberPresent = true;
89 : }
90 0 : return true;
91 : }
92 :
93 : bool
94 0 : RegistrationOptions::Init(const nsAString& aJSON)
95 : {
96 0 : AutoJSAPI jsapi;
97 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
98 0 : if (!cleanGlobal) {
99 0 : return false;
100 : }
101 0 : if (!jsapi.Init(cleanGlobal)) {
102 0 : return false;
103 : }
104 0 : JSContext* cx = jsapi.cx();
105 0 : JS::Rooted<JS::Value> json(cx);
106 0 : bool ok = ParseJSON(cx, aJSON, &json);
107 0 : NS_ENSURE_TRUE(ok, false);
108 0 : return Init(cx, json);
109 : }
110 :
111 : bool
112 0 : RegistrationOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
113 : {
114 0 : RegistrationOptionsAtoms* atomsCache = GetAtomCache<RegistrationOptionsAtoms>(cx);
115 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
116 0 : return false;
117 : }
118 :
119 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
120 0 : if (!obj) {
121 0 : return false;
122 : }
123 0 : rval.set(JS::ObjectValue(*obj));
124 :
125 0 : if (mScope.WasPassed()) {
126 : do {
127 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
128 0 : JS::Rooted<JS::Value> temp(cx);
129 0 : nsString const & currentValue = mScope.InternalValue();
130 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
131 0 : return false;
132 : }
133 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->scope_id, temp, JSPROP_ENUMERATE)) {
134 0 : return false;
135 : }
136 0 : break;
137 : } while(0);
138 : }
139 :
140 0 : return true;
141 : }
142 :
143 : bool
144 0 : RegistrationOptions::ToJSON(nsAString& aJSON) const
145 : {
146 0 : AutoJSAPI jsapi;
147 0 : jsapi.Init();
148 0 : JSContext *cx = jsapi.cx();
149 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
150 : // because we'll only be creating objects, in ways that have no
151 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
152 : // which likewise guarantees no side-effects for the sorts of
153 : // things we will pass it.
154 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
155 0 : JS::Rooted<JS::Value> val(cx);
156 0 : if (!ToObjectInternal(cx, &val)) {
157 0 : return false;
158 : }
159 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
160 0 : return StringifyToJSON(cx, obj, aJSON);
161 : }
162 :
163 : void
164 0 : RegistrationOptions::TraceDictionary(JSTracer* trc)
165 : {
166 0 : }
167 :
168 : RegistrationOptions&
169 0 : RegistrationOptions::operator=(const RegistrationOptions& aOther)
170 : {
171 0 : mScope.Reset();
172 0 : if (aOther.mScope.WasPassed()) {
173 0 : mScope.Construct(aOther.mScope.Value());
174 : }
175 0 : return *this;
176 : }
177 :
178 : namespace binding_detail {
179 : } // namespace binding_detail
180 :
181 :
182 : namespace ServiceWorkerContainerBinding {
183 :
184 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTargetBinding::NativeType>::value,
185 : "Can't inherit from an interface with a different ownership model.");
186 :
187 : static bool
188 0 : get_controller(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, JSJitGetterCallArgs args)
189 : {
190 0 : auto result(StrongOrRawPtr<mozilla::dom::workers::ServiceWorker>(self->GetController()));
191 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
192 0 : if (!result) {
193 0 : args.rval().setNull();
194 0 : return true;
195 : }
196 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
197 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
198 0 : return false;
199 : }
200 0 : return true;
201 : }
202 :
203 : static const JSJitInfo controller_getterinfo = {
204 : { (JSJitGetterOp)get_controller },
205 : { prototypes::id::ServiceWorkerContainer },
206 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
207 : JSJitInfo::Getter,
208 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
209 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
210 : false, /* isInfallible. False in setters. */
211 : false, /* isMovable. Not relevant for setters. */
212 : false, /* isEliminatable. Not relevant for setters. */
213 : false, /* isAlwaysInSlot. Only relevant for getters. */
214 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
215 : false, /* isTypedMethod. Only relevant for methods. */
216 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
217 : };
218 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
219 : static_assert(0 < 1, "There is no slot for us");
220 :
221 : static bool
222 0 : get_ready(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, JSJitGetterCallArgs args)
223 : {
224 0 : binding_detail::FastErrorResult rv;
225 0 : auto result(StrongOrRawPtr<Promise>(self->GetReady(rv)));
226 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
227 0 : return false;
228 : }
229 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
230 0 : if (!ToJSValue(cx, result, args.rval())) {
231 0 : return false;
232 : }
233 0 : return true;
234 : }
235 :
236 : static bool
237 0 : get_ready_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, JSJitGetterCallArgs args)
238 : {
239 0 : bool ok = get_ready(cx, obj, self, args);
240 0 : if (ok) {
241 0 : return true;
242 : }
243 0 : JS::Rooted<JSObject*> globalForPromise(cx);
244 : // We can't use xpc::XrayAwareCalleeGlobal here because we have no
245 : // callee. Use our hacky version instead.
246 0 : if (!xpc::XrayAwareCalleeGlobalForSpecializedGetters(cx, obj,
247 : &globalForPromise)) {
248 0 : return false;
249 : }
250 0 : return ConvertExceptionToPromise(cx, globalForPromise, args.rval());
251 : }
252 :
253 : static const JSJitInfo ready_getterinfo = {
254 : { (JSJitGetterOp)get_ready_promiseWrapper },
255 : { prototypes::id::ServiceWorkerContainer },
256 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
257 : JSJitInfo::Getter,
258 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
259 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
260 : false, /* isInfallible. False in setters. */
261 : false, /* isMovable. Not relevant for setters. */
262 : false, /* isEliminatable. Not relevant for setters. */
263 : false, /* isAlwaysInSlot. Only relevant for getters. */
264 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
265 : false, /* isTypedMethod. Only relevant for methods. */
266 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
267 : };
268 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
269 : static_assert(0 < 1, "There is no slot for us");
270 :
271 : static bool
272 0 : _register_(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, const JSJitMethodCallArgs& args)
273 : {
274 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
275 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ServiceWorkerContainer.register");
276 : }
277 0 : binding_detail::FakeString arg0;
278 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
279 0 : return false;
280 : }
281 0 : NormalizeUSVString(arg0);
282 0 : binding_detail::FastRegistrationOptions arg1;
283 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of ServiceWorkerContainer.register", false)) {
284 0 : return false;
285 : }
286 0 : binding_detail::FastErrorResult rv;
287 0 : auto result(StrongOrRawPtr<Promise>(self->Register(Constify(arg0), Constify(arg1), rv)));
288 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
289 0 : return false;
290 : }
291 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
292 : static_assert(!IsPointer<decltype(result)>::value,
293 : "NewObject implies that we need to keep the object alive with a strong reference.");
294 0 : if (!ToJSValue(cx, result, args.rval())) {
295 0 : return false;
296 : }
297 0 : return true;
298 : }
299 :
300 : static bool
301 0 : _register__promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, const JSJitMethodCallArgs& args)
302 : {
303 : // Make sure to save the callee before someone maybe messes
304 : // with rval().
305 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
306 0 : bool ok = _register_(cx, obj, self, args);
307 0 : if (ok) {
308 0 : return true;
309 : }
310 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
311 0 : args.rval());
312 : }
313 :
314 : static const JSJitInfo register_methodinfo = {
315 : { (JSJitGetterOp)_register__promiseWrapper },
316 : { prototypes::id::ServiceWorkerContainer },
317 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
318 : JSJitInfo::Method,
319 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
320 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
321 : false, /* isInfallible. False in setters. */
322 : false, /* isMovable. Not relevant for setters. */
323 : false, /* isEliminatable. Not relevant for setters. */
324 : false, /* isAlwaysInSlot. Only relevant for getters. */
325 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
326 : false, /* isTypedMethod. Only relevant for methods. */
327 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
328 : };
329 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
330 : static_assert(0 < 1, "There is no slot for us");
331 :
332 : static bool
333 0 : getRegistration(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, const JSJitMethodCallArgs& args)
334 : {
335 0 : binding_detail::FakeString arg0;
336 0 : if (args.hasDefined(0)) {
337 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
338 0 : return false;
339 : }
340 0 : NormalizeUSVString(arg0);
341 : } else {
342 : static const char16_t data[] = { 0 };
343 0 : arg0.Rebind(data, ArrayLength(data) - 1);
344 : }
345 0 : binding_detail::FastErrorResult rv;
346 0 : auto result(StrongOrRawPtr<Promise>(self->GetRegistration(Constify(arg0), rv)));
347 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
348 0 : return false;
349 : }
350 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
351 : static_assert(!IsPointer<decltype(result)>::value,
352 : "NewObject implies that we need to keep the object alive with a strong reference.");
353 0 : if (!ToJSValue(cx, result, args.rval())) {
354 0 : return false;
355 : }
356 0 : return true;
357 : }
358 :
359 : static bool
360 0 : getRegistration_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, const JSJitMethodCallArgs& args)
361 : {
362 : // Make sure to save the callee before someone maybe messes
363 : // with rval().
364 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
365 0 : bool ok = getRegistration(cx, obj, self, args);
366 0 : if (ok) {
367 0 : return true;
368 : }
369 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
370 0 : args.rval());
371 : }
372 :
373 : static const JSJitInfo getRegistration_methodinfo = {
374 : { (JSJitGetterOp)getRegistration_promiseWrapper },
375 : { prototypes::id::ServiceWorkerContainer },
376 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
377 : JSJitInfo::Method,
378 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
379 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
380 : false, /* isInfallible. False in setters. */
381 : false, /* isMovable. Not relevant for setters. */
382 : false, /* isEliminatable. Not relevant for setters. */
383 : false, /* isAlwaysInSlot. Only relevant for getters. */
384 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
385 : false, /* isTypedMethod. Only relevant for methods. */
386 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
387 : };
388 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
389 : static_assert(0 < 1, "There is no slot for us");
390 :
391 : static bool
392 0 : getRegistrations(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, const JSJitMethodCallArgs& args)
393 : {
394 0 : binding_detail::FastErrorResult rv;
395 0 : auto result(StrongOrRawPtr<Promise>(self->GetRegistrations(rv)));
396 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
397 0 : return false;
398 : }
399 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
400 : static_assert(!IsPointer<decltype(result)>::value,
401 : "NewObject implies that we need to keep the object alive with a strong reference.");
402 0 : if (!ToJSValue(cx, result, args.rval())) {
403 0 : return false;
404 : }
405 0 : return true;
406 : }
407 :
408 : static bool
409 0 : getRegistrations_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, const JSJitMethodCallArgs& args)
410 : {
411 : // Make sure to save the callee before someone maybe messes
412 : // with rval().
413 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
414 0 : bool ok = getRegistrations(cx, obj, self, args);
415 0 : if (ok) {
416 0 : return true;
417 : }
418 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
419 0 : args.rval());
420 : }
421 :
422 : static const JSJitInfo getRegistrations_methodinfo = {
423 : { (JSJitGetterOp)getRegistrations_promiseWrapper },
424 : { prototypes::id::ServiceWorkerContainer },
425 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
426 : JSJitInfo::Method,
427 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
428 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
429 : false, /* isInfallible. False in setters. */
430 : false, /* isMovable. Not relevant for setters. */
431 : false, /* isEliminatable. Not relevant for setters. */
432 : false, /* isAlwaysInSlot. Only relevant for getters. */
433 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
434 : false, /* isTypedMethod. Only relevant for methods. */
435 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
436 : };
437 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
438 : static_assert(0 < 1, "There is no slot for us");
439 :
440 : static bool
441 0 : get_oncontrollerchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, JSJitGetterCallArgs args)
442 : {
443 0 : RefPtr<EventHandlerNonNull> result(self->GetOncontrollerchange());
444 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
445 0 : if (result) {
446 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
447 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
448 0 : return false;
449 : }
450 0 : return true;
451 : } else {
452 0 : args.rval().setNull();
453 0 : return true;
454 : }
455 : }
456 :
457 : static bool
458 0 : set_oncontrollerchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, JSJitSetterCallArgs args)
459 : {
460 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
461 0 : if (args[0].isObject()) {
462 : { // scope for tempRoot
463 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
464 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
465 : }
466 : } else {
467 0 : arg0 = nullptr;
468 : }
469 0 : self->SetOncontrollerchange(Constify(arg0));
470 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
471 :
472 0 : return true;
473 : }
474 :
475 : static const JSJitInfo oncontrollerchange_getterinfo = {
476 : { (JSJitGetterOp)get_oncontrollerchange },
477 : { prototypes::id::ServiceWorkerContainer },
478 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
479 : JSJitInfo::Getter,
480 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
481 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
482 : false, /* isInfallible. False in setters. */
483 : false, /* isMovable. Not relevant for setters. */
484 : false, /* isEliminatable. Not relevant for setters. */
485 : false, /* isAlwaysInSlot. Only relevant for getters. */
486 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
487 : false, /* isTypedMethod. Only relevant for methods. */
488 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
489 : };
490 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
491 : static_assert(0 < 1, "There is no slot for us");
492 : static const JSJitInfo oncontrollerchange_setterinfo = {
493 : { (JSJitGetterOp)set_oncontrollerchange },
494 : { prototypes::id::ServiceWorkerContainer },
495 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
496 : JSJitInfo::Setter,
497 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
498 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
499 : false, /* isInfallible. False in setters. */
500 : false, /* isMovable. Not relevant for setters. */
501 : false, /* isEliminatable. Not relevant for setters. */
502 : false, /* isAlwaysInSlot. Only relevant for getters. */
503 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
504 : false, /* isTypedMethod. Only relevant for methods. */
505 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
506 : };
507 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
508 : static_assert(0 < 1, "There is no slot for us");
509 :
510 : static bool
511 0 : get_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, JSJitGetterCallArgs args)
512 : {
513 0 : RefPtr<EventHandlerNonNull> result(self->GetOnerror());
514 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
515 0 : if (result) {
516 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
517 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
518 0 : return false;
519 : }
520 0 : return true;
521 : } else {
522 0 : args.rval().setNull();
523 0 : return true;
524 : }
525 : }
526 :
527 : static bool
528 0 : set_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, JSJitSetterCallArgs args)
529 : {
530 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
531 0 : if (args[0].isObject()) {
532 : { // scope for tempRoot
533 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
534 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
535 : }
536 : } else {
537 0 : arg0 = nullptr;
538 : }
539 0 : self->SetOnerror(Constify(arg0));
540 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
541 :
542 0 : return true;
543 : }
544 :
545 : static const JSJitInfo onerror_getterinfo = {
546 : { (JSJitGetterOp)get_onerror },
547 : { prototypes::id::ServiceWorkerContainer },
548 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
549 : JSJitInfo::Getter,
550 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
551 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
552 : false, /* isInfallible. False in setters. */
553 : false, /* isMovable. Not relevant for setters. */
554 : false, /* isEliminatable. Not relevant for setters. */
555 : false, /* isAlwaysInSlot. Only relevant for getters. */
556 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
557 : false, /* isTypedMethod. Only relevant for methods. */
558 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
559 : };
560 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
561 : static_assert(0 < 1, "There is no slot for us");
562 : static const JSJitInfo onerror_setterinfo = {
563 : { (JSJitGetterOp)set_onerror },
564 : { prototypes::id::ServiceWorkerContainer },
565 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
566 : JSJitInfo::Setter,
567 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
568 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
569 : false, /* isInfallible. False in setters. */
570 : false, /* isMovable. Not relevant for setters. */
571 : false, /* isEliminatable. Not relevant for setters. */
572 : false, /* isAlwaysInSlot. Only relevant for getters. */
573 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
574 : false, /* isTypedMethod. Only relevant for methods. */
575 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
576 : };
577 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
578 : static_assert(0 < 1, "There is no slot for us");
579 :
580 : static bool
581 0 : get_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, JSJitGetterCallArgs args)
582 : {
583 0 : RefPtr<EventHandlerNonNull> result(self->GetOnmessage());
584 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
585 0 : if (result) {
586 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
587 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
588 0 : return false;
589 : }
590 0 : return true;
591 : } else {
592 0 : args.rval().setNull();
593 0 : return true;
594 : }
595 : }
596 :
597 : static bool
598 0 : set_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, JSJitSetterCallArgs args)
599 : {
600 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
601 0 : if (args[0].isObject()) {
602 : { // scope for tempRoot
603 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
604 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
605 : }
606 : } else {
607 0 : arg0 = nullptr;
608 : }
609 0 : self->SetOnmessage(Constify(arg0));
610 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
611 :
612 0 : return true;
613 : }
614 :
615 : static const JSJitInfo onmessage_getterinfo = {
616 : { (JSJitGetterOp)get_onmessage },
617 : { prototypes::id::ServiceWorkerContainer },
618 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
619 : JSJitInfo::Getter,
620 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
621 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
622 : false, /* isInfallible. False in setters. */
623 : false, /* isMovable. Not relevant for setters. */
624 : false, /* isEliminatable. Not relevant for setters. */
625 : false, /* isAlwaysInSlot. Only relevant for getters. */
626 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
627 : false, /* isTypedMethod. Only relevant for methods. */
628 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
629 : };
630 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
631 : static_assert(0 < 1, "There is no slot for us");
632 : static const JSJitInfo onmessage_setterinfo = {
633 : { (JSJitGetterOp)set_onmessage },
634 : { prototypes::id::ServiceWorkerContainer },
635 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
636 : JSJitInfo::Setter,
637 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
638 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
639 : false, /* isInfallible. False in setters. */
640 : false, /* isMovable. Not relevant for setters. */
641 : false, /* isEliminatable. Not relevant for setters. */
642 : false, /* isAlwaysInSlot. Only relevant for getters. */
643 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
644 : false, /* isTypedMethod. Only relevant for methods. */
645 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
646 : };
647 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
648 : static_assert(0 < 1, "There is no slot for us");
649 :
650 : static bool
651 0 : getScopeForUrl(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerContainer* self, const JSJitMethodCallArgs& args)
652 : {
653 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
654 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ServiceWorkerContainer.getScopeForUrl");
655 : }
656 0 : binding_detail::FakeString arg0;
657 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
658 0 : return false;
659 : }
660 0 : binding_detail::FastErrorResult rv;
661 0 : DOMString result;
662 0 : self->GetScopeForUrl(NonNullHelper(Constify(arg0)), result, rv);
663 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
664 0 : return false;
665 : }
666 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
667 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
668 0 : return false;
669 : }
670 0 : return true;
671 : }
672 :
673 : static const JSJitInfo getScopeForUrl_methodinfo = {
674 : { (JSJitGetterOp)getScopeForUrl },
675 : { prototypes::id::ServiceWorkerContainer },
676 : { PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth },
677 : JSJitInfo::Method,
678 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
679 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
680 : false, /* isInfallible. False in setters. */
681 : false, /* isMovable. Not relevant for setters. */
682 : false, /* isEliminatable. Not relevant for setters. */
683 : false, /* isAlwaysInSlot. Only relevant for getters. */
684 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
685 : false, /* isTypedMethod. Only relevant for methods. */
686 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
687 : };
688 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
689 : static_assert(0 < 1, "There is no slot for us");
690 :
691 : static bool
692 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
693 : {
694 0 : mozilla::dom::ServiceWorkerContainer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorkerContainer>(obj);
695 : // We don't want to preserve if we don't have a wrapper, and we
696 : // obviously can't preserve if we're not initialized.
697 0 : if (self && self->GetWrapperPreserveColor()) {
698 0 : PreserveWrapper(self);
699 : }
700 0 : return true;
701 : }
702 :
703 : static void
704 0 : _finalize(js::FreeOp* fop, JSObject* obj)
705 : {
706 0 : mozilla::dom::ServiceWorkerContainer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorkerContainer>(obj);
707 0 : if (self) {
708 0 : ClearWrapper(self, self, obj);
709 0 : AddForDeferredFinalization<mozilla::dom::ServiceWorkerContainer>(self);
710 : }
711 0 : }
712 :
713 : static void
714 0 : _objectMoved(JSObject* obj, const JSObject* old)
715 : {
716 0 : mozilla::dom::ServiceWorkerContainer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorkerContainer>(obj);
717 0 : if (self) {
718 0 : UpdateWrapper(self, self, obj, old);
719 : }
720 0 : }
721 :
722 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
723 : #if defined(__clang__)
724 : #pragma clang diagnostic push
725 : #pragma clang diagnostic ignored "-Wmissing-braces"
726 : #endif
727 : static const JSFunctionSpec sMethods_specs[] = {
728 : JS_FNSPEC("register", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(®ister_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
729 : JS_FNSPEC("getRegistration", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&getRegistration_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
730 : JS_FNSPEC("getRegistrations", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&getRegistrations_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
731 : JS_FS_END,
732 : JS_FNSPEC("getScopeForUrl", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getScopeForUrl_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
733 : JS_FS_END
734 : };
735 : #if defined(__clang__)
736 : #pragma clang diagnostic pop
737 : #endif
738 :
739 : static PrefableDisablers sMethods_disablers4 = {
740 : true, false, 0, nullptr
741 : };
742 :
743 : // Can't be const because the pref-enabled boolean needs to be writable
744 : static Prefable<const JSFunctionSpec> sMethods[] = {
745 : { nullptr, &sMethods_specs[0] },
746 : { &sMethods_disablers4, &sMethods_specs[4] },
747 : { nullptr, nullptr }
748 : };
749 :
750 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
751 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
752 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
753 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
754 :
755 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
756 : #if defined(__clang__)
757 : #pragma clang diagnostic push
758 : #pragma clang diagnostic ignored "-Wmissing-braces"
759 : #endif
760 : static const JSPropertySpec sAttributes_specs[] = {
761 : { "ready", JSPROP_SHARED | JSPROP_ENUMERATE, GenericPromiseReturningBindingGetter, &ready_getterinfo, nullptr, nullptr },
762 : { "oncontrollerchange", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &oncontrollerchange_getterinfo, GenericBindingSetter, &oncontrollerchange_setterinfo },
763 : { "onerror", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onerror_getterinfo, GenericBindingSetter, &onerror_setterinfo },
764 : { "onmessage", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onmessage_getterinfo, GenericBindingSetter, &onmessage_setterinfo },
765 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
766 : };
767 : #if defined(__clang__)
768 : #pragma clang diagnostic pop
769 : #endif
770 :
771 :
772 : // Can't be const because the pref-enabled boolean needs to be writable
773 : static Prefable<const JSPropertySpec> sAttributes[] = {
774 : { nullptr, &sAttributes_specs[0] },
775 : { nullptr, nullptr }
776 : };
777 :
778 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
779 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
780 : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
781 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
782 :
783 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
784 : #if defined(__clang__)
785 : #pragma clang diagnostic push
786 : #pragma clang diagnostic ignored "-Wmissing-braces"
787 : #endif
788 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
789 : { "controller", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &controller_getterinfo, nullptr, nullptr },
790 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
791 : };
792 : #if defined(__clang__)
793 : #pragma clang diagnostic pop
794 : #endif
795 :
796 :
797 : // Can't be const because the pref-enabled boolean needs to be writable
798 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
799 : { nullptr, &sUnforgeableAttributes_specs[0] },
800 : { nullptr, nullptr }
801 : };
802 :
803 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
804 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
805 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
806 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
807 :
808 :
809 : static uint16_t sNativeProperties_sortedPropertyIndices[9];
810 : static PropertyInfo sNativeProperties_propertyInfos[9];
811 :
812 : static const NativePropertiesN<3> sNativeProperties = {
813 : false, 0,
814 : false, 0,
815 : true, 0 /* sMethods */,
816 : true, 1 /* sAttributes */,
817 : false, 0,
818 : true, 2 /* sUnforgeableAttributes */,
819 : false, 0,
820 : -1,
821 : 9,
822 : sNativeProperties_sortedPropertyIndices,
823 : {
824 : { sMethods, &sNativeProperties_propertyInfos[0] },
825 : { sAttributes, &sNativeProperties_propertyInfos[4] },
826 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[8] }
827 : }
828 : };
829 : static_assert(9 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
830 : "We have a property info count that is oversized");
831 :
832 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
833 : {
834 : "Function",
835 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
836 : &sBoringInterfaceObjectClassClassOps,
837 : JS_NULL_CLASS_SPEC,
838 : JS_NULL_CLASS_EXT,
839 : &sInterfaceObjectClassObjectOps
840 : },
841 : eInterface,
842 : true,
843 : prototypes::id::ServiceWorkerContainer,
844 : PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth,
845 : sNativePropertyHooks,
846 : "function ServiceWorkerContainer() {\n [native code]\n}",
847 : EventTargetBinding::GetConstructorObject
848 : };
849 :
850 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
851 : {
852 : "ServiceWorkerContainerPrototype",
853 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
854 : JS_NULL_CLASS_OPS,
855 : JS_NULL_CLASS_SPEC,
856 : JS_NULL_CLASS_EXT,
857 : JS_NULL_OBJECT_OPS
858 : },
859 : eInterfacePrototype,
860 : false,
861 : prototypes::id::ServiceWorkerContainer,
862 : PrototypeTraits<prototypes::id::ServiceWorkerContainer>::Depth,
863 : sNativePropertyHooks,
864 : "[object ServiceWorkerContainerPrototype]",
865 : EventTargetBinding::GetProtoObject
866 : };
867 :
868 : bool
869 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
870 : {
871 0 : return ServiceWorkerContainer::IsEnabled(aCx, aObj);
872 : }
873 :
874 : JSObject*
875 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
876 : {
877 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
878 : }
879 :
880 : static const js::ClassOps sClassOps = {
881 : _addProperty, /* addProperty */
882 : nullptr, /* delProperty */
883 : nullptr, /* getProperty */
884 : nullptr, /* setProperty */
885 : nullptr, /* enumerate */
886 : nullptr, /* newEnumerate */
887 : nullptr, /* resolve */
888 : nullptr, /* mayResolve */
889 : _finalize, /* finalize */
890 : nullptr, /* call */
891 : nullptr, /* hasInstance */
892 : nullptr, /* construct */
893 : nullptr, /* trace */
894 : };
895 :
896 : static const js::ClassExtension sClassExtension = {
897 : nullptr, /* weakmapKeyDelegateOp */
898 : _objectMoved /* objectMovedOp */
899 : };
900 :
901 : static const DOMJSClass sClass = {
902 : { "ServiceWorkerContainer",
903 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
904 : &sClassOps,
905 : JS_NULL_CLASS_SPEC,
906 : &sClassExtension,
907 : JS_NULL_OBJECT_OPS
908 : },
909 : { prototypes::id::EventTarget, prototypes::id::ServiceWorkerContainer, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
910 : IsBaseOf<nsISupports, mozilla::dom::ServiceWorkerContainer >::value,
911 : sNativePropertyHooks,
912 : FindAssociatedGlobalForNative<mozilla::dom::ServiceWorkerContainer>::Get,
913 : GetProtoObjectHandle,
914 : GetCCParticipant<mozilla::dom::ServiceWorkerContainer>::Get()
915 : };
916 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
917 : "Must have the right minimal number of reserved slots.");
918 : static_assert(1 >= 1,
919 : "Must have enough reserved slots.");
920 :
921 : const JSClass*
922 0 : GetJSClass()
923 : {
924 0 : return sClass.ToJSClass();
925 : }
926 :
927 : bool
928 0 : Wrap(JSContext* aCx, mozilla::dom::ServiceWorkerContainer* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
929 : {
930 : MOZ_ASSERT(static_cast<mozilla::dom::ServiceWorkerContainer*>(aObject) ==
931 : reinterpret_cast<mozilla::dom::ServiceWorkerContainer*>(aObject),
932 : "Multiple inheritance for mozilla::dom::ServiceWorkerContainer is broken.");
933 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
934 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
935 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
936 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
937 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
938 0 : MOZ_ASSERT(!aCache->GetWrapper(),
939 : "You should probably not be using Wrap() directly; use "
940 : "GetOrCreateDOMReflector instead");
941 :
942 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
943 : "nsISupports must be on our primary inheritance chain");
944 :
945 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
946 0 : if (!global) {
947 0 : return false;
948 : }
949 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
950 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
951 :
952 : // That might have ended up wrapping us already, due to the wonders
953 : // of XBL. Check for that, and bail out as needed.
954 0 : aReflector.set(aCache->GetWrapper());
955 0 : if (aReflector) {
956 : #ifdef DEBUG
957 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
958 : #endif // DEBUG
959 0 : return true;
960 : }
961 :
962 0 : JSAutoCompartment ac(aCx, global);
963 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
964 0 : if (!canonicalProto) {
965 0 : return false;
966 : }
967 0 : JS::Rooted<JSObject*> proto(aCx);
968 0 : if (aGivenProto) {
969 0 : proto = aGivenProto;
970 : // Unfortunately, while aGivenProto was in the compartment of aCx
971 : // coming in, we changed compartments to that of "parent" so may need
972 : // to wrap the proto here.
973 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
974 0 : if (!JS_WrapObject(aCx, &proto)) {
975 0 : return false;
976 : }
977 : }
978 : } else {
979 0 : proto = canonicalProto;
980 : }
981 :
982 0 : BindingJSObjectCreator<mozilla::dom::ServiceWorkerContainer> creator(aCx);
983 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
984 0 : if (!aReflector) {
985 0 : return false;
986 : }
987 :
988 0 : aCache->SetWrapper(aReflector);
989 :
990 : // Important: do unforgeable property setup after we have handed
991 : // over ownership of the C++ object to obj as needed, so that if
992 : // we fail and it ends up GCed it won't have problems in the
993 : // finalizer trying to drop its ownership of the C++ object.
994 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
995 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
996 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
997 0 : aCache->ReleaseWrapper(aObject);
998 0 : aCache->ClearWrapper();
999 0 : return false;
1000 : }
1001 0 : creator.InitializationSucceeded();
1002 :
1003 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1004 : aCache->GetWrapperPreserveColor() == aReflector);
1005 : // If proto != canonicalProto, we have to preserve our wrapper;
1006 : // otherwise we won't be able to properly recreate it later, since
1007 : // we won't know what proto to use. Note that we don't check
1008 : // aGivenProto here, since it's entirely possible (and even
1009 : // somewhat common) to have a non-null aGivenProto which is the
1010 : // same as canonicalProto.
1011 0 : if (proto != canonicalProto) {
1012 0 : PreserveWrapper(aObject);
1013 : }
1014 :
1015 0 : return true;
1016 : }
1017 :
1018 : const NativePropertyHooks sNativePropertyHooks[] = { {
1019 : nullptr,
1020 : nullptr,
1021 : nullptr,
1022 : { sNativeProperties.Upcast(), nullptr },
1023 : prototypes::id::ServiceWorkerContainer,
1024 : constructors::id::ServiceWorkerContainer,
1025 : EventTargetBinding::sNativePropertyHooks,
1026 : &DefaultXrayExpandoObjectClass
1027 : } };
1028 :
1029 : void
1030 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1031 : {
1032 0 : JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObjectHandle(aCx));
1033 0 : if (!parentProto) {
1034 0 : return;
1035 : }
1036 :
1037 0 : JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObjectHandle(aCx));
1038 0 : if (!constructorProto) {
1039 0 : return;
1040 : }
1041 :
1042 : static bool sIdsInited = false;
1043 0 : if (!sIdsInited && NS_IsMainThread()) {
1044 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1045 0 : return;
1046 : }
1047 0 : sIdsInited = true;
1048 : }
1049 :
1050 : static bool sPrefCachesInited = false;
1051 0 : if (!sPrefCachesInited && NS_IsMainThread()) {
1052 0 : sPrefCachesInited = true;
1053 0 : Preferences::AddBoolVarCache(&sMethods[1].disablers->enabled, "dom.serviceWorkers.testing.enabled");
1054 : }
1055 :
1056 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ServiceWorkerContainer);
1057 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ServiceWorkerContainer);
1058 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1059 : &sPrototypeClass.mBase, protoCache,
1060 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1061 : interfaceCache,
1062 : sNativeProperties.Upcast(),
1063 : nullptr,
1064 : "ServiceWorkerContainer", aDefineOnGlobal,
1065 : nullptr,
1066 0 : false);
1067 :
1068 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
1069 : {
1070 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
1071 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
1072 0 : if (!unforgeableHolder) {
1073 0 : *protoCache = nullptr;
1074 0 : if (interfaceCache) {
1075 0 : *interfaceCache = nullptr;
1076 : }
1077 0 : return;
1078 : }
1079 : }
1080 :
1081 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
1082 0 : *protoCache = nullptr;
1083 0 : if (interfaceCache) {
1084 0 : *interfaceCache = nullptr;
1085 : }
1086 0 : return;
1087 : }
1088 :
1089 0 : if (*protoCache) {
1090 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
1091 0 : JS::ObjectValue(*unforgeableHolder));
1092 : }
1093 : }
1094 :
1095 : JS::Handle<JSObject*>
1096 0 : GetProtoObjectHandle(JSContext* aCx)
1097 : {
1098 : /* Get the interface prototype object for this class. This will create the
1099 : object as needed. */
1100 0 : bool aDefineOnGlobal = true;
1101 :
1102 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1103 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1104 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1105 0 : return nullptr;
1106 : }
1107 :
1108 : /* Check to see whether the interface objects are already installed */
1109 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1110 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::ServiceWorkerContainer)) {
1111 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1112 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1113 : }
1114 :
1115 : /*
1116 : * The object might _still_ be null, but that's OK.
1117 : *
1118 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1119 : * traced by TraceProtoAndIfaceCache() and its contents are never
1120 : * changed after they have been set.
1121 : *
1122 : * Calling address() avoids the read read barrier that does gray
1123 : * unmarking, but it's not possible for the object to be gray here.
1124 : */
1125 :
1126 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::ServiceWorkerContainer);
1127 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1128 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1129 : }
1130 :
1131 : JS::Handle<JSObject*>
1132 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1133 : {
1134 : /* Get the interface object for this class. This will create the object as
1135 : needed. */
1136 :
1137 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1138 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1139 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1140 0 : return nullptr;
1141 : }
1142 :
1143 : /* Check to see whether the interface objects are already installed */
1144 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1145 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::ServiceWorkerContainer)) {
1146 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1147 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1148 : }
1149 :
1150 : /*
1151 : * The object might _still_ be null, but that's OK.
1152 : *
1153 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1154 : * traced by TraceProtoAndIfaceCache() and its contents are never
1155 : * changed after they have been set.
1156 : *
1157 : * Calling address() avoids the read read barrier that does gray
1158 : * unmarking, but it's not possible for the object to be gray here.
1159 : */
1160 :
1161 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::ServiceWorkerContainer);
1162 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1163 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1164 : }
1165 :
1166 : JSObject*
1167 0 : GetConstructorObject(JSContext* aCx)
1168 : {
1169 0 : return GetConstructorObjectHandle(aCx);
1170 : }
1171 :
1172 : } // namespace ServiceWorkerContainerBinding
1173 :
1174 :
1175 :
1176 : } // namespace dom
1177 : } // namespace mozilla
|