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