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