/work/obj-fuzz/dom/bindings/CommentBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM Comment.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "CharacterDataBinding.h" |
4 | | #include "CommentBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/Comment.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/XrayExpandoClass.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 Comment_Binding { |
21 | | |
22 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<CharacterData_Binding::NativeType>::value, |
23 | | "Can't inherit from an interface with a different ownership model."); |
24 | | |
25 | | static bool |
26 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
27 | 0 | { |
28 | 0 | mozilla::dom::Comment* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Comment>(obj); |
29 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
30 | 0 | // obviously can't preserve if we're not initialized. |
31 | 0 | if (self && self->GetWrapperPreserveColor()) { |
32 | 0 | PreserveWrapper(self); |
33 | 0 | } |
34 | 0 | return true; |
35 | 0 | } |
36 | | |
37 | | static void |
38 | | _finalize(js::FreeOp* fop, JSObject* obj) |
39 | 0 | { |
40 | 0 | mozilla::dom::Comment* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Comment>(obj); |
41 | 0 | if (self) { |
42 | 0 | ClearWrapper(self, self, obj); |
43 | 0 | AddForDeferredFinalization<mozilla::dom::Comment>(self); |
44 | 0 | } |
45 | 0 | } |
46 | | |
47 | | static size_t |
48 | | _objectMoved(JSObject* obj, JSObject* old) |
49 | 0 | { |
50 | 0 | mozilla::dom::Comment* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Comment>(obj); |
51 | 0 | if (self) { |
52 | 0 | UpdateWrapper(self, self, obj, old); |
53 | 0 | } |
54 | 0 |
|
55 | 0 | return 0; |
56 | 0 | } |
57 | | |
58 | | static bool |
59 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
60 | 0 | { |
61 | 0 | AUTO_PROFILER_LABEL_FAST("Comment constructor", DOM, cx); |
62 | 0 |
|
63 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
64 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
65 | 0 | if (!args.isConstructing()) { |
66 | 0 | // XXXbz wish I could get the name from the callee instead of |
67 | 0 | // Adding more relocations |
68 | 0 | return ThrowConstructorWithoutNew(cx, "Comment"); |
69 | 0 | } |
70 | 0 | |
71 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
72 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
73 | 0 | return false; |
74 | 0 | } |
75 | 0 | |
76 | 0 | GlobalObject global(cx, obj); |
77 | 0 | if (global.Failed()) { |
78 | 0 | return false; |
79 | 0 | } |
80 | 0 | |
81 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
82 | 0 | binding_detail::FakeString arg0; |
83 | 0 | if (args.hasDefined(0)) { |
84 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
85 | 0 | return false; |
86 | 0 | } |
87 | 0 | } else { |
88 | 0 | static const char16_t data[] = { 0 }; |
89 | 0 | arg0.Rebind(data, ArrayLength(data) - 1); |
90 | 0 | } |
91 | 0 | Maybe<JSAutoRealm> ar; |
92 | 0 | if (objIsXray) { |
93 | 0 | obj = js::CheckedUnwrap(obj); |
94 | 0 | if (!obj) { |
95 | 0 | return false; |
96 | 0 | } |
97 | 0 | ar.emplace(cx, obj); |
98 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
99 | 0 | return false; |
100 | 0 | } |
101 | 0 | } |
102 | 0 | FastErrorResult rv; |
103 | 0 | auto result(StrongOrRawPtr<mozilla::dom::Comment>(mozilla::dom::Comment::Constructor(global, NonNullHelper(Constify(arg0)), rv))); |
104 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
105 | 0 | return false; |
106 | 0 | } |
107 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
108 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
109 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
110 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
111 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
112 | 0 | return false; |
113 | 0 | } |
114 | 0 | return true; |
115 | 0 | } |
116 | | |
117 | | static const js::ClassOps sInterfaceObjectClassOps = { |
118 | | nullptr, /* addProperty */ |
119 | | nullptr, /* delProperty */ |
120 | | nullptr, /* enumerate */ |
121 | | nullptr, /* newEnumerate */ |
122 | | nullptr, /* resolve */ |
123 | | nullptr, /* mayResolve */ |
124 | | nullptr, /* finalize */ |
125 | | _constructor, /* call */ |
126 | | nullptr, /* hasInstance */ |
127 | | _constructor, /* construct */ |
128 | | nullptr, /* trace */ |
129 | | }; |
130 | | |
131 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
132 | | { |
133 | | "Function", |
134 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
135 | | &sInterfaceObjectClassOps, |
136 | | JS_NULL_CLASS_SPEC, |
137 | | JS_NULL_CLASS_EXT, |
138 | | &sInterfaceObjectClassObjectOps |
139 | | }, |
140 | | eInterface, |
141 | | true, |
142 | | prototypes::id::Comment, |
143 | | PrototypeTraits<prototypes::id::Comment>::Depth, |
144 | | sNativePropertyHooks, |
145 | | "function Comment() {\n [native code]\n}", |
146 | | CharacterData_Binding::GetConstructorObject |
147 | | }; |
148 | | |
149 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
150 | | { |
151 | | "CommentPrototype", |
152 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
153 | | JS_NULL_CLASS_OPS, |
154 | | JS_NULL_CLASS_SPEC, |
155 | | JS_NULL_CLASS_EXT, |
156 | | JS_NULL_OBJECT_OPS |
157 | | }, |
158 | | eInterfacePrototype, |
159 | | false, |
160 | | prototypes::id::Comment, |
161 | | PrototypeTraits<prototypes::id::Comment>::Depth, |
162 | | sNativePropertyHooks, |
163 | | "[object CommentPrototype]", |
164 | | CharacterData_Binding::GetProtoObject |
165 | | }; |
166 | | |
167 | | static const js::ClassOps sClassOps = { |
168 | | _addProperty, /* addProperty */ |
169 | | nullptr, /* delProperty */ |
170 | | nullptr, /* enumerate */ |
171 | | nullptr, /* newEnumerate */ |
172 | | nullptr, /* resolve */ |
173 | | nullptr, /* mayResolve */ |
174 | | _finalize, /* finalize */ |
175 | | nullptr, /* call */ |
176 | | nullptr, /* hasInstance */ |
177 | | nullptr, /* construct */ |
178 | | nullptr, /* trace */ |
179 | | }; |
180 | | |
181 | | static const js::ClassExtension sClassExtension = { |
182 | | nullptr, /* weakmapKeyDelegateOp */ |
183 | | _objectMoved /* objectMovedOp */ |
184 | | }; |
185 | | |
186 | | static const DOMJSClass sClass = { |
187 | | { "Comment", |
188 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
189 | | &sClassOps, |
190 | | JS_NULL_CLASS_SPEC, |
191 | | &sClassExtension, |
192 | | JS_NULL_OBJECT_OPS |
193 | | }, |
194 | | { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::CharacterData, prototypes::id::Comment, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
195 | | IsBaseOf<nsISupports, mozilla::dom::Comment >::value, |
196 | | sNativePropertyHooks, |
197 | | FindAssociatedGlobalForNative<mozilla::dom::Comment>::Get, |
198 | | GetProtoObjectHandle, |
199 | | GetCCParticipant<mozilla::dom::Comment>::Get() |
200 | | }; |
201 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
202 | | "Must have the right minimal number of reserved slots."); |
203 | | static_assert(1 >= 1, |
204 | | "Must have enough reserved slots."); |
205 | | |
206 | | const JSClass* |
207 | | GetJSClass() |
208 | 0 | { |
209 | 0 | return sClass.ToJSClass(); |
210 | 0 | } |
211 | | |
212 | | bool |
213 | | Wrap(JSContext* aCx, mozilla::dom::Comment* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
214 | 0 | { |
215 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Comment>::value, |
216 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
217 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Comment*>(aObject) == |
218 | 0 | reinterpret_cast<mozilla::dom::Comment*>(aObject), |
219 | 0 | "Multiple inheritance for mozilla::dom::Comment is broken."); |
220 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::CharacterData*>(aObject) == |
221 | 0 | reinterpret_cast<mozilla::dom::CharacterData*>(aObject), |
222 | 0 | "Multiple inheritance for mozilla::dom::CharacterData is broken."); |
223 | 0 | MOZ_ASSERT(static_cast<nsINode*>(aObject) == |
224 | 0 | reinterpret_cast<nsINode*>(aObject), |
225 | 0 | "Multiple inheritance for nsINode is broken."); |
226 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
227 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
228 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
229 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
230 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
231 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
232 | 0 | "You should probably not be using Wrap() directly; use " |
233 | 0 | "GetOrCreateDOMReflector instead"); |
234 | 0 |
|
235 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
236 | 0 | "nsISupports must be on our primary inheritance chain"); |
237 | 0 |
|
238 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
239 | 0 | if (!global) { |
240 | 0 | return false; |
241 | 0 | } |
242 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
243 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
244 | 0 |
|
245 | 0 | // That might have ended up wrapping us already, due to the wonders |
246 | 0 | // of XBL. Check for that, and bail out as needed. |
247 | 0 | aReflector.set(aCache->GetWrapper()); |
248 | 0 | if (aReflector) { |
249 | | #ifdef DEBUG |
250 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
251 | | #endif // DEBUG |
252 | | return true; |
253 | 0 | } |
254 | 0 |
|
255 | 0 | JSAutoRealm ar(aCx, global); |
256 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
257 | 0 | if (!canonicalProto) { |
258 | 0 | return false; |
259 | 0 | } |
260 | 0 | JS::Rooted<JSObject*> proto(aCx); |
261 | 0 | if (aGivenProto) { |
262 | 0 | proto = aGivenProto; |
263 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
264 | 0 | // coming in, we changed compartments to that of "parent" so may need |
265 | 0 | // to wrap the proto here. |
266 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
267 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
268 | 0 | return false; |
269 | 0 | } |
270 | 0 | } |
271 | 0 | } else { |
272 | 0 | proto = canonicalProto; |
273 | 0 | } |
274 | 0 |
|
275 | 0 | BindingJSObjectCreator<mozilla::dom::Comment> creator(aCx); |
276 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
277 | 0 | if (!aReflector) { |
278 | 0 | return false; |
279 | 0 | } |
280 | 0 | |
281 | 0 | aCache->SetWrapper(aReflector); |
282 | 0 | creator.InitializationSucceeded(); |
283 | 0 |
|
284 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
285 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
286 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
287 | 0 | // otherwise we won't be able to properly recreate it later, since |
288 | 0 | // we won't know what proto to use. Note that we don't check |
289 | 0 | // aGivenProto here, since it's entirely possible (and even |
290 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
291 | 0 | // same as canonicalProto. |
292 | 0 | if (proto != canonicalProto) { |
293 | 0 | PreserveWrapper(aObject); |
294 | 0 | } |
295 | 0 |
|
296 | 0 | return true; |
297 | 0 | } |
298 | | |
299 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
300 | | nullptr, |
301 | | nullptr, |
302 | | nullptr, |
303 | | { nullptr, nullptr }, |
304 | | prototypes::id::Comment, |
305 | | constructors::id::Comment, |
306 | | CharacterData_Binding::sNativePropertyHooks, |
307 | | &DefaultXrayExpandoObjectClass |
308 | | } }; |
309 | | |
310 | | void |
311 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
312 | 0 | { |
313 | 0 | JS::Handle<JSObject*> parentProto(CharacterData_Binding::GetProtoObjectHandle(aCx)); |
314 | 0 | if (!parentProto) { |
315 | 0 | return; |
316 | 0 | } |
317 | 0 | |
318 | 0 | JS::Handle<JSObject*> constructorProto(CharacterData_Binding::GetConstructorObjectHandle(aCx)); |
319 | 0 | if (!constructorProto) { |
320 | 0 | return; |
321 | 0 | } |
322 | 0 | |
323 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Comment); |
324 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Comment); |
325 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
326 | 0 | &sPrototypeClass.mBase, protoCache, |
327 | 0 | nullptr, |
328 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
329 | 0 | interfaceCache, |
330 | 0 | nullptr, |
331 | 0 | nullptr, |
332 | 0 | "Comment", aDefineOnGlobal, |
333 | 0 | nullptr, |
334 | 0 | false); |
335 | 0 | } |
336 | | |
337 | | JSObject* |
338 | | GetConstructorObject(JSContext* aCx) |
339 | 0 | { |
340 | 0 | return GetConstructorObjectHandle(aCx); |
341 | 0 | } |
342 | | |
343 | | } // namespace Comment_Binding |
344 | | |
345 | | |
346 | | |
347 | | } // namespace dom |
348 | | } // namespace mozilla |