Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM CSS.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "CSSBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "mozilla/OwningNonNull.h"
6 : #include "mozilla/dom/BindingUtils.h"
7 : #include "mozilla/dom/CSS.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 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 : namespace CSSBinding {
17 :
18 : static bool
19 0 : supports(JSContext* cx, unsigned argc, JS::Value* vp)
20 : {
21 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
22 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
23 :
24 0 : unsigned argcount = std::min(args.length(), 2u);
25 0 : switch (argcount) {
26 : case 1: {
27 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
28 0 : if (global.Failed()) {
29 0 : return false;
30 : }
31 :
32 0 : binding_detail::FakeString arg0;
33 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
34 0 : return false;
35 : }
36 0 : binding_detail::FastErrorResult rv;
37 0 : bool result(mozilla::dom::CSS::Supports(global, NonNullHelper(Constify(arg0)), rv));
38 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
39 0 : return false;
40 : }
41 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
42 0 : args.rval().setBoolean(result);
43 0 : return true;
44 : break;
45 : }
46 : case 2: {
47 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
48 0 : if (global.Failed()) {
49 0 : return false;
50 : }
51 :
52 0 : binding_detail::FakeString arg0;
53 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
54 0 : return false;
55 : }
56 0 : binding_detail::FakeString arg1;
57 0 : if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
58 0 : return false;
59 : }
60 0 : binding_detail::FastErrorResult rv;
61 0 : bool result(mozilla::dom::CSS::Supports(global, NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), rv));
62 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
63 0 : return false;
64 : }
65 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
66 0 : args.rval().setBoolean(result);
67 0 : return true;
68 : break;
69 : }
70 : default: {
71 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSS.supports");
72 : break;
73 : }
74 : }
75 : MOZ_CRASH("We have an always-returning default case");
76 : return false;
77 : }
78 :
79 : static bool
80 0 : escape(JSContext* cx, unsigned argc, JS::Value* vp)
81 : {
82 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
83 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
84 :
85 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
86 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSS.escape");
87 : }
88 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
89 0 : if (global.Failed()) {
90 0 : return false;
91 : }
92 :
93 0 : binding_detail::FakeString arg0;
94 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
95 0 : return false;
96 : }
97 0 : DOMString result;
98 0 : mozilla::dom::CSS::Escape(global, NonNullHelper(Constify(arg0)), result);
99 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
100 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
101 0 : return false;
102 : }
103 0 : return true;
104 : }
105 :
106 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
107 : #if defined(__clang__)
108 : #pragma clang diagnostic push
109 : #pragma clang diagnostic ignored "-Wmissing-braces"
110 : #endif
111 : static const JSFunctionSpec sStaticMethods_specs[] = {
112 : JS_FNSPEC("supports", supports, nullptr, 1, JSPROP_ENUMERATE, nullptr),
113 : JS_FNSPEC("escape", escape, nullptr, 1, JSPROP_ENUMERATE, nullptr),
114 : JS_FS_END
115 : };
116 : #if defined(__clang__)
117 : #pragma clang diagnostic pop
118 : #endif
119 :
120 :
121 : // Can't be const because the pref-enabled boolean needs to be writable
122 : static Prefable<const JSFunctionSpec> sStaticMethods[] = {
123 : { nullptr, &sStaticMethods_specs[0] },
124 : { nullptr, nullptr }
125 : };
126 :
127 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
128 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
129 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
130 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
131 :
132 :
133 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
134 : static PropertyInfo sNativeProperties_propertyInfos[2];
135 :
136 : static const NativePropertiesN<1> sNativeProperties = {
137 : true, 0 /* sStaticMethods */,
138 : false, 0,
139 : false, 0,
140 : false, 0,
141 : false, 0,
142 : false, 0,
143 : false, 0,
144 : -1,
145 : 2,
146 : sNativeProperties_sortedPropertyIndices,
147 : {
148 : { sStaticMethods, &sNativeProperties_propertyInfos[0] }
149 : }
150 : };
151 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
152 : "We have a property info count that is oversized");
153 :
154 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
155 : {
156 : "Function",
157 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
158 : &sBoringInterfaceObjectClassClassOps,
159 : JS_NULL_CLASS_SPEC,
160 : JS_NULL_CLASS_EXT,
161 : &sInterfaceObjectClassObjectOps
162 : },
163 : eInterface,
164 : false,
165 : prototypes::id::_ID_Count,
166 : 0,
167 : sNativePropertyHooks,
168 : "function CSS() {\n [native code]\n}",
169 : JS::GetRealmFunctionPrototype
170 : };
171 :
172 : JSObject*
173 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
174 : {
175 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
176 : }
177 :
178 : const NativePropertyHooks sNativePropertyHooks[] = { {
179 : nullptr,
180 : nullptr,
181 : nullptr,
182 : { sNativeProperties.Upcast(), nullptr },
183 : prototypes::id::_ID_Count,
184 : constructors::id::CSS,
185 : nullptr,
186 : &DefaultXrayExpandoObjectClass
187 : } };
188 :
189 : void
190 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
191 : {
192 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
193 0 : if (!constructorProto) {
194 0 : return;
195 : }
196 :
197 : static bool sIdsInited = false;
198 0 : if (!sIdsInited && NS_IsMainThread()) {
199 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
200 0 : return;
201 : }
202 0 : sIdsInited = true;
203 : }
204 :
205 0 : JS::Heap<JSObject*>* protoCache = nullptr;
206 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CSS);
207 0 : dom::CreateInterfaceObjects(aCx, aGlobal, nullptr,
208 : nullptr, protoCache,
209 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
210 : interfaceCache,
211 : sNativeProperties.Upcast(),
212 : nullptr,
213 : "CSS", aDefineOnGlobal,
214 : nullptr,
215 0 : false);
216 : }
217 :
218 : JS::Handle<JSObject*>
219 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
220 : {
221 : /* Get the interface object for this class. This will create the object as
222 : needed. */
223 :
224 : /* Make sure our global is sane. Hopefully we can remove this sometime */
225 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
226 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
227 0 : return nullptr;
228 : }
229 :
230 : /* Check to see whether the interface objects are already installed */
231 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
232 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::CSS)) {
233 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
234 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
235 : }
236 :
237 : /*
238 : * The object might _still_ be null, but that's OK.
239 : *
240 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
241 : * traced by TraceProtoAndIfaceCache() and its contents are never
242 : * changed after they have been set.
243 : *
244 : * Calling address() avoids the read read barrier that does gray
245 : * unmarking, but it's not possible for the object to be gray here.
246 : */
247 :
248 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::CSS);
249 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
250 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
251 : }
252 :
253 : JSObject*
254 0 : GetConstructorObject(JSContext* aCx)
255 : {
256 0 : return GetConstructorObjectHandle(aCx);
257 : }
258 :
259 : } // namespace CSSBinding
260 :
261 :
262 :
263 : } // namespace dom
264 : } // namespace mozilla
|