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