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