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