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