Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM BatteryManager.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "BatteryManager.h"
4 : #include "BatteryManagerBinding.h"
5 : #include "EventHandlerBinding.h"
6 : #include "EventTargetBinding.h"
7 : #include "WrapperFactory.h"
8 : #include "mozilla/FloatingPoint.h"
9 : #include "mozilla/OwningNonNull.h"
10 : #include "mozilla/dom/BindingUtils.h"
11 : #include "mozilla/dom/DOMJSClass.h"
12 : #include "mozilla/dom/NonRefcountedDOMObject.h"
13 : #include "mozilla/dom/Nullable.h"
14 : #include "mozilla/dom/PrimitiveConversions.h"
15 : #include "mozilla/dom/XrayExpandoClass.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 : namespace BatteryManagerBinding {
21 :
22 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTargetBinding::NativeType>::value,
23 : "Can't inherit from an interface with a different ownership model.");
24 :
25 : static bool
26 0 : get_charging(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitGetterCallArgs args)
27 : {
28 0 : bool result(self->Charging());
29 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
30 0 : args.rval().setBoolean(result);
31 0 : return true;
32 : }
33 :
34 : static const JSJitInfo charging_getterinfo = {
35 : { (JSJitGetterOp)get_charging },
36 : { prototypes::id::BatteryManager },
37 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
38 : JSJitInfo::Getter,
39 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
40 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
41 : true, /* isInfallible. False in setters. */
42 : false, /* isMovable. Not relevant for setters. */
43 : false, /* isEliminatable. Not relevant for setters. */
44 : false, /* isAlwaysInSlot. Only relevant for getters. */
45 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
46 : false, /* isTypedMethod. Only relevant for methods. */
47 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
48 : };
49 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
50 : static_assert(0 < 1, "There is no slot for us");
51 :
52 : static bool
53 0 : get_chargingTime(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitGetterCallArgs args)
54 : {
55 0 : double result(self->ChargingTime());
56 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
57 0 : args.rval().set(JS_NumberValue(double(result)));
58 0 : return true;
59 : }
60 :
61 : static const JSJitInfo chargingTime_getterinfo = {
62 : { (JSJitGetterOp)get_chargingTime },
63 : { prototypes::id::BatteryManager },
64 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
65 : JSJitInfo::Getter,
66 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
67 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
68 : true, /* isInfallible. False in setters. */
69 : false, /* isMovable. Not relevant for setters. */
70 : false, /* isEliminatable. Not relevant for setters. */
71 : false, /* isAlwaysInSlot. Only relevant for getters. */
72 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
73 : false, /* isTypedMethod. Only relevant for methods. */
74 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
75 : };
76 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
77 : static_assert(0 < 1, "There is no slot for us");
78 :
79 : static bool
80 0 : get_dischargingTime(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitGetterCallArgs args)
81 : {
82 0 : double result(self->DischargingTime());
83 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
84 0 : args.rval().set(JS_NumberValue(double(result)));
85 0 : return true;
86 : }
87 :
88 : static const JSJitInfo dischargingTime_getterinfo = {
89 : { (JSJitGetterOp)get_dischargingTime },
90 : { prototypes::id::BatteryManager },
91 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
92 : JSJitInfo::Getter,
93 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
94 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
95 : true, /* isInfallible. False in setters. */
96 : false, /* isMovable. Not relevant for setters. */
97 : false, /* isEliminatable. Not relevant for setters. */
98 : false, /* isAlwaysInSlot. Only relevant for getters. */
99 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
100 : false, /* isTypedMethod. Only relevant for methods. */
101 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
102 : };
103 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
104 : static_assert(0 < 1, "There is no slot for us");
105 :
106 : static bool
107 0 : get_level(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitGetterCallArgs args)
108 : {
109 0 : double result(self->Level());
110 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
111 0 : args.rval().set(JS_NumberValue(double(result)));
112 0 : return true;
113 : }
114 :
115 : static const JSJitInfo level_getterinfo = {
116 : { (JSJitGetterOp)get_level },
117 : { prototypes::id::BatteryManager },
118 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
119 : JSJitInfo::Getter,
120 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
121 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
122 : true, /* isInfallible. False in setters. */
123 : false, /* isMovable. Not relevant for setters. */
124 : false, /* isEliminatable. Not relevant for setters. */
125 : false, /* isAlwaysInSlot. Only relevant for getters. */
126 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
127 : false, /* isTypedMethod. Only relevant for methods. */
128 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
129 : };
130 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
131 : static_assert(0 < 1, "There is no slot for us");
132 :
133 : static bool
134 0 : get_onchargingchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitGetterCallArgs args)
135 : {
136 0 : RefPtr<EventHandlerNonNull> result(self->GetOnchargingchange());
137 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
138 0 : if (result) {
139 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
140 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
141 0 : return false;
142 : }
143 0 : return true;
144 : } else {
145 0 : args.rval().setNull();
146 0 : return true;
147 : }
148 : }
149 :
150 : static bool
151 0 : set_onchargingchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitSetterCallArgs args)
152 : {
153 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
154 0 : if (args[0].isObject()) {
155 : { // scope for tempRoot
156 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
157 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
158 : }
159 : } else {
160 0 : arg0 = nullptr;
161 : }
162 0 : self->SetOnchargingchange(Constify(arg0));
163 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
164 :
165 0 : return true;
166 : }
167 :
168 : static const JSJitInfo onchargingchange_getterinfo = {
169 : { (JSJitGetterOp)get_onchargingchange },
170 : { prototypes::id::BatteryManager },
171 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
172 : JSJitInfo::Getter,
173 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
174 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
175 : false, /* isInfallible. False in setters. */
176 : false, /* isMovable. Not relevant for setters. */
177 : false, /* isEliminatable. Not relevant for setters. */
178 : false, /* isAlwaysInSlot. Only relevant for getters. */
179 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
180 : false, /* isTypedMethod. Only relevant for methods. */
181 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
182 : };
183 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
184 : static_assert(0 < 1, "There is no slot for us");
185 : static const JSJitInfo onchargingchange_setterinfo = {
186 : { (JSJitGetterOp)set_onchargingchange },
187 : { prototypes::id::BatteryManager },
188 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
189 : JSJitInfo::Setter,
190 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
191 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
192 : false, /* isInfallible. False in setters. */
193 : false, /* isMovable. Not relevant for setters. */
194 : false, /* isEliminatable. Not relevant for setters. */
195 : false, /* isAlwaysInSlot. Only relevant for getters. */
196 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
197 : false, /* isTypedMethod. Only relevant for methods. */
198 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
199 : };
200 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
201 : static_assert(0 < 1, "There is no slot for us");
202 :
203 : static bool
204 0 : get_onchargingtimechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitGetterCallArgs args)
205 : {
206 0 : RefPtr<EventHandlerNonNull> result(self->GetOnchargingtimechange());
207 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
208 0 : if (result) {
209 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
210 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
211 0 : return false;
212 : }
213 0 : return true;
214 : } else {
215 0 : args.rval().setNull();
216 0 : return true;
217 : }
218 : }
219 :
220 : static bool
221 0 : set_onchargingtimechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitSetterCallArgs args)
222 : {
223 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
224 0 : if (args[0].isObject()) {
225 : { // scope for tempRoot
226 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
227 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
228 : }
229 : } else {
230 0 : arg0 = nullptr;
231 : }
232 0 : self->SetOnchargingtimechange(Constify(arg0));
233 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
234 :
235 0 : return true;
236 : }
237 :
238 : static const JSJitInfo onchargingtimechange_getterinfo = {
239 : { (JSJitGetterOp)get_onchargingtimechange },
240 : { prototypes::id::BatteryManager },
241 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
242 : JSJitInfo::Getter,
243 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
244 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
245 : false, /* isInfallible. False in setters. */
246 : false, /* isMovable. Not relevant for setters. */
247 : false, /* isEliminatable. Not relevant for setters. */
248 : false, /* isAlwaysInSlot. Only relevant for getters. */
249 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
250 : false, /* isTypedMethod. Only relevant for methods. */
251 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
252 : };
253 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
254 : static_assert(0 < 1, "There is no slot for us");
255 : static const JSJitInfo onchargingtimechange_setterinfo = {
256 : { (JSJitGetterOp)set_onchargingtimechange },
257 : { prototypes::id::BatteryManager },
258 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
259 : JSJitInfo::Setter,
260 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
261 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
262 : false, /* isInfallible. False in setters. */
263 : false, /* isMovable. Not relevant for setters. */
264 : false, /* isEliminatable. Not relevant for setters. */
265 : false, /* isAlwaysInSlot. Only relevant for getters. */
266 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
267 : false, /* isTypedMethod. Only relevant for methods. */
268 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
269 : };
270 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
271 : static_assert(0 < 1, "There is no slot for us");
272 :
273 : static bool
274 0 : get_ondischargingtimechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitGetterCallArgs args)
275 : {
276 0 : RefPtr<EventHandlerNonNull> result(self->GetOndischargingtimechange());
277 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
278 0 : if (result) {
279 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
280 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
281 0 : return false;
282 : }
283 0 : return true;
284 : } else {
285 0 : args.rval().setNull();
286 0 : return true;
287 : }
288 : }
289 :
290 : static bool
291 0 : set_ondischargingtimechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitSetterCallArgs args)
292 : {
293 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
294 0 : if (args[0].isObject()) {
295 : { // scope for tempRoot
296 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
297 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
298 : }
299 : } else {
300 0 : arg0 = nullptr;
301 : }
302 0 : self->SetOndischargingtimechange(Constify(arg0));
303 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
304 :
305 0 : return true;
306 : }
307 :
308 : static const JSJitInfo ondischargingtimechange_getterinfo = {
309 : { (JSJitGetterOp)get_ondischargingtimechange },
310 : { prototypes::id::BatteryManager },
311 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
312 : JSJitInfo::Getter,
313 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
314 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
315 : false, /* isInfallible. False in setters. */
316 : false, /* isMovable. Not relevant for setters. */
317 : false, /* isEliminatable. Not relevant for setters. */
318 : false, /* isAlwaysInSlot. Only relevant for getters. */
319 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
320 : false, /* isTypedMethod. Only relevant for methods. */
321 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
322 : };
323 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
324 : static_assert(0 < 1, "There is no slot for us");
325 : static const JSJitInfo ondischargingtimechange_setterinfo = {
326 : { (JSJitGetterOp)set_ondischargingtimechange },
327 : { prototypes::id::BatteryManager },
328 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
329 : JSJitInfo::Setter,
330 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
331 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
332 : false, /* isInfallible. False in setters. */
333 : false, /* isMovable. Not relevant for setters. */
334 : false, /* isEliminatable. Not relevant for setters. */
335 : false, /* isAlwaysInSlot. Only relevant for getters. */
336 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
337 : false, /* isTypedMethod. Only relevant for methods. */
338 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
339 : };
340 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
341 : static_assert(0 < 1, "There is no slot for us");
342 :
343 : static bool
344 0 : get_onlevelchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitGetterCallArgs args)
345 : {
346 0 : RefPtr<EventHandlerNonNull> result(self->GetOnlevelchange());
347 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
348 0 : if (result) {
349 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
350 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
351 0 : return false;
352 : }
353 0 : return true;
354 : } else {
355 0 : args.rval().setNull();
356 0 : return true;
357 : }
358 : }
359 :
360 : static bool
361 0 : set_onlevelchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::battery::BatteryManager* self, JSJitSetterCallArgs args)
362 : {
363 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
364 0 : if (args[0].isObject()) {
365 : { // scope for tempRoot
366 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
367 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
368 : }
369 : } else {
370 0 : arg0 = nullptr;
371 : }
372 0 : self->SetOnlevelchange(Constify(arg0));
373 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
374 :
375 0 : return true;
376 : }
377 :
378 : static const JSJitInfo onlevelchange_getterinfo = {
379 : { (JSJitGetterOp)get_onlevelchange },
380 : { prototypes::id::BatteryManager },
381 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
382 : JSJitInfo::Getter,
383 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
384 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
385 : false, /* isInfallible. False in setters. */
386 : false, /* isMovable. Not relevant for setters. */
387 : false, /* isEliminatable. Not relevant for setters. */
388 : false, /* isAlwaysInSlot. Only relevant for getters. */
389 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
390 : false, /* isTypedMethod. Only relevant for methods. */
391 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
392 : };
393 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
394 : static_assert(0 < 1, "There is no slot for us");
395 : static const JSJitInfo onlevelchange_setterinfo = {
396 : { (JSJitGetterOp)set_onlevelchange },
397 : { prototypes::id::BatteryManager },
398 : { PrototypeTraits<prototypes::id::BatteryManager>::Depth },
399 : JSJitInfo::Setter,
400 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
401 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
402 : false, /* isInfallible. False in setters. */
403 : false, /* isMovable. Not relevant for setters. */
404 : false, /* isEliminatable. Not relevant for setters. */
405 : false, /* isAlwaysInSlot. Only relevant for getters. */
406 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
407 : false, /* isTypedMethod. Only relevant for methods. */
408 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
409 : };
410 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
411 : static_assert(0 < 1, "There is no slot for us");
412 :
413 : static bool
414 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
415 : {
416 0 : mozilla::dom::battery::BatteryManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::battery::BatteryManager>(obj);
417 : // We don't want to preserve if we don't have a wrapper, and we
418 : // obviously can't preserve if we're not initialized.
419 0 : if (self && self->GetWrapperPreserveColor()) {
420 0 : PreserveWrapper(self);
421 : }
422 0 : return true;
423 : }
424 :
425 : static void
426 0 : _finalize(js::FreeOp* fop, JSObject* obj)
427 : {
428 0 : mozilla::dom::battery::BatteryManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::battery::BatteryManager>(obj);
429 0 : if (self) {
430 0 : ClearWrapper(self, self, obj);
431 0 : AddForDeferredFinalization<mozilla::dom::battery::BatteryManager>(self);
432 : }
433 0 : }
434 :
435 : static void
436 0 : _objectMoved(JSObject* obj, const JSObject* old)
437 : {
438 0 : mozilla::dom::battery::BatteryManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::battery::BatteryManager>(obj);
439 0 : if (self) {
440 0 : UpdateWrapper(self, self, obj, old);
441 : }
442 0 : }
443 :
444 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
445 : #if defined(__clang__)
446 : #pragma clang diagnostic push
447 : #pragma clang diagnostic ignored "-Wmissing-braces"
448 : #endif
449 : static const JSPropertySpec sAttributes_specs[] = {
450 : { "charging", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &charging_getterinfo, nullptr, nullptr },
451 : { "chargingTime", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &chargingTime_getterinfo, nullptr, nullptr },
452 : { "dischargingTime", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &dischargingTime_getterinfo, nullptr, nullptr },
453 : { "level", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &level_getterinfo, nullptr, nullptr },
454 : { "onchargingchange", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onchargingchange_getterinfo, GenericBindingSetter, &onchargingchange_setterinfo },
455 : { "onchargingtimechange", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onchargingtimechange_getterinfo, GenericBindingSetter, &onchargingtimechange_setterinfo },
456 : { "ondischargingtimechange", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &ondischargingtimechange_getterinfo, GenericBindingSetter, &ondischargingtimechange_setterinfo },
457 : { "onlevelchange", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onlevelchange_getterinfo, GenericBindingSetter, &onlevelchange_setterinfo },
458 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
459 : };
460 : #if defined(__clang__)
461 : #pragma clang diagnostic pop
462 : #endif
463 :
464 :
465 : // Can't be const because the pref-enabled boolean needs to be writable
466 : static Prefable<const JSPropertySpec> sAttributes[] = {
467 : { nullptr, &sAttributes_specs[0] },
468 : { nullptr, nullptr }
469 : };
470 :
471 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
472 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
473 : static_assert(8 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
474 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
475 :
476 :
477 : static uint16_t sNativeProperties_sortedPropertyIndices[8];
478 : static PropertyInfo sNativeProperties_propertyInfos[8];
479 :
480 : static const NativePropertiesN<1> sNativeProperties = {
481 : false, 0,
482 : false, 0,
483 : false, 0,
484 : true, 0 /* sAttributes */,
485 : false, 0,
486 : false, 0,
487 : false, 0,
488 : -1,
489 : 8,
490 : sNativeProperties_sortedPropertyIndices,
491 : {
492 : { sAttributes, &sNativeProperties_propertyInfos[0] }
493 : }
494 : };
495 : static_assert(8 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
496 : "We have a property info count that is oversized");
497 :
498 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
499 : {
500 : "Function",
501 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
502 : &sBoringInterfaceObjectClassClassOps,
503 : JS_NULL_CLASS_SPEC,
504 : JS_NULL_CLASS_EXT,
505 : &sInterfaceObjectClassObjectOps
506 : },
507 : eInterface,
508 : true,
509 : prototypes::id::BatteryManager,
510 : PrototypeTraits<prototypes::id::BatteryManager>::Depth,
511 : sNativePropertyHooks,
512 : "function BatteryManager() {\n [native code]\n}",
513 : EventTargetBinding::GetConstructorObject
514 : };
515 :
516 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
517 : {
518 : "BatteryManagerPrototype",
519 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
520 : JS_NULL_CLASS_OPS,
521 : JS_NULL_CLASS_SPEC,
522 : JS_NULL_CLASS_EXT,
523 : JS_NULL_OBJECT_OPS
524 : },
525 : eInterfacePrototype,
526 : false,
527 : prototypes::id::BatteryManager,
528 : PrototypeTraits<prototypes::id::BatteryManager>::Depth,
529 : sNativePropertyHooks,
530 : "[object BatteryManagerPrototype]",
531 : EventTargetBinding::GetProtoObject
532 : };
533 :
534 : JSObject*
535 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
536 : {
537 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
538 : }
539 :
540 : static const js::ClassOps sClassOps = {
541 : _addProperty, /* addProperty */
542 : nullptr, /* delProperty */
543 : nullptr, /* getProperty */
544 : nullptr, /* setProperty */
545 : nullptr, /* enumerate */
546 : nullptr, /* newEnumerate */
547 : nullptr, /* resolve */
548 : nullptr, /* mayResolve */
549 : _finalize, /* finalize */
550 : nullptr, /* call */
551 : nullptr, /* hasInstance */
552 : nullptr, /* construct */
553 : nullptr, /* trace */
554 : };
555 :
556 : static const js::ClassExtension sClassExtension = {
557 : nullptr, /* weakmapKeyDelegateOp */
558 : _objectMoved /* objectMovedOp */
559 : };
560 :
561 : static const DOMJSClass sClass = {
562 : { "BatteryManager",
563 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
564 : &sClassOps,
565 : JS_NULL_CLASS_SPEC,
566 : &sClassExtension,
567 : JS_NULL_OBJECT_OPS
568 : },
569 : { prototypes::id::EventTarget, prototypes::id::BatteryManager, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
570 : IsBaseOf<nsISupports, mozilla::dom::battery::BatteryManager >::value,
571 : sNativePropertyHooks,
572 : FindAssociatedGlobalForNative<mozilla::dom::battery::BatteryManager>::Get,
573 : GetProtoObjectHandle,
574 : GetCCParticipant<mozilla::dom::battery::BatteryManager>::Get()
575 : };
576 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
577 : "Must have the right minimal number of reserved slots.");
578 : static_assert(1 >= 1,
579 : "Must have enough reserved slots.");
580 :
581 : const JSClass*
582 0 : GetJSClass()
583 : {
584 0 : return sClass.ToJSClass();
585 : }
586 :
587 : bool
588 0 : Wrap(JSContext* aCx, mozilla::dom::battery::BatteryManager* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
589 : {
590 : MOZ_ASSERT(static_cast<mozilla::dom::battery::BatteryManager*>(aObject) ==
591 : reinterpret_cast<mozilla::dom::battery::BatteryManager*>(aObject),
592 : "Multiple inheritance for mozilla::dom::battery::BatteryManager is broken.");
593 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
594 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
595 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
596 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
597 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
598 0 : MOZ_ASSERT(!aCache->GetWrapper(),
599 : "You should probably not be using Wrap() directly; use "
600 : "GetOrCreateDOMReflector instead");
601 :
602 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
603 : "nsISupports must be on our primary inheritance chain");
604 :
605 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
606 0 : if (!global) {
607 0 : return false;
608 : }
609 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
610 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
611 :
612 : // That might have ended up wrapping us already, due to the wonders
613 : // of XBL. Check for that, and bail out as needed.
614 0 : aReflector.set(aCache->GetWrapper());
615 0 : if (aReflector) {
616 : #ifdef DEBUG
617 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
618 : #endif // DEBUG
619 0 : return true;
620 : }
621 :
622 0 : JSAutoCompartment ac(aCx, global);
623 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
624 0 : if (!canonicalProto) {
625 0 : return false;
626 : }
627 0 : JS::Rooted<JSObject*> proto(aCx);
628 0 : if (aGivenProto) {
629 0 : proto = aGivenProto;
630 : // Unfortunately, while aGivenProto was in the compartment of aCx
631 : // coming in, we changed compartments to that of "parent" so may need
632 : // to wrap the proto here.
633 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
634 0 : if (!JS_WrapObject(aCx, &proto)) {
635 0 : return false;
636 : }
637 : }
638 : } else {
639 0 : proto = canonicalProto;
640 : }
641 :
642 0 : BindingJSObjectCreator<mozilla::dom::battery::BatteryManager> creator(aCx);
643 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
644 0 : if (!aReflector) {
645 0 : return false;
646 : }
647 :
648 0 : aCache->SetWrapper(aReflector);
649 0 : creator.InitializationSucceeded();
650 :
651 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
652 : aCache->GetWrapperPreserveColor() == aReflector);
653 : // If proto != canonicalProto, we have to preserve our wrapper;
654 : // otherwise we won't be able to properly recreate it later, since
655 : // we won't know what proto to use. Note that we don't check
656 : // aGivenProto here, since it's entirely possible (and even
657 : // somewhat common) to have a non-null aGivenProto which is the
658 : // same as canonicalProto.
659 0 : if (proto != canonicalProto) {
660 0 : PreserveWrapper(aObject);
661 : }
662 :
663 0 : return true;
664 : }
665 :
666 : const NativePropertyHooks sNativePropertyHooks[] = { {
667 : nullptr,
668 : nullptr,
669 : nullptr,
670 : { sNativeProperties.Upcast(), nullptr },
671 : prototypes::id::BatteryManager,
672 : constructors::id::BatteryManager,
673 : EventTargetBinding::sNativePropertyHooks,
674 : &DefaultXrayExpandoObjectClass
675 : } };
676 :
677 : void
678 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
679 : {
680 0 : JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObjectHandle(aCx));
681 0 : if (!parentProto) {
682 0 : return;
683 : }
684 :
685 0 : JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObjectHandle(aCx));
686 0 : if (!constructorProto) {
687 0 : return;
688 : }
689 :
690 : static bool sIdsInited = false;
691 0 : if (!sIdsInited && NS_IsMainThread()) {
692 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
693 0 : return;
694 : }
695 0 : sIdsInited = true;
696 : }
697 :
698 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::BatteryManager);
699 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::BatteryManager);
700 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
701 : &sPrototypeClass.mBase, protoCache,
702 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
703 : interfaceCache,
704 : sNativeProperties.Upcast(),
705 : nullptr,
706 : "BatteryManager", aDefineOnGlobal,
707 : nullptr,
708 0 : false);
709 : }
710 :
711 : JS::Handle<JSObject*>
712 0 : GetProtoObjectHandle(JSContext* aCx)
713 : {
714 : /* Get the interface prototype object for this class. This will create the
715 : object as needed. */
716 0 : bool aDefineOnGlobal = true;
717 :
718 : /* Make sure our global is sane. Hopefully we can remove this sometime */
719 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
720 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
721 0 : return nullptr;
722 : }
723 :
724 : /* Check to see whether the interface objects are already installed */
725 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
726 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::BatteryManager)) {
727 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
728 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
729 : }
730 :
731 : /*
732 : * The object might _still_ be null, but that's OK.
733 : *
734 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
735 : * traced by TraceProtoAndIfaceCache() and its contents are never
736 : * changed after they have been set.
737 : *
738 : * Calling address() avoids the read read barrier that does gray
739 : * unmarking, but it's not possible for the object to be gray here.
740 : */
741 :
742 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::BatteryManager);
743 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
744 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
745 : }
746 :
747 : JS::Handle<JSObject*>
748 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
749 : {
750 : /* Get the interface object for this class. This will create the object as
751 : needed. */
752 :
753 : /* Make sure our global is sane. Hopefully we can remove this sometime */
754 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
755 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
756 0 : return nullptr;
757 : }
758 :
759 : /* Check to see whether the interface objects are already installed */
760 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
761 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::BatteryManager)) {
762 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
763 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
764 : }
765 :
766 : /*
767 : * The object might _still_ be null, but that's OK.
768 : *
769 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
770 : * traced by TraceProtoAndIfaceCache() and its contents are never
771 : * changed after they have been set.
772 : *
773 : * Calling address() avoids the read read barrier that does gray
774 : * unmarking, but it's not possible for the object to be gray here.
775 : */
776 :
777 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::BatteryManager);
778 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
779 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
780 : }
781 :
782 : JSObject*
783 0 : GetConstructorObject(JSContext* aCx)
784 : {
785 0 : return GetConstructorObjectHandle(aCx);
786 : }
787 :
788 : } // namespace BatteryManagerBinding
789 :
790 :
791 :
792 : } // namespace dom
793 : } // namespace mozilla
|