/work/obj-fuzz/dom/bindings/AnimatableBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM Animatable.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AnimatableBinding.h" |
4 | | #include "AtomList.h" |
5 | | #include "mozilla/FloatingPoint.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
9 | | #include "mozilla/dom/PrimitiveConversions.h" |
10 | | #include "mozilla/dom/ScriptSettings.h" |
11 | | #include "mozilla/dom/SimpleGlobalObject.h" |
12 | | #include "mozilla/dom/UnionConversions.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
18 | | using namespace mozilla::dom::binding_detail; |
19 | | |
20 | | |
21 | | |
22 | | AnimationFilter::AnimationFilter() |
23 | 0 | { |
24 | 0 | // Safe to pass a null context if we pass a null value |
25 | 0 | Init(nullptr, JS::NullHandleValue); |
26 | 0 | } |
27 | | |
28 | | |
29 | | |
30 | | bool |
31 | | AnimationFilter::InitIds(JSContext* cx, AnimationFilterAtoms* atomsCache) |
32 | 0 | { |
33 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
34 | 0 |
|
35 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
36 | 0 | // uninitialized. |
37 | 0 | if (!atomsCache->subtree_id.init(cx, "subtree")) { |
38 | 0 | return false; |
39 | 0 | } |
40 | 0 | return true; |
41 | 0 | } |
42 | | |
43 | | bool |
44 | | AnimationFilter::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
45 | 0 | { |
46 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
47 | 0 | // Since in that case we will not have to do any property gets |
48 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
49 | 0 | // checkers by static analysis tools |
50 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
51 | 0 | AnimationFilterAtoms* atomsCache = nullptr; |
52 | 0 | if (cx) { |
53 | 0 | atomsCache = GetAtomCache<AnimationFilterAtoms>(cx); |
54 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
55 | 0 | return false; |
56 | 0 | } |
57 | 0 | } |
58 | 0 | |
59 | 0 | if (!IsConvertibleToDictionary(val)) { |
60 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
61 | 0 | } |
62 | 0 | |
63 | 0 | bool isNull = val.isNullOrUndefined(); |
64 | 0 | // We only need these if !isNull, in which case we have |cx|. |
65 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
66 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
67 | 0 | if (!isNull) { |
68 | 0 | MOZ_ASSERT(cx); |
69 | 0 | object.emplace(cx, &val.toObject()); |
70 | 0 | temp.emplace(cx); |
71 | 0 | } |
72 | 0 | if (!isNull) { |
73 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->subtree_id, temp.ptr())) { |
74 | 0 | return false; |
75 | 0 | } |
76 | 0 | } |
77 | 0 | if (!isNull && !temp->isUndefined()) { |
78 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mSubtree)) { |
79 | 0 | return false; |
80 | 0 | } |
81 | 0 | } else { |
82 | 0 | mSubtree = false; |
83 | 0 | } |
84 | 0 | mIsAnyMemberPresent = true; |
85 | 0 | return true; |
86 | 0 | } |
87 | | |
88 | | bool |
89 | | AnimationFilter::Init(const nsAString& aJSON) |
90 | 0 | { |
91 | 0 | AutoJSAPI jsapi; |
92 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
93 | 0 | if (!cleanGlobal) { |
94 | 0 | return false; |
95 | 0 | } |
96 | 0 | if (!jsapi.Init(cleanGlobal)) { |
97 | 0 | return false; |
98 | 0 | } |
99 | 0 | JSContext* cx = jsapi.cx(); |
100 | 0 | JS::Rooted<JS::Value> json(cx); |
101 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
102 | 0 | NS_ENSURE_TRUE(ok, false); |
103 | 0 | return Init(cx, json); |
104 | 0 | } |
105 | | |
106 | | bool |
107 | | AnimationFilter::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
108 | 0 | { |
109 | 0 | AnimationFilterAtoms* atomsCache = GetAtomCache<AnimationFilterAtoms>(cx); |
110 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
111 | 0 | return false; |
112 | 0 | } |
113 | 0 | |
114 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
115 | 0 | if (!obj) { |
116 | 0 | return false; |
117 | 0 | } |
118 | 0 | rval.set(JS::ObjectValue(*obj)); |
119 | 0 |
|
120 | 0 | do { |
121 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
122 | 0 | JS::Rooted<JS::Value> temp(cx); |
123 | 0 | bool const & currentValue = mSubtree; |
124 | 0 | temp.setBoolean(currentValue); |
125 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->subtree_id, temp, JSPROP_ENUMERATE)) { |
126 | 0 | return false; |
127 | 0 | } |
128 | 0 | break; |
129 | 0 | } while(false); |
130 | 0 |
|
131 | 0 | return true; |
132 | 0 | } |
133 | | |
134 | | bool |
135 | | AnimationFilter::ToJSON(nsAString& aJSON) const |
136 | 0 | { |
137 | 0 | AutoJSAPI jsapi; |
138 | 0 | jsapi.Init(); |
139 | 0 | JSContext *cx = jsapi.cx(); |
140 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
141 | 0 | // because we'll only be creating objects, in ways that have no |
142 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
143 | 0 | // which likewise guarantees no side-effects for the sorts of |
144 | 0 | // things we will pass it. |
145 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
146 | 0 | JS::Rooted<JS::Value> val(cx); |
147 | 0 | if (!ToObjectInternal(cx, &val)) { |
148 | 0 | return false; |
149 | 0 | } |
150 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
151 | 0 | return StringifyToJSON(cx, obj, aJSON); |
152 | 0 | } |
153 | | |
154 | | void |
155 | | AnimationFilter::TraceDictionary(JSTracer* trc) |
156 | 0 | { |
157 | 0 | } |
158 | | |
159 | | AnimationFilter& |
160 | | AnimationFilter::operator=(const AnimationFilter& aOther) |
161 | 0 | { |
162 | 0 | DictionaryBase::operator=(aOther); |
163 | 0 | mSubtree = aOther.mSubtree; |
164 | 0 | return *this; |
165 | 0 | } |
166 | | |
167 | | namespace binding_detail { |
168 | | } // namespace binding_detail |
169 | | |
170 | | |
171 | | |
172 | | KeyframeAnimationOptions::KeyframeAnimationOptions() |
173 | | : KeyframeEffectOptions(FastDictionaryInitializer()) |
174 | 0 | { |
175 | 0 | // Safe to pass a null context if we pass a null value |
176 | 0 | Init(nullptr, JS::NullHandleValue); |
177 | 0 | } |
178 | | |
179 | | |
180 | | |
181 | | bool |
182 | | KeyframeAnimationOptions::InitIds(JSContext* cx, KeyframeAnimationOptionsAtoms* atomsCache) |
183 | 0 | { |
184 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
185 | 0 |
|
186 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
187 | 0 | // uninitialized. |
188 | 0 | if (!atomsCache->id_id.init(cx, "id")) { |
189 | 0 | return false; |
190 | 0 | } |
191 | 0 | return true; |
192 | 0 | } |
193 | | |
194 | | bool |
195 | | KeyframeAnimationOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
196 | 0 | { |
197 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
198 | 0 | // Since in that case we will not have to do any property gets |
199 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
200 | 0 | // checkers by static analysis tools |
201 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
202 | 0 | KeyframeAnimationOptionsAtoms* atomsCache = nullptr; |
203 | 0 | if (cx) { |
204 | 0 | atomsCache = GetAtomCache<KeyframeAnimationOptionsAtoms>(cx); |
205 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
206 | 0 | return false; |
207 | 0 | } |
208 | 0 | } |
209 | 0 | |
210 | 0 | // Per spec, we init the parent's members first |
211 | 0 | if (!KeyframeEffectOptions::Init(cx, val)) { |
212 | 0 | return false; |
213 | 0 | } |
214 | 0 | |
215 | 0 | bool isNull = val.isNullOrUndefined(); |
216 | 0 | // We only need these if !isNull, in which case we have |cx|. |
217 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
218 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
219 | 0 | if (!isNull) { |
220 | 0 | MOZ_ASSERT(cx); |
221 | 0 | object.emplace(cx, &val.toObject()); |
222 | 0 | temp.emplace(cx); |
223 | 0 | } |
224 | 0 | if (!isNull) { |
225 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->id_id, temp.ptr())) { |
226 | 0 | return false; |
227 | 0 | } |
228 | 0 | } |
229 | 0 | if (!isNull && !temp->isUndefined()) { |
230 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mId)) { |
231 | 0 | return false; |
232 | 0 | } |
233 | 0 | } else { |
234 | 0 | static const char16_t data[] = { 0 }; |
235 | 0 | mId.Rebind(data, ArrayLength(data) - 1); |
236 | 0 | } |
237 | 0 | mIsAnyMemberPresent = true; |
238 | 0 | return true; |
239 | 0 | } |
240 | | |
241 | | bool |
242 | | KeyframeAnimationOptions::Init(const nsAString& aJSON) |
243 | 0 | { |
244 | 0 | AutoJSAPI jsapi; |
245 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
246 | 0 | if (!cleanGlobal) { |
247 | 0 | return false; |
248 | 0 | } |
249 | 0 | if (!jsapi.Init(cleanGlobal)) { |
250 | 0 | return false; |
251 | 0 | } |
252 | 0 | JSContext* cx = jsapi.cx(); |
253 | 0 | JS::Rooted<JS::Value> json(cx); |
254 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
255 | 0 | NS_ENSURE_TRUE(ok, false); |
256 | 0 | return Init(cx, json); |
257 | 0 | } |
258 | | |
259 | | bool |
260 | | KeyframeAnimationOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
261 | 0 | { |
262 | 0 | KeyframeAnimationOptionsAtoms* atomsCache = GetAtomCache<KeyframeAnimationOptionsAtoms>(cx); |
263 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
264 | 0 | return false; |
265 | 0 | } |
266 | 0 | |
267 | 0 | // Per spec, we define the parent's members first |
268 | 0 | if (!KeyframeEffectOptions::ToObjectInternal(cx, rval)) { |
269 | 0 | return false; |
270 | 0 | } |
271 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
272 | 0 |
|
273 | 0 | do { |
274 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
275 | 0 | JS::Rooted<JS::Value> temp(cx); |
276 | 0 | nsString const & currentValue = mId; |
277 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
278 | 0 | return false; |
279 | 0 | } |
280 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) { |
281 | 0 | return false; |
282 | 0 | } |
283 | 0 | break; |
284 | 0 | } while(false); |
285 | 0 |
|
286 | 0 | return true; |
287 | 0 | } |
288 | | |
289 | | bool |
290 | | KeyframeAnimationOptions::ToJSON(nsAString& aJSON) const |
291 | 0 | { |
292 | 0 | AutoJSAPI jsapi; |
293 | 0 | jsapi.Init(); |
294 | 0 | JSContext *cx = jsapi.cx(); |
295 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
296 | 0 | // because we'll only be creating objects, in ways that have no |
297 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
298 | 0 | // which likewise guarantees no side-effects for the sorts of |
299 | 0 | // things we will pass it. |
300 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
301 | 0 | JS::Rooted<JS::Value> val(cx); |
302 | 0 | if (!ToObjectInternal(cx, &val)) { |
303 | 0 | return false; |
304 | 0 | } |
305 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
306 | 0 | return StringifyToJSON(cx, obj, aJSON); |
307 | 0 | } |
308 | | |
309 | | void |
310 | | KeyframeAnimationOptions::TraceDictionary(JSTracer* trc) |
311 | 0 | { |
312 | 0 | KeyframeEffectOptions::TraceDictionary(trc); |
313 | 0 | } |
314 | | |
315 | | KeyframeAnimationOptions& |
316 | | KeyframeAnimationOptions::operator=(const KeyframeAnimationOptions& aOther) |
317 | 0 | { |
318 | 0 | KeyframeEffectOptions::operator=(aOther); |
319 | 0 | mId = aOther.mId; |
320 | 0 | return *this; |
321 | 0 | } |
322 | | |
323 | | namespace binding_detail { |
324 | | } // namespace binding_detail |
325 | | |
326 | | |
327 | | } // namespace dom |
328 | | } // namespace mozilla |