/work/obj-fuzz/dom/bindings/IdleDeadlineBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM IdleDeadline.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "IdleDeadlineBinding.h" |
4 | | #include "WrapperFactory.h" |
5 | | #include "mozilla/FloatingPoint.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/DOMJSClass.h" |
9 | | #include "mozilla/dom/IdleDeadline.h" |
10 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/PrimitiveConversions.h" |
12 | | #include "mozilla/dom/XrayExpandoClass.h" |
13 | | #include "nsGlobalWindowInner.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
19 | | using namespace mozilla::dom::binding_detail; |
20 | | |
21 | | |
22 | | namespace IdleDeadline_Binding { |
23 | | |
24 | | MOZ_CAN_RUN_SCRIPT static bool |
25 | | timeRemaining(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IdleDeadline* self, const JSJitMethodCallArgs& args) |
26 | 0 | { |
27 | 0 | AUTO_PROFILER_LABEL_FAST("IdleDeadline.timeRemaining", DOM, cx); |
28 | 0 |
|
29 | 0 | double result(self->TimeRemaining()); |
30 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
31 | 0 | args.rval().set(JS_NumberValue(double(result))); |
32 | 0 | return true; |
33 | 0 | } |
34 | | |
35 | | static const JSJitInfo timeRemaining_methodinfo = { |
36 | | { (JSJitGetterOp)timeRemaining }, |
37 | | { prototypes::id::IdleDeadline }, |
38 | | { PrototypeTraits<prototypes::id::IdleDeadline>::Depth }, |
39 | | JSJitInfo::Method, |
40 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
41 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
42 | | true, /* isInfallible. False in setters. */ |
43 | | false, /* isMovable. Not relevant for setters. */ |
44 | | false, /* isEliminatable. Not relevant for setters. */ |
45 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
46 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
47 | | false, /* isTypedMethod. Only relevant for methods. */ |
48 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
49 | | }; |
50 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
51 | | static_assert(0 < 1, "There is no slot for us"); |
52 | | |
53 | | MOZ_CAN_RUN_SCRIPT static bool |
54 | | get_didTimeout(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IdleDeadline* self, JSJitGetterCallArgs args) |
55 | 0 | { |
56 | 0 | AUTO_PROFILER_LABEL_FAST("get IdleDeadline.didTimeout", DOM, cx); |
57 | 0 |
|
58 | 0 | bool result(self->DidTimeout()); |
59 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
60 | 0 | args.rval().setBoolean(result); |
61 | 0 | return true; |
62 | 0 | } |
63 | | |
64 | | static const JSJitInfo didTimeout_getterinfo = { |
65 | | { (JSJitGetterOp)get_didTimeout }, |
66 | | { prototypes::id::IdleDeadline }, |
67 | | { PrototypeTraits<prototypes::id::IdleDeadline>::Depth }, |
68 | | JSJitInfo::Getter, |
69 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
70 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
71 | | true, /* isInfallible. False in setters. */ |
72 | | false, /* isMovable. Not relevant for setters. */ |
73 | | false, /* isEliminatable. Not relevant for setters. */ |
74 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
75 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
76 | | false, /* isTypedMethod. Only relevant for methods. */ |
77 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
78 | | }; |
79 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
80 | | static_assert(0 < 1, "There is no slot for us"); |
81 | | |
82 | | static bool |
83 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
84 | 0 | { |
85 | 0 | mozilla::dom::IdleDeadline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IdleDeadline>(obj); |
86 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
87 | 0 | // obviously can't preserve if we're not initialized. |
88 | 0 | if (self && self->GetWrapperPreserveColor()) { |
89 | 0 | PreserveWrapper(self); |
90 | 0 | } |
91 | 0 | return true; |
92 | 0 | } |
93 | | |
94 | | static void |
95 | | _finalize(js::FreeOp* fop, JSObject* obj) |
96 | 0 | { |
97 | 0 | mozilla::dom::IdleDeadline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IdleDeadline>(obj); |
98 | 0 | if (self) { |
99 | 0 | ClearWrapper(self, self, obj); |
100 | 0 | AddForDeferredFinalization<mozilla::dom::IdleDeadline>(self); |
101 | 0 | } |
102 | 0 | } |
103 | | |
104 | | static size_t |
105 | | _objectMoved(JSObject* obj, JSObject* old) |
106 | 0 | { |
107 | 0 | mozilla::dom::IdleDeadline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IdleDeadline>(obj); |
108 | 0 | if (self) { |
109 | 0 | UpdateWrapper(self, self, obj, old); |
110 | 0 | } |
111 | 0 |
|
112 | 0 | return 0; |
113 | 0 | } |
114 | | |
115 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
116 | | #if defined(__clang__) |
117 | | #pragma clang diagnostic push |
118 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
119 | | #endif |
120 | | static const JSFunctionSpec sMethods_specs[] = { |
121 | | JS_FNSPEC("timeRemaining", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&timeRemaining_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
122 | | JS_FS_END |
123 | | }; |
124 | | #if defined(__clang__) |
125 | | #pragma clang diagnostic pop |
126 | | #endif |
127 | | |
128 | | |
129 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
130 | | { nullptr, &sMethods_specs[0] }, |
131 | | { nullptr, nullptr } |
132 | | }; |
133 | | |
134 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
135 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
136 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
137 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
138 | | |
139 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
140 | | #if defined(__clang__) |
141 | | #pragma clang diagnostic push |
142 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
143 | | #endif |
144 | | static const JSPropertySpec sAttributes_specs[] = { |
145 | | { "didTimeout", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &didTimeout_getterinfo, nullptr, nullptr }, |
146 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
147 | | }; |
148 | | #if defined(__clang__) |
149 | | #pragma clang diagnostic pop |
150 | | #endif |
151 | | |
152 | | |
153 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
154 | | { nullptr, &sAttributes_specs[0] }, |
155 | | { nullptr, nullptr } |
156 | | }; |
157 | | |
158 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
159 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
160 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
161 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
162 | | |
163 | | |
164 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
165 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
166 | | |
167 | | static const NativePropertiesN<2> sNativeProperties = { |
168 | | false, 0, |
169 | | false, 0, |
170 | | true, 0 /* sMethods */, |
171 | | true, 1 /* sAttributes */, |
172 | | false, 0, |
173 | | false, 0, |
174 | | false, 0, |
175 | | -1, |
176 | | 2, |
177 | | sNativeProperties_sortedPropertyIndices, |
178 | | { |
179 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
180 | | { sAttributes, &sNativeProperties_propertyInfos[1] } |
181 | | } |
182 | | }; |
183 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
184 | | "We have a property info count that is oversized"); |
185 | | |
186 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
187 | | { |
188 | | "Function", |
189 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
190 | | &sBoringInterfaceObjectClassClassOps, |
191 | | JS_NULL_CLASS_SPEC, |
192 | | JS_NULL_CLASS_EXT, |
193 | | &sInterfaceObjectClassObjectOps |
194 | | }, |
195 | | eInterface, |
196 | | true, |
197 | | prototypes::id::IdleDeadline, |
198 | | PrototypeTraits<prototypes::id::IdleDeadline>::Depth, |
199 | | sNativePropertyHooks, |
200 | | "function IdleDeadline() {\n [native code]\n}", |
201 | | JS::GetRealmFunctionPrototype |
202 | | }; |
203 | | |
204 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
205 | | { |
206 | | "IdleDeadlinePrototype", |
207 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
208 | | JS_NULL_CLASS_OPS, |
209 | | JS_NULL_CLASS_SPEC, |
210 | | JS_NULL_CLASS_EXT, |
211 | | JS_NULL_OBJECT_OPS |
212 | | }, |
213 | | eInterfacePrototype, |
214 | | false, |
215 | | prototypes::id::IdleDeadline, |
216 | | PrototypeTraits<prototypes::id::IdleDeadline>::Depth, |
217 | | sNativePropertyHooks, |
218 | | "[object IdleDeadlinePrototype]", |
219 | | JS::GetRealmObjectPrototype |
220 | | }; |
221 | | |
222 | | bool |
223 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
224 | 0 | { |
225 | 0 | return nsGlobalWindowInner::IsRequestIdleCallbackEnabled(aCx, aObj); |
226 | 0 | } |
227 | | |
228 | | static const js::ClassOps sClassOps = { |
229 | | _addProperty, /* addProperty */ |
230 | | nullptr, /* delProperty */ |
231 | | nullptr, /* enumerate */ |
232 | | nullptr, /* newEnumerate */ |
233 | | nullptr, /* resolve */ |
234 | | nullptr, /* mayResolve */ |
235 | | _finalize, /* finalize */ |
236 | | nullptr, /* call */ |
237 | | nullptr, /* hasInstance */ |
238 | | nullptr, /* construct */ |
239 | | nullptr, /* trace */ |
240 | | }; |
241 | | |
242 | | static const js::ClassExtension sClassExtension = { |
243 | | nullptr, /* weakmapKeyDelegateOp */ |
244 | | _objectMoved /* objectMovedOp */ |
245 | | }; |
246 | | |
247 | | static const DOMJSClass sClass = { |
248 | | { "IdleDeadline", |
249 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
250 | | &sClassOps, |
251 | | JS_NULL_CLASS_SPEC, |
252 | | &sClassExtension, |
253 | | JS_NULL_OBJECT_OPS |
254 | | }, |
255 | | { prototypes::id::IdleDeadline, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
256 | | IsBaseOf<nsISupports, mozilla::dom::IdleDeadline >::value, |
257 | | sNativePropertyHooks, |
258 | | FindAssociatedGlobalForNative<mozilla::dom::IdleDeadline>::Get, |
259 | | GetProtoObjectHandle, |
260 | | GetCCParticipant<mozilla::dom::IdleDeadline>::Get() |
261 | | }; |
262 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
263 | | "Must have the right minimal number of reserved slots."); |
264 | | static_assert(1 >= 1, |
265 | | "Must have enough reserved slots."); |
266 | | |
267 | | const JSClass* |
268 | | GetJSClass() |
269 | 0 | { |
270 | 0 | return sClass.ToJSClass(); |
271 | 0 | } |
272 | | |
273 | | bool |
274 | | Wrap(JSContext* aCx, mozilla::dom::IdleDeadline* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
275 | 0 | { |
276 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::IdleDeadline>::value, |
277 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
278 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::IdleDeadline*>(aObject) == |
279 | 0 | reinterpret_cast<mozilla::dom::IdleDeadline*>(aObject), |
280 | 0 | "Multiple inheritance for mozilla::dom::IdleDeadline is broken."); |
281 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
282 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
283 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
284 | 0 | "You should probably not be using Wrap() directly; use " |
285 | 0 | "GetOrCreateDOMReflector instead"); |
286 | 0 |
|
287 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
288 | 0 | "nsISupports must be on our primary inheritance chain"); |
289 | 0 |
|
290 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
291 | 0 | if (!global) { |
292 | 0 | return false; |
293 | 0 | } |
294 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
295 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
296 | 0 |
|
297 | 0 | // That might have ended up wrapping us already, due to the wonders |
298 | 0 | // of XBL. Check for that, and bail out as needed. |
299 | 0 | aReflector.set(aCache->GetWrapper()); |
300 | 0 | if (aReflector) { |
301 | | #ifdef DEBUG |
302 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
303 | | #endif // DEBUG |
304 | | return true; |
305 | 0 | } |
306 | 0 |
|
307 | 0 | JSAutoRealm ar(aCx, global); |
308 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
309 | 0 | if (!canonicalProto) { |
310 | 0 | return false; |
311 | 0 | } |
312 | 0 | JS::Rooted<JSObject*> proto(aCx); |
313 | 0 | if (aGivenProto) { |
314 | 0 | proto = aGivenProto; |
315 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
316 | 0 | // coming in, we changed compartments to that of "parent" so may need |
317 | 0 | // to wrap the proto here. |
318 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
319 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
320 | 0 | return false; |
321 | 0 | } |
322 | 0 | } |
323 | 0 | } else { |
324 | 0 | proto = canonicalProto; |
325 | 0 | } |
326 | 0 |
|
327 | 0 | BindingJSObjectCreator<mozilla::dom::IdleDeadline> creator(aCx); |
328 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
329 | 0 | if (!aReflector) { |
330 | 0 | return false; |
331 | 0 | } |
332 | 0 | |
333 | 0 | aCache->SetWrapper(aReflector); |
334 | 0 | creator.InitializationSucceeded(); |
335 | 0 |
|
336 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
337 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
338 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
339 | 0 | // otherwise we won't be able to properly recreate it later, since |
340 | 0 | // we won't know what proto to use. Note that we don't check |
341 | 0 | // aGivenProto here, since it's entirely possible (and even |
342 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
343 | 0 | // same as canonicalProto. |
344 | 0 | if (proto != canonicalProto) { |
345 | 0 | PreserveWrapper(aObject); |
346 | 0 | } |
347 | 0 |
|
348 | 0 | return true; |
349 | 0 | } |
350 | | |
351 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
352 | | nullptr, |
353 | | nullptr, |
354 | | nullptr, |
355 | | { sNativeProperties.Upcast(), nullptr }, |
356 | | prototypes::id::IdleDeadline, |
357 | | constructors::id::IdleDeadline, |
358 | | nullptr, |
359 | | &DefaultXrayExpandoObjectClass |
360 | | } }; |
361 | | |
362 | | void |
363 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
364 | 0 | { |
365 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
366 | 0 | if (!parentProto) { |
367 | 0 | return; |
368 | 0 | } |
369 | 0 | |
370 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
371 | 0 | if (!constructorProto) { |
372 | 0 | return; |
373 | 0 | } |
374 | 0 | |
375 | 0 | static bool sIdsInited = false; |
376 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
377 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
378 | 0 | return; |
379 | 0 | } |
380 | 0 | sIdsInited = true; |
381 | 0 | } |
382 | 0 |
|
383 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::IdleDeadline); |
384 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::IdleDeadline); |
385 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
386 | 0 | &sPrototypeClass.mBase, protoCache, |
387 | 0 | nullptr, |
388 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
389 | 0 | interfaceCache, |
390 | 0 | sNativeProperties.Upcast(), |
391 | 0 | nullptr, |
392 | 0 | "IdleDeadline", aDefineOnGlobal, |
393 | 0 | nullptr, |
394 | 0 | false); |
395 | 0 | } |
396 | | |
397 | | JSObject* |
398 | | GetConstructorObject(JSContext* aCx) |
399 | 0 | { |
400 | 0 | return GetConstructorObjectHandle(aCx); |
401 | 0 | } |
402 | | |
403 | | } // namespace IdleDeadline_Binding |
404 | | |
405 | | |
406 | | |
407 | | } // namespace dom |
408 | | } // namespace mozilla |