/work/obj-fuzz/dom/bindings/XULMenuElementBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM XULMenuElement.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "WrapperFactory.h" |
4 | | #include "XULElementBinding.h" |
5 | | #include "XULMenuElementBinding.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/DOMJSClass.h" |
9 | | #include "mozilla/dom/Element.h" |
10 | | #include "mozilla/dom/KeyboardEvent.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/Nullable.h" |
13 | | #include "mozilla/dom/PrimitiveConversions.h" |
14 | | #include "mozilla/dom/XULMenuElement.h" |
15 | | #include "mozilla/dom/XrayExpandoClass.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | |
20 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
21 | | using namespace mozilla::dom::binding_detail; |
22 | | |
23 | | |
24 | | namespace XULMenuElement_Binding { |
25 | | |
26 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<XULElement_Binding::NativeType>::value, |
27 | | "Can't inherit from an interface with a different ownership model."); |
28 | | |
29 | | MOZ_CAN_RUN_SCRIPT static bool |
30 | | get_activeChild(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XULMenuElement* self, JSJitGetterCallArgs args) |
31 | 0 | { |
32 | 0 | AUTO_PROFILER_LABEL_FAST("get XULMenuElement.activeChild", DOM, cx); |
33 | 0 |
|
34 | 0 | auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetActiveChild())); |
35 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
36 | 0 | if (!result) { |
37 | 0 | args.rval().setNull(); |
38 | 0 | return true; |
39 | 0 | } |
40 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
41 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
42 | 0 | return false; |
43 | 0 | } |
44 | 0 | return true; |
45 | 0 | } |
46 | | |
47 | | MOZ_CAN_RUN_SCRIPT static bool |
48 | | set_activeChild(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XULMenuElement* self, JSJitSetterCallArgs args) |
49 | 0 | { |
50 | 0 | AUTO_PROFILER_LABEL_FAST("set XULMenuElement.activeChild", DOM, cx); |
51 | 0 |
|
52 | 0 | mozilla::dom::Element* arg0; |
53 | 0 | if (args[0].isObject()) { |
54 | 0 | { |
55 | 0 | nsresult rv = UnwrapObject<prototypes::id::Element, mozilla::dom::Element>(args[0], arg0); |
56 | 0 | if (NS_FAILED(rv)) { |
57 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Value being assigned to XULMenuElement.activeChild", "Element"); |
58 | 0 | return false; |
59 | 0 | } |
60 | 0 | } |
61 | 0 | } else if (args[0].isNullOrUndefined()) { |
62 | 0 | arg0 = nullptr; |
63 | 0 | } else { |
64 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Value being assigned to XULMenuElement.activeChild"); |
65 | 0 | return false; |
66 | 0 | } |
67 | 0 | self->SetActiveChild(MOZ_KnownLive(Constify(arg0))); |
68 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
69 | 0 |
|
70 | 0 | return true; |
71 | 0 | } |
72 | | |
73 | | static const JSJitInfo activeChild_getterinfo = { |
74 | | { (JSJitGetterOp)get_activeChild }, |
75 | | { prototypes::id::XULMenuElement }, |
76 | | { PrototypeTraits<prototypes::id::XULMenuElement>::Depth }, |
77 | | JSJitInfo::Getter, |
78 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
79 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
80 | | false, /* isInfallible. False in setters. */ |
81 | | false, /* isMovable. Not relevant for setters. */ |
82 | | false, /* isEliminatable. Not relevant for setters. */ |
83 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
84 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
85 | | false, /* isTypedMethod. Only relevant for methods. */ |
86 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
87 | | }; |
88 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
89 | | static_assert(0 < 1, "There is no slot for us"); |
90 | | static const JSJitInfo activeChild_setterinfo = { |
91 | | { (JSJitGetterOp)set_activeChild }, |
92 | | { prototypes::id::XULMenuElement }, |
93 | | { PrototypeTraits<prototypes::id::XULMenuElement>::Depth }, |
94 | | JSJitInfo::Setter, |
95 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
96 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
97 | | false, /* isInfallible. False in setters. */ |
98 | | false, /* isMovable. Not relevant for setters. */ |
99 | | false, /* isEliminatable. Not relevant for setters. */ |
100 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
101 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
102 | | false, /* isTypedMethod. Only relevant for methods. */ |
103 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
104 | | }; |
105 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
106 | | static_assert(0 < 1, "There is no slot for us"); |
107 | | |
108 | | MOZ_CAN_RUN_SCRIPT static bool |
109 | | handleKeyPress(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XULMenuElement* self, const JSJitMethodCallArgs& args) |
110 | 0 | { |
111 | 0 | AUTO_PROFILER_LABEL_FAST("XULMenuElement.handleKeyPress", DOM, cx); |
112 | 0 |
|
113 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
114 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XULMenuElement.handleKeyPress"); |
115 | 0 | } |
116 | 0 | NonNull<mozilla::dom::KeyboardEvent> arg0; |
117 | 0 | if (args[0].isObject()) { |
118 | 0 | { |
119 | 0 | nsresult rv = UnwrapObject<prototypes::id::KeyboardEvent, mozilla::dom::KeyboardEvent>(args[0], arg0); |
120 | 0 | if (NS_FAILED(rv)) { |
121 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of XULMenuElement.handleKeyPress", "KeyboardEvent"); |
122 | 0 | return false; |
123 | 0 | } |
124 | 0 | } |
125 | 0 | } else { |
126 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of XULMenuElement.handleKeyPress"); |
127 | 0 | return false; |
128 | 0 | } |
129 | 0 | bool result(self->HandleKeyPress(MOZ_KnownLive(NonNullHelper(arg0)))); |
130 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
131 | 0 | args.rval().setBoolean(result); |
132 | 0 | return true; |
133 | 0 | } |
134 | | |
135 | | static const JSJitInfo handleKeyPress_methodinfo = { |
136 | | { (JSJitGetterOp)handleKeyPress }, |
137 | | { prototypes::id::XULMenuElement }, |
138 | | { PrototypeTraits<prototypes::id::XULMenuElement>::Depth }, |
139 | | JSJitInfo::Method, |
140 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
141 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
142 | | false, /* isInfallible. False in setters. */ |
143 | | false, /* isMovable. Not relevant for setters. */ |
144 | | false, /* isEliminatable. Not relevant for setters. */ |
145 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
146 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
147 | | false, /* isTypedMethod. Only relevant for methods. */ |
148 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
149 | | }; |
150 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
151 | | static_assert(0 < 1, "There is no slot for us"); |
152 | | |
153 | | MOZ_CAN_RUN_SCRIPT static bool |
154 | | get_openedWithKey(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XULMenuElement* self, JSJitGetterCallArgs args) |
155 | 0 | { |
156 | 0 | AUTO_PROFILER_LABEL_FAST("get XULMenuElement.openedWithKey", DOM, cx); |
157 | 0 |
|
158 | 0 | bool result(self->OpenedWithKey()); |
159 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
160 | 0 | args.rval().setBoolean(result); |
161 | 0 | return true; |
162 | 0 | } |
163 | | |
164 | | static const JSJitInfo openedWithKey_getterinfo = { |
165 | | { (JSJitGetterOp)get_openedWithKey }, |
166 | | { prototypes::id::XULMenuElement }, |
167 | | { PrototypeTraits<prototypes::id::XULMenuElement>::Depth }, |
168 | | JSJitInfo::Getter, |
169 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
170 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
171 | | true, /* isInfallible. False in setters. */ |
172 | | false, /* isMovable. Not relevant for setters. */ |
173 | | false, /* isEliminatable. Not relevant for setters. */ |
174 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
175 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
176 | | false, /* isTypedMethod. Only relevant for methods. */ |
177 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
178 | | }; |
179 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
180 | | static_assert(0 < 1, "There is no slot for us"); |
181 | | |
182 | | static bool |
183 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
184 | 0 | { |
185 | 0 | mozilla::dom::XULMenuElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::XULMenuElement>(obj); |
186 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
187 | 0 | // obviously can't preserve if we're not initialized. |
188 | 0 | if (self && self->GetWrapperPreserveColor()) { |
189 | 0 | PreserveWrapper(self); |
190 | 0 | } |
191 | 0 | return true; |
192 | 0 | } |
193 | | |
194 | | static void |
195 | | _finalize(js::FreeOp* fop, JSObject* obj) |
196 | 0 | { |
197 | 0 | mozilla::dom::XULMenuElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::XULMenuElement>(obj); |
198 | 0 | if (self) { |
199 | 0 | ClearWrapper(self, self, obj); |
200 | 0 | AddForDeferredFinalization<mozilla::dom::XULMenuElement>(self); |
201 | 0 | } |
202 | 0 | } |
203 | | |
204 | | static size_t |
205 | | _objectMoved(JSObject* obj, JSObject* old) |
206 | 0 | { |
207 | 0 | mozilla::dom::XULMenuElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::XULMenuElement>(obj); |
208 | 0 | if (self) { |
209 | 0 | UpdateWrapper(self, self, obj, old); |
210 | 0 | } |
211 | 0 |
|
212 | 0 | return 0; |
213 | 0 | } |
214 | | |
215 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
216 | | #if defined(__clang__) |
217 | | #pragma clang diagnostic push |
218 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
219 | | #endif |
220 | | static const JSFunctionSpec sMethods_specs[] = { |
221 | | JS_FNSPEC("handleKeyPress", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&handleKeyPress_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
222 | | JS_FS_END |
223 | | }; |
224 | | #if defined(__clang__) |
225 | | #pragma clang diagnostic pop |
226 | | #endif |
227 | | |
228 | | |
229 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
230 | | { nullptr, &sMethods_specs[0] }, |
231 | | { nullptr, nullptr } |
232 | | }; |
233 | | |
234 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
235 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
236 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
237 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
238 | | |
239 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
240 | | #if defined(__clang__) |
241 | | #pragma clang diagnostic push |
242 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
243 | | #endif |
244 | | static const JSPropertySpec sAttributes_specs[] = { |
245 | | { "activeChild", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &activeChild_getterinfo, GenericSetter<NormalThisPolicy>, &activeChild_setterinfo }, |
246 | | { "openedWithKey", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &openedWithKey_getterinfo, nullptr, nullptr }, |
247 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
248 | | }; |
249 | | #if defined(__clang__) |
250 | | #pragma clang diagnostic pop |
251 | | #endif |
252 | | |
253 | | |
254 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
255 | | { nullptr, &sAttributes_specs[0] }, |
256 | | { nullptr, nullptr } |
257 | | }; |
258 | | |
259 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
260 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
261 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
262 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
263 | | |
264 | | |
265 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
266 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
267 | | |
268 | | static const NativePropertiesN<2> sNativeProperties = { |
269 | | false, 0, |
270 | | false, 0, |
271 | | true, 0 /* sMethods */, |
272 | | true, 1 /* sAttributes */, |
273 | | false, 0, |
274 | | false, 0, |
275 | | false, 0, |
276 | | -1, |
277 | | 3, |
278 | | sNativeProperties_sortedPropertyIndices, |
279 | | { |
280 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
281 | | { sAttributes, &sNativeProperties_propertyInfos[1] } |
282 | | } |
283 | | }; |
284 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
285 | | "We have a property info count that is oversized"); |
286 | | |
287 | | static bool |
288 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
289 | 0 | { |
290 | 0 | AUTO_PROFILER_LABEL_FAST("XULMenuElement constructor", DOM, cx); |
291 | 0 |
|
292 | 0 | return HTMLConstructor(cx, argc, vp, |
293 | 0 | constructors::id::XULMenuElement, |
294 | 0 | prototypes::id::XULMenuElement, |
295 | 0 | CreateInterfaceObjects); |
296 | 0 | } |
297 | | |
298 | | static const js::ClassOps sInterfaceObjectClassOps = { |
299 | | nullptr, /* addProperty */ |
300 | | nullptr, /* delProperty */ |
301 | | nullptr, /* enumerate */ |
302 | | nullptr, /* newEnumerate */ |
303 | | nullptr, /* resolve */ |
304 | | nullptr, /* mayResolve */ |
305 | | nullptr, /* finalize */ |
306 | | _constructor, /* call */ |
307 | | nullptr, /* hasInstance */ |
308 | | _constructor, /* construct */ |
309 | | nullptr, /* trace */ |
310 | | }; |
311 | | |
312 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
313 | | { |
314 | | "Function", |
315 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
316 | | &sInterfaceObjectClassOps, |
317 | | JS_NULL_CLASS_SPEC, |
318 | | JS_NULL_CLASS_EXT, |
319 | | &sInterfaceObjectClassObjectOps |
320 | | }, |
321 | | eInterface, |
322 | | true, |
323 | | prototypes::id::XULMenuElement, |
324 | | PrototypeTraits<prototypes::id::XULMenuElement>::Depth, |
325 | | sNativePropertyHooks, |
326 | | "function XULMenuElement() {\n [native code]\n}", |
327 | | XULElement_Binding::GetConstructorObject |
328 | | }; |
329 | | |
330 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
331 | | { |
332 | | "XULMenuElementPrototype", |
333 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
334 | | JS_NULL_CLASS_OPS, |
335 | | JS_NULL_CLASS_SPEC, |
336 | | JS_NULL_CLASS_EXT, |
337 | | JS_NULL_OBJECT_OPS |
338 | | }, |
339 | | eInterfacePrototype, |
340 | | false, |
341 | | prototypes::id::XULMenuElement, |
342 | | PrototypeTraits<prototypes::id::XULMenuElement>::Depth, |
343 | | sNativePropertyHooks, |
344 | | "[object XULMenuElementPrototype]", |
345 | | XULElement_Binding::GetProtoObject |
346 | | }; |
347 | | |
348 | | bool |
349 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
350 | 0 | { |
351 | 0 | return IsChromeOrXBL(aCx, aObj); |
352 | 0 | } |
353 | | |
354 | | static const js::ClassOps sClassOps = { |
355 | | _addProperty, /* addProperty */ |
356 | | nullptr, /* delProperty */ |
357 | | nullptr, /* enumerate */ |
358 | | nullptr, /* newEnumerate */ |
359 | | nullptr, /* resolve */ |
360 | | nullptr, /* mayResolve */ |
361 | | _finalize, /* finalize */ |
362 | | nullptr, /* call */ |
363 | | nullptr, /* hasInstance */ |
364 | | nullptr, /* construct */ |
365 | | nullptr, /* trace */ |
366 | | }; |
367 | | |
368 | | static const js::ClassExtension sClassExtension = { |
369 | | nullptr, /* weakmapKeyDelegateOp */ |
370 | | _objectMoved /* objectMovedOp */ |
371 | | }; |
372 | | |
373 | | static const DOMJSClass sClass = { |
374 | | { "XULMenuElement", |
375 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
376 | | &sClassOps, |
377 | | JS_NULL_CLASS_SPEC, |
378 | | &sClassExtension, |
379 | | JS_NULL_OBJECT_OPS |
380 | | }, |
381 | | { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Element, prototypes::id::XULElement, prototypes::id::XULMenuElement, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
382 | | IsBaseOf<nsISupports, mozilla::dom::XULMenuElement >::value, |
383 | | sNativePropertyHooks, |
384 | | FindAssociatedGlobalForNative<mozilla::dom::XULMenuElement>::Get, |
385 | | GetProtoObjectHandle, |
386 | | GetCCParticipant<mozilla::dom::XULMenuElement>::Get() |
387 | | }; |
388 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
389 | | "Must have the right minimal number of reserved slots."); |
390 | | static_assert(1 >= 1, |
391 | | "Must have enough reserved slots."); |
392 | | |
393 | | const JSClass* |
394 | | GetJSClass() |
395 | 0 | { |
396 | 0 | return sClass.ToJSClass(); |
397 | 0 | } |
398 | | |
399 | | bool |
400 | | Wrap(JSContext* aCx, mozilla::dom::XULMenuElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
401 | 0 | { |
402 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::XULMenuElement>::value, |
403 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
404 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::XULMenuElement*>(aObject) == |
405 | 0 | reinterpret_cast<mozilla::dom::XULMenuElement*>(aObject), |
406 | 0 | "Multiple inheritance for mozilla::dom::XULMenuElement is broken."); |
407 | 0 | MOZ_ASSERT(static_cast<nsXULElement*>(aObject) == |
408 | 0 | reinterpret_cast<nsXULElement*>(aObject), |
409 | 0 | "Multiple inheritance for nsXULElement is broken."); |
410 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Element*>(aObject) == |
411 | 0 | reinterpret_cast<mozilla::dom::Element*>(aObject), |
412 | 0 | "Multiple inheritance for mozilla::dom::Element is broken."); |
413 | 0 | MOZ_ASSERT(static_cast<nsINode*>(aObject) == |
414 | 0 | reinterpret_cast<nsINode*>(aObject), |
415 | 0 | "Multiple inheritance for nsINode is broken."); |
416 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
417 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
418 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
419 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
420 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
421 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
422 | 0 | "You should probably not be using Wrap() directly; use " |
423 | 0 | "GetOrCreateDOMReflector instead"); |
424 | 0 |
|
425 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
426 | 0 | "nsISupports must be on our primary inheritance chain"); |
427 | 0 |
|
428 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
429 | 0 | if (!global) { |
430 | 0 | return false; |
431 | 0 | } |
432 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
433 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
434 | 0 |
|
435 | 0 | // That might have ended up wrapping us already, due to the wonders |
436 | 0 | // of XBL. Check for that, and bail out as needed. |
437 | 0 | aReflector.set(aCache->GetWrapper()); |
438 | 0 | if (aReflector) { |
439 | | #ifdef DEBUG |
440 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
441 | | #endif // DEBUG |
442 | | return true; |
443 | 0 | } |
444 | 0 |
|
445 | 0 | JSAutoRealm ar(aCx, global); |
446 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
447 | 0 | if (!canonicalProto) { |
448 | 0 | return false; |
449 | 0 | } |
450 | 0 | JS::Rooted<JSObject*> proto(aCx); |
451 | 0 | if (aGivenProto) { |
452 | 0 | proto = aGivenProto; |
453 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
454 | 0 | // coming in, we changed compartments to that of "parent" so may need |
455 | 0 | // to wrap the proto here. |
456 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
457 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
458 | 0 | return false; |
459 | 0 | } |
460 | 0 | } |
461 | 0 | } else { |
462 | 0 | proto = canonicalProto; |
463 | 0 | } |
464 | 0 |
|
465 | 0 | BindingJSObjectCreator<mozilla::dom::XULMenuElement> creator(aCx); |
466 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
467 | 0 | if (!aReflector) { |
468 | 0 | return false; |
469 | 0 | } |
470 | 0 | |
471 | 0 | aCache->SetWrapper(aReflector); |
472 | 0 | creator.InitializationSucceeded(); |
473 | 0 |
|
474 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
475 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
476 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
477 | 0 | // otherwise we won't be able to properly recreate it later, since |
478 | 0 | // we won't know what proto to use. Note that we don't check |
479 | 0 | // aGivenProto here, since it's entirely possible (and even |
480 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
481 | 0 | // same as canonicalProto. |
482 | 0 | if (proto != canonicalProto) { |
483 | 0 | PreserveWrapper(aObject); |
484 | 0 | } |
485 | 0 |
|
486 | 0 | return true; |
487 | 0 | } |
488 | | |
489 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
490 | | nullptr, |
491 | | nullptr, |
492 | | nullptr, |
493 | | { sNativeProperties.Upcast(), nullptr }, |
494 | | prototypes::id::XULMenuElement, |
495 | | constructors::id::XULMenuElement, |
496 | | XULElement_Binding::sNativePropertyHooks, |
497 | | &DefaultXrayExpandoObjectClass |
498 | | } }; |
499 | | |
500 | | void |
501 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
502 | 0 | { |
503 | 0 | JS::Handle<JSObject*> parentProto(XULElement_Binding::GetProtoObjectHandle(aCx)); |
504 | 0 | if (!parentProto) { |
505 | 0 | return; |
506 | 0 | } |
507 | 0 | |
508 | 0 | JS::Handle<JSObject*> constructorProto(XULElement_Binding::GetConstructorObjectHandle(aCx)); |
509 | 0 | if (!constructorProto) { |
510 | 0 | return; |
511 | 0 | } |
512 | 0 | |
513 | 0 | static bool sIdsInited = false; |
514 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
515 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
516 | 0 | return; |
517 | 0 | } |
518 | 0 | sIdsInited = true; |
519 | 0 | } |
520 | 0 |
|
521 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::XULMenuElement); |
522 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::XULMenuElement); |
523 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
524 | 0 | &sPrototypeClass.mBase, protoCache, |
525 | 0 | nullptr, |
526 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
527 | 0 | interfaceCache, |
528 | 0 | sNativeProperties.Upcast(), |
529 | 0 | nullptr, |
530 | 0 | "XULMenuElement", aDefineOnGlobal, |
531 | 0 | nullptr, |
532 | 0 | false); |
533 | 0 | } |
534 | | |
535 | | JSObject* |
536 | | GetConstructorObject(JSContext* aCx) |
537 | 0 | { |
538 | 0 | return GetConstructorObjectHandle(aCx); |
539 | 0 | } |
540 | | |
541 | | } // namespace XULMenuElement_Binding |
542 | | |
543 | | |
544 | | |
545 | | } // namespace dom |
546 | | } // namespace mozilla |