Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM XMLSerializer.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "WrapperFactory.h"
4 : #include "XMLSerializerBinding.h"
5 : #include "mozilla/OwningNonNull.h"
6 : #include "mozilla/dom/BindingUtils.h"
7 : #include "mozilla/dom/DOMJSClass.h"
8 : #include "mozilla/dom/NonRefcountedDOMObject.h"
9 : #include "mozilla/dom/Nullable.h"
10 : #include "mozilla/dom/XrayExpandoClass.h"
11 : #include "nsContentUtils.h"
12 : #include "nsDOMSerializer.h"
13 : #include "nsINode.h"
14 : #include "nsIOutputStream.h"
15 : #include "nsISupports.h"
16 : #include "xpcjsid.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 : namespace XMLSerializerBinding {
22 :
23 : static bool
24 0 : serializeToString(JSContext* cx, JS::Handle<JSObject*> obj, nsDOMSerializer* self, const JSJitMethodCallArgs& args)
25 : {
26 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
27 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XMLSerializer.serializeToString");
28 : }
29 0 : NonNull<nsINode> arg0;
30 0 : if (args[0].isObject()) {
31 : {
32 0 : nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(args[0], arg0);
33 0 : if (NS_FAILED(rv)) {
34 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of XMLSerializer.serializeToString", "Node");
35 0 : return false;
36 : }
37 : }
38 : } else {
39 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of XMLSerializer.serializeToString");
40 0 : return false;
41 : }
42 0 : binding_detail::FastErrorResult rv;
43 0 : DOMString result;
44 0 : self->SerializeToString(NonNullHelper(arg0), result, rv);
45 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
46 0 : return false;
47 : }
48 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
49 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
50 0 : return false;
51 : }
52 0 : return true;
53 : }
54 :
55 : static const JSJitInfo serializeToString_methodinfo = {
56 : { (JSJitGetterOp)serializeToString },
57 : { prototypes::id::XMLSerializer },
58 : { PrototypeTraits<prototypes::id::XMLSerializer>::Depth },
59 : JSJitInfo::Method,
60 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
61 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
62 : false, /* isInfallible. False in setters. */
63 : false, /* isMovable. Not relevant for setters. */
64 : false, /* isEliminatable. Not relevant for setters. */
65 : false, /* isAlwaysInSlot. Only relevant for getters. */
66 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
67 : false, /* isTypedMethod. Only relevant for methods. */
68 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
69 : };
70 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
71 : static_assert(0 < 1, "There is no slot for us");
72 :
73 : static bool
74 0 : serializeToStream(JSContext* cx, JS::Handle<JSObject*> obj, nsDOMSerializer* self, const JSJitMethodCallArgs& args)
75 : {
76 0 : if (MOZ_UNLIKELY(args.length() < 3)) {
77 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XMLSerializer.serializeToStream");
78 : }
79 0 : NonNull<nsINode> arg0;
80 0 : if (args[0].isObject()) {
81 : {
82 0 : nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(args[0], arg0);
83 0 : if (NS_FAILED(rv)) {
84 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of XMLSerializer.serializeToStream", "Node");
85 0 : return false;
86 : }
87 : }
88 : } else {
89 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of XMLSerializer.serializeToStream");
90 0 : return false;
91 : }
92 : nsIOutputStream* arg1;
93 0 : RefPtr<nsIOutputStream> arg1_holder;
94 0 : if (args[1].isObject()) {
95 0 : JS::Rooted<JSObject*> source(cx, &args[1].toObject());
96 0 : if (NS_FAILED(UnwrapArg<nsIOutputStream>(cx, source, getter_AddRefs(arg1_holder)))) {
97 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 2 of XMLSerializer.serializeToStream", "OutputStream");
98 0 : return false;
99 : }
100 0 : MOZ_ASSERT(arg1_holder);
101 0 : arg1 = arg1_holder;
102 : } else {
103 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of XMLSerializer.serializeToStream");
104 0 : return false;
105 : }
106 0 : binding_detail::FakeString arg2;
107 0 : if (!ConvertJSValueToString(cx, args[2], eNull, eNull, arg2)) {
108 0 : return false;
109 : }
110 0 : binding_detail::FastErrorResult rv;
111 0 : self->SerializeToStream(NonNullHelper(arg0), NonNullHelper(arg1), NonNullHelper(Constify(arg2)), rv);
112 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
113 0 : return false;
114 : }
115 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
116 0 : args.rval().setUndefined();
117 0 : return true;
118 : }
119 :
120 : static const JSJitInfo serializeToStream_methodinfo = {
121 : { (JSJitGetterOp)serializeToStream },
122 : { prototypes::id::XMLSerializer },
123 : { PrototypeTraits<prototypes::id::XMLSerializer>::Depth },
124 : JSJitInfo::Method,
125 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
126 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
127 : false, /* isInfallible. False in setters. */
128 : false, /* isMovable. Not relevant for setters. */
129 : false, /* isEliminatable. Not relevant for setters. */
130 : false, /* isAlwaysInSlot. Only relevant for getters. */
131 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
132 : false, /* isTypedMethod. Only relevant for methods. */
133 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
134 : };
135 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
136 : static_assert(0 < 1, "There is no slot for us");
137 :
138 : static bool
139 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
140 : {
141 0 : nsDOMSerializer* self = UnwrapPossiblyNotInitializedDOMObject<nsDOMSerializer>(obj);
142 : // We don't want to preserve if we don't have a wrapper, and we
143 : // obviously can't preserve if we're not initialized.
144 0 : if (self && self->GetWrapperPreserveColor()) {
145 0 : PreserveWrapper(self);
146 : }
147 0 : return true;
148 : }
149 :
150 : static void
151 0 : _finalize(js::FreeOp* fop, JSObject* obj)
152 : {
153 0 : nsDOMSerializer* self = UnwrapPossiblyNotInitializedDOMObject<nsDOMSerializer>(obj);
154 0 : if (self) {
155 0 : ClearWrapper(self, self, obj);
156 0 : AddForDeferredFinalization<nsDOMSerializer>(self);
157 : }
158 0 : }
159 :
160 : static void
161 0 : _objectMoved(JSObject* obj, const JSObject* old)
162 : {
163 0 : nsDOMSerializer* self = UnwrapPossiblyNotInitializedDOMObject<nsDOMSerializer>(obj);
164 0 : if (self) {
165 0 : UpdateWrapper(self, self, obj, old);
166 : }
167 0 : }
168 :
169 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
170 : #if defined(__clang__)
171 : #pragma clang diagnostic push
172 : #pragma clang diagnostic ignored "-Wmissing-braces"
173 : #endif
174 : static const JSFunctionSpec sMethods_specs[] = {
175 : JS_FNSPEC("serializeToString", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&serializeToString_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
176 : JS_FS_END,
177 : JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
178 : JS_FS_END
179 : };
180 : #if defined(__clang__)
181 : #pragma clang diagnostic pop
182 : #endif
183 :
184 : static PrefableDisablers sMethods_disablers2 = {
185 : true, false, 0, &WantsQueryInterface<nsDOMSerializer>::Enabled
186 : };
187 :
188 : // Can't be const because the pref-enabled boolean needs to be writable
189 : static Prefable<const JSFunctionSpec> sMethods[] = {
190 : { nullptr, &sMethods_specs[0] },
191 : { &sMethods_disablers2, &sMethods_specs[2] },
192 : { nullptr, nullptr }
193 : };
194 :
195 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
196 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
197 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
198 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
199 :
200 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
201 : #if defined(__clang__)
202 : #pragma clang diagnostic push
203 : #pragma clang diagnostic ignored "-Wmissing-braces"
204 : #endif
205 : static const JSFunctionSpec sChromeMethods_specs[] = {
206 : JS_FNSPEC("serializeToStream", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&serializeToStream_methodinfo), 3, JSPROP_ENUMERATE, nullptr),
207 : JS_FS_END
208 : };
209 : #if defined(__clang__)
210 : #pragma clang diagnostic pop
211 : #endif
212 :
213 :
214 : // Can't be const because the pref-enabled boolean needs to be writable
215 : static Prefable<const JSFunctionSpec> sChromeMethods[] = {
216 : { nullptr, &sChromeMethods_specs[0] },
217 : { nullptr, nullptr }
218 : };
219 :
220 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
221 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
222 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
223 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
224 :
225 :
226 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
227 : static PropertyInfo sNativeProperties_propertyInfos[2];
228 :
229 : static const NativePropertiesN<1> sNativeProperties = {
230 : false, 0,
231 : false, 0,
232 : true, 0 /* sMethods */,
233 : false, 0,
234 : false, 0,
235 : false, 0,
236 : false, 0,
237 : -1,
238 : 2,
239 : sNativeProperties_sortedPropertyIndices,
240 : {
241 : { sMethods, &sNativeProperties_propertyInfos[0] }
242 : }
243 : };
244 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
245 : "We have a property info count that is oversized");
246 :
247 : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
248 : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
249 :
250 : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
251 : false, 0,
252 : false, 0,
253 : true, 0 /* sChromeMethods */,
254 : false, 0,
255 : false, 0,
256 : false, 0,
257 : false, 0,
258 : -1,
259 : 1,
260 : sChromeOnlyNativeProperties_sortedPropertyIndices,
261 : {
262 : { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
263 : }
264 : };
265 : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
266 : "We have a property info count that is oversized");
267 :
268 : static bool
269 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
270 : {
271 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
272 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
273 0 : if (!args.isConstructing()) {
274 : // XXXbz wish I could get the name from the callee instead of
275 : // Adding more relocations
276 0 : return ThrowConstructorWithoutNew(cx, "XMLSerializer");
277 : }
278 :
279 0 : GlobalObject global(cx, obj);
280 0 : if (global.Failed()) {
281 0 : return false;
282 : }
283 :
284 0 : JS::Rooted<JSObject*> desiredProto(cx);
285 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
286 0 : return false;
287 : }
288 :
289 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
290 0 : Maybe<JSAutoCompartment> ac;
291 0 : if (objIsXray) {
292 0 : obj = js::CheckedUnwrap(obj);
293 0 : if (!obj) {
294 0 : return false;
295 : }
296 0 : ac.emplace(cx, obj);
297 0 : if (!JS_WrapObject(cx, &desiredProto)) {
298 0 : return false;
299 : }
300 : }
301 0 : binding_detail::FastErrorResult rv;
302 0 : auto result(StrongOrRawPtr<nsDOMSerializer>(nsDOMSerializer::Constructor(global, rv)));
303 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
304 0 : return false;
305 : }
306 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
307 : static_assert(!IsPointer<decltype(result)>::value,
308 : "NewObject implies that we need to keep the object alive with a strong reference.");
309 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
310 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
311 0 : return false;
312 : }
313 0 : return true;
314 : }
315 :
316 : static const js::ClassOps sInterfaceObjectClassOps = {
317 : nullptr, /* addProperty */
318 : nullptr, /* delProperty */
319 : nullptr, /* getProperty */
320 : nullptr, /* setProperty */
321 : nullptr, /* enumerate */
322 : nullptr, /* newEnumerate */
323 : nullptr, /* resolve */
324 : nullptr, /* mayResolve */
325 : nullptr, /* finalize */
326 : _constructor, /* call */
327 : nullptr, /* hasInstance */
328 : _constructor, /* construct */
329 : nullptr, /* trace */
330 : };
331 :
332 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
333 : {
334 : "Function",
335 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
336 : &sInterfaceObjectClassOps,
337 : JS_NULL_CLASS_SPEC,
338 : JS_NULL_CLASS_EXT,
339 : &sInterfaceObjectClassObjectOps
340 : },
341 : eInterface,
342 : true,
343 : prototypes::id::XMLSerializer,
344 : PrototypeTraits<prototypes::id::XMLSerializer>::Depth,
345 : sNativePropertyHooks,
346 : "function XMLSerializer() {\n [native code]\n}",
347 : JS::GetRealmFunctionPrototype
348 : };
349 :
350 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
351 : {
352 : "XMLSerializerPrototype",
353 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
354 : JS_NULL_CLASS_OPS,
355 : JS_NULL_CLASS_SPEC,
356 : JS_NULL_CLASS_EXT,
357 : JS_NULL_OBJECT_OPS
358 : },
359 : eInterfacePrototype,
360 : false,
361 : prototypes::id::XMLSerializer,
362 : PrototypeTraits<prototypes::id::XMLSerializer>::Depth,
363 : sNativePropertyHooks,
364 : "[object XMLSerializerPrototype]",
365 : JS::GetRealmObjectPrototype
366 : };
367 :
368 : JSObject*
369 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
370 : {
371 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
372 : }
373 :
374 : static const js::ClassOps sClassOps = {
375 : _addProperty, /* addProperty */
376 : nullptr, /* delProperty */
377 : nullptr, /* getProperty */
378 : nullptr, /* setProperty */
379 : nullptr, /* enumerate */
380 : nullptr, /* newEnumerate */
381 : nullptr, /* resolve */
382 : nullptr, /* mayResolve */
383 : _finalize, /* finalize */
384 : nullptr, /* call */
385 : nullptr, /* hasInstance */
386 : nullptr, /* construct */
387 : nullptr, /* trace */
388 : };
389 :
390 : static const js::ClassExtension sClassExtension = {
391 : nullptr, /* weakmapKeyDelegateOp */
392 : _objectMoved /* objectMovedOp */
393 : };
394 :
395 : static const DOMJSClass sClass = {
396 : { "XMLSerializer",
397 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
398 : &sClassOps,
399 : JS_NULL_CLASS_SPEC,
400 : &sClassExtension,
401 : JS_NULL_OBJECT_OPS
402 : },
403 : { prototypes::id::XMLSerializer, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
404 : IsBaseOf<nsISupports, nsDOMSerializer >::value,
405 : sNativePropertyHooks,
406 : FindAssociatedGlobalForNative<nsDOMSerializer>::Get,
407 : GetProtoObjectHandle,
408 : GetCCParticipant<nsDOMSerializer>::Get()
409 : };
410 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
411 : "Must have the right minimal number of reserved slots.");
412 : static_assert(1 >= 1,
413 : "Must have enough reserved slots.");
414 :
415 : const JSClass*
416 0 : GetJSClass()
417 : {
418 0 : return sClass.ToJSClass();
419 : }
420 :
421 : bool
422 0 : Wrap(JSContext* aCx, nsDOMSerializer* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
423 : {
424 : MOZ_ASSERT(static_cast<nsDOMSerializer*>(aObject) ==
425 : reinterpret_cast<nsDOMSerializer*>(aObject),
426 : "Multiple inheritance for nsDOMSerializer is broken.");
427 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
428 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
429 0 : MOZ_ASSERT(!aCache->GetWrapper(),
430 : "You should probably not be using Wrap() directly; use "
431 : "GetOrCreateDOMReflector instead");
432 :
433 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
434 : "nsISupports must be on our primary inheritance chain");
435 :
436 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
437 0 : if (!global) {
438 0 : return false;
439 : }
440 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
441 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
442 :
443 : // That might have ended up wrapping us already, due to the wonders
444 : // of XBL. Check for that, and bail out as needed.
445 0 : aReflector.set(aCache->GetWrapper());
446 0 : if (aReflector) {
447 : #ifdef DEBUG
448 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
449 : #endif // DEBUG
450 0 : return true;
451 : }
452 :
453 0 : JSAutoCompartment ac(aCx, global);
454 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
455 0 : if (!canonicalProto) {
456 0 : return false;
457 : }
458 0 : JS::Rooted<JSObject*> proto(aCx);
459 0 : if (aGivenProto) {
460 0 : proto = aGivenProto;
461 : // Unfortunately, while aGivenProto was in the compartment of aCx
462 : // coming in, we changed compartments to that of "parent" so may need
463 : // to wrap the proto here.
464 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
465 0 : if (!JS_WrapObject(aCx, &proto)) {
466 0 : return false;
467 : }
468 : }
469 : } else {
470 0 : proto = canonicalProto;
471 : }
472 :
473 0 : BindingJSObjectCreator<nsDOMSerializer> creator(aCx);
474 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
475 0 : if (!aReflector) {
476 0 : return false;
477 : }
478 :
479 0 : aCache->SetWrapper(aReflector);
480 0 : creator.InitializationSucceeded();
481 :
482 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
483 : aCache->GetWrapperPreserveColor() == aReflector);
484 : // If proto != canonicalProto, we have to preserve our wrapper;
485 : // otherwise we won't be able to properly recreate it later, since
486 : // we won't know what proto to use. Note that we don't check
487 : // aGivenProto here, since it's entirely possible (and even
488 : // somewhat common) to have a non-null aGivenProto which is the
489 : // same as canonicalProto.
490 0 : if (proto != canonicalProto) {
491 0 : PreserveWrapper(aObject);
492 : }
493 :
494 0 : return true;
495 : }
496 :
497 : const NativePropertyHooks sNativePropertyHooks[] = { {
498 : nullptr,
499 : nullptr,
500 : nullptr,
501 : { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
502 : prototypes::id::XMLSerializer,
503 : constructors::id::XMLSerializer,
504 : nullptr,
505 : &DefaultXrayExpandoObjectClass
506 : } };
507 :
508 : void
509 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
510 : {
511 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
512 0 : if (!parentProto) {
513 0 : return;
514 : }
515 :
516 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
517 0 : if (!constructorProto) {
518 0 : return;
519 : }
520 :
521 : static bool sIdsInited = false;
522 0 : if (!sIdsInited && NS_IsMainThread()) {
523 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
524 0 : return;
525 : }
526 0 : if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
527 0 : return;
528 : }
529 0 : sIdsInited = true;
530 : }
531 :
532 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::XMLSerializer);
533 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::XMLSerializer);
534 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
535 : &sPrototypeClass.mBase, protoCache,
536 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
537 : interfaceCache,
538 : sNativeProperties.Upcast(),
539 0 : nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
540 : "XMLSerializer", aDefineOnGlobal,
541 : nullptr,
542 0 : false);
543 : }
544 :
545 : JS::Handle<JSObject*>
546 0 : GetProtoObjectHandle(JSContext* aCx)
547 : {
548 : /* Get the interface prototype object for this class. This will create the
549 : object as needed. */
550 0 : bool aDefineOnGlobal = true;
551 :
552 : /* Make sure our global is sane. Hopefully we can remove this sometime */
553 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
554 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
555 0 : return nullptr;
556 : }
557 :
558 : /* Check to see whether the interface objects are already installed */
559 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
560 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::XMLSerializer)) {
561 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
562 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
563 : }
564 :
565 : /*
566 : * The object might _still_ be null, but that's OK.
567 : *
568 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
569 : * traced by TraceProtoAndIfaceCache() and its contents are never
570 : * changed after they have been set.
571 : *
572 : * Calling address() avoids the read read barrier that does gray
573 : * unmarking, but it's not possible for the object to be gray here.
574 : */
575 :
576 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::XMLSerializer);
577 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
578 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
579 : }
580 :
581 : JS::Handle<JSObject*>
582 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
583 : {
584 : /* Get the interface object for this class. This will create the object as
585 : needed. */
586 :
587 : /* Make sure our global is sane. Hopefully we can remove this sometime */
588 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
589 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
590 0 : return nullptr;
591 : }
592 :
593 : /* Check to see whether the interface objects are already installed */
594 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
595 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::XMLSerializer)) {
596 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
597 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
598 : }
599 :
600 : /*
601 : * The object might _still_ be null, but that's OK.
602 : *
603 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
604 : * traced by TraceProtoAndIfaceCache() and its contents are never
605 : * changed after they have been set.
606 : *
607 : * Calling address() avoids the read read barrier that does gray
608 : * unmarking, but it's not possible for the object to be gray here.
609 : */
610 :
611 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::XMLSerializer);
612 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
613 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
614 : }
615 :
616 : JSObject*
617 0 : GetConstructorObject(JSContext* aCx)
618 : {
619 0 : return GetConstructorObjectHandle(aCx);
620 : }
621 :
622 : } // namespace XMLSerializerBinding
623 :
624 :
625 :
626 : } // namespace dom
627 : } // namespace mozilla
|