Line data Source code
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 "nsGlobalWindow.h"
14 :
15 : namespace mozilla {
16 : namespace dom {
17 :
18 : namespace IdleDeadlineBinding {
19 :
20 : static bool
21 0 : timeRemaining(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IdleDeadline* self, const JSJitMethodCallArgs& args)
22 : {
23 0 : double result(self->TimeRemaining());
24 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
25 0 : args.rval().set(JS_NumberValue(double(result)));
26 0 : return true;
27 : }
28 :
29 : static const JSJitInfo timeRemaining_methodinfo = {
30 : { (JSJitGetterOp)timeRemaining },
31 : { prototypes::id::IdleDeadline },
32 : { PrototypeTraits<prototypes::id::IdleDeadline>::Depth },
33 : JSJitInfo::Method,
34 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
35 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
36 : true, /* isInfallible. False in setters. */
37 : false, /* isMovable. Not relevant for setters. */
38 : false, /* isEliminatable. Not relevant for setters. */
39 : false, /* isAlwaysInSlot. Only relevant for getters. */
40 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
41 : false, /* isTypedMethod. Only relevant for methods. */
42 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
43 : };
44 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
45 : static_assert(0 < 1, "There is no slot for us");
46 :
47 : static bool
48 0 : get_didTimeout(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IdleDeadline* self, JSJitGetterCallArgs args)
49 : {
50 0 : bool result(self->DidTimeout());
51 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
52 0 : args.rval().setBoolean(result);
53 0 : return true;
54 : }
55 :
56 : static const JSJitInfo didTimeout_getterinfo = {
57 : { (JSJitGetterOp)get_didTimeout },
58 : { prototypes::id::IdleDeadline },
59 : { PrototypeTraits<prototypes::id::IdleDeadline>::Depth },
60 : JSJitInfo::Getter,
61 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
62 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
63 : true, /* isInfallible. False in setters. */
64 : false, /* isMovable. Not relevant for setters. */
65 : false, /* isEliminatable. Not relevant for setters. */
66 : false, /* isAlwaysInSlot. Only relevant for getters. */
67 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
68 : false, /* isTypedMethod. Only relevant for methods. */
69 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
70 : };
71 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
72 : static_assert(0 < 1, "There is no slot for us");
73 :
74 : static bool
75 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
76 : {
77 0 : mozilla::dom::IdleDeadline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IdleDeadline>(obj);
78 : // We don't want to preserve if we don't have a wrapper, and we
79 : // obviously can't preserve if we're not initialized.
80 0 : if (self && self->GetWrapperPreserveColor()) {
81 0 : PreserveWrapper(self);
82 : }
83 0 : return true;
84 : }
85 :
86 : static void
87 0 : _finalize(js::FreeOp* fop, JSObject* obj)
88 : {
89 0 : mozilla::dom::IdleDeadline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IdleDeadline>(obj);
90 0 : if (self) {
91 0 : ClearWrapper(self, self, obj);
92 0 : AddForDeferredFinalization<mozilla::dom::IdleDeadline>(self);
93 : }
94 0 : }
95 :
96 : static void
97 0 : _objectMoved(JSObject* obj, const JSObject* old)
98 : {
99 0 : mozilla::dom::IdleDeadline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IdleDeadline>(obj);
100 0 : if (self) {
101 0 : UpdateWrapper(self, self, obj, old);
102 : }
103 0 : }
104 :
105 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
106 : #if defined(__clang__)
107 : #pragma clang diagnostic push
108 : #pragma clang diagnostic ignored "-Wmissing-braces"
109 : #endif
110 : static const JSFunctionSpec sMethods_specs[] = {
111 : JS_FNSPEC("timeRemaining", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&timeRemaining_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
112 : JS_FS_END
113 : };
114 : #if defined(__clang__)
115 : #pragma clang diagnostic pop
116 : #endif
117 :
118 :
119 : // Can't be const because the pref-enabled boolean needs to be writable
120 : static Prefable<const JSFunctionSpec> sMethods[] = {
121 : { nullptr, &sMethods_specs[0] },
122 : { nullptr, nullptr }
123 : };
124 :
125 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
126 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
127 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
128 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
129 :
130 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
131 : #if defined(__clang__)
132 : #pragma clang diagnostic push
133 : #pragma clang diagnostic ignored "-Wmissing-braces"
134 : #endif
135 : static const JSPropertySpec sAttributes_specs[] = {
136 : { "didTimeout", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &didTimeout_getterinfo, nullptr, nullptr },
137 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
138 : };
139 : #if defined(__clang__)
140 : #pragma clang diagnostic pop
141 : #endif
142 :
143 :
144 : // Can't be const because the pref-enabled boolean needs to be writable
145 : static Prefable<const JSPropertySpec> sAttributes[] = {
146 : { nullptr, &sAttributes_specs[0] },
147 : { nullptr, nullptr }
148 : };
149 :
150 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
151 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
152 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
153 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
154 :
155 :
156 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
157 : static PropertyInfo sNativeProperties_propertyInfos[2];
158 :
159 : static const NativePropertiesN<2> sNativeProperties = {
160 : false, 0,
161 : false, 0,
162 : true, 0 /* sMethods */,
163 : true, 1 /* sAttributes */,
164 : false, 0,
165 : false, 0,
166 : false, 0,
167 : -1,
168 : 2,
169 : sNativeProperties_sortedPropertyIndices,
170 : {
171 : { sMethods, &sNativeProperties_propertyInfos[0] },
172 : { sAttributes, &sNativeProperties_propertyInfos[1] }
173 : }
174 : };
175 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
176 : "We have a property info count that is oversized");
177 :
178 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
179 : {
180 : "Function",
181 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
182 : &sBoringInterfaceObjectClassClassOps,
183 : JS_NULL_CLASS_SPEC,
184 : JS_NULL_CLASS_EXT,
185 : &sInterfaceObjectClassObjectOps
186 : },
187 : eInterface,
188 : true,
189 : prototypes::id::IdleDeadline,
190 : PrototypeTraits<prototypes::id::IdleDeadline>::Depth,
191 : sNativePropertyHooks,
192 : "function IdleDeadline() {\n [native code]\n}",
193 : JS::GetRealmFunctionPrototype
194 : };
195 :
196 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
197 : {
198 : "IdleDeadlinePrototype",
199 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
200 : JS_NULL_CLASS_OPS,
201 : JS_NULL_CLASS_SPEC,
202 : JS_NULL_CLASS_EXT,
203 : JS_NULL_OBJECT_OPS
204 : },
205 : eInterfacePrototype,
206 : false,
207 : prototypes::id::IdleDeadline,
208 : PrototypeTraits<prototypes::id::IdleDeadline>::Depth,
209 : sNativePropertyHooks,
210 : "[object IdleDeadlinePrototype]",
211 : JS::GetRealmObjectPrototype
212 : };
213 :
214 : bool
215 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
216 : {
217 0 : return nsGlobalWindow::IsRequestIdleCallbackEnabled(aCx, aObj);
218 : }
219 :
220 : JSObject*
221 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
222 : {
223 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
224 : }
225 :
226 : static const js::ClassOps sClassOps = {
227 : _addProperty, /* addProperty */
228 : nullptr, /* delProperty */
229 : nullptr, /* getProperty */
230 : nullptr, /* setProperty */
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 0 : GetJSClass()
269 : {
270 0 : return sClass.ToJSClass();
271 : }
272 :
273 : bool
274 1 : Wrap(JSContext* aCx, mozilla::dom::IdleDeadline* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
275 : {
276 : MOZ_ASSERT(static_cast<mozilla::dom::IdleDeadline*>(aObject) ==
277 : reinterpret_cast<mozilla::dom::IdleDeadline*>(aObject),
278 : "Multiple inheritance for mozilla::dom::IdleDeadline is broken.");
279 1 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
280 1 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
281 1 : MOZ_ASSERT(!aCache->GetWrapper(),
282 : "You should probably not be using Wrap() directly; use "
283 : "GetOrCreateDOMReflector instead");
284 :
285 1 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
286 : "nsISupports must be on our primary inheritance chain");
287 :
288 2 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
289 1 : if (!global) {
290 0 : return false;
291 : }
292 1 : MOZ_ASSERT(JS_IsGlobalObject(global));
293 1 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
294 :
295 : // That might have ended up wrapping us already, due to the wonders
296 : // of XBL. Check for that, and bail out as needed.
297 1 : aReflector.set(aCache->GetWrapper());
298 1 : if (aReflector) {
299 : #ifdef DEBUG
300 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
301 : #endif // DEBUG
302 0 : return true;
303 : }
304 :
305 2 : JSAutoCompartment ac(aCx, global);
306 1 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
307 1 : if (!canonicalProto) {
308 0 : return false;
309 : }
310 2 : JS::Rooted<JSObject*> proto(aCx);
311 1 : if (aGivenProto) {
312 0 : proto = aGivenProto;
313 : // Unfortunately, while aGivenProto was in the compartment of aCx
314 : // coming in, we changed compartments to that of "parent" so may need
315 : // to wrap the proto here.
316 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
317 0 : if (!JS_WrapObject(aCx, &proto)) {
318 0 : return false;
319 : }
320 : }
321 : } else {
322 1 : proto = canonicalProto;
323 : }
324 :
325 2 : BindingJSObjectCreator<mozilla::dom::IdleDeadline> creator(aCx);
326 1 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
327 1 : if (!aReflector) {
328 0 : return false;
329 : }
330 :
331 1 : aCache->SetWrapper(aReflector);
332 1 : creator.InitializationSucceeded();
333 :
334 1 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
335 : aCache->GetWrapperPreserveColor() == aReflector);
336 : // If proto != canonicalProto, we have to preserve our wrapper;
337 : // otherwise we won't be able to properly recreate it later, since
338 : // we won't know what proto to use. Note that we don't check
339 : // aGivenProto here, since it's entirely possible (and even
340 : // somewhat common) to have a non-null aGivenProto which is the
341 : // same as canonicalProto.
342 1 : if (proto != canonicalProto) {
343 0 : PreserveWrapper(aObject);
344 : }
345 :
346 1 : return true;
347 : }
348 :
349 : const NativePropertyHooks sNativePropertyHooks[] = { {
350 : nullptr,
351 : nullptr,
352 : nullptr,
353 : { sNativeProperties.Upcast(), nullptr },
354 : prototypes::id::IdleDeadline,
355 : constructors::id::IdleDeadline,
356 : nullptr,
357 : &DefaultXrayExpandoObjectClass
358 : } };
359 :
360 : void
361 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
362 : {
363 2 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
364 1 : if (!parentProto) {
365 0 : return;
366 : }
367 :
368 2 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
369 1 : if (!constructorProto) {
370 0 : return;
371 : }
372 :
373 : static bool sIdsInited = false;
374 1 : if (!sIdsInited && NS_IsMainThread()) {
375 1 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
376 0 : return;
377 : }
378 1 : sIdsInited = true;
379 : }
380 :
381 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::IdleDeadline);
382 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::IdleDeadline);
383 2 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
384 : &sPrototypeClass.mBase, protoCache,
385 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
386 : interfaceCache,
387 : sNativeProperties.Upcast(),
388 : nullptr,
389 : "IdleDeadline", aDefineOnGlobal,
390 : nullptr,
391 1 : false);
392 : }
393 :
394 : JS::Handle<JSObject*>
395 1 : GetProtoObjectHandle(JSContext* aCx)
396 : {
397 : /* Get the interface prototype object for this class. This will create the
398 : object as needed. */
399 1 : bool aDefineOnGlobal = true;
400 :
401 : /* Make sure our global is sane. Hopefully we can remove this sometime */
402 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
403 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
404 0 : return nullptr;
405 : }
406 :
407 : /* Check to see whether the interface objects are already installed */
408 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
409 1 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::IdleDeadline)) {
410 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
411 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
412 : }
413 :
414 : /*
415 : * The object might _still_ be null, but that's OK.
416 : *
417 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
418 : * traced by TraceProtoAndIfaceCache() and its contents are never
419 : * changed after they have been set.
420 : *
421 : * Calling address() avoids the read read barrier that does gray
422 : * unmarking, but it's not possible for the object to be gray here.
423 : */
424 :
425 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::IdleDeadline);
426 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
427 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
428 : }
429 :
430 : JS::Handle<JSObject*>
431 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
432 : {
433 : /* Get the interface object for this class. This will create the object as
434 : needed. */
435 :
436 : /* Make sure our global is sane. Hopefully we can remove this sometime */
437 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
438 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
439 0 : return nullptr;
440 : }
441 :
442 : /* Check to see whether the interface objects are already installed */
443 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
444 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::IdleDeadline)) {
445 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
446 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
447 : }
448 :
449 : /*
450 : * The object might _still_ be null, but that's OK.
451 : *
452 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
453 : * traced by TraceProtoAndIfaceCache() and its contents are never
454 : * changed after they have been set.
455 : *
456 : * Calling address() avoids the read read barrier that does gray
457 : * unmarking, but it's not possible for the object to be gray here.
458 : */
459 :
460 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::IdleDeadline);
461 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
462 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
463 : }
464 :
465 : JSObject*
466 0 : GetConstructorObject(JSContext* aCx)
467 : {
468 0 : return GetConstructorObjectHandle(aCx);
469 : }
470 :
471 : } // namespace IdleDeadlineBinding
472 :
473 :
474 :
475 : } // namespace dom
476 : } // namespace mozilla
|