Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM NodeFilter.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "NodeFilterBinding.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/PrimitiveConversions.h"
11 : #include "mozilla/dom/XrayExpandoClass.h"
12 : #include "nsINode.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : namespace NodeFilterBinding {
18 :
19 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
20 : #if defined(__clang__)
21 : #pragma clang diagnostic push
22 : #pragma clang diagnostic ignored "-Wmissing-braces"
23 : #endif
24 : static const ConstantSpec sConstants_specs[] = {
25 : { "FILTER_ACCEPT", JS::Int32Value(1) },
26 : { "FILTER_REJECT", JS::Int32Value(2) },
27 : { "FILTER_SKIP", JS::Int32Value(3) },
28 : { "SHOW_ALL", JS::NumberValue(4294967295U) },
29 : { "SHOW_ELEMENT", JS::NumberValue(1U) },
30 : { "SHOW_ATTRIBUTE", JS::NumberValue(2U) },
31 : { "SHOW_TEXT", JS::NumberValue(4U) },
32 : { "SHOW_CDATA_SECTION", JS::NumberValue(8U) },
33 : { "SHOW_ENTITY_REFERENCE", JS::NumberValue(16U) },
34 : { "SHOW_ENTITY", JS::NumberValue(32U) },
35 : { "SHOW_PROCESSING_INSTRUCTION", JS::NumberValue(64U) },
36 : { "SHOW_COMMENT", JS::NumberValue(128U) },
37 : { "SHOW_DOCUMENT", JS::NumberValue(256U) },
38 : { "SHOW_DOCUMENT_TYPE", JS::NumberValue(512U) },
39 : { "SHOW_DOCUMENT_FRAGMENT", JS::NumberValue(1024U) },
40 : { "SHOW_NOTATION", JS::NumberValue(2048U) },
41 : { 0, JS::UndefinedValue() }
42 : };
43 : #if defined(__clang__)
44 : #pragma clang diagnostic pop
45 : #endif
46 :
47 :
48 : // Can't be const because the pref-enabled boolean needs to be writable
49 : static Prefable<const ConstantSpec> sConstants[] = {
50 : { nullptr, &sConstants_specs[0] },
51 : { nullptr, nullptr }
52 : };
53 :
54 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
55 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
56 : static_assert(16 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
57 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
58 :
59 :
60 : static uint16_t sNativeProperties_sortedPropertyIndices[16];
61 : static PropertyInfo sNativeProperties_propertyInfos[16];
62 :
63 : static const NativePropertiesN<1> sNativeProperties = {
64 : false, 0,
65 : false, 0,
66 : false, 0,
67 : false, 0,
68 : false, 0,
69 : false, 0,
70 : true, 0 /* sConstants */,
71 : -1,
72 : 16,
73 : sNativeProperties_sortedPropertyIndices,
74 : {
75 : { sConstants, &sNativeProperties_propertyInfos[0] }
76 : }
77 : };
78 : static_assert(16 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
79 : "We have a property info count that is oversized");
80 :
81 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
82 : {
83 : "Function",
84 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
85 : &sBoringInterfaceObjectClassClassOps,
86 : JS_NULL_CLASS_SPEC,
87 : JS_NULL_CLASS_EXT,
88 : &sInterfaceObjectClassObjectOps
89 : },
90 : eInterface,
91 : false,
92 : prototypes::id::_ID_Count,
93 : 0,
94 : sNativePropertyHooks,
95 : "function NodeFilter() {\n [native code]\n}",
96 : JS::GetRealmFunctionPrototype
97 : };
98 :
99 : JSObject*
100 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
101 : {
102 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
103 : }
104 :
105 : const NativePropertyHooks sNativePropertyHooks[] = { {
106 : nullptr,
107 : nullptr,
108 : nullptr,
109 : { sNativeProperties.Upcast(), nullptr },
110 : prototypes::id::_ID_Count,
111 : constructors::id::NodeFilter,
112 : nullptr,
113 : &DefaultXrayExpandoObjectClass
114 : } };
115 :
116 : void
117 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
118 : {
119 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
120 0 : if (!constructorProto) {
121 0 : return;
122 : }
123 :
124 : static bool sIdsInited = false;
125 0 : if (!sIdsInited && NS_IsMainThread()) {
126 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
127 0 : return;
128 : }
129 0 : sIdsInited = true;
130 : }
131 :
132 0 : JS::Heap<JSObject*>* protoCache = nullptr;
133 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::NodeFilter);
134 0 : dom::CreateInterfaceObjects(aCx, aGlobal, nullptr,
135 : nullptr, protoCache,
136 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
137 : interfaceCache,
138 : sNativeProperties.Upcast(),
139 : nullptr,
140 : "NodeFilter", aDefineOnGlobal,
141 : nullptr,
142 0 : false);
143 : }
144 :
145 : JS::Handle<JSObject*>
146 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
147 : {
148 : /* Get the interface object for this class. This will create the object as
149 : needed. */
150 :
151 : /* Make sure our global is sane. Hopefully we can remove this sometime */
152 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
153 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
154 0 : return nullptr;
155 : }
156 :
157 : /* Check to see whether the interface objects are already installed */
158 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
159 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::NodeFilter)) {
160 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
161 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
162 : }
163 :
164 : /*
165 : * The object might _still_ be null, but that's OK.
166 : *
167 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
168 : * traced by TraceProtoAndIfaceCache() and its contents are never
169 : * changed after they have been set.
170 : *
171 : * Calling address() avoids the read read barrier that does gray
172 : * unmarking, but it's not possible for the object to be gray here.
173 : */
174 :
175 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::NodeFilter);
176 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
177 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
178 : }
179 :
180 : JSObject*
181 0 : GetConstructorObject(JSContext* aCx)
182 : {
183 0 : return GetConstructorObjectHandle(aCx);
184 : }
185 :
186 : } // namespace NodeFilterBinding
187 :
188 :
189 :
190 : uint16_t
191 0 : NodeFilter::AcceptNode(JSContext* cx, JS::Handle<JS::Value> aThisVal, nsINode& node, ErrorResult& aRv)
192 : {
193 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
194 0 : JS::AutoValueVector argv(cx);
195 0 : if (!argv.resize(1)) {
196 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
197 0 : return uint16_t(0);
198 : }
199 0 : unsigned argc = 1;
200 :
201 : do {
202 0 : if (!GetOrCreateDOMReflector(cx, node, argv[0])) {
203 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
204 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
205 0 : return uint16_t(0);
206 : }
207 0 : break;
208 : } while (0);
209 :
210 0 : bool isCallable = JS::IsCallable(mCallback);
211 0 : JS::Rooted<JS::Value> callable(cx);
212 0 : if (isCallable) {
213 0 : callable = JS::ObjectValue(*mCallback);
214 : } else {
215 0 : NodeFilterAtoms* atomsCache = GetAtomCache<NodeFilterAtoms>(cx);
216 0 : if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
217 0 : !GetCallableProperty(cx, atomsCache->acceptNode_id, &callable)) {
218 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
219 0 : return uint16_t(0);
220 : }
221 : }
222 0 : JS::Rooted<JS::Value> thisValue(cx, isCallable ? aThisVal.get()
223 0 : : JS::ObjectValue(*mCallback));
224 0 : if (!JS::Call(cx, thisValue, callable,
225 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
226 0 : aRv.NoteJSContextException(cx);
227 0 : return uint16_t(0);
228 : }
229 : uint16_t rvalDecl;
230 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, rval, &rvalDecl)) {
231 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
232 0 : return uint16_t(0);
233 : }
234 0 : return rvalDecl;
235 : }
236 :
237 : bool
238 0 : NodeFilter::InitIds(JSContext* cx, NodeFilterAtoms* atomsCache)
239 : {
240 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
241 :
242 : // Initialize these in reverse order so that any failure leaves the first one
243 : // uninitialized.
244 0 : if (!atomsCache->acceptNode_id.init(cx, "acceptNode")) {
245 0 : return false;
246 : }
247 0 : return true;
248 : }
249 :
250 :
251 :
252 : namespace binding_detail {
253 : } // namespace binding_detail
254 :
255 :
256 : } // namespace dom
257 : } // namespace mozilla
|