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