Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM HTMLMenuElement.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "HTMLElementBinding.h"
4 : #include "HTMLMenuElementBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/OwningNonNull.h"
7 : #include "mozilla/dom/BindingUtils.h"
8 : #include "mozilla/dom/CustomElementRegistry.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/HTMLMenuElement.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/Nullable.h"
13 : #include "mozilla/dom/PrimitiveConversions.h"
14 : #include "mozilla/dom/XrayExpandoClass.h"
15 : #include "nsContentUtils.h"
16 : #include "nsIMenuBuilder.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 : namespace HTMLMenuElementBinding {
22 :
23 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<HTMLElementBinding::NativeType>::value,
24 : "Can't inherit from an interface with a different ownership model.");
25 :
26 : static bool
27 0 : get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLMenuElement* self, JSJitGetterCallArgs args)
28 : {
29 0 : DOMString result;
30 0 : self->GetType(result);
31 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
32 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
33 0 : return false;
34 : }
35 0 : return true;
36 : }
37 :
38 : static bool
39 0 : set_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLMenuElement* self, JSJitSetterCallArgs args)
40 : {
41 0 : binding_detail::FakeString arg0;
42 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
43 0 : return false;
44 : }
45 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
46 0 : Maybe<AutoCEReaction> ceReaction;
47 0 : if (reactionsStack) {
48 0 : ceReaction.emplace(reactionsStack);
49 : }
50 0 : binding_detail::FastErrorResult rv;
51 0 : self->SetType(NonNullHelper(Constify(arg0)), rv);
52 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
53 0 : return false;
54 : }
55 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
56 :
57 0 : return true;
58 : }
59 :
60 : static const JSJitInfo type_getterinfo = {
61 : { (JSJitGetterOp)get_type },
62 : { prototypes::id::HTMLMenuElement },
63 : { PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth },
64 : JSJitInfo::Getter,
65 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
66 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
67 : false, /* isInfallible. False in setters. */
68 : false, /* isMovable. Not relevant for setters. */
69 : false, /* isEliminatable. Not relevant for setters. */
70 : false, /* isAlwaysInSlot. Only relevant for getters. */
71 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
72 : false, /* isTypedMethod. Only relevant for methods. */
73 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
74 : };
75 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
76 : static_assert(0 < 1, "There is no slot for us");
77 : static const JSJitInfo type_setterinfo = {
78 : { (JSJitGetterOp)set_type },
79 : { prototypes::id::HTMLMenuElement },
80 : { PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth },
81 : JSJitInfo::Setter,
82 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
83 : JSVAL_TYPE_UNDEFINED, /* 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 0 : get_label(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLMenuElement* self, JSJitGetterCallArgs args)
97 : {
98 0 : DOMString result;
99 0 : self->GetLabel(result);
100 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
101 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
102 0 : return false;
103 : }
104 0 : return true;
105 : }
106 :
107 : static bool
108 0 : set_label(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLMenuElement* self, JSJitSetterCallArgs args)
109 : {
110 0 : binding_detail::FakeString arg0;
111 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
112 0 : return false;
113 : }
114 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
115 0 : Maybe<AutoCEReaction> ceReaction;
116 0 : if (reactionsStack) {
117 0 : ceReaction.emplace(reactionsStack);
118 : }
119 0 : binding_detail::FastErrorResult rv;
120 0 : self->SetLabel(NonNullHelper(Constify(arg0)), rv);
121 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
122 0 : return false;
123 : }
124 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
125 :
126 0 : return true;
127 : }
128 :
129 : static const JSJitInfo label_getterinfo = {
130 : { (JSJitGetterOp)get_label },
131 : { prototypes::id::HTMLMenuElement },
132 : { PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth },
133 : JSJitInfo::Getter,
134 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
135 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
136 : false, /* isInfallible. False in setters. */
137 : false, /* isMovable. Not relevant for setters. */
138 : false, /* isEliminatable. Not relevant for setters. */
139 : false, /* isAlwaysInSlot. Only relevant for getters. */
140 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
141 : false, /* isTypedMethod. Only relevant for methods. */
142 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
143 : };
144 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
145 : static_assert(0 < 1, "There is no slot for us");
146 : static const JSJitInfo label_setterinfo = {
147 : { (JSJitGetterOp)set_label },
148 : { prototypes::id::HTMLMenuElement },
149 : { PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth },
150 : JSJitInfo::Setter,
151 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
152 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
153 : false, /* isInfallible. False in setters. */
154 : false, /* isMovable. Not relevant for setters. */
155 : false, /* isEliminatable. Not relevant for setters. */
156 : false, /* isAlwaysInSlot. Only relevant for getters. */
157 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
158 : false, /* isTypedMethod. Only relevant for methods. */
159 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
160 : };
161 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
162 : static_assert(0 < 1, "There is no slot for us");
163 :
164 : static bool
165 0 : get_compact(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLMenuElement* self, JSJitGetterCallArgs args)
166 : {
167 0 : bool result(self->Compact());
168 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
169 0 : args.rval().setBoolean(result);
170 0 : return true;
171 : }
172 :
173 : static bool
174 0 : set_compact(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLMenuElement* self, JSJitSetterCallArgs args)
175 : {
176 : bool arg0;
177 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
178 0 : return false;
179 : }
180 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
181 0 : Maybe<AutoCEReaction> ceReaction;
182 0 : if (reactionsStack) {
183 0 : ceReaction.emplace(reactionsStack);
184 : }
185 0 : binding_detail::FastErrorResult rv;
186 0 : self->SetCompact(arg0, rv);
187 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
188 0 : return false;
189 : }
190 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
191 :
192 0 : return true;
193 : }
194 :
195 : static const JSJitInfo compact_getterinfo = {
196 : { (JSJitGetterOp)get_compact },
197 : { prototypes::id::HTMLMenuElement },
198 : { PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth },
199 : JSJitInfo::Getter,
200 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
201 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
202 : true, /* isInfallible. False in setters. */
203 : false, /* isMovable. Not relevant for setters. */
204 : false, /* isEliminatable. Not relevant for setters. */
205 : false, /* isAlwaysInSlot. Only relevant for getters. */
206 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
207 : false, /* isTypedMethod. Only relevant for methods. */
208 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
209 : };
210 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
211 : static_assert(0 < 1, "There is no slot for us");
212 : static const JSJitInfo compact_setterinfo = {
213 : { (JSJitGetterOp)set_compact },
214 : { prototypes::id::HTMLMenuElement },
215 : { PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth },
216 : JSJitInfo::Setter,
217 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
218 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
219 : false, /* isInfallible. False in setters. */
220 : false, /* isMovable. Not relevant for setters. */
221 : false, /* isEliminatable. Not relevant for setters. */
222 : false, /* isAlwaysInSlot. Only relevant for getters. */
223 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
224 : false, /* isTypedMethod. Only relevant for methods. */
225 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
226 : };
227 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
228 : static_assert(0 < 1, "There is no slot for us");
229 :
230 : static bool
231 0 : sendShowEvent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLMenuElement* self, const JSJitMethodCallArgs& args)
232 : {
233 0 : self->SendShowEvent();
234 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
235 0 : args.rval().setUndefined();
236 0 : return true;
237 : }
238 :
239 : static const JSJitInfo sendShowEvent_methodinfo = {
240 : { (JSJitGetterOp)sendShowEvent },
241 : { prototypes::id::HTMLMenuElement },
242 : { PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth },
243 : JSJitInfo::Method,
244 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
245 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
246 : true, /* isInfallible. False in setters. */
247 : false, /* isMovable. Not relevant for setters. */
248 : false, /* isEliminatable. Not relevant for setters. */
249 : false, /* isAlwaysInSlot. Only relevant for getters. */
250 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
251 : false, /* isTypedMethod. Only relevant for methods. */
252 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
253 : };
254 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
255 : static_assert(0 < 1, "There is no slot for us");
256 :
257 : static bool
258 0 : createBuilder(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLMenuElement* self, const JSJitMethodCallArgs& args)
259 : {
260 0 : auto result(StrongOrRawPtr<nsIMenuBuilder>(self->CreateBuilder()));
261 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
262 0 : if (!result) {
263 0 : args.rval().setNull();
264 0 : return true;
265 : }
266 0 : if (!WrapObject(cx, result, &NS_GET_IID(nsIMenuBuilder), args.rval())) {
267 0 : return false;
268 : }
269 0 : return true;
270 : }
271 :
272 : static const JSJitInfo createBuilder_methodinfo = {
273 : { (JSJitGetterOp)createBuilder },
274 : { prototypes::id::HTMLMenuElement },
275 : { PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth },
276 : JSJitInfo::Method,
277 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
278 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
279 : false, /* isInfallible. False in setters. */
280 : false, /* isMovable. Not relevant for setters. */
281 : false, /* isEliminatable. Not relevant for setters. */
282 : false, /* isAlwaysInSlot. Only relevant for getters. */
283 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
284 : false, /* isTypedMethod. Only relevant for methods. */
285 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
286 : };
287 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
288 : static_assert(0 < 1, "There is no slot for us");
289 :
290 : static bool
291 0 : build(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLMenuElement* self, const JSJitMethodCallArgs& args)
292 : {
293 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
294 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "HTMLMenuElement.build");
295 : }
296 : nsIMenuBuilder* arg0;
297 0 : RefPtr<nsIMenuBuilder> arg0_holder;
298 0 : if (args[0].isObject()) {
299 0 : JS::Rooted<JSObject*> source(cx, &args[0].toObject());
300 0 : if (NS_FAILED(UnwrapArg<nsIMenuBuilder>(cx, source, getter_AddRefs(arg0_holder)))) {
301 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of HTMLMenuElement.build", "MenuBuilder");
302 0 : return false;
303 : }
304 0 : MOZ_ASSERT(arg0_holder);
305 0 : arg0 = arg0_holder;
306 : } else {
307 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of HTMLMenuElement.build");
308 0 : return false;
309 : }
310 0 : self->Build(NonNullHelper(arg0));
311 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
312 0 : args.rval().setUndefined();
313 0 : return true;
314 : }
315 :
316 : static const JSJitInfo build_methodinfo = {
317 : { (JSJitGetterOp)build },
318 : { prototypes::id::HTMLMenuElement },
319 : { PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth },
320 : JSJitInfo::Method,
321 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
322 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
323 : false, /* isInfallible. False in setters. */
324 : false, /* isMovable. Not relevant for setters. */
325 : false, /* isEliminatable. Not relevant for setters. */
326 : false, /* isAlwaysInSlot. Only relevant for getters. */
327 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
328 : false, /* isTypedMethod. Only relevant for methods. */
329 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
330 : };
331 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
332 : static_assert(0 < 1, "There is no slot for us");
333 :
334 : static bool
335 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
336 : {
337 0 : mozilla::dom::HTMLMenuElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLMenuElement>(obj);
338 : // We don't want to preserve if we don't have a wrapper, and we
339 : // obviously can't preserve if we're not initialized.
340 0 : if (self && self->GetWrapperPreserveColor()) {
341 0 : PreserveWrapper(self);
342 : }
343 0 : return true;
344 : }
345 :
346 : static void
347 0 : _finalize(js::FreeOp* fop, JSObject* obj)
348 : {
349 0 : mozilla::dom::HTMLMenuElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLMenuElement>(obj);
350 0 : if (self) {
351 0 : ClearWrapper(self, self, obj);
352 0 : AddForDeferredFinalization<mozilla::dom::HTMLMenuElement>(self);
353 : }
354 0 : }
355 :
356 : static void
357 0 : _objectMoved(JSObject* obj, const JSObject* old)
358 : {
359 0 : mozilla::dom::HTMLMenuElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLMenuElement>(obj);
360 0 : if (self) {
361 0 : UpdateWrapper(self, self, obj, old);
362 : }
363 0 : }
364 :
365 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
366 : #if defined(__clang__)
367 : #pragma clang diagnostic push
368 : #pragma clang diagnostic ignored "-Wmissing-braces"
369 : #endif
370 : static const JSFunctionSpec sChromeMethods_specs[] = {
371 : JS_FNSPEC("sendShowEvent", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&sendShowEvent_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
372 : JS_FNSPEC("createBuilder", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&createBuilder_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
373 : JS_FNSPEC("build", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&build_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
374 : JS_FS_END
375 : };
376 : #if defined(__clang__)
377 : #pragma clang diagnostic pop
378 : #endif
379 :
380 :
381 : // Can't be const because the pref-enabled boolean needs to be writable
382 : static Prefable<const JSFunctionSpec> sChromeMethods[] = {
383 : { nullptr, &sChromeMethods_specs[0] },
384 : { nullptr, nullptr }
385 : };
386 :
387 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
388 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
389 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
390 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
391 :
392 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
393 : #if defined(__clang__)
394 : #pragma clang diagnostic push
395 : #pragma clang diagnostic ignored "-Wmissing-braces"
396 : #endif
397 : static const JSPropertySpec sAttributes_specs[] = {
398 : { "type", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &type_getterinfo, GenericBindingSetter, &type_setterinfo },
399 : { "label", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &label_getterinfo, GenericBindingSetter, &label_setterinfo },
400 : { "compact", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &compact_getterinfo, GenericBindingSetter, &compact_setterinfo },
401 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
402 : };
403 : #if defined(__clang__)
404 : #pragma clang diagnostic pop
405 : #endif
406 :
407 :
408 : // Can't be const because the pref-enabled boolean needs to be writable
409 : static Prefable<const JSPropertySpec> sAttributes[] = {
410 : { nullptr, &sAttributes_specs[0] },
411 : { nullptr, nullptr }
412 : };
413 :
414 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
415 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
416 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
417 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
418 :
419 :
420 : static uint16_t sNativeProperties_sortedPropertyIndices[3];
421 : static PropertyInfo sNativeProperties_propertyInfos[3];
422 :
423 : static const NativePropertiesN<1> sNativeProperties = {
424 : false, 0,
425 : false, 0,
426 : false, 0,
427 : true, 0 /* sAttributes */,
428 : false, 0,
429 : false, 0,
430 : false, 0,
431 : -1,
432 : 3,
433 : sNativeProperties_sortedPropertyIndices,
434 : {
435 : { sAttributes, &sNativeProperties_propertyInfos[0] }
436 : }
437 : };
438 : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
439 : "We have a property info count that is oversized");
440 :
441 : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[3];
442 : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[3];
443 :
444 : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
445 : false, 0,
446 : false, 0,
447 : true, 0 /* sChromeMethods */,
448 : false, 0,
449 : false, 0,
450 : false, 0,
451 : false, 0,
452 : -1,
453 : 3,
454 : sChromeOnlyNativeProperties_sortedPropertyIndices,
455 : {
456 : { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
457 : }
458 : };
459 : static_assert(3 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
460 : "We have a property info count that is oversized");
461 :
462 : static bool
463 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
464 : {
465 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
466 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
467 0 : if (!args.isConstructing()) {
468 : // XXXbz wish I could get the name from the callee instead of
469 : // Adding more relocations
470 0 : return ThrowConstructorWithoutNew(cx, "HTMLMenuElement");
471 : }
472 :
473 0 : GlobalObject global(cx, obj);
474 0 : if (global.Failed()) {
475 0 : return false;
476 : }
477 :
478 : // The newTarget might be a cross-compartment wrapper. Get the underlying object
479 : // so we can do the spec's object-identity checks.
480 0 : JS::Rooted<JSObject*> newTarget(cx, js::CheckedUnwrap(&args.newTarget().toObject()));
481 0 : if (!newTarget) {
482 0 : return ThrowErrorMessage(cx, MSG_ILLEGAL_CONSTRUCTOR);
483 : }
484 :
485 : // Step 2 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
486 : // Enter the compartment of our underlying newTarget object, so we end
487 : // up comparing to the constructor object for our interface from that global.
488 : {
489 0 : JSAutoCompartment ac(cx, newTarget);
490 0 : JS::Handle<JSObject*> constructor(GetConstructorObjectHandle(cx));
491 0 : if (!constructor) {
492 0 : return false;
493 : }
494 0 : if (newTarget == constructor) {
495 0 : return ThrowErrorMessage(cx, MSG_ILLEGAL_CONSTRUCTOR);
496 : }
497 : }
498 :
499 0 : JS::Rooted<JSObject*> desiredProto(cx);
500 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
501 0 : return false;
502 : }
503 0 : if (!desiredProto) {
504 : // Step 7 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
505 : // This fallback behavior is designed to match analogous behavior for the
506 : // JavaScript built-ins. So we enter the compartment of our underlying
507 : // newTarget object and fall back to the prototype object from that global.
508 : // XXX The spec says to use GetFunctionRealm(), which is not actually
509 : // the same thing as what we have here (e.g. in the case of scripted callable proxies
510 : // whose target is not same-compartment with the proxy, or bound functions, etc).
511 : // https://bugzilla.mozilla.org/show_bug.cgi?id=1317658
512 : {
513 0 : JSAutoCompartment ac(cx, newTarget);
514 0 : desiredProto = GetProtoObjectHandle(cx);
515 0 : if (!desiredProto) {
516 0 : return false;
517 : }
518 : }
519 :
520 : // desiredProto is in the compartment of the underlying newTarget object.
521 : // Wrap it into the context compartment.
522 0 : if (!JS_WrapObject(cx, &desiredProto)) {
523 0 : return false;
524 : }
525 : }
526 :
527 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
528 0 : Maybe<JSAutoCompartment> ac;
529 0 : if (objIsXray) {
530 0 : obj = js::CheckedUnwrap(obj);
531 0 : if (!obj) {
532 0 : return false;
533 : }
534 0 : ac.emplace(cx, obj);
535 0 : if (!JS_WrapObject(cx, &desiredProto)) {
536 0 : return false;
537 : }
538 : }
539 0 : binding_detail::FastErrorResult rv;
540 0 : auto result(StrongOrRawPtr<mozilla::dom::HTMLMenuElement>(CreateHTMLElement(global, args, rv)));
541 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
542 0 : return false;
543 : }
544 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
545 : static_assert(!IsPointer<decltype(result)>::value,
546 : "NewObject implies that we need to keep the object alive with a strong reference.");
547 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
548 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
549 0 : return false;
550 : }
551 0 : return true;
552 : }
553 :
554 : static const js::ClassOps sInterfaceObjectClassOps = {
555 : nullptr, /* addProperty */
556 : nullptr, /* delProperty */
557 : nullptr, /* getProperty */
558 : nullptr, /* setProperty */
559 : nullptr, /* enumerate */
560 : nullptr, /* newEnumerate */
561 : nullptr, /* resolve */
562 : nullptr, /* mayResolve */
563 : nullptr, /* finalize */
564 : _constructor, /* call */
565 : nullptr, /* hasInstance */
566 : _constructor, /* construct */
567 : nullptr, /* trace */
568 : };
569 :
570 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
571 : {
572 : "Function",
573 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
574 : &sInterfaceObjectClassOps,
575 : JS_NULL_CLASS_SPEC,
576 : JS_NULL_CLASS_EXT,
577 : &sInterfaceObjectClassObjectOps
578 : },
579 : eInterface,
580 : true,
581 : prototypes::id::HTMLMenuElement,
582 : PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth,
583 : sNativePropertyHooks,
584 : "function HTMLMenuElement() {\n [native code]\n}",
585 : HTMLElementBinding::GetConstructorObject
586 : };
587 :
588 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
589 : {
590 : "HTMLMenuElementPrototype",
591 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
592 : JS_NULL_CLASS_OPS,
593 : JS_NULL_CLASS_SPEC,
594 : JS_NULL_CLASS_EXT,
595 : JS_NULL_OBJECT_OPS
596 : },
597 : eInterfacePrototype,
598 : false,
599 : prototypes::id::HTMLMenuElement,
600 : PrototypeTraits<prototypes::id::HTMLMenuElement>::Depth,
601 : sNativePropertyHooks,
602 : "[object HTMLMenuElementPrototype]",
603 : HTMLElementBinding::GetProtoObject
604 : };
605 :
606 : JSObject*
607 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
608 : {
609 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
610 : }
611 :
612 : static const js::ClassOps sClassOps = {
613 : _addProperty, /* addProperty */
614 : nullptr, /* delProperty */
615 : nullptr, /* getProperty */
616 : nullptr, /* setProperty */
617 : nullptr, /* enumerate */
618 : nullptr, /* newEnumerate */
619 : nullptr, /* resolve */
620 : nullptr, /* mayResolve */
621 : _finalize, /* finalize */
622 : nullptr, /* call */
623 : nullptr, /* hasInstance */
624 : nullptr, /* construct */
625 : nullptr, /* trace */
626 : };
627 :
628 : static const js::ClassExtension sClassExtension = {
629 : nullptr, /* weakmapKeyDelegateOp */
630 : _objectMoved /* objectMovedOp */
631 : };
632 :
633 : static const DOMJSClass sClass = {
634 : { "HTMLMenuElement",
635 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
636 : &sClassOps,
637 : JS_NULL_CLASS_SPEC,
638 : &sClassExtension,
639 : JS_NULL_OBJECT_OPS
640 : },
641 : { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Element, prototypes::id::HTMLElement, prototypes::id::HTMLMenuElement, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
642 : IsBaseOf<nsISupports, mozilla::dom::HTMLMenuElement >::value,
643 : sNativePropertyHooks,
644 : FindAssociatedGlobalForNative<mozilla::dom::HTMLMenuElement>::Get,
645 : GetProtoObjectHandle,
646 : GetCCParticipant<mozilla::dom::HTMLMenuElement>::Get()
647 : };
648 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
649 : "Must have the right minimal number of reserved slots.");
650 : static_assert(1 >= 1,
651 : "Must have enough reserved slots.");
652 :
653 : const JSClass*
654 0 : GetJSClass()
655 : {
656 0 : return sClass.ToJSClass();
657 : }
658 :
659 : bool
660 0 : Wrap(JSContext* aCx, mozilla::dom::HTMLMenuElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
661 : {
662 : MOZ_ASSERT(static_cast<mozilla::dom::HTMLMenuElement*>(aObject) ==
663 : reinterpret_cast<mozilla::dom::HTMLMenuElement*>(aObject),
664 : "Multiple inheritance for mozilla::dom::HTMLMenuElement is broken.");
665 : MOZ_ASSERT(static_cast<nsGenericHTMLElement*>(aObject) ==
666 : reinterpret_cast<nsGenericHTMLElement*>(aObject),
667 : "Multiple inheritance for nsGenericHTMLElement is broken.");
668 : MOZ_ASSERT(static_cast<mozilla::dom::Element*>(aObject) ==
669 : reinterpret_cast<mozilla::dom::Element*>(aObject),
670 : "Multiple inheritance for mozilla::dom::Element is broken.");
671 : MOZ_ASSERT(static_cast<nsINode*>(aObject) ==
672 : reinterpret_cast<nsINode*>(aObject),
673 : "Multiple inheritance for nsINode is broken.");
674 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
675 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
676 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
677 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
678 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
679 0 : MOZ_ASSERT(!aCache->GetWrapper(),
680 : "You should probably not be using Wrap() directly; use "
681 : "GetOrCreateDOMReflector instead");
682 :
683 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
684 : "nsISupports must be on our primary inheritance chain");
685 :
686 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
687 0 : if (!global) {
688 0 : return false;
689 : }
690 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
691 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
692 :
693 : // That might have ended up wrapping us already, due to the wonders
694 : // of XBL. Check for that, and bail out as needed.
695 0 : aReflector.set(aCache->GetWrapper());
696 0 : if (aReflector) {
697 : #ifdef DEBUG
698 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
699 : #endif // DEBUG
700 0 : return true;
701 : }
702 :
703 0 : JSAutoCompartment ac(aCx, global);
704 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
705 0 : if (!canonicalProto) {
706 0 : return false;
707 : }
708 0 : JS::Rooted<JSObject*> proto(aCx);
709 0 : if (aGivenProto) {
710 0 : proto = aGivenProto;
711 : // Unfortunately, while aGivenProto was in the compartment of aCx
712 : // coming in, we changed compartments to that of "parent" so may need
713 : // to wrap the proto here.
714 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
715 0 : if (!JS_WrapObject(aCx, &proto)) {
716 0 : return false;
717 : }
718 : }
719 : } else {
720 0 : proto = canonicalProto;
721 : }
722 :
723 0 : BindingJSObjectCreator<mozilla::dom::HTMLMenuElement> creator(aCx);
724 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
725 0 : if (!aReflector) {
726 0 : return false;
727 : }
728 :
729 0 : aCache->SetWrapper(aReflector);
730 0 : creator.InitializationSucceeded();
731 :
732 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
733 : aCache->GetWrapperPreserveColor() == aReflector);
734 : // If proto != canonicalProto, we have to preserve our wrapper;
735 : // otherwise we won't be able to properly recreate it later, since
736 : // we won't know what proto to use. Note that we don't check
737 : // aGivenProto here, since it's entirely possible (and even
738 : // somewhat common) to have a non-null aGivenProto which is the
739 : // same as canonicalProto.
740 0 : if (proto != canonicalProto) {
741 0 : PreserveWrapper(aObject);
742 : }
743 :
744 0 : return true;
745 : }
746 :
747 : const NativePropertyHooks sNativePropertyHooks[] = { {
748 : nullptr,
749 : nullptr,
750 : nullptr,
751 : { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
752 : prototypes::id::HTMLMenuElement,
753 : constructors::id::HTMLMenuElement,
754 : HTMLElementBinding::sNativePropertyHooks,
755 : &DefaultXrayExpandoObjectClass
756 : } };
757 :
758 : void
759 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
760 : {
761 0 : JS::Handle<JSObject*> parentProto(HTMLElementBinding::GetProtoObjectHandle(aCx));
762 0 : if (!parentProto) {
763 0 : return;
764 : }
765 :
766 0 : JS::Handle<JSObject*> constructorProto(HTMLElementBinding::GetConstructorObjectHandle(aCx));
767 0 : if (!constructorProto) {
768 0 : return;
769 : }
770 :
771 : static bool sIdsInited = false;
772 0 : if (!sIdsInited && NS_IsMainThread()) {
773 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
774 0 : return;
775 : }
776 0 : if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
777 0 : return;
778 : }
779 0 : sIdsInited = true;
780 : }
781 :
782 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::HTMLMenuElement);
783 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::HTMLMenuElement);
784 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
785 : &sPrototypeClass.mBase, protoCache,
786 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
787 : interfaceCache,
788 : sNativeProperties.Upcast(),
789 0 : nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
790 : "HTMLMenuElement", aDefineOnGlobal,
791 : nullptr,
792 0 : false);
793 : }
794 :
795 : JS::Handle<JSObject*>
796 0 : GetProtoObjectHandle(JSContext* aCx)
797 : {
798 : /* Get the interface prototype object for this class. This will create the
799 : object as needed. */
800 0 : bool aDefineOnGlobal = true;
801 :
802 : /* Make sure our global is sane. Hopefully we can remove this sometime */
803 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
804 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
805 0 : return nullptr;
806 : }
807 :
808 : /* Check to see whether the interface objects are already installed */
809 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
810 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::HTMLMenuElement)) {
811 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
812 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
813 : }
814 :
815 : /*
816 : * The object might _still_ be null, but that's OK.
817 : *
818 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
819 : * traced by TraceProtoAndIfaceCache() and its contents are never
820 : * changed after they have been set.
821 : *
822 : * Calling address() avoids the read read barrier that does gray
823 : * unmarking, but it's not possible for the object to be gray here.
824 : */
825 :
826 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::HTMLMenuElement);
827 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
828 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
829 : }
830 :
831 : JS::Handle<JSObject*>
832 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
833 : {
834 : /* Get the interface object for this class. This will create the object as
835 : needed. */
836 :
837 : /* Make sure our global is sane. Hopefully we can remove this sometime */
838 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
839 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
840 0 : return nullptr;
841 : }
842 :
843 : /* Check to see whether the interface objects are already installed */
844 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
845 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::HTMLMenuElement)) {
846 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
847 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
848 : }
849 :
850 : /*
851 : * The object might _still_ be null, but that's OK.
852 : *
853 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
854 : * traced by TraceProtoAndIfaceCache() and its contents are never
855 : * changed after they have been set.
856 : *
857 : * Calling address() avoids the read read barrier that does gray
858 : * unmarking, but it's not possible for the object to be gray here.
859 : */
860 :
861 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::HTMLMenuElement);
862 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
863 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
864 : }
865 :
866 : JSObject*
867 0 : GetConstructorObject(JSContext* aCx)
868 : {
869 0 : return GetConstructorObjectHandle(aCx);
870 : }
871 :
872 : } // namespace HTMLMenuElementBinding
873 :
874 :
875 :
876 : } // namespace dom
877 : } // namespace mozilla
|