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