/work/obj-fuzz/dom/bindings/PresentationRequestBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM PresentationRequest.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "EventHandlerBinding.h" |
4 | | #include "EventTargetBinding.h" |
5 | | #include "PresentationRequestBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/Preferences.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/DOMJSClass.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/Nullable.h" |
13 | | #include "mozilla/dom/PresentationRequest.h" |
14 | | #include "mozilla/dom/Promise.h" |
15 | | #include "mozilla/dom/ToJSValue.h" |
16 | | #include "mozilla/dom/XrayExpandoClass.h" |
17 | | #include "nsContentUtils.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 | | namespace PresentationRequest_Binding { |
27 | | |
28 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
29 | | "Can't inherit from an interface with a different ownership model."); |
30 | | |
31 | | MOZ_CAN_RUN_SCRIPT static bool |
32 | | start(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationRequest* self, const JSJitMethodCallArgs& args) |
33 | 0 | { |
34 | 0 | AUTO_PROFILER_LABEL_FAST("PresentationRequest.start", DOM, cx); |
35 | 0 |
|
36 | 0 | FastErrorResult rv; |
37 | 0 | auto result(StrongOrRawPtr<Promise>(self->Start(rv))); |
38 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
39 | 0 | return false; |
40 | 0 | } |
41 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
42 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
43 | 0 | return false; |
44 | 0 | } |
45 | 0 | return true; |
46 | 0 | } |
47 | | |
48 | | MOZ_CAN_RUN_SCRIPT static bool |
49 | | start_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationRequest* self, const JSJitMethodCallArgs& args) |
50 | 0 | { |
51 | 0 | bool ok = start(cx, obj, self, args); |
52 | 0 | if (ok) { |
53 | 0 | return true; |
54 | 0 | } |
55 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
56 | 0 | } |
57 | | |
58 | | static const JSJitInfo start_methodinfo = { |
59 | | { (JSJitGetterOp)start_promiseWrapper }, |
60 | | { prototypes::id::PresentationRequest }, |
61 | | { PrototypeTraits<prototypes::id::PresentationRequest>::Depth }, |
62 | | JSJitInfo::Method, |
63 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
64 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
65 | | false, /* isInfallible. False in setters. */ |
66 | | false, /* isMovable. Not relevant for setters. */ |
67 | | false, /* isEliminatable. Not relevant for setters. */ |
68 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
69 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
70 | | false, /* isTypedMethod. Only relevant for methods. */ |
71 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
72 | | }; |
73 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
74 | | static_assert(0 < 1, "There is no slot for us"); |
75 | | |
76 | | MOZ_CAN_RUN_SCRIPT static bool |
77 | | reconnect(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationRequest* self, const JSJitMethodCallArgs& args) |
78 | 0 | { |
79 | 0 | AUTO_PROFILER_LABEL_FAST("PresentationRequest.reconnect", DOM, cx); |
80 | 0 |
|
81 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
82 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PresentationRequest.reconnect"); |
83 | 0 | } |
84 | 0 | binding_detail::FakeString arg0; |
85 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
86 | 0 | return false; |
87 | 0 | } |
88 | 0 | FastErrorResult rv; |
89 | 0 | auto result(StrongOrRawPtr<Promise>(self->Reconnect(NonNullHelper(Constify(arg0)), rv))); |
90 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
91 | 0 | return false; |
92 | 0 | } |
93 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
94 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
95 | 0 | return false; |
96 | 0 | } |
97 | 0 | return true; |
98 | 0 | } |
99 | | |
100 | | MOZ_CAN_RUN_SCRIPT static bool |
101 | | reconnect_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationRequest* self, const JSJitMethodCallArgs& args) |
102 | 0 | { |
103 | 0 | bool ok = reconnect(cx, obj, self, args); |
104 | 0 | if (ok) { |
105 | 0 | return true; |
106 | 0 | } |
107 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
108 | 0 | } |
109 | | |
110 | | static const JSJitInfo reconnect_methodinfo = { |
111 | | { (JSJitGetterOp)reconnect_promiseWrapper }, |
112 | | { prototypes::id::PresentationRequest }, |
113 | | { PrototypeTraits<prototypes::id::PresentationRequest>::Depth }, |
114 | | JSJitInfo::Method, |
115 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
116 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
117 | | false, /* isInfallible. False in setters. */ |
118 | | false, /* isMovable. Not relevant for setters. */ |
119 | | false, /* isEliminatable. Not relevant for setters. */ |
120 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
121 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
122 | | false, /* isTypedMethod. Only relevant for methods. */ |
123 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
124 | | }; |
125 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
126 | | static_assert(0 < 1, "There is no slot for us"); |
127 | | |
128 | | MOZ_CAN_RUN_SCRIPT static bool |
129 | | getAvailability(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationRequest* self, const JSJitMethodCallArgs& args) |
130 | 0 | { |
131 | 0 | AUTO_PROFILER_LABEL_FAST("PresentationRequest.getAvailability", DOM, cx); |
132 | 0 |
|
133 | 0 | FastErrorResult rv; |
134 | 0 | auto result(StrongOrRawPtr<Promise>(self->GetAvailability(rv))); |
135 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
136 | 0 | return false; |
137 | 0 | } |
138 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
139 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
140 | 0 | return false; |
141 | 0 | } |
142 | 0 | return true; |
143 | 0 | } |
144 | | |
145 | | MOZ_CAN_RUN_SCRIPT static bool |
146 | | getAvailability_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationRequest* self, const JSJitMethodCallArgs& args) |
147 | 0 | { |
148 | 0 | bool ok = getAvailability(cx, obj, self, args); |
149 | 0 | if (ok) { |
150 | 0 | return true; |
151 | 0 | } |
152 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
153 | 0 | } |
154 | | |
155 | | static const JSJitInfo getAvailability_methodinfo = { |
156 | | { (JSJitGetterOp)getAvailability_promiseWrapper }, |
157 | | { prototypes::id::PresentationRequest }, |
158 | | { PrototypeTraits<prototypes::id::PresentationRequest>::Depth }, |
159 | | JSJitInfo::Method, |
160 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
161 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
162 | | false, /* isInfallible. False in setters. */ |
163 | | false, /* isMovable. Not relevant for setters. */ |
164 | | false, /* isEliminatable. Not relevant for setters. */ |
165 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
166 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
167 | | false, /* isTypedMethod. Only relevant for methods. */ |
168 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
169 | | }; |
170 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
171 | | static_assert(0 < 1, "There is no slot for us"); |
172 | | |
173 | | MOZ_CAN_RUN_SCRIPT static bool |
174 | | get_onconnectionavailable(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationRequest* self, JSJitGetterCallArgs args) |
175 | 0 | { |
176 | 0 | AUTO_PROFILER_LABEL_FAST("get PresentationRequest.onconnectionavailable", DOM, cx); |
177 | 0 |
|
178 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnconnectionavailable()); |
179 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
180 | 0 | if (result) { |
181 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
182 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
183 | 0 | return false; |
184 | 0 | } |
185 | 0 | return true; |
186 | 0 | } else { |
187 | 0 | args.rval().setNull(); |
188 | 0 | return true; |
189 | 0 | } |
190 | 0 | } |
191 | | |
192 | | MOZ_CAN_RUN_SCRIPT static bool |
193 | | set_onconnectionavailable(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationRequest* self, JSJitSetterCallArgs args) |
194 | 0 | { |
195 | 0 | AUTO_PROFILER_LABEL_FAST("set PresentationRequest.onconnectionavailable", DOM, cx); |
196 | 0 |
|
197 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
198 | 0 | if (args[0].isObject()) { |
199 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
200 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
201 | 0 | } |
202 | 0 | } else { |
203 | 0 | arg0 = nullptr; |
204 | 0 | } |
205 | 0 | self->SetOnconnectionavailable(Constify(arg0)); |
206 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
207 | 0 |
|
208 | 0 | return true; |
209 | 0 | } |
210 | | |
211 | | static const JSJitInfo onconnectionavailable_getterinfo = { |
212 | | { (JSJitGetterOp)get_onconnectionavailable }, |
213 | | { prototypes::id::PresentationRequest }, |
214 | | { PrototypeTraits<prototypes::id::PresentationRequest>::Depth }, |
215 | | JSJitInfo::Getter, |
216 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
217 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
218 | | false, /* isInfallible. False in setters. */ |
219 | | false, /* isMovable. Not relevant for setters. */ |
220 | | false, /* isEliminatable. Not relevant for setters. */ |
221 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
222 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
223 | | false, /* isTypedMethod. Only relevant for methods. */ |
224 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
225 | | }; |
226 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
227 | | static_assert(0 < 1, "There is no slot for us"); |
228 | | static const JSJitInfo onconnectionavailable_setterinfo = { |
229 | | { (JSJitGetterOp)set_onconnectionavailable }, |
230 | | { prototypes::id::PresentationRequest }, |
231 | | { PrototypeTraits<prototypes::id::PresentationRequest>::Depth }, |
232 | | JSJitInfo::Setter, |
233 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
234 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
235 | | false, /* isInfallible. False in setters. */ |
236 | | false, /* isMovable. Not relevant for setters. */ |
237 | | false, /* isEliminatable. Not relevant for setters. */ |
238 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
239 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
240 | | false, /* isTypedMethod. Only relevant for methods. */ |
241 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
242 | | }; |
243 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
244 | | static_assert(0 < 1, "There is no slot for us"); |
245 | | |
246 | | MOZ_CAN_RUN_SCRIPT static bool |
247 | | startWithDevice(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationRequest* self, const JSJitMethodCallArgs& args) |
248 | 0 | { |
249 | 0 | AUTO_PROFILER_LABEL_FAST("PresentationRequest.startWithDevice", DOM, cx); |
250 | 0 |
|
251 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
252 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PresentationRequest.startWithDevice"); |
253 | 0 | } |
254 | 0 | binding_detail::FakeString arg0; |
255 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
256 | 0 | return false; |
257 | 0 | } |
258 | 0 | FastErrorResult rv; |
259 | 0 | auto result(StrongOrRawPtr<Promise>(self->StartWithDevice(NonNullHelper(Constify(arg0)), rv))); |
260 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
261 | 0 | return false; |
262 | 0 | } |
263 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
264 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
265 | 0 | return false; |
266 | 0 | } |
267 | 0 | return true; |
268 | 0 | } |
269 | | |
270 | | MOZ_CAN_RUN_SCRIPT static bool |
271 | | startWithDevice_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationRequest* self, const JSJitMethodCallArgs& args) |
272 | 0 | { |
273 | 0 | bool ok = startWithDevice(cx, obj, self, args); |
274 | 0 | if (ok) { |
275 | 0 | return true; |
276 | 0 | } |
277 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
278 | 0 | } |
279 | | |
280 | | static const JSJitInfo startWithDevice_methodinfo = { |
281 | | { (JSJitGetterOp)startWithDevice_promiseWrapper }, |
282 | | { prototypes::id::PresentationRequest }, |
283 | | { PrototypeTraits<prototypes::id::PresentationRequest>::Depth }, |
284 | | JSJitInfo::Method, |
285 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
286 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
287 | | false, /* isInfallible. False in setters. */ |
288 | | false, /* isMovable. Not relevant for setters. */ |
289 | | false, /* isEliminatable. Not relevant for setters. */ |
290 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
291 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
292 | | false, /* isTypedMethod. Only relevant for methods. */ |
293 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
294 | | }; |
295 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
296 | | static_assert(0 < 1, "There is no slot for us"); |
297 | | |
298 | | static bool |
299 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
300 | 0 | { |
301 | 0 | mozilla::dom::PresentationRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PresentationRequest>(obj); |
302 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
303 | 0 | // obviously can't preserve if we're not initialized. |
304 | 0 | if (self && self->GetWrapperPreserveColor()) { |
305 | 0 | PreserveWrapper(self); |
306 | 0 | } |
307 | 0 | return true; |
308 | 0 | } |
309 | | |
310 | | static void |
311 | | _finalize(js::FreeOp* fop, JSObject* obj) |
312 | 0 | { |
313 | 0 | mozilla::dom::PresentationRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PresentationRequest>(obj); |
314 | 0 | if (self) { |
315 | 0 | ClearWrapper(self, self, obj); |
316 | 0 | AddForDeferredFinalization<mozilla::dom::PresentationRequest>(self); |
317 | 0 | } |
318 | 0 | } |
319 | | |
320 | | static size_t |
321 | | _objectMoved(JSObject* obj, JSObject* old) |
322 | 0 | { |
323 | 0 | mozilla::dom::PresentationRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PresentationRequest>(obj); |
324 | 0 | if (self) { |
325 | 0 | UpdateWrapper(self, self, obj, old); |
326 | 0 | } |
327 | 0 |
|
328 | 0 | return 0; |
329 | 0 | } |
330 | | |
331 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
332 | | #if defined(__clang__) |
333 | | #pragma clang diagnostic push |
334 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
335 | | #endif |
336 | | static const JSFunctionSpec sMethods_specs[] = { |
337 | | JS_FNSPEC("start", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&start_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
338 | | JS_FNSPEC("reconnect", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&reconnect_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
339 | | JS_FNSPEC("getAvailability", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&getAvailability_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
340 | | JS_FS_END |
341 | | }; |
342 | | #if defined(__clang__) |
343 | | #pragma clang diagnostic pop |
344 | | #endif |
345 | | |
346 | | |
347 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
348 | | { nullptr, &sMethods_specs[0] }, |
349 | | { nullptr, nullptr } |
350 | | }; |
351 | | |
352 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
353 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
354 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
355 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
356 | | |
357 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
358 | | #if defined(__clang__) |
359 | | #pragma clang diagnostic push |
360 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
361 | | #endif |
362 | | static const JSFunctionSpec sChromeMethods_specs[] = { |
363 | | JS_FNSPEC("startWithDevice", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&startWithDevice_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
364 | | JS_FS_END |
365 | | }; |
366 | | #if defined(__clang__) |
367 | | #pragma clang diagnostic pop |
368 | | #endif |
369 | | |
370 | | |
371 | | static const Prefable<const JSFunctionSpec> sChromeMethods[] = { |
372 | | { nullptr, &sChromeMethods_specs[0] }, |
373 | | { nullptr, nullptr } |
374 | | }; |
375 | | |
376 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
377 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
378 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
379 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
380 | | |
381 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
382 | | #if defined(__clang__) |
383 | | #pragma clang diagnostic push |
384 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
385 | | #endif |
386 | | static const JSPropertySpec sAttributes_specs[] = { |
387 | | { "onconnectionavailable", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onconnectionavailable_getterinfo, GenericSetter<NormalThisPolicy>, &onconnectionavailable_setterinfo }, |
388 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
389 | | }; |
390 | | #if defined(__clang__) |
391 | | #pragma clang diagnostic pop |
392 | | #endif |
393 | | |
394 | | |
395 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
396 | | { nullptr, &sAttributes_specs[0] }, |
397 | | { nullptr, nullptr } |
398 | | }; |
399 | | |
400 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
401 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
402 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
403 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
404 | | |
405 | | |
406 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
407 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
408 | | |
409 | | static const NativePropertiesN<2> sNativeProperties = { |
410 | | false, 0, |
411 | | false, 0, |
412 | | true, 0 /* sMethods */, |
413 | | true, 1 /* sAttributes */, |
414 | | false, 0, |
415 | | false, 0, |
416 | | false, 0, |
417 | | -1, |
418 | | 4, |
419 | | sNativeProperties_sortedPropertyIndices, |
420 | | { |
421 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
422 | | { sAttributes, &sNativeProperties_propertyInfos[3] } |
423 | | } |
424 | | }; |
425 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
426 | | "We have a property info count that is oversized"); |
427 | | |
428 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1]; |
429 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1]; |
430 | | |
431 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
432 | | false, 0, |
433 | | false, 0, |
434 | | true, 0 /* sChromeMethods */, |
435 | | false, 0, |
436 | | false, 0, |
437 | | false, 0, |
438 | | false, 0, |
439 | | -1, |
440 | | 1, |
441 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
442 | | { |
443 | | { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] } |
444 | | } |
445 | | }; |
446 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
447 | | "We have a property info count that is oversized"); |
448 | | |
449 | | static bool |
450 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
451 | 0 | { |
452 | 0 | AUTO_PROFILER_LABEL_FAST("PresentationRequest constructor", DOM, cx); |
453 | 0 |
|
454 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
455 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
456 | 0 | if (!args.isConstructing()) { |
457 | 0 | // XXXbz wish I could get the name from the callee instead of |
458 | 0 | // Adding more relocations |
459 | 0 | return ThrowConstructorWithoutNew(cx, "PresentationRequest"); |
460 | 0 | } |
461 | 0 | |
462 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
463 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
464 | 0 | return false; |
465 | 0 | } |
466 | 0 | |
467 | 0 | unsigned argcount = std::min(args.length(), 1u); |
468 | 0 | switch (argcount) { |
469 | 0 | case 1: { |
470 | 0 | if (args[0].isObject()) { |
471 | 0 | do { |
472 | 0 | binding_detail::AutoSequence<nsString> arg0; |
473 | 0 | JS::ForOfIterator iter(cx); |
474 | 0 | if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) { |
475 | 0 | return false; |
476 | 0 | } |
477 | 0 | if (!iter.valueIsIterable()) { |
478 | 0 | break; |
479 | 0 | } |
480 | 0 | binding_detail::AutoSequence<nsString> &arr = arg0; |
481 | 0 | JS::Rooted<JS::Value> temp(cx); |
482 | 0 | while (true) { |
483 | 0 | bool done; |
484 | 0 | if (!iter.next(&temp, &done)) { |
485 | 0 | return false; |
486 | 0 | } |
487 | 0 | if (done) { |
488 | 0 | break; |
489 | 0 | } |
490 | 0 | nsString* slotPtr = arr.AppendElement(mozilla::fallible); |
491 | 0 | if (!slotPtr) { |
492 | 0 | JS_ReportOutOfMemory(cx); |
493 | 0 | return false; |
494 | 0 | } |
495 | 0 | nsString& slot = *slotPtr; |
496 | 0 | if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) { |
497 | 0 | return false; |
498 | 0 | } |
499 | 0 | } |
500 | 0 | GlobalObject global(cx, obj); |
501 | 0 | if (global.Failed()) { |
502 | 0 | return false; |
503 | 0 | } |
504 | 0 | |
505 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
506 | 0 | Maybe<JSAutoRealm> ar; |
507 | 0 | if (objIsXray) { |
508 | 0 | obj = js::CheckedUnwrap(obj); |
509 | 0 | if (!obj) { |
510 | 0 | return false; |
511 | 0 | } |
512 | 0 | ar.emplace(cx, obj); |
513 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
514 | 0 | return false; |
515 | 0 | } |
516 | 0 | } |
517 | 0 | FastErrorResult rv; |
518 | 0 | auto result(StrongOrRawPtr<mozilla::dom::PresentationRequest>(mozilla::dom::PresentationRequest::Constructor(global, Constify(arg0), rv))); |
519 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
520 | 0 | return false; |
521 | 0 | } |
522 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
523 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
524 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
525 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
526 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
527 | 0 | return false; |
528 | 0 | } |
529 | 0 | return true; |
530 | 0 | } while (false); |
531 | 0 | } |
532 | 0 | GlobalObject global(cx, obj); |
533 | 0 | if (global.Failed()) { |
534 | 0 | return false; |
535 | 0 | } |
536 | 0 | |
537 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
538 | 0 | binding_detail::FakeString arg0; |
539 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
540 | 0 | return false; |
541 | 0 | } |
542 | 0 | Maybe<JSAutoRealm> ar; |
543 | 0 | if (objIsXray) { |
544 | 0 | obj = js::CheckedUnwrap(obj); |
545 | 0 | if (!obj) { |
546 | 0 | return false; |
547 | 0 | } |
548 | 0 | ar.emplace(cx, obj); |
549 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
550 | 0 | return false; |
551 | 0 | } |
552 | 0 | } |
553 | 0 | FastErrorResult rv; |
554 | 0 | auto result(StrongOrRawPtr<mozilla::dom::PresentationRequest>(mozilla::dom::PresentationRequest::Constructor(global, NonNullHelper(Constify(arg0)), rv))); |
555 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
556 | 0 | return false; |
557 | 0 | } |
558 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
559 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
560 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
561 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
562 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
563 | 0 | return false; |
564 | 0 | } |
565 | 0 | return true; |
566 | 0 | break; |
567 | 0 | } |
568 | 0 | default: { |
569 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PresentationRequest"); |
570 | 0 | break; |
571 | 0 | } |
572 | 0 | } |
573 | 0 | MOZ_CRASH("We have an always-returning default case"); |
574 | 0 | return false; |
575 | 0 | } |
576 | | |
577 | | static const js::ClassOps sInterfaceObjectClassOps = { |
578 | | nullptr, /* addProperty */ |
579 | | nullptr, /* delProperty */ |
580 | | nullptr, /* enumerate */ |
581 | | nullptr, /* newEnumerate */ |
582 | | nullptr, /* resolve */ |
583 | | nullptr, /* mayResolve */ |
584 | | nullptr, /* finalize */ |
585 | | _constructor, /* call */ |
586 | | nullptr, /* hasInstance */ |
587 | | _constructor, /* construct */ |
588 | | nullptr, /* trace */ |
589 | | }; |
590 | | |
591 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
592 | | { |
593 | | "Function", |
594 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
595 | | &sInterfaceObjectClassOps, |
596 | | JS_NULL_CLASS_SPEC, |
597 | | JS_NULL_CLASS_EXT, |
598 | | &sInterfaceObjectClassObjectOps |
599 | | }, |
600 | | eInterface, |
601 | | true, |
602 | | prototypes::id::PresentationRequest, |
603 | | PrototypeTraits<prototypes::id::PresentationRequest>::Depth, |
604 | | sNativePropertyHooks, |
605 | | "function PresentationRequest() {\n [native code]\n}", |
606 | | EventTarget_Binding::GetConstructorObject |
607 | | }; |
608 | | |
609 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
610 | | { |
611 | | "PresentationRequestPrototype", |
612 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
613 | | JS_NULL_CLASS_OPS, |
614 | | JS_NULL_CLASS_SPEC, |
615 | | JS_NULL_CLASS_EXT, |
616 | | JS_NULL_OBJECT_OPS |
617 | | }, |
618 | | eInterfacePrototype, |
619 | | false, |
620 | | prototypes::id::PresentationRequest, |
621 | | PrototypeTraits<prototypes::id::PresentationRequest>::Depth, |
622 | | sNativePropertyHooks, |
623 | | "[object PresentationRequestPrototype]", |
624 | | EventTarget_Binding::GetProtoObject |
625 | | }; |
626 | | |
627 | | bool |
628 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
629 | 0 | { |
630 | 0 | static bool sPrefValue; |
631 | 0 | static bool sPrefCacheSetUp = false; |
632 | 0 | if (!sPrefCacheSetUp) { |
633 | 0 | sPrefCacheSetUp = true; |
634 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.presentation.controller.enabled"); |
635 | 0 | } |
636 | 0 |
|
637 | 0 | return sPrefValue; |
638 | 0 | } |
639 | | |
640 | | static const js::ClassOps sClassOps = { |
641 | | _addProperty, /* addProperty */ |
642 | | nullptr, /* delProperty */ |
643 | | nullptr, /* enumerate */ |
644 | | nullptr, /* newEnumerate */ |
645 | | nullptr, /* resolve */ |
646 | | nullptr, /* mayResolve */ |
647 | | _finalize, /* finalize */ |
648 | | nullptr, /* call */ |
649 | | nullptr, /* hasInstance */ |
650 | | nullptr, /* construct */ |
651 | | nullptr, /* trace */ |
652 | | }; |
653 | | |
654 | | static const js::ClassExtension sClassExtension = { |
655 | | nullptr, /* weakmapKeyDelegateOp */ |
656 | | _objectMoved /* objectMovedOp */ |
657 | | }; |
658 | | |
659 | | static const DOMJSClass sClass = { |
660 | | { "PresentationRequest", |
661 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
662 | | &sClassOps, |
663 | | JS_NULL_CLASS_SPEC, |
664 | | &sClassExtension, |
665 | | JS_NULL_OBJECT_OPS |
666 | | }, |
667 | | { prototypes::id::EventTarget, prototypes::id::PresentationRequest, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
668 | | IsBaseOf<nsISupports, mozilla::dom::PresentationRequest >::value, |
669 | | sNativePropertyHooks, |
670 | | FindAssociatedGlobalForNative<mozilla::dom::PresentationRequest>::Get, |
671 | | GetProtoObjectHandle, |
672 | | GetCCParticipant<mozilla::dom::PresentationRequest>::Get() |
673 | | }; |
674 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
675 | | "Must have the right minimal number of reserved slots."); |
676 | | static_assert(1 >= 1, |
677 | | "Must have enough reserved slots."); |
678 | | |
679 | | const JSClass* |
680 | | GetJSClass() |
681 | 0 | { |
682 | 0 | return sClass.ToJSClass(); |
683 | 0 | } |
684 | | |
685 | | bool |
686 | | Wrap(JSContext* aCx, mozilla::dom::PresentationRequest* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
687 | 0 | { |
688 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::PresentationRequest>::value, |
689 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
690 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::PresentationRequest*>(aObject) == |
691 | 0 | reinterpret_cast<mozilla::dom::PresentationRequest*>(aObject), |
692 | 0 | "Multiple inheritance for mozilla::dom::PresentationRequest is broken."); |
693 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
694 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
695 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
696 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
697 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
698 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
699 | 0 | "You should probably not be using Wrap() directly; use " |
700 | 0 | "GetOrCreateDOMReflector instead"); |
701 | 0 |
|
702 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
703 | 0 | "nsISupports must be on our primary inheritance chain"); |
704 | 0 |
|
705 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
706 | 0 | if (!global) { |
707 | 0 | return false; |
708 | 0 | } |
709 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
710 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
711 | 0 |
|
712 | 0 | // That might have ended up wrapping us already, due to the wonders |
713 | 0 | // of XBL. Check for that, and bail out as needed. |
714 | 0 | aReflector.set(aCache->GetWrapper()); |
715 | 0 | if (aReflector) { |
716 | | #ifdef DEBUG |
717 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
718 | | #endif // DEBUG |
719 | | return true; |
720 | 0 | } |
721 | 0 |
|
722 | 0 | JSAutoRealm ar(aCx, global); |
723 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
724 | 0 | if (!canonicalProto) { |
725 | 0 | return false; |
726 | 0 | } |
727 | 0 | JS::Rooted<JSObject*> proto(aCx); |
728 | 0 | if (aGivenProto) { |
729 | 0 | proto = aGivenProto; |
730 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
731 | 0 | // coming in, we changed compartments to that of "parent" so may need |
732 | 0 | // to wrap the proto here. |
733 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
734 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
735 | 0 | return false; |
736 | 0 | } |
737 | 0 | } |
738 | 0 | } else { |
739 | 0 | proto = canonicalProto; |
740 | 0 | } |
741 | 0 |
|
742 | 0 | BindingJSObjectCreator<mozilla::dom::PresentationRequest> creator(aCx); |
743 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
744 | 0 | if (!aReflector) { |
745 | 0 | return false; |
746 | 0 | } |
747 | 0 | |
748 | 0 | aCache->SetWrapper(aReflector); |
749 | 0 | creator.InitializationSucceeded(); |
750 | 0 |
|
751 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
752 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
753 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
754 | 0 | // otherwise we won't be able to properly recreate it later, since |
755 | 0 | // we won't know what proto to use. Note that we don't check |
756 | 0 | // aGivenProto here, since it's entirely possible (and even |
757 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
758 | 0 | // same as canonicalProto. |
759 | 0 | if (proto != canonicalProto) { |
760 | 0 | PreserveWrapper(aObject); |
761 | 0 | } |
762 | 0 |
|
763 | 0 | return true; |
764 | 0 | } |
765 | | |
766 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
767 | | nullptr, |
768 | | nullptr, |
769 | | nullptr, |
770 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
771 | | prototypes::id::PresentationRequest, |
772 | | constructors::id::PresentationRequest, |
773 | | EventTarget_Binding::sNativePropertyHooks, |
774 | | &DefaultXrayExpandoObjectClass |
775 | | } }; |
776 | | |
777 | | void |
778 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
779 | 0 | { |
780 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
781 | 0 | if (!parentProto) { |
782 | 0 | return; |
783 | 0 | } |
784 | 0 | |
785 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
786 | 0 | if (!constructorProto) { |
787 | 0 | return; |
788 | 0 | } |
789 | 0 | |
790 | 0 | static bool sIdsInited = false; |
791 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
792 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
793 | 0 | return; |
794 | 0 | } |
795 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
796 | 0 | return; |
797 | 0 | } |
798 | 0 | sIdsInited = true; |
799 | 0 | } |
800 | 0 |
|
801 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PresentationRequest); |
802 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PresentationRequest); |
803 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
804 | 0 | &sPrototypeClass.mBase, protoCache, |
805 | 0 | nullptr, |
806 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr, |
807 | 0 | interfaceCache, |
808 | 0 | sNativeProperties.Upcast(), |
809 | 0 | sChromeOnlyNativeProperties.Upcast(), |
810 | 0 | "PresentationRequest", aDefineOnGlobal, |
811 | 0 | nullptr, |
812 | 0 | false); |
813 | 0 | } |
814 | | |
815 | | JSObject* |
816 | | GetConstructorObject(JSContext* aCx) |
817 | 0 | { |
818 | 0 | return GetConstructorObjectHandle(aCx); |
819 | 0 | } |
820 | | |
821 | | } // namespace PresentationRequest_Binding |
822 | | |
823 | | |
824 | | |
825 | | } // namespace dom |
826 | | } // namespace mozilla |