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