/work/obj-fuzz/dom/bindings/FetchEventBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM FetchEvent.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "ExtendableEventBinding.h" |
5 | | #include "FetchEventBinding.h" |
6 | | #include "ServiceWorkerEvents.h" |
7 | | #include "WrapperFactory.h" |
8 | | #include "mozilla/OwningNonNull.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/DOMJSClass.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/PrimitiveConversions.h" |
13 | | #include "mozilla/dom/Promise.h" |
14 | | #include "mozilla/dom/Request.h" |
15 | | #include "mozilla/dom/ScriptSettings.h" |
16 | | #include "mozilla/dom/ToJSValue.h" |
17 | | #include "nsThreadUtils.h" |
18 | | |
19 | | namespace mozilla { |
20 | | namespace dom { |
21 | | |
22 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
23 | | using namespace mozilla::dom::binding_detail; |
24 | | |
25 | | |
26 | | |
27 | | FetchEventInit::FetchEventInit() |
28 | | : EventInit(FastDictionaryInitializer()) |
29 | 0 | { |
30 | 0 | // Safe to pass a null context if we pass a null value |
31 | 0 | Init(nullptr, JS::NullHandleValue); |
32 | 0 | } |
33 | | |
34 | | |
35 | | |
36 | | bool |
37 | | FetchEventInit::InitIds(JSContext* cx, FetchEventInitAtoms* atomsCache) |
38 | 0 | { |
39 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
40 | 0 |
|
41 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
42 | 0 | // uninitialized. |
43 | 0 | if (!atomsCache->request_id.init(cx, "request") || |
44 | 0 | !atomsCache->isReload_id.init(cx, "isReload") || |
45 | 0 | !atomsCache->clientId_id.init(cx, "clientId")) { |
46 | 0 | return false; |
47 | 0 | } |
48 | 0 | return true; |
49 | 0 | } |
50 | | |
51 | | bool |
52 | | FetchEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
53 | 0 | { |
54 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
55 | 0 | // Since in that case we will not have to do any property gets |
56 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
57 | 0 | // checkers by static analysis tools |
58 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
59 | 0 | FetchEventInitAtoms* atomsCache = nullptr; |
60 | 0 | if (cx) { |
61 | 0 | atomsCache = GetAtomCache<FetchEventInitAtoms>(cx); |
62 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
63 | 0 | return false; |
64 | 0 | } |
65 | 0 | } |
66 | 0 | |
67 | 0 | // Per spec, we init the parent's members first |
68 | 0 | if (!EventInit::Init(cx, val)) { |
69 | 0 | return false; |
70 | 0 | } |
71 | 0 | |
72 | 0 | bool isNull = val.isNullOrUndefined(); |
73 | 0 | // We only need these if !isNull, in which case we have |cx|. |
74 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
75 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
76 | 0 | if (!isNull) { |
77 | 0 | MOZ_ASSERT(cx); |
78 | 0 | object.emplace(cx, &val.toObject()); |
79 | 0 | temp.emplace(cx); |
80 | 0 | } |
81 | 0 | if (!isNull) { |
82 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->clientId_id, temp.ptr())) { |
83 | 0 | return false; |
84 | 0 | } |
85 | 0 | } |
86 | 0 | if (!isNull && !temp->isUndefined()) { |
87 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mClientId)) { |
88 | 0 | return false; |
89 | 0 | } |
90 | 0 | } else { |
91 | 0 | static const char16_t data[] = { 0 }; |
92 | 0 | mClientId.Rebind(data, ArrayLength(data) - 1); |
93 | 0 | } |
94 | 0 | mIsAnyMemberPresent = true; |
95 | 0 |
|
96 | 0 | if (!isNull) { |
97 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->isReload_id, temp.ptr())) { |
98 | 0 | return false; |
99 | 0 | } |
100 | 0 | } |
101 | 0 | if (!isNull && !temp->isUndefined()) { |
102 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mIsReload)) { |
103 | 0 | return false; |
104 | 0 | } |
105 | 0 | } else { |
106 | 0 | mIsReload = false; |
107 | 0 | } |
108 | 0 | mIsAnyMemberPresent = true; |
109 | 0 |
|
110 | 0 | if (!isNull) { |
111 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->request_id, temp.ptr())) { |
112 | 0 | return false; |
113 | 0 | } |
114 | 0 | } |
115 | 0 | if (!isNull && !temp->isUndefined()) { |
116 | 0 | if (temp.ref().isObject()) { |
117 | 0 | static_assert(IsRefcounted<mozilla::dom::Request>::value, "We can only store refcounted classes.");{ |
118 | 0 | nsresult rv = UnwrapObject<prototypes::id::Request, mozilla::dom::Request>(temp.ptr(), mRequest); |
119 | 0 | if (NS_FAILED(rv)) { |
120 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'request' member of FetchEventInit", "Request"); |
121 | 0 | return false; |
122 | 0 | } |
123 | 0 | } |
124 | 0 | } else { |
125 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'request' member of FetchEventInit"); |
126 | 0 | return false; |
127 | 0 | } |
128 | 0 | mIsAnyMemberPresent = true; |
129 | 0 | } else if (cx) { |
130 | 0 | // Don't error out if we have no cx. In that |
131 | 0 | // situation the caller is default-constructing us and we'll |
132 | 0 | // just assume they know what they're doing. |
133 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
134 | 0 | "'request' member of FetchEventInit"); |
135 | 0 | } |
136 | 0 | return true; |
137 | 0 | } |
138 | | |
139 | | bool |
140 | | FetchEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
141 | 0 | { |
142 | 0 | FetchEventInitAtoms* atomsCache = GetAtomCache<FetchEventInitAtoms>(cx); |
143 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
144 | 0 | return false; |
145 | 0 | } |
146 | 0 | |
147 | 0 | // Per spec, we define the parent's members first |
148 | 0 | if (!EventInit::ToObjectInternal(cx, rval)) { |
149 | 0 | return false; |
150 | 0 | } |
151 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
152 | 0 |
|
153 | 0 | do { |
154 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
155 | 0 | JS::Rooted<JS::Value> temp(cx); |
156 | 0 | nsString const & currentValue = mClientId; |
157 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
158 | 0 | return false; |
159 | 0 | } |
160 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->clientId_id, temp, JSPROP_ENUMERATE)) { |
161 | 0 | return false; |
162 | 0 | } |
163 | 0 | break; |
164 | 0 | } while(false); |
165 | 0 |
|
166 | 0 | do { |
167 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
168 | 0 | JS::Rooted<JS::Value> temp(cx); |
169 | 0 | bool const & currentValue = mIsReload; |
170 | 0 | temp.setBoolean(currentValue); |
171 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->isReload_id, temp, JSPROP_ENUMERATE)) { |
172 | 0 | return false; |
173 | 0 | } |
174 | 0 | break; |
175 | 0 | } while(false); |
176 | 0 |
|
177 | 0 | do { |
178 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
179 | 0 | JS::Rooted<JS::Value> temp(cx); |
180 | 0 | OwningNonNull<mozilla::dom::Request> const & currentValue = mRequest; |
181 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
182 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
183 | 0 | return false; |
184 | 0 | } |
185 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->request_id, temp, JSPROP_ENUMERATE)) { |
186 | 0 | return false; |
187 | 0 | } |
188 | 0 | break; |
189 | 0 | } while(false); |
190 | 0 |
|
191 | 0 | return true; |
192 | 0 | } |
193 | | |
194 | | void |
195 | | FetchEventInit::TraceDictionary(JSTracer* trc) |
196 | 0 | { |
197 | 0 | EventInit::TraceDictionary(trc); |
198 | 0 | } |
199 | | |
200 | | |
201 | | |
202 | | FetchEventInit& |
203 | | FetchEventInit::operator=(const FetchEventInit& aOther) |
204 | 0 | { |
205 | 0 | EventInit::operator=(aOther); |
206 | 0 | mClientId = aOther.mClientId; |
207 | 0 | mIsReload = aOther.mIsReload; |
208 | 0 | mRequest = aOther.mRequest; |
209 | 0 | return *this; |
210 | 0 | } |
211 | | |
212 | | namespace binding_detail { |
213 | | } // namespace binding_detail |
214 | | |
215 | | |
216 | | namespace FetchEvent_Binding { |
217 | | |
218 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<ExtendableEvent_Binding::NativeType>::value, |
219 | | "Can't inherit from an interface with a different ownership model."); |
220 | | |
221 | | MOZ_CAN_RUN_SCRIPT static bool |
222 | | get_request(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FetchEvent* self, JSJitGetterCallArgs args) |
223 | 0 | { |
224 | 0 | AUTO_PROFILER_LABEL_FAST("get FetchEvent.request", DOM, cx); |
225 | 0 |
|
226 | 0 | auto result(StrongOrRawPtr<mozilla::dom::Request>(self->Request_())); |
227 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
228 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
229 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
230 | 0 | return false; |
231 | 0 | } |
232 | 0 | return true; |
233 | 0 | } |
234 | | |
235 | | static const JSJitInfo request_getterinfo = { |
236 | | { (JSJitGetterOp)get_request }, |
237 | | { prototypes::id::FetchEvent }, |
238 | | { PrototypeTraits<prototypes::id::FetchEvent>::Depth }, |
239 | | JSJitInfo::Getter, |
240 | | JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */ |
241 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
242 | | false, /* isInfallible. False in setters. */ |
243 | | true, /* isMovable. Not relevant for setters. */ |
244 | | true, /* isEliminatable. Not relevant for setters. */ |
245 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
246 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
247 | | false, /* isTypedMethod. Only relevant for methods. */ |
248 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
249 | | }; |
250 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
251 | | static_assert(0 < 1, "There is no slot for us"); |
252 | | |
253 | | MOZ_CAN_RUN_SCRIPT static bool |
254 | | get_clientId(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FetchEvent* self, JSJitGetterCallArgs args) |
255 | 0 | { |
256 | 0 | AUTO_PROFILER_LABEL_FAST("get FetchEvent.clientId", DOM, cx); |
257 | 0 |
|
258 | 0 | DOMString result; |
259 | 0 | self->GetClientId(result); |
260 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
261 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
262 | 0 | return false; |
263 | 0 | } |
264 | 0 | return true; |
265 | 0 | } |
266 | | |
267 | | static const JSJitInfo clientId_getterinfo = { |
268 | | { (JSJitGetterOp)get_clientId }, |
269 | | { prototypes::id::FetchEvent }, |
270 | | { PrototypeTraits<prototypes::id::FetchEvent>::Depth }, |
271 | | JSJitInfo::Getter, |
272 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
273 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
274 | | false, /* isInfallible. False in setters. */ |
275 | | false, /* isMovable. Not relevant for setters. */ |
276 | | false, /* isEliminatable. Not relevant for setters. */ |
277 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
278 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
279 | | false, /* isTypedMethod. Only relevant for methods. */ |
280 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
281 | | }; |
282 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
283 | | static_assert(0 < 1, "There is no slot for us"); |
284 | | |
285 | | MOZ_CAN_RUN_SCRIPT static bool |
286 | | get_isReload(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FetchEvent* self, JSJitGetterCallArgs args) |
287 | 0 | { |
288 | 0 | AUTO_PROFILER_LABEL_FAST("get FetchEvent.isReload", DOM, cx); |
289 | 0 |
|
290 | 0 | bool result(self->IsReload()); |
291 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
292 | 0 | args.rval().setBoolean(result); |
293 | 0 | return true; |
294 | 0 | } |
295 | | |
296 | | static const JSJitInfo isReload_getterinfo = { |
297 | | { (JSJitGetterOp)get_isReload }, |
298 | | { prototypes::id::FetchEvent }, |
299 | | { PrototypeTraits<prototypes::id::FetchEvent>::Depth }, |
300 | | JSJitInfo::Getter, |
301 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
302 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
303 | | true, /* isInfallible. False in setters. */ |
304 | | false, /* isMovable. Not relevant for setters. */ |
305 | | false, /* isEliminatable. Not relevant for setters. */ |
306 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
307 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
308 | | false, /* isTypedMethod. Only relevant for methods. */ |
309 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
310 | | }; |
311 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
312 | | static_assert(0 < 1, "There is no slot for us"); |
313 | | |
314 | | MOZ_CAN_RUN_SCRIPT static bool |
315 | | respondWith(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FetchEvent* self, const JSJitMethodCallArgs& args) |
316 | 0 | { |
317 | 0 | AUTO_PROFILER_LABEL_FAST("FetchEvent.respondWith", DOM, cx); |
318 | 0 |
|
319 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
320 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "FetchEvent.respondWith"); |
321 | 0 | } |
322 | 0 | OwningNonNull<Promise> arg0; |
323 | 0 | { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm, |
324 | 0 | // etc. |
325 | 0 |
|
326 | 0 | JS::Rooted<JSObject*> globalObj(cx); |
327 | 0 | globalObj = JS::CurrentGlobalOrNull(cx); |
328 | 0 | JSAutoRealm ar(cx, globalObj); |
329 | 0 | GlobalObject promiseGlobal(cx, globalObj); |
330 | 0 | if (promiseGlobal.Failed()) { |
331 | 0 | return false; |
332 | 0 | } |
333 | 0 | |
334 | 0 | JS::Rooted<JS::Value> valueToResolve(cx, args[0]); |
335 | 0 | if (!JS_WrapValue(cx, &valueToResolve)) { |
336 | 0 | return false; |
337 | 0 | } |
338 | 0 | binding_detail::FastErrorResult promiseRv; |
339 | 0 | nsCOMPtr<nsIGlobalObject> global = |
340 | 0 | do_QueryInterface(promiseGlobal.GetAsSupports()); |
341 | 0 | if (!global) { |
342 | 0 | promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED); |
343 | 0 | MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx)); |
344 | 0 | return false; |
345 | 0 | } |
346 | 0 | arg0 = Promise::Resolve(global, cx, valueToResolve, |
347 | 0 | promiseRv); |
348 | 0 | if (promiseRv.MaybeSetPendingException(cx)) { |
349 | 0 | return false; |
350 | 0 | } |
351 | 0 | } |
352 | 0 | FastErrorResult rv; |
353 | 0 | self->RespondWith(cx, NonNullHelper(arg0), rv); |
354 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
355 | 0 | return false; |
356 | 0 | } |
357 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
358 | 0 | args.rval().setUndefined(); |
359 | 0 | return true; |
360 | 0 | } |
361 | | |
362 | | static const JSJitInfo respondWith_methodinfo = { |
363 | | { (JSJitGetterOp)respondWith }, |
364 | | { prototypes::id::FetchEvent }, |
365 | | { PrototypeTraits<prototypes::id::FetchEvent>::Depth }, |
366 | | JSJitInfo::Method, |
367 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
368 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
369 | | false, /* isInfallible. False in setters. */ |
370 | | false, /* isMovable. Not relevant for setters. */ |
371 | | false, /* isEliminatable. Not relevant for setters. */ |
372 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
373 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
374 | | false, /* isTypedMethod. Only relevant for methods. */ |
375 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
376 | | }; |
377 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
378 | | static_assert(0 < 1, "There is no slot for us"); |
379 | | |
380 | | MOZ_CAN_RUN_SCRIPT static bool |
381 | | get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FetchEvent* self, JSJitGetterCallArgs args) |
382 | 0 | { |
383 | 0 | AUTO_PROFILER_LABEL_FAST("get FetchEvent.isTrusted", DOM, cx); |
384 | 0 |
|
385 | 0 | bool result(self->IsTrusted()); |
386 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
387 | 0 | args.rval().setBoolean(result); |
388 | 0 | return true; |
389 | 0 | } |
390 | | |
391 | | static const JSJitInfo isTrusted_getterinfo = { |
392 | | { (JSJitGetterOp)get_isTrusted }, |
393 | | { prototypes::id::FetchEvent }, |
394 | | { PrototypeTraits<prototypes::id::FetchEvent>::Depth }, |
395 | | JSJitInfo::Getter, |
396 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
397 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
398 | | true, /* isInfallible. False in setters. */ |
399 | | true, /* isMovable. Not relevant for setters. */ |
400 | | true, /* isEliminatable. Not relevant for setters. */ |
401 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
402 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
403 | | false, /* isTypedMethod. Only relevant for methods. */ |
404 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
405 | | }; |
406 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
407 | | static_assert(0 < 1, "There is no slot for us"); |
408 | | |
409 | | static bool |
410 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
411 | 0 | { |
412 | 0 | mozilla::dom::FetchEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FetchEvent>(obj); |
413 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
414 | 0 | // obviously can't preserve if we're not initialized. |
415 | 0 | if (self && self->GetWrapperPreserveColor()) { |
416 | 0 | PreserveWrapper(self); |
417 | 0 | } |
418 | 0 | return true; |
419 | 0 | } |
420 | | |
421 | | static void |
422 | | _finalize(js::FreeOp* fop, JSObject* obj) |
423 | 0 | { |
424 | 0 | mozilla::dom::FetchEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FetchEvent>(obj); |
425 | 0 | if (self) { |
426 | 0 | ClearWrapper(self, self, obj); |
427 | 0 | AddForDeferredFinalization<mozilla::dom::FetchEvent>(self); |
428 | 0 | } |
429 | 0 | } |
430 | | |
431 | | static size_t |
432 | | _objectMoved(JSObject* obj, JSObject* old) |
433 | 0 | { |
434 | 0 | mozilla::dom::FetchEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FetchEvent>(obj); |
435 | 0 | if (self) { |
436 | 0 | UpdateWrapper(self, self, obj, old); |
437 | 0 | } |
438 | 0 |
|
439 | 0 | return 0; |
440 | 0 | } |
441 | | |
442 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
443 | | #if defined(__clang__) |
444 | | #pragma clang diagnostic push |
445 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
446 | | #endif |
447 | | static const JSFunctionSpec sMethods_specs[] = { |
448 | | JS_FNSPEC("respondWith", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&respondWith_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
449 | | JS_FS_END |
450 | | }; |
451 | | #if defined(__clang__) |
452 | | #pragma clang diagnostic pop |
453 | | #endif |
454 | | |
455 | | |
456 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
457 | | { nullptr, &sMethods_specs[0] }, |
458 | | { nullptr, nullptr } |
459 | | }; |
460 | | |
461 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
462 | | #if defined(__clang__) |
463 | | #pragma clang diagnostic push |
464 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
465 | | #endif |
466 | | static const JSPropertySpec sAttributes_specs[] = { |
467 | | { "request", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &request_getterinfo, nullptr, nullptr }, |
468 | | { "clientId", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &clientId_getterinfo, nullptr, nullptr }, |
469 | | { "isReload", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isReload_getterinfo, nullptr, nullptr }, |
470 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
471 | | }; |
472 | | #if defined(__clang__) |
473 | | #pragma clang diagnostic pop |
474 | | #endif |
475 | | |
476 | | |
477 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
478 | | { nullptr, &sAttributes_specs[0] }, |
479 | | { nullptr, nullptr } |
480 | | }; |
481 | | |
482 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
483 | | #if defined(__clang__) |
484 | | #pragma clang diagnostic push |
485 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
486 | | #endif |
487 | | static const JSPropertySpec sUnforgeableAttributes_specs[] = { |
488 | | { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr }, |
489 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
490 | | }; |
491 | | #if defined(__clang__) |
492 | | #pragma clang diagnostic pop |
493 | | #endif |
494 | | |
495 | | |
496 | | static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = { |
497 | | { nullptr, &sUnforgeableAttributes_specs[0] }, |
498 | | { nullptr, nullptr } |
499 | | }; |
500 | | |
501 | | |
502 | | static const NativePropertiesN<3> sNativeProperties = { |
503 | | false, 0, |
504 | | false, 0, |
505 | | true, 0 /* sMethods */, |
506 | | true, 1 /* sAttributes */, |
507 | | false, 0, |
508 | | true, 2 /* sUnforgeableAttributes */, |
509 | | false, 0, |
510 | | -1, |
511 | | 0, |
512 | | nullptr, |
513 | | { |
514 | | { sMethods, nullptr }, |
515 | | { sAttributes, nullptr }, |
516 | | { sUnforgeableAttributes, nullptr } |
517 | | } |
518 | | }; |
519 | | |
520 | | static bool |
521 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
522 | 0 | { |
523 | 0 | AUTO_PROFILER_LABEL_FAST("FetchEvent constructor", DOM, cx); |
524 | 0 |
|
525 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
526 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
527 | 0 | if (!args.isConstructing()) { |
528 | 0 | // XXXbz wish I could get the name from the callee instead of |
529 | 0 | // Adding more relocations |
530 | 0 | return ThrowConstructorWithoutNew(cx, "FetchEvent"); |
531 | 0 | } |
532 | 0 | |
533 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
534 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
535 | 0 | return false; |
536 | 0 | } |
537 | 0 | |
538 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
539 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "FetchEvent"); |
540 | 0 | } |
541 | 0 | GlobalObject global(cx, obj); |
542 | 0 | if (global.Failed()) { |
543 | 0 | return false; |
544 | 0 | } |
545 | 0 | |
546 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
547 | 0 | binding_detail::FakeString arg0; |
548 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
549 | 0 | return false; |
550 | 0 | } |
551 | 0 | binding_detail::FastFetchEventInit arg1; |
552 | 0 | if (!arg1.Init(cx, args[1], "Argument 2 of FetchEvent.constructor", false)) { |
553 | 0 | return false; |
554 | 0 | } |
555 | 0 | Maybe<JSAutoRealm> ar; |
556 | 0 | if (objIsXray) { |
557 | 0 | obj = js::CheckedUnwrap(obj); |
558 | 0 | if (!obj) { |
559 | 0 | return false; |
560 | 0 | } |
561 | 0 | ar.emplace(cx, obj); |
562 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
563 | 0 | return false; |
564 | 0 | } |
565 | 0 | } |
566 | 0 | FastErrorResult rv; |
567 | 0 | auto result(StrongOrRawPtr<mozilla::dom::FetchEvent>(mozilla::dom::FetchEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv))); |
568 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
569 | 0 | return false; |
570 | 0 | } |
571 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
572 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
573 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
574 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
575 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
576 | 0 | return false; |
577 | 0 | } |
578 | 0 | return true; |
579 | 0 | } |
580 | | |
581 | | static const js::ClassOps sInterfaceObjectClassOps = { |
582 | | nullptr, /* addProperty */ |
583 | | nullptr, /* delProperty */ |
584 | | nullptr, /* enumerate */ |
585 | | nullptr, /* newEnumerate */ |
586 | | nullptr, /* resolve */ |
587 | | nullptr, /* mayResolve */ |
588 | | nullptr, /* finalize */ |
589 | | _constructor, /* call */ |
590 | | nullptr, /* hasInstance */ |
591 | | _constructor, /* construct */ |
592 | | nullptr, /* trace */ |
593 | | }; |
594 | | |
595 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
596 | | { |
597 | | "Function", |
598 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
599 | | &sInterfaceObjectClassOps, |
600 | | JS_NULL_CLASS_SPEC, |
601 | | JS_NULL_CLASS_EXT, |
602 | | &sInterfaceObjectClassObjectOps |
603 | | }, |
604 | | eInterface, |
605 | | true, |
606 | | prototypes::id::FetchEvent, |
607 | | PrototypeTraits<prototypes::id::FetchEvent>::Depth, |
608 | | &sEmptyNativePropertyHooks, |
609 | | "function FetchEvent() {\n [native code]\n}", |
610 | | ExtendableEvent_Binding::GetConstructorObject |
611 | | }; |
612 | | |
613 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
614 | | { |
615 | | "FetchEventPrototype", |
616 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */), |
617 | | JS_NULL_CLASS_OPS, |
618 | | JS_NULL_CLASS_SPEC, |
619 | | JS_NULL_CLASS_EXT, |
620 | | JS_NULL_OBJECT_OPS |
621 | | }, |
622 | | eInterfacePrototype, |
623 | | false, |
624 | | prototypes::id::FetchEvent, |
625 | | PrototypeTraits<prototypes::id::FetchEvent>::Depth, |
626 | | &sEmptyNativePropertyHooks, |
627 | | "[object FetchEventPrototype]", |
628 | | ExtendableEvent_Binding::GetProtoObject |
629 | | }; |
630 | | |
631 | | bool |
632 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
633 | 0 | { |
634 | 0 | MOZ_ASSERT(!NS_IsMainThread(), "Why did we even get called?"); |
635 | 0 |
|
636 | 0 | const char* name = js::GetObjectClass(aObj)->name; |
637 | 0 | if (strcmp(name, "ServiceWorkerGlobalScope")) { |
638 | 0 | return false; |
639 | 0 | } |
640 | 0 | |
641 | 0 | return ServiceWorkerVisible(aCx, aObj); |
642 | 0 | } |
643 | | |
644 | | static const js::ClassOps sClassOps = { |
645 | | _addProperty, /* addProperty */ |
646 | | nullptr, /* delProperty */ |
647 | | nullptr, /* enumerate */ |
648 | | nullptr, /* newEnumerate */ |
649 | | nullptr, /* resolve */ |
650 | | nullptr, /* mayResolve */ |
651 | | _finalize, /* finalize */ |
652 | | nullptr, /* call */ |
653 | | nullptr, /* hasInstance */ |
654 | | nullptr, /* construct */ |
655 | | nullptr, /* trace */ |
656 | | }; |
657 | | |
658 | | static const js::ClassExtension sClassExtension = { |
659 | | nullptr, /* weakmapKeyDelegateOp */ |
660 | | _objectMoved /* objectMovedOp */ |
661 | | }; |
662 | | |
663 | | static const DOMJSClass sClass = { |
664 | | { "FetchEvent", |
665 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE, |
666 | | &sClassOps, |
667 | | JS_NULL_CLASS_SPEC, |
668 | | &sClassExtension, |
669 | | JS_NULL_OBJECT_OPS |
670 | | }, |
671 | | { prototypes::id::Event, prototypes::id::ExtendableEvent, prototypes::id::FetchEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
672 | | IsBaseOf<nsISupports, mozilla::dom::FetchEvent >::value, |
673 | | &sEmptyNativePropertyHooks, |
674 | | FindAssociatedGlobalForNative<mozilla::dom::FetchEvent>::Get, |
675 | | GetProtoObjectHandle, |
676 | | GetCCParticipant<mozilla::dom::FetchEvent>::Get() |
677 | | }; |
678 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
679 | | "Must have the right minimal number of reserved slots."); |
680 | | static_assert(1 >= 1, |
681 | | "Must have enough reserved slots."); |
682 | | |
683 | | const JSClass* |
684 | | GetJSClass() |
685 | 0 | { |
686 | 0 | return sClass.ToJSClass(); |
687 | 0 | } |
688 | | |
689 | | bool |
690 | | Wrap(JSContext* aCx, mozilla::dom::FetchEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
691 | 0 | { |
692 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::FetchEvent>::value, |
693 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
694 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::FetchEvent*>(aObject) == |
695 | 0 | reinterpret_cast<mozilla::dom::FetchEvent*>(aObject), |
696 | 0 | "Multiple inheritance for mozilla::dom::FetchEvent is broken."); |
697 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ExtendableEvent*>(aObject) == |
698 | 0 | reinterpret_cast<mozilla::dom::ExtendableEvent*>(aObject), |
699 | 0 | "Multiple inheritance for mozilla::dom::ExtendableEvent is broken."); |
700 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) == |
701 | 0 | reinterpret_cast<mozilla::dom::Event*>(aObject), |
702 | 0 | "Multiple inheritance for mozilla::dom::Event is broken."); |
703 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
704 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
705 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
706 | 0 | "You should probably not be using Wrap() directly; use " |
707 | 0 | "GetOrCreateDOMReflector instead"); |
708 | 0 |
|
709 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
710 | 0 | "nsISupports must be on our primary inheritance chain"); |
711 | 0 |
|
712 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
713 | 0 | if (!global) { |
714 | 0 | return false; |
715 | 0 | } |
716 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
717 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
718 | 0 |
|
719 | 0 | // That might have ended up wrapping us already, due to the wonders |
720 | 0 | // of XBL. Check for that, and bail out as needed. |
721 | 0 | aReflector.set(aCache->GetWrapper()); |
722 | 0 | if (aReflector) { |
723 | | #ifdef DEBUG |
724 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
725 | | #endif // DEBUG |
726 | | return true; |
727 | 0 | } |
728 | 0 |
|
729 | 0 | JSAutoRealm ar(aCx, global); |
730 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
731 | 0 | if (!canonicalProto) { |
732 | 0 | return false; |
733 | 0 | } |
734 | 0 | JS::Rooted<JSObject*> proto(aCx); |
735 | 0 | if (aGivenProto) { |
736 | 0 | proto = aGivenProto; |
737 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
738 | 0 | // coming in, we changed compartments to that of "parent" so may need |
739 | 0 | // to wrap the proto here. |
740 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
741 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
742 | 0 | return false; |
743 | 0 | } |
744 | 0 | } |
745 | 0 | } else { |
746 | 0 | proto = canonicalProto; |
747 | 0 | } |
748 | 0 |
|
749 | 0 | BindingJSObjectCreator<mozilla::dom::FetchEvent> creator(aCx); |
750 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
751 | 0 | if (!aReflector) { |
752 | 0 | return false; |
753 | 0 | } |
754 | 0 | |
755 | 0 | aCache->SetWrapper(aReflector); |
756 | 0 |
|
757 | 0 | // Important: do unforgeable property setup after we have handed |
758 | 0 | // over ownership of the C++ object to obj as needed, so that if |
759 | 0 | // we fail and it ends up GCed it won't have problems in the |
760 | 0 | // finalizer trying to drop its ownership of the C++ object. |
761 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx, |
762 | 0 | &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject()); |
763 | 0 | if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) { |
764 | 0 | aCache->ReleaseWrapper(aObject); |
765 | 0 | aCache->ClearWrapper(); |
766 | 0 | return false; |
767 | 0 | } |
768 | 0 | creator.InitializationSucceeded(); |
769 | 0 |
|
770 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
771 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
772 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
773 | 0 | // otherwise we won't be able to properly recreate it later, since |
774 | 0 | // we won't know what proto to use. Note that we don't check |
775 | 0 | // aGivenProto here, since it's entirely possible (and even |
776 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
777 | 0 | // same as canonicalProto. |
778 | 0 | if (proto != canonicalProto) { |
779 | 0 | PreserveWrapper(aObject); |
780 | 0 | } |
781 | 0 |
|
782 | 0 | return true; |
783 | 0 | } |
784 | | |
785 | | void |
786 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
787 | 0 | { |
788 | 0 | JS::Handle<JSObject*> parentProto(ExtendableEvent_Binding::GetProtoObjectHandle(aCx)); |
789 | 0 | if (!parentProto) { |
790 | 0 | return; |
791 | 0 | } |
792 | 0 | |
793 | 0 | JS::Handle<JSObject*> constructorProto(ExtendableEvent_Binding::GetConstructorObjectHandle(aCx)); |
794 | 0 | if (!constructorProto) { |
795 | 0 | return; |
796 | 0 | } |
797 | 0 | |
798 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::FetchEvent); |
799 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::FetchEvent); |
800 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
801 | 0 | &sPrototypeClass.mBase, protoCache, |
802 | 0 | nullptr, |
803 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr, |
804 | 0 | interfaceCache, |
805 | 0 | sNativeProperties.Upcast(), |
806 | 0 | nullptr, |
807 | 0 | "FetchEvent", aDefineOnGlobal, |
808 | 0 | nullptr, |
809 | 0 | false); |
810 | 0 |
|
811 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx); |
812 | 0 | { |
813 | 0 | JS::Rooted<JSObject*> holderProto(aCx, *protoCache); |
814 | 0 | unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto); |
815 | 0 | if (!unforgeableHolder) { |
816 | 0 | *protoCache = nullptr; |
817 | 0 | if (interfaceCache) { |
818 | 0 | *interfaceCache = nullptr; |
819 | 0 | } |
820 | 0 | return; |
821 | 0 | } |
822 | 0 | } |
823 | 0 |
|
824 | 0 | if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) { |
825 | 0 | *protoCache = nullptr; |
826 | 0 | if (interfaceCache) { |
827 | 0 | *interfaceCache = nullptr; |
828 | 0 | } |
829 | 0 | return; |
830 | 0 | } |
831 | 0 |
|
832 | 0 | if (*protoCache) { |
833 | 0 | js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE, |
834 | 0 | JS::ObjectValue(*unforgeableHolder)); |
835 | 0 | } |
836 | 0 | } |
837 | | |
838 | | JSObject* |
839 | | GetConstructorObject(JSContext* aCx) |
840 | 0 | { |
841 | 0 | return GetConstructorObjectHandle(aCx); |
842 | 0 | } |
843 | | |
844 | | } // namespace FetchEvent_Binding |
845 | | |
846 | | |
847 | | |
848 | | } // namespace dom |
849 | | } // namespace mozilla |