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