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