Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM BaseKeyframeTypes.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "BaseKeyframeTypesBinding.h"
5 : #include "jsapi.h"
6 : #include "mozilla/FloatingPoint.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/NonRefcountedDOMObject.h"
10 : #include "mozilla/dom/PrimitiveConversions.h"
11 : #include "mozilla/dom/ScriptSettings.h"
12 : #include "mozilla/dom/SimpleGlobalObject.h"
13 : #include "nsContentUtils.h"
14 :
15 : namespace mozilla {
16 : namespace dom {
17 :
18 : namespace CompositeOperationValues {
19 : extern const EnumEntry strings[4] = {
20 : {"replace", 7},
21 : {"add", 3},
22 : {"accumulate", 10},
23 : { nullptr, 0 }
24 : };
25 : } // namespace CompositeOperationValues
26 :
27 : bool
28 0 : ToJSValue(JSContext* aCx, CompositeOperation aArgument, JS::MutableHandle<JS::Value> aValue)
29 : {
30 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(CompositeOperationValues::strings));
31 : JSString* resultStr =
32 0 : JS_NewStringCopyN(aCx, CompositeOperationValues::strings[uint32_t(aArgument)].value,
33 0 : CompositeOperationValues::strings[uint32_t(aArgument)].length);
34 0 : if (!resultStr) {
35 0 : return false;
36 : }
37 0 : aValue.setString(resultStr);
38 0 : return true;
39 : }
40 :
41 :
42 :
43 0 : BaseKeyframe::BaseKeyframe()
44 : {
45 : // Safe to pass a null context if we pass a null value
46 0 : Init(nullptr, JS::NullHandleValue);
47 0 : }
48 :
49 :
50 :
51 : bool
52 0 : BaseKeyframe::InitIds(JSContext* cx, BaseKeyframeAtoms* atomsCache)
53 : {
54 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
55 :
56 : // Initialize these in reverse order so that any failure leaves the first one
57 : // uninitialized.
58 0 : if (!atomsCache->simulateComputeValuesFailure_id.init(cx, "simulateComputeValuesFailure") ||
59 0 : !atomsCache->offset_id.init(cx, "offset") ||
60 0 : !atomsCache->easing_id.init(cx, "easing") ||
61 0 : !atomsCache->composite_id.init(cx, "composite")) {
62 0 : return false;
63 : }
64 0 : return true;
65 : }
66 :
67 : bool
68 0 : BaseKeyframe::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
69 : {
70 : // Passing a null JSContext is OK only if we're initing from null,
71 : // Since in that case we will not have to do any property gets
72 : // Also evaluate isNullOrUndefined in order to avoid false-positive
73 : // checkers by static analysis tools
74 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
75 0 : BaseKeyframeAtoms* atomsCache = nullptr;
76 0 : if (cx) {
77 0 : atomsCache = GetAtomCache<BaseKeyframeAtoms>(cx);
78 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
79 0 : return false;
80 : }
81 : }
82 :
83 0 : if (!IsConvertibleToDictionary(val)) {
84 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
85 : }
86 :
87 0 : bool isNull = val.isNullOrUndefined();
88 : // We only need these if !isNull, in which case we have |cx|.
89 0 : Maybe<JS::Rooted<JSObject *> > object;
90 0 : Maybe<JS::Rooted<JS::Value> > temp;
91 0 : if (!isNull) {
92 0 : MOZ_ASSERT(cx);
93 0 : object.emplace(cx, &val.toObject());
94 0 : temp.emplace(cx);
95 : }
96 0 : if (!isNull) {
97 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->composite_id, temp.ptr())) {
98 0 : return false;
99 : }
100 : }
101 0 : if (!isNull && !temp->isUndefined()) {
102 0 : mComposite.Construct();
103 : {
104 : int index;
105 0 : if (!FindEnumStringIndex<true>(cx, temp.ref(), CompositeOperationValues::strings, "CompositeOperation", "'composite' member of BaseKeyframe", &index)) {
106 0 : return false;
107 : }
108 0 : MOZ_ASSERT(index >= 0);
109 0 : (mComposite.Value()) = static_cast<CompositeOperation>(index);
110 : }
111 0 : mIsAnyMemberPresent = true;
112 : }
113 :
114 0 : if (!isNull) {
115 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->easing_id, temp.ptr())) {
116 0 : return false;
117 : }
118 : }
119 0 : if (!isNull && !temp->isUndefined()) {
120 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mEasing)) {
121 0 : return false;
122 : }
123 : } else {
124 : static const char16_t data[] = { 'l', 'i', 'n', 'e', 'a', 'r', 0 };
125 0 : mEasing.Rebind(data, ArrayLength(data) - 1);
126 : }
127 0 : mIsAnyMemberPresent = true;
128 :
129 0 : if (!isNull) {
130 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->offset_id, temp.ptr())) {
131 0 : return false;
132 : }
133 : }
134 0 : if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
135 0 : mOffset.SetNull();
136 0 : } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mOffset.SetValue())) {
137 0 : return false;
138 0 : } else if (!mozilla::IsFinite(mOffset.Value())) {
139 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'offset' member of BaseKeyframe");
140 0 : return false;
141 : }
142 0 : mIsAnyMemberPresent = true;
143 :
144 0 : if (!isNull) {
145 0 : if (nsContentUtils::ThreadsafeIsSystemCaller(cx)) {
146 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->simulateComputeValuesFailure_id, temp.ptr())) {
147 0 : return false;
148 : }
149 : } else {
150 0 : temp->setUndefined();
151 : }
152 : }
153 0 : if (!isNull && !temp->isUndefined()) {
154 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mSimulateComputeValuesFailure)) {
155 0 : return false;
156 : }
157 : } else {
158 0 : mSimulateComputeValuesFailure = false;
159 : }
160 0 : mIsAnyMemberPresent = true;
161 0 : return true;
162 : }
163 :
164 : bool
165 0 : BaseKeyframe::Init(const nsAString& aJSON)
166 : {
167 0 : AutoJSAPI jsapi;
168 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
169 0 : if (!cleanGlobal) {
170 0 : return false;
171 : }
172 0 : if (!jsapi.Init(cleanGlobal)) {
173 0 : return false;
174 : }
175 0 : JSContext* cx = jsapi.cx();
176 0 : JS::Rooted<JS::Value> json(cx);
177 0 : bool ok = ParseJSON(cx, aJSON, &json);
178 0 : NS_ENSURE_TRUE(ok, false);
179 0 : return Init(cx, json);
180 : }
181 :
182 : bool
183 0 : BaseKeyframe::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
184 : {
185 0 : BaseKeyframeAtoms* atomsCache = GetAtomCache<BaseKeyframeAtoms>(cx);
186 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
187 0 : return false;
188 : }
189 :
190 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
191 0 : if (!obj) {
192 0 : return false;
193 : }
194 0 : rval.set(JS::ObjectValue(*obj));
195 :
196 0 : if (mComposite.WasPassed()) {
197 : do {
198 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
199 0 : JS::Rooted<JS::Value> temp(cx);
200 0 : CompositeOperation const & currentValue = mComposite.InternalValue();
201 0 : if (!ToJSValue(cx, currentValue, &temp)) {
202 0 : return false;
203 : }
204 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->composite_id, temp, JSPROP_ENUMERATE)) {
205 0 : return false;
206 : }
207 0 : break;
208 : } while(0);
209 : }
210 :
211 : do {
212 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
213 0 : JS::Rooted<JS::Value> temp(cx);
214 0 : nsString const & currentValue = mEasing;
215 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
216 0 : return false;
217 : }
218 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->easing_id, temp, JSPROP_ENUMERATE)) {
219 0 : return false;
220 : }
221 0 : break;
222 : } while(0);
223 :
224 : do {
225 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
226 0 : JS::Rooted<JS::Value> temp(cx);
227 0 : Nullable<double> const & currentValue = mOffset;
228 0 : if (currentValue.IsNull()) {
229 0 : temp.setNull();
230 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->offset_id, temp, JSPROP_ENUMERATE)) {
231 0 : return false;
232 : }
233 0 : break;
234 : }
235 0 : temp.set(JS_NumberValue(double(currentValue.Value())));
236 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->offset_id, temp, JSPROP_ENUMERATE)) {
237 0 : return false;
238 : }
239 0 : break;
240 : } while(0);
241 :
242 0 : if (nsContentUtils::ThreadsafeIsSystemCaller(cx)) {
243 : do {
244 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
245 0 : JS::Rooted<JS::Value> temp(cx);
246 0 : bool const & currentValue = mSimulateComputeValuesFailure;
247 0 : temp.setBoolean(currentValue);
248 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->simulateComputeValuesFailure_id, temp, JSPROP_ENUMERATE)) {
249 0 : return false;
250 : }
251 0 : break;
252 : } while(0);
253 : }
254 :
255 0 : return true;
256 : }
257 :
258 : bool
259 0 : BaseKeyframe::ToJSON(nsAString& aJSON) const
260 : {
261 0 : AutoJSAPI jsapi;
262 0 : jsapi.Init();
263 0 : JSContext *cx = jsapi.cx();
264 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
265 : // because we'll only be creating objects, in ways that have no
266 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
267 : // which likewise guarantees no side-effects for the sorts of
268 : // things we will pass it.
269 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
270 0 : JS::Rooted<JS::Value> val(cx);
271 0 : if (!ToObjectInternal(cx, &val)) {
272 0 : return false;
273 : }
274 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
275 0 : return StringifyToJSON(cx, obj, aJSON);
276 : }
277 :
278 : void
279 0 : BaseKeyframe::TraceDictionary(JSTracer* trc)
280 : {
281 0 : }
282 :
283 : BaseKeyframe&
284 0 : BaseKeyframe::operator=(const BaseKeyframe& aOther)
285 : {
286 0 : mComposite.Reset();
287 0 : if (aOther.mComposite.WasPassed()) {
288 0 : mComposite.Construct(aOther.mComposite.Value());
289 : }
290 0 : mEasing = aOther.mEasing;
291 0 : mOffset = aOther.mOffset;
292 0 : mSimulateComputeValuesFailure = aOther.mSimulateComputeValuesFailure;
293 0 : return *this;
294 : }
295 :
296 : namespace binding_detail {
297 : } // namespace binding_detail
298 :
299 :
300 :
301 0 : BasePropertyIndexedKeyframe::BasePropertyIndexedKeyframe()
302 : {
303 : // Safe to pass a null context if we pass a null value
304 0 : Init(nullptr, JS::NullHandleValue);
305 0 : }
306 :
307 :
308 :
309 : bool
310 0 : BasePropertyIndexedKeyframe::InitIds(JSContext* cx, BasePropertyIndexedKeyframeAtoms* atomsCache)
311 : {
312 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
313 :
314 : // Initialize these in reverse order so that any failure leaves the first one
315 : // uninitialized.
316 0 : if (!atomsCache->easing_id.init(cx, "easing") ||
317 0 : !atomsCache->composite_id.init(cx, "composite")) {
318 0 : return false;
319 : }
320 0 : return true;
321 : }
322 :
323 : bool
324 0 : BasePropertyIndexedKeyframe::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
325 : {
326 : // Passing a null JSContext is OK only if we're initing from null,
327 : // Since in that case we will not have to do any property gets
328 : // Also evaluate isNullOrUndefined in order to avoid false-positive
329 : // checkers by static analysis tools
330 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
331 0 : BasePropertyIndexedKeyframeAtoms* atomsCache = nullptr;
332 0 : if (cx) {
333 0 : atomsCache = GetAtomCache<BasePropertyIndexedKeyframeAtoms>(cx);
334 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
335 0 : return false;
336 : }
337 : }
338 :
339 0 : if (!IsConvertibleToDictionary(val)) {
340 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
341 : }
342 :
343 0 : bool isNull = val.isNullOrUndefined();
344 : // We only need these if !isNull, in which case we have |cx|.
345 0 : Maybe<JS::Rooted<JSObject *> > object;
346 0 : Maybe<JS::Rooted<JS::Value> > temp;
347 0 : if (!isNull) {
348 0 : MOZ_ASSERT(cx);
349 0 : object.emplace(cx, &val.toObject());
350 0 : temp.emplace(cx);
351 : }
352 0 : if (!isNull) {
353 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->composite_id, temp.ptr())) {
354 0 : return false;
355 : }
356 : }
357 0 : if (!isNull && !temp->isUndefined()) {
358 0 : mComposite.Construct();
359 : {
360 : int index;
361 0 : if (!FindEnumStringIndex<true>(cx, temp.ref(), CompositeOperationValues::strings, "CompositeOperation", "'composite' member of BasePropertyIndexedKeyframe", &index)) {
362 0 : return false;
363 : }
364 0 : MOZ_ASSERT(index >= 0);
365 0 : (mComposite.Value()) = static_cast<CompositeOperation>(index);
366 : }
367 0 : mIsAnyMemberPresent = true;
368 : }
369 :
370 0 : if (!isNull) {
371 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->easing_id, temp.ptr())) {
372 0 : return false;
373 : }
374 : }
375 0 : if (!isNull && !temp->isUndefined()) {
376 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mEasing)) {
377 0 : return false;
378 : }
379 : } else {
380 : static const char16_t data[] = { 'l', 'i', 'n', 'e', 'a', 'r', 0 };
381 0 : mEasing.Rebind(data, ArrayLength(data) - 1);
382 : }
383 0 : mIsAnyMemberPresent = true;
384 0 : return true;
385 : }
386 :
387 : bool
388 0 : BasePropertyIndexedKeyframe::Init(const nsAString& aJSON)
389 : {
390 0 : AutoJSAPI jsapi;
391 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
392 0 : if (!cleanGlobal) {
393 0 : return false;
394 : }
395 0 : if (!jsapi.Init(cleanGlobal)) {
396 0 : return false;
397 : }
398 0 : JSContext* cx = jsapi.cx();
399 0 : JS::Rooted<JS::Value> json(cx);
400 0 : bool ok = ParseJSON(cx, aJSON, &json);
401 0 : NS_ENSURE_TRUE(ok, false);
402 0 : return Init(cx, json);
403 : }
404 :
405 : bool
406 0 : BasePropertyIndexedKeyframe::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
407 : {
408 0 : BasePropertyIndexedKeyframeAtoms* atomsCache = GetAtomCache<BasePropertyIndexedKeyframeAtoms>(cx);
409 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
410 0 : return false;
411 : }
412 :
413 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
414 0 : if (!obj) {
415 0 : return false;
416 : }
417 0 : rval.set(JS::ObjectValue(*obj));
418 :
419 0 : if (mComposite.WasPassed()) {
420 : do {
421 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
422 0 : JS::Rooted<JS::Value> temp(cx);
423 0 : CompositeOperation const & currentValue = mComposite.InternalValue();
424 0 : if (!ToJSValue(cx, currentValue, &temp)) {
425 0 : return false;
426 : }
427 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->composite_id, temp, JSPROP_ENUMERATE)) {
428 0 : return false;
429 : }
430 0 : break;
431 : } while(0);
432 : }
433 :
434 : do {
435 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
436 0 : JS::Rooted<JS::Value> temp(cx);
437 0 : nsString const & currentValue = mEasing;
438 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
439 0 : return false;
440 : }
441 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->easing_id, temp, JSPROP_ENUMERATE)) {
442 0 : return false;
443 : }
444 0 : break;
445 : } while(0);
446 :
447 0 : return true;
448 : }
449 :
450 : bool
451 0 : BasePropertyIndexedKeyframe::ToJSON(nsAString& aJSON) const
452 : {
453 0 : AutoJSAPI jsapi;
454 0 : jsapi.Init();
455 0 : JSContext *cx = jsapi.cx();
456 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
457 : // because we'll only be creating objects, in ways that have no
458 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
459 : // which likewise guarantees no side-effects for the sorts of
460 : // things we will pass it.
461 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
462 0 : JS::Rooted<JS::Value> val(cx);
463 0 : if (!ToObjectInternal(cx, &val)) {
464 0 : return false;
465 : }
466 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
467 0 : return StringifyToJSON(cx, obj, aJSON);
468 : }
469 :
470 : void
471 0 : BasePropertyIndexedKeyframe::TraceDictionary(JSTracer* trc)
472 : {
473 0 : }
474 :
475 : BasePropertyIndexedKeyframe&
476 0 : BasePropertyIndexedKeyframe::operator=(const BasePropertyIndexedKeyframe& aOther)
477 : {
478 0 : mComposite.Reset();
479 0 : if (aOther.mComposite.WasPassed()) {
480 0 : mComposite.Construct(aOther.mComposite.Value());
481 : }
482 0 : mEasing = aOther.mEasing;
483 0 : return *this;
484 : }
485 :
486 : namespace binding_detail {
487 : } // namespace binding_detail
488 :
489 :
490 :
491 0 : BaseComputedKeyframe::BaseComputedKeyframe()
492 0 : : BaseKeyframe(FastDictionaryInitializer())
493 : {
494 : // Safe to pass a null context if we pass a null value
495 0 : Init(nullptr, JS::NullHandleValue);
496 0 : }
497 :
498 :
499 :
500 : bool
501 0 : BaseComputedKeyframe::InitIds(JSContext* cx, BaseComputedKeyframeAtoms* atomsCache)
502 : {
503 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
504 :
505 : // Initialize these in reverse order so that any failure leaves the first one
506 : // uninitialized.
507 0 : if (!atomsCache->computedOffset_id.init(cx, "computedOffset")) {
508 0 : return false;
509 : }
510 0 : return true;
511 : }
512 :
513 : bool
514 0 : BaseComputedKeyframe::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
515 : {
516 : // Passing a null JSContext is OK only if we're initing from null,
517 : // Since in that case we will not have to do any property gets
518 : // Also evaluate isNullOrUndefined in order to avoid false-positive
519 : // checkers by static analysis tools
520 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
521 0 : BaseComputedKeyframeAtoms* atomsCache = nullptr;
522 0 : if (cx) {
523 0 : atomsCache = GetAtomCache<BaseComputedKeyframeAtoms>(cx);
524 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
525 0 : return false;
526 : }
527 : }
528 :
529 : // Per spec, we init the parent's members first
530 0 : if (!BaseKeyframe::Init(cx, val)) {
531 0 : return false;
532 : }
533 :
534 0 : bool isNull = val.isNullOrUndefined();
535 : // We only need these if !isNull, in which case we have |cx|.
536 0 : Maybe<JS::Rooted<JSObject *> > object;
537 0 : Maybe<JS::Rooted<JS::Value> > temp;
538 0 : if (!isNull) {
539 0 : MOZ_ASSERT(cx);
540 0 : object.emplace(cx, &val.toObject());
541 0 : temp.emplace(cx);
542 : }
543 0 : if (!isNull) {
544 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->computedOffset_id, temp.ptr())) {
545 0 : return false;
546 : }
547 : }
548 0 : if (!isNull && !temp->isUndefined()) {
549 0 : mComputedOffset.Construct();
550 0 : if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &(mComputedOffset.Value()))) {
551 0 : return false;
552 0 : } else if (!mozilla::IsFinite((mComputedOffset.Value()))) {
553 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'computedOffset' member of BaseComputedKeyframe");
554 0 : return false;
555 : }
556 0 : mIsAnyMemberPresent = true;
557 : }
558 0 : return true;
559 : }
560 :
561 : bool
562 0 : BaseComputedKeyframe::Init(const nsAString& aJSON)
563 : {
564 0 : AutoJSAPI jsapi;
565 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
566 0 : if (!cleanGlobal) {
567 0 : return false;
568 : }
569 0 : if (!jsapi.Init(cleanGlobal)) {
570 0 : return false;
571 : }
572 0 : JSContext* cx = jsapi.cx();
573 0 : JS::Rooted<JS::Value> json(cx);
574 0 : bool ok = ParseJSON(cx, aJSON, &json);
575 0 : NS_ENSURE_TRUE(ok, false);
576 0 : return Init(cx, json);
577 : }
578 :
579 : bool
580 0 : BaseComputedKeyframe::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
581 : {
582 0 : BaseComputedKeyframeAtoms* atomsCache = GetAtomCache<BaseComputedKeyframeAtoms>(cx);
583 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
584 0 : return false;
585 : }
586 :
587 : // Per spec, we define the parent's members first
588 0 : if (!BaseKeyframe::ToObjectInternal(cx, rval)) {
589 0 : return false;
590 : }
591 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
592 :
593 0 : if (mComputedOffset.WasPassed()) {
594 : do {
595 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
596 0 : JS::Rooted<JS::Value> temp(cx);
597 0 : double const & currentValue = mComputedOffset.InternalValue();
598 0 : temp.set(JS_NumberValue(double(currentValue)));
599 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->computedOffset_id, temp, JSPROP_ENUMERATE)) {
600 0 : return false;
601 : }
602 0 : break;
603 : } while(0);
604 : }
605 :
606 0 : return true;
607 : }
608 :
609 : bool
610 0 : BaseComputedKeyframe::ToJSON(nsAString& aJSON) const
611 : {
612 0 : AutoJSAPI jsapi;
613 0 : jsapi.Init();
614 0 : JSContext *cx = jsapi.cx();
615 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
616 : // because we'll only be creating objects, in ways that have no
617 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
618 : // which likewise guarantees no side-effects for the sorts of
619 : // things we will pass it.
620 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
621 0 : JS::Rooted<JS::Value> val(cx);
622 0 : if (!ToObjectInternal(cx, &val)) {
623 0 : return false;
624 : }
625 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
626 0 : return StringifyToJSON(cx, obj, aJSON);
627 : }
628 :
629 : void
630 0 : BaseComputedKeyframe::TraceDictionary(JSTracer* trc)
631 : {
632 0 : BaseKeyframe::TraceDictionary(trc);
633 0 : }
634 :
635 : BaseComputedKeyframe&
636 0 : BaseComputedKeyframe::operator=(const BaseComputedKeyframe& aOther)
637 : {
638 0 : BaseKeyframe::operator=(aOther);
639 0 : mComputedOffset.Reset();
640 0 : if (aOther.mComputedOffset.WasPassed()) {
641 0 : mComputedOffset.Construct(aOther.mComputedOffset.Value());
642 : }
643 0 : return *this;
644 : }
645 :
646 : namespace binding_detail {
647 : } // namespace binding_detail
648 :
649 :
650 : } // namespace dom
651 : } // namespace mozilla
|