Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM APZTestData.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "APZTestDataBinding.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 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 :
17 0 : FrameUniformity::FrameUniformity()
18 : {
19 : // Safe to pass a null context if we pass a null value
20 0 : Init(nullptr, JS::NullHandleValue);
21 0 : }
22 :
23 :
24 :
25 : bool
26 0 : FrameUniformity::InitIds(JSContext* cx, FrameUniformityAtoms* atomsCache)
27 : {
28 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
29 :
30 : // Initialize these in reverse order so that any failure leaves the first one
31 : // uninitialized.
32 0 : if (!atomsCache->layerAddress_id.init(cx, "layerAddress") ||
33 0 : !atomsCache->frameUniformity_id.init(cx, "frameUniformity")) {
34 0 : return false;
35 : }
36 0 : return true;
37 : }
38 :
39 : bool
40 0 : FrameUniformity::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 : FrameUniformityAtoms* atomsCache = nullptr;
48 0 : if (cx) {
49 0 : atomsCache = GetAtomCache<FrameUniformityAtoms>(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->frameUniformity_id, temp.ptr())) {
70 0 : return false;
71 : }
72 : }
73 0 : if (!isNull && !temp->isUndefined()) {
74 0 : mFrameUniformity.Construct();
75 0 : if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &(mFrameUniformity.Value()))) {
76 0 : return false;
77 0 : } else if (!mozilla::IsFinite((mFrameUniformity.Value()))) {
78 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'frameUniformity' member of FrameUniformity");
79 0 : return false;
80 : }
81 0 : mIsAnyMemberPresent = true;
82 : }
83 :
84 0 : if (!isNull) {
85 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->layerAddress_id, temp.ptr())) {
86 0 : return false;
87 : }
88 : }
89 0 : if (!isNull && !temp->isUndefined()) {
90 0 : mLayerAddress.Construct();
91 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mLayerAddress.Value()))) {
92 0 : return false;
93 : }
94 0 : mIsAnyMemberPresent = true;
95 : }
96 0 : return true;
97 : }
98 :
99 : bool
100 0 : FrameUniformity::Init(const nsAString& aJSON)
101 : {
102 0 : AutoJSAPI jsapi;
103 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
104 0 : if (!cleanGlobal) {
105 0 : return false;
106 : }
107 0 : if (!jsapi.Init(cleanGlobal)) {
108 0 : return false;
109 : }
110 0 : JSContext* cx = jsapi.cx();
111 0 : JS::Rooted<JS::Value> json(cx);
112 0 : bool ok = ParseJSON(cx, aJSON, &json);
113 0 : NS_ENSURE_TRUE(ok, false);
114 0 : return Init(cx, json);
115 : }
116 :
117 : bool
118 0 : FrameUniformity::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
119 : {
120 0 : FrameUniformityAtoms* atomsCache = GetAtomCache<FrameUniformityAtoms>(cx);
121 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
122 0 : return false;
123 : }
124 :
125 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
126 0 : if (!obj) {
127 0 : return false;
128 : }
129 0 : rval.set(JS::ObjectValue(*obj));
130 :
131 0 : if (mFrameUniformity.WasPassed()) {
132 : do {
133 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
134 0 : JS::Rooted<JS::Value> temp(cx);
135 0 : float const & currentValue = mFrameUniformity.InternalValue();
136 0 : temp.set(JS_NumberValue(double(currentValue)));
137 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->frameUniformity_id, temp, JSPROP_ENUMERATE)) {
138 0 : return false;
139 : }
140 0 : break;
141 : } while(0);
142 : }
143 :
144 0 : if (mLayerAddress.WasPassed()) {
145 : do {
146 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
147 0 : JS::Rooted<JS::Value> temp(cx);
148 0 : uint32_t const & currentValue = mLayerAddress.InternalValue();
149 0 : temp.setNumber(currentValue);
150 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->layerAddress_id, temp, JSPROP_ENUMERATE)) {
151 0 : return false;
152 : }
153 0 : break;
154 : } while(0);
155 : }
156 :
157 0 : return true;
158 : }
159 :
160 : bool
161 0 : FrameUniformity::ToJSON(nsAString& aJSON) const
162 : {
163 0 : AutoJSAPI jsapi;
164 0 : jsapi.Init();
165 0 : JSContext *cx = jsapi.cx();
166 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
167 : // because we'll only be creating objects, in ways that have no
168 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
169 : // which likewise guarantees no side-effects for the sorts of
170 : // things we will pass it.
171 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
172 0 : JS::Rooted<JS::Value> val(cx);
173 0 : if (!ToObjectInternal(cx, &val)) {
174 0 : return false;
175 : }
176 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
177 0 : return StringifyToJSON(cx, obj, aJSON);
178 : }
179 :
180 : void
181 0 : FrameUniformity::TraceDictionary(JSTracer* trc)
182 : {
183 0 : }
184 :
185 : FrameUniformity&
186 0 : FrameUniformity::operator=(const FrameUniformity& aOther)
187 : {
188 0 : mFrameUniformity.Reset();
189 0 : if (aOther.mFrameUniformity.WasPassed()) {
190 0 : mFrameUniformity.Construct(aOther.mFrameUniformity.Value());
191 : }
192 0 : mLayerAddress.Reset();
193 0 : if (aOther.mLayerAddress.WasPassed()) {
194 0 : mLayerAddress.Construct(aOther.mLayerAddress.Value());
195 : }
196 0 : return *this;
197 : }
198 :
199 : namespace binding_detail {
200 : } // namespace binding_detail
201 :
202 :
203 :
204 0 : ScrollFrameDataEntry::ScrollFrameDataEntry()
205 : {
206 : // Safe to pass a null context if we pass a null value
207 0 : Init(nullptr, JS::NullHandleValue);
208 0 : }
209 :
210 :
211 :
212 : bool
213 0 : ScrollFrameDataEntry::InitIds(JSContext* cx, ScrollFrameDataEntryAtoms* atomsCache)
214 : {
215 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
216 :
217 : // Initialize these in reverse order so that any failure leaves the first one
218 : // uninitialized.
219 0 : if (!atomsCache->value_id.init(cx, "value") ||
220 0 : !atomsCache->key_id.init(cx, "key")) {
221 0 : return false;
222 : }
223 0 : return true;
224 : }
225 :
226 : bool
227 0 : ScrollFrameDataEntry::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
228 : {
229 : // Passing a null JSContext is OK only if we're initing from null,
230 : // Since in that case we will not have to do any property gets
231 : // Also evaluate isNullOrUndefined in order to avoid false-positive
232 : // checkers by static analysis tools
233 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
234 0 : ScrollFrameDataEntryAtoms* atomsCache = nullptr;
235 0 : if (cx) {
236 0 : atomsCache = GetAtomCache<ScrollFrameDataEntryAtoms>(cx);
237 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
238 0 : return false;
239 : }
240 : }
241 :
242 0 : if (!IsConvertibleToDictionary(val)) {
243 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
244 : }
245 :
246 0 : bool isNull = val.isNullOrUndefined();
247 : // We only need these if !isNull, in which case we have |cx|.
248 0 : Maybe<JS::Rooted<JSObject *> > object;
249 0 : Maybe<JS::Rooted<JS::Value> > temp;
250 0 : if (!isNull) {
251 0 : MOZ_ASSERT(cx);
252 0 : object.emplace(cx, &val.toObject());
253 0 : temp.emplace(cx);
254 : }
255 0 : if (!isNull) {
256 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->key_id, temp.ptr())) {
257 0 : return false;
258 : }
259 : }
260 0 : if (!isNull && !temp->isUndefined()) {
261 0 : mKey.Construct();
262 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mKey.Value()))) {
263 0 : return false;
264 : }
265 0 : mIsAnyMemberPresent = true;
266 : }
267 :
268 0 : if (!isNull) {
269 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->value_id, temp.ptr())) {
270 0 : return false;
271 : }
272 : }
273 0 : if (!isNull && !temp->isUndefined()) {
274 0 : mValue.Construct();
275 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mValue.Value()))) {
276 0 : return false;
277 : }
278 0 : mIsAnyMemberPresent = true;
279 : }
280 0 : return true;
281 : }
282 :
283 : bool
284 0 : ScrollFrameDataEntry::Init(const nsAString& aJSON)
285 : {
286 0 : AutoJSAPI jsapi;
287 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
288 0 : if (!cleanGlobal) {
289 0 : return false;
290 : }
291 0 : if (!jsapi.Init(cleanGlobal)) {
292 0 : return false;
293 : }
294 0 : JSContext* cx = jsapi.cx();
295 0 : JS::Rooted<JS::Value> json(cx);
296 0 : bool ok = ParseJSON(cx, aJSON, &json);
297 0 : NS_ENSURE_TRUE(ok, false);
298 0 : return Init(cx, json);
299 : }
300 :
301 : bool
302 0 : ScrollFrameDataEntry::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
303 : {
304 0 : ScrollFrameDataEntryAtoms* atomsCache = GetAtomCache<ScrollFrameDataEntryAtoms>(cx);
305 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
306 0 : return false;
307 : }
308 :
309 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
310 0 : if (!obj) {
311 0 : return false;
312 : }
313 0 : rval.set(JS::ObjectValue(*obj));
314 :
315 0 : if (mKey.WasPassed()) {
316 : do {
317 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
318 0 : JS::Rooted<JS::Value> temp(cx);
319 0 : nsString const & currentValue = mKey.InternalValue();
320 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
321 0 : return false;
322 : }
323 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->key_id, temp, JSPROP_ENUMERATE)) {
324 0 : return false;
325 : }
326 0 : break;
327 : } while(0);
328 : }
329 :
330 0 : if (mValue.WasPassed()) {
331 : do {
332 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
333 0 : JS::Rooted<JS::Value> temp(cx);
334 0 : nsString const & currentValue = mValue.InternalValue();
335 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
336 0 : return false;
337 : }
338 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->value_id, temp, JSPROP_ENUMERATE)) {
339 0 : return false;
340 : }
341 0 : break;
342 : } while(0);
343 : }
344 :
345 0 : return true;
346 : }
347 :
348 : bool
349 0 : ScrollFrameDataEntry::ToJSON(nsAString& aJSON) const
350 : {
351 0 : AutoJSAPI jsapi;
352 0 : jsapi.Init();
353 0 : JSContext *cx = jsapi.cx();
354 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
355 : // because we'll only be creating objects, in ways that have no
356 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
357 : // which likewise guarantees no side-effects for the sorts of
358 : // things we will pass it.
359 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
360 0 : JS::Rooted<JS::Value> val(cx);
361 0 : if (!ToObjectInternal(cx, &val)) {
362 0 : return false;
363 : }
364 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
365 0 : return StringifyToJSON(cx, obj, aJSON);
366 : }
367 :
368 : void
369 0 : ScrollFrameDataEntry::TraceDictionary(JSTracer* trc)
370 : {
371 0 : }
372 :
373 : ScrollFrameDataEntry&
374 0 : ScrollFrameDataEntry::operator=(const ScrollFrameDataEntry& aOther)
375 : {
376 0 : mKey.Reset();
377 0 : if (aOther.mKey.WasPassed()) {
378 0 : mKey.Construct(aOther.mKey.Value());
379 : }
380 0 : mValue.Reset();
381 0 : if (aOther.mValue.WasPassed()) {
382 0 : mValue.Construct(aOther.mValue.Value());
383 : }
384 0 : return *this;
385 : }
386 :
387 : namespace binding_detail {
388 : } // namespace binding_detail
389 :
390 :
391 :
392 0 : FrameUniformityResults::FrameUniformityResults()
393 : {
394 : // Safe to pass a null context if we pass a null value
395 0 : Init(nullptr, JS::NullHandleValue);
396 0 : }
397 :
398 :
399 :
400 : bool
401 0 : FrameUniformityResults::InitIds(JSContext* cx, FrameUniformityResultsAtoms* atomsCache)
402 : {
403 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
404 :
405 : // Initialize these in reverse order so that any failure leaves the first one
406 : // uninitialized.
407 0 : if (!atomsCache->layerUniformities_id.init(cx, "layerUniformities")) {
408 0 : return false;
409 : }
410 0 : return true;
411 : }
412 :
413 : bool
414 0 : FrameUniformityResults::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
415 : {
416 : // Passing a null JSContext is OK only if we're initing from null,
417 : // Since in that case we will not have to do any property gets
418 : // Also evaluate isNullOrUndefined in order to avoid false-positive
419 : // checkers by static analysis tools
420 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
421 0 : FrameUniformityResultsAtoms* atomsCache = nullptr;
422 0 : if (cx) {
423 0 : atomsCache = GetAtomCache<FrameUniformityResultsAtoms>(cx);
424 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
425 0 : return false;
426 : }
427 : }
428 :
429 0 : if (!IsConvertibleToDictionary(val)) {
430 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
431 : }
432 :
433 0 : bool isNull = val.isNullOrUndefined();
434 : // We only need these if !isNull, in which case we have |cx|.
435 0 : Maybe<JS::Rooted<JSObject *> > object;
436 0 : Maybe<JS::Rooted<JS::Value> > temp;
437 0 : if (!isNull) {
438 0 : MOZ_ASSERT(cx);
439 0 : object.emplace(cx, &val.toObject());
440 0 : temp.emplace(cx);
441 : }
442 0 : if (!isNull) {
443 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->layerUniformities_id, temp.ptr())) {
444 0 : return false;
445 : }
446 : }
447 0 : if (!isNull && !temp->isUndefined()) {
448 0 : mLayerUniformities.Construct();
449 0 : if (temp.ref().isObject()) {
450 0 : JS::ForOfIterator iter(cx);
451 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
452 0 : return false;
453 : }
454 0 : if (!iter.valueIsIterable()) {
455 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'layerUniformities' member of FrameUniformityResults");
456 0 : return false;
457 : }
458 0 : Sequence<FrameUniformity> &arr = (mLayerUniformities.Value());
459 0 : JS::Rooted<JS::Value> temp(cx);
460 : while (true) {
461 : bool done;
462 0 : if (!iter.next(&temp, &done)) {
463 0 : return false;
464 : }
465 0 : if (done) {
466 0 : break;
467 : }
468 0 : FrameUniformity* slotPtr = arr.AppendElement(mozilla::fallible);
469 0 : if (!slotPtr) {
470 0 : JS_ReportOutOfMemory(cx);
471 0 : return false;
472 : }
473 0 : FrameUniformity& slot = *slotPtr;
474 0 : if (!slot.Init(cx, temp, "Element of 'layerUniformities' member of FrameUniformityResults", passedToJSImpl)) {
475 0 : return false;
476 : }
477 0 : }
478 : } else {
479 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'layerUniformities' member of FrameUniformityResults");
480 0 : return false;
481 : }
482 0 : mIsAnyMemberPresent = true;
483 : }
484 0 : return true;
485 : }
486 :
487 : bool
488 0 : FrameUniformityResults::Init(const nsAString& aJSON)
489 : {
490 0 : AutoJSAPI jsapi;
491 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
492 0 : if (!cleanGlobal) {
493 0 : return false;
494 : }
495 0 : if (!jsapi.Init(cleanGlobal)) {
496 0 : return false;
497 : }
498 0 : JSContext* cx = jsapi.cx();
499 0 : JS::Rooted<JS::Value> json(cx);
500 0 : bool ok = ParseJSON(cx, aJSON, &json);
501 0 : NS_ENSURE_TRUE(ok, false);
502 0 : return Init(cx, json);
503 : }
504 :
505 : bool
506 0 : FrameUniformityResults::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
507 : {
508 0 : FrameUniformityResultsAtoms* atomsCache = GetAtomCache<FrameUniformityResultsAtoms>(cx);
509 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
510 0 : return false;
511 : }
512 :
513 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
514 0 : if (!obj) {
515 0 : return false;
516 : }
517 0 : rval.set(JS::ObjectValue(*obj));
518 :
519 0 : if (mLayerUniformities.WasPassed()) {
520 : do {
521 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
522 0 : JS::Rooted<JS::Value> temp(cx);
523 0 : Sequence<FrameUniformity> const & currentValue = mLayerUniformities.InternalValue();
524 :
525 0 : uint32_t length = currentValue.Length();
526 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
527 0 : if (!returnArray) {
528 0 : return false;
529 : }
530 : // Scope for 'tmp'
531 : {
532 0 : JS::Rooted<JS::Value> tmp(cx);
533 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
534 : // Control block to let us common up the JS_DefineElement calls when there
535 : // are different ways to succeed at wrapping the object.
536 : do {
537 0 : if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
538 0 : return false;
539 : }
540 0 : break;
541 : } while (0);
542 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
543 : JSPROP_ENUMERATE)) {
544 0 : return false;
545 : }
546 : }
547 : }
548 0 : temp.setObject(*returnArray);
549 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->layerUniformities_id, temp, JSPROP_ENUMERATE)) {
550 0 : return false;
551 : }
552 0 : break;
553 : } while(0);
554 : }
555 :
556 0 : return true;
557 : }
558 :
559 : bool
560 0 : FrameUniformityResults::ToJSON(nsAString& aJSON) const
561 : {
562 0 : AutoJSAPI jsapi;
563 0 : jsapi.Init();
564 0 : JSContext *cx = jsapi.cx();
565 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
566 : // because we'll only be creating objects, in ways that have no
567 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
568 : // which likewise guarantees no side-effects for the sorts of
569 : // things we will pass it.
570 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
571 0 : JS::Rooted<JS::Value> val(cx);
572 0 : if (!ToObjectInternal(cx, &val)) {
573 0 : return false;
574 : }
575 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
576 0 : return StringifyToJSON(cx, obj, aJSON);
577 : }
578 :
579 : void
580 0 : FrameUniformityResults::TraceDictionary(JSTracer* trc)
581 : {
582 0 : }
583 :
584 : FrameUniformityResults&
585 0 : FrameUniformityResults::operator=(const FrameUniformityResults& aOther)
586 : {
587 0 : mLayerUniformities.Reset();
588 0 : if (aOther.mLayerUniformities.WasPassed()) {
589 0 : mLayerUniformities.Construct(aOther.mLayerUniformities.Value());
590 : }
591 0 : return *this;
592 : }
593 :
594 : namespace binding_detail {
595 : } // namespace binding_detail
596 :
597 :
598 :
599 0 : ScrollFrameData::ScrollFrameData()
600 : {
601 : // Safe to pass a null context if we pass a null value
602 0 : Init(nullptr, JS::NullHandleValue);
603 0 : }
604 :
605 :
606 :
607 : bool
608 0 : ScrollFrameData::InitIds(JSContext* cx, ScrollFrameDataAtoms* atomsCache)
609 : {
610 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
611 :
612 : // Initialize these in reverse order so that any failure leaves the first one
613 : // uninitialized.
614 0 : if (!atomsCache->scrollId_id.init(cx, "scrollId") ||
615 0 : !atomsCache->entries_id.init(cx, "entries")) {
616 0 : return false;
617 : }
618 0 : return true;
619 : }
620 :
621 : bool
622 0 : ScrollFrameData::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
623 : {
624 : // Passing a null JSContext is OK only if we're initing from null,
625 : // Since in that case we will not have to do any property gets
626 : // Also evaluate isNullOrUndefined in order to avoid false-positive
627 : // checkers by static analysis tools
628 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
629 0 : ScrollFrameDataAtoms* atomsCache = nullptr;
630 0 : if (cx) {
631 0 : atomsCache = GetAtomCache<ScrollFrameDataAtoms>(cx);
632 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
633 0 : return false;
634 : }
635 : }
636 :
637 0 : if (!IsConvertibleToDictionary(val)) {
638 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
639 : }
640 :
641 0 : bool isNull = val.isNullOrUndefined();
642 : // We only need these if !isNull, in which case we have |cx|.
643 0 : Maybe<JS::Rooted<JSObject *> > object;
644 0 : Maybe<JS::Rooted<JS::Value> > temp;
645 0 : if (!isNull) {
646 0 : MOZ_ASSERT(cx);
647 0 : object.emplace(cx, &val.toObject());
648 0 : temp.emplace(cx);
649 : }
650 0 : if (!isNull) {
651 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->entries_id, temp.ptr())) {
652 0 : return false;
653 : }
654 : }
655 0 : if (!isNull && !temp->isUndefined()) {
656 0 : mEntries.Construct();
657 0 : if (temp.ref().isObject()) {
658 0 : JS::ForOfIterator iter(cx);
659 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
660 0 : return false;
661 : }
662 0 : if (!iter.valueIsIterable()) {
663 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'entries' member of ScrollFrameData");
664 0 : return false;
665 : }
666 0 : Sequence<ScrollFrameDataEntry> &arr = (mEntries.Value());
667 0 : JS::Rooted<JS::Value> temp(cx);
668 : while (true) {
669 : bool done;
670 0 : if (!iter.next(&temp, &done)) {
671 0 : return false;
672 : }
673 0 : if (done) {
674 0 : break;
675 : }
676 0 : ScrollFrameDataEntry* slotPtr = arr.AppendElement(mozilla::fallible);
677 0 : if (!slotPtr) {
678 0 : JS_ReportOutOfMemory(cx);
679 0 : return false;
680 : }
681 0 : ScrollFrameDataEntry& slot = *slotPtr;
682 0 : if (!slot.Init(cx, temp, "Element of 'entries' member of ScrollFrameData", passedToJSImpl)) {
683 0 : return false;
684 : }
685 0 : }
686 : } else {
687 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'entries' member of ScrollFrameData");
688 0 : return false;
689 : }
690 0 : mIsAnyMemberPresent = true;
691 : }
692 :
693 0 : if (!isNull) {
694 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->scrollId_id, temp.ptr())) {
695 0 : return false;
696 : }
697 : }
698 0 : if (!isNull && !temp->isUndefined()) {
699 0 : mScrollId.Construct();
700 0 : if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mScrollId.Value()))) {
701 0 : return false;
702 : }
703 0 : mIsAnyMemberPresent = true;
704 : }
705 0 : return true;
706 : }
707 :
708 : bool
709 0 : ScrollFrameData::Init(const nsAString& aJSON)
710 : {
711 0 : AutoJSAPI jsapi;
712 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
713 0 : if (!cleanGlobal) {
714 0 : return false;
715 : }
716 0 : if (!jsapi.Init(cleanGlobal)) {
717 0 : return false;
718 : }
719 0 : JSContext* cx = jsapi.cx();
720 0 : JS::Rooted<JS::Value> json(cx);
721 0 : bool ok = ParseJSON(cx, aJSON, &json);
722 0 : NS_ENSURE_TRUE(ok, false);
723 0 : return Init(cx, json);
724 : }
725 :
726 : bool
727 0 : ScrollFrameData::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
728 : {
729 0 : ScrollFrameDataAtoms* atomsCache = GetAtomCache<ScrollFrameDataAtoms>(cx);
730 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
731 0 : return false;
732 : }
733 :
734 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
735 0 : if (!obj) {
736 0 : return false;
737 : }
738 0 : rval.set(JS::ObjectValue(*obj));
739 :
740 0 : if (mEntries.WasPassed()) {
741 : do {
742 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
743 0 : JS::Rooted<JS::Value> temp(cx);
744 0 : Sequence<ScrollFrameDataEntry> const & currentValue = mEntries.InternalValue();
745 :
746 0 : uint32_t length = currentValue.Length();
747 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
748 0 : if (!returnArray) {
749 0 : return false;
750 : }
751 : // Scope for 'tmp'
752 : {
753 0 : JS::Rooted<JS::Value> tmp(cx);
754 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
755 : // Control block to let us common up the JS_DefineElement calls when there
756 : // are different ways to succeed at wrapping the object.
757 : do {
758 0 : if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
759 0 : return false;
760 : }
761 0 : break;
762 : } while (0);
763 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
764 : JSPROP_ENUMERATE)) {
765 0 : return false;
766 : }
767 : }
768 : }
769 0 : temp.setObject(*returnArray);
770 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->entries_id, temp, JSPROP_ENUMERATE)) {
771 0 : return false;
772 : }
773 0 : break;
774 : } while(0);
775 : }
776 :
777 0 : if (mScrollId.WasPassed()) {
778 : do {
779 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
780 0 : JS::Rooted<JS::Value> temp(cx);
781 0 : uint64_t const & currentValue = mScrollId.InternalValue();
782 0 : temp.set(JS_NumberValue(double(currentValue)));
783 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->scrollId_id, temp, JSPROP_ENUMERATE)) {
784 0 : return false;
785 : }
786 0 : break;
787 : } while(0);
788 : }
789 :
790 0 : return true;
791 : }
792 :
793 : bool
794 0 : ScrollFrameData::ToJSON(nsAString& aJSON) const
795 : {
796 0 : AutoJSAPI jsapi;
797 0 : jsapi.Init();
798 0 : JSContext *cx = jsapi.cx();
799 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
800 : // because we'll only be creating objects, in ways that have no
801 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
802 : // which likewise guarantees no side-effects for the sorts of
803 : // things we will pass it.
804 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
805 0 : JS::Rooted<JS::Value> val(cx);
806 0 : if (!ToObjectInternal(cx, &val)) {
807 0 : return false;
808 : }
809 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
810 0 : return StringifyToJSON(cx, obj, aJSON);
811 : }
812 :
813 : void
814 0 : ScrollFrameData::TraceDictionary(JSTracer* trc)
815 : {
816 0 : }
817 :
818 : ScrollFrameData&
819 0 : ScrollFrameData::operator=(const ScrollFrameData& aOther)
820 : {
821 0 : mEntries.Reset();
822 0 : if (aOther.mEntries.WasPassed()) {
823 0 : mEntries.Construct(aOther.mEntries.Value());
824 : }
825 0 : mScrollId.Reset();
826 0 : if (aOther.mScrollId.WasPassed()) {
827 0 : mScrollId.Construct(aOther.mScrollId.Value());
828 : }
829 0 : return *this;
830 : }
831 :
832 : namespace binding_detail {
833 : } // namespace binding_detail
834 :
835 :
836 :
837 0 : APZBucket::APZBucket()
838 : {
839 : // Safe to pass a null context if we pass a null value
840 0 : Init(nullptr, JS::NullHandleValue);
841 0 : }
842 :
843 :
844 :
845 : bool
846 0 : APZBucket::InitIds(JSContext* cx, APZBucketAtoms* atomsCache)
847 : {
848 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
849 :
850 : // Initialize these in reverse order so that any failure leaves the first one
851 : // uninitialized.
852 0 : if (!atomsCache->sequenceNumber_id.init(cx, "sequenceNumber") ||
853 0 : !atomsCache->scrollFrames_id.init(cx, "scrollFrames")) {
854 0 : return false;
855 : }
856 0 : return true;
857 : }
858 :
859 : bool
860 0 : APZBucket::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
861 : {
862 : // Passing a null JSContext is OK only if we're initing from null,
863 : // Since in that case we will not have to do any property gets
864 : // Also evaluate isNullOrUndefined in order to avoid false-positive
865 : // checkers by static analysis tools
866 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
867 0 : APZBucketAtoms* atomsCache = nullptr;
868 0 : if (cx) {
869 0 : atomsCache = GetAtomCache<APZBucketAtoms>(cx);
870 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
871 0 : return false;
872 : }
873 : }
874 :
875 0 : if (!IsConvertibleToDictionary(val)) {
876 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
877 : }
878 :
879 0 : bool isNull = val.isNullOrUndefined();
880 : // We only need these if !isNull, in which case we have |cx|.
881 0 : Maybe<JS::Rooted<JSObject *> > object;
882 0 : Maybe<JS::Rooted<JS::Value> > temp;
883 0 : if (!isNull) {
884 0 : MOZ_ASSERT(cx);
885 0 : object.emplace(cx, &val.toObject());
886 0 : temp.emplace(cx);
887 : }
888 0 : if (!isNull) {
889 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->scrollFrames_id, temp.ptr())) {
890 0 : return false;
891 : }
892 : }
893 0 : if (!isNull && !temp->isUndefined()) {
894 0 : mScrollFrames.Construct();
895 0 : if (temp.ref().isObject()) {
896 0 : JS::ForOfIterator iter(cx);
897 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
898 0 : return false;
899 : }
900 0 : if (!iter.valueIsIterable()) {
901 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'scrollFrames' member of APZBucket");
902 0 : return false;
903 : }
904 0 : Sequence<ScrollFrameData> &arr = (mScrollFrames.Value());
905 0 : JS::Rooted<JS::Value> temp(cx);
906 : while (true) {
907 : bool done;
908 0 : if (!iter.next(&temp, &done)) {
909 0 : return false;
910 : }
911 0 : if (done) {
912 0 : break;
913 : }
914 0 : ScrollFrameData* slotPtr = arr.AppendElement(mozilla::fallible);
915 0 : if (!slotPtr) {
916 0 : JS_ReportOutOfMemory(cx);
917 0 : return false;
918 : }
919 0 : ScrollFrameData& slot = *slotPtr;
920 0 : if (!slot.Init(cx, temp, "Element of 'scrollFrames' member of APZBucket", passedToJSImpl)) {
921 0 : return false;
922 : }
923 0 : }
924 : } else {
925 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'scrollFrames' member of APZBucket");
926 0 : return false;
927 : }
928 0 : mIsAnyMemberPresent = true;
929 : }
930 :
931 0 : if (!isNull) {
932 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->sequenceNumber_id, temp.ptr())) {
933 0 : return false;
934 : }
935 : }
936 0 : if (!isNull && !temp->isUndefined()) {
937 0 : mSequenceNumber.Construct();
938 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mSequenceNumber.Value()))) {
939 0 : return false;
940 : }
941 0 : mIsAnyMemberPresent = true;
942 : }
943 0 : return true;
944 : }
945 :
946 : bool
947 0 : APZBucket::Init(const nsAString& aJSON)
948 : {
949 0 : AutoJSAPI jsapi;
950 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
951 0 : if (!cleanGlobal) {
952 0 : return false;
953 : }
954 0 : if (!jsapi.Init(cleanGlobal)) {
955 0 : return false;
956 : }
957 0 : JSContext* cx = jsapi.cx();
958 0 : JS::Rooted<JS::Value> json(cx);
959 0 : bool ok = ParseJSON(cx, aJSON, &json);
960 0 : NS_ENSURE_TRUE(ok, false);
961 0 : return Init(cx, json);
962 : }
963 :
964 : bool
965 0 : APZBucket::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
966 : {
967 0 : APZBucketAtoms* atomsCache = GetAtomCache<APZBucketAtoms>(cx);
968 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
969 0 : return false;
970 : }
971 :
972 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
973 0 : if (!obj) {
974 0 : return false;
975 : }
976 0 : rval.set(JS::ObjectValue(*obj));
977 :
978 0 : if (mScrollFrames.WasPassed()) {
979 : do {
980 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
981 0 : JS::Rooted<JS::Value> temp(cx);
982 0 : Sequence<ScrollFrameData> const & currentValue = mScrollFrames.InternalValue();
983 :
984 0 : uint32_t length = currentValue.Length();
985 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
986 0 : if (!returnArray) {
987 0 : return false;
988 : }
989 : // Scope for 'tmp'
990 : {
991 0 : JS::Rooted<JS::Value> tmp(cx);
992 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
993 : // Control block to let us common up the JS_DefineElement calls when there
994 : // are different ways to succeed at wrapping the object.
995 : do {
996 0 : if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
997 0 : return false;
998 : }
999 0 : break;
1000 : } while (0);
1001 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1002 : JSPROP_ENUMERATE)) {
1003 0 : return false;
1004 : }
1005 : }
1006 : }
1007 0 : temp.setObject(*returnArray);
1008 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->scrollFrames_id, temp, JSPROP_ENUMERATE)) {
1009 0 : return false;
1010 : }
1011 0 : break;
1012 : } while(0);
1013 : }
1014 :
1015 0 : if (mSequenceNumber.WasPassed()) {
1016 : do {
1017 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1018 0 : JS::Rooted<JS::Value> temp(cx);
1019 0 : uint32_t const & currentValue = mSequenceNumber.InternalValue();
1020 0 : temp.setNumber(currentValue);
1021 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->sequenceNumber_id, temp, JSPROP_ENUMERATE)) {
1022 0 : return false;
1023 : }
1024 0 : break;
1025 : } while(0);
1026 : }
1027 :
1028 0 : return true;
1029 : }
1030 :
1031 : bool
1032 0 : APZBucket::ToJSON(nsAString& aJSON) const
1033 : {
1034 0 : AutoJSAPI jsapi;
1035 0 : jsapi.Init();
1036 0 : JSContext *cx = jsapi.cx();
1037 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
1038 : // because we'll only be creating objects, in ways that have no
1039 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1040 : // which likewise guarantees no side-effects for the sorts of
1041 : // things we will pass it.
1042 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
1043 0 : JS::Rooted<JS::Value> val(cx);
1044 0 : if (!ToObjectInternal(cx, &val)) {
1045 0 : return false;
1046 : }
1047 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
1048 0 : return StringifyToJSON(cx, obj, aJSON);
1049 : }
1050 :
1051 : void
1052 0 : APZBucket::TraceDictionary(JSTracer* trc)
1053 : {
1054 0 : }
1055 :
1056 : APZBucket&
1057 0 : APZBucket::operator=(const APZBucket& aOther)
1058 : {
1059 0 : mScrollFrames.Reset();
1060 0 : if (aOther.mScrollFrames.WasPassed()) {
1061 0 : mScrollFrames.Construct(aOther.mScrollFrames.Value());
1062 : }
1063 0 : mSequenceNumber.Reset();
1064 0 : if (aOther.mSequenceNumber.WasPassed()) {
1065 0 : mSequenceNumber.Construct(aOther.mSequenceNumber.Value());
1066 : }
1067 0 : return *this;
1068 : }
1069 :
1070 : namespace binding_detail {
1071 : } // namespace binding_detail
1072 :
1073 :
1074 :
1075 0 : APZTestData::APZTestData()
1076 : {
1077 : // Safe to pass a null context if we pass a null value
1078 0 : Init(nullptr, JS::NullHandleValue);
1079 0 : }
1080 :
1081 :
1082 :
1083 : bool
1084 0 : APZTestData::InitIds(JSContext* cx, APZTestDataAtoms* atomsCache)
1085 : {
1086 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
1087 :
1088 : // Initialize these in reverse order so that any failure leaves the first one
1089 : // uninitialized.
1090 0 : if (!atomsCache->repaintRequests_id.init(cx, "repaintRequests") ||
1091 0 : !atomsCache->paints_id.init(cx, "paints")) {
1092 0 : return false;
1093 : }
1094 0 : return true;
1095 : }
1096 :
1097 : bool
1098 0 : APZTestData::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
1099 : {
1100 : // Passing a null JSContext is OK only if we're initing from null,
1101 : // Since in that case we will not have to do any property gets
1102 : // Also evaluate isNullOrUndefined in order to avoid false-positive
1103 : // checkers by static analysis tools
1104 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
1105 0 : APZTestDataAtoms* atomsCache = nullptr;
1106 0 : if (cx) {
1107 0 : atomsCache = GetAtomCache<APZTestDataAtoms>(cx);
1108 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1109 0 : return false;
1110 : }
1111 : }
1112 :
1113 0 : if (!IsConvertibleToDictionary(val)) {
1114 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
1115 : }
1116 :
1117 0 : bool isNull = val.isNullOrUndefined();
1118 : // We only need these if !isNull, in which case we have |cx|.
1119 0 : Maybe<JS::Rooted<JSObject *> > object;
1120 0 : Maybe<JS::Rooted<JS::Value> > temp;
1121 0 : if (!isNull) {
1122 0 : MOZ_ASSERT(cx);
1123 0 : object.emplace(cx, &val.toObject());
1124 0 : temp.emplace(cx);
1125 : }
1126 0 : if (!isNull) {
1127 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->paints_id, temp.ptr())) {
1128 0 : return false;
1129 : }
1130 : }
1131 0 : if (!isNull && !temp->isUndefined()) {
1132 0 : mPaints.Construct();
1133 0 : if (temp.ref().isObject()) {
1134 0 : JS::ForOfIterator iter(cx);
1135 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
1136 0 : return false;
1137 : }
1138 0 : if (!iter.valueIsIterable()) {
1139 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'paints' member of APZTestData");
1140 0 : return false;
1141 : }
1142 0 : Sequence<APZBucket> &arr = (mPaints.Value());
1143 0 : JS::Rooted<JS::Value> temp(cx);
1144 : while (true) {
1145 : bool done;
1146 0 : if (!iter.next(&temp, &done)) {
1147 0 : return false;
1148 : }
1149 0 : if (done) {
1150 0 : break;
1151 : }
1152 0 : APZBucket* slotPtr = arr.AppendElement(mozilla::fallible);
1153 0 : if (!slotPtr) {
1154 0 : JS_ReportOutOfMemory(cx);
1155 0 : return false;
1156 : }
1157 0 : APZBucket& slot = *slotPtr;
1158 0 : if (!slot.Init(cx, temp, "Element of 'paints' member of APZTestData", passedToJSImpl)) {
1159 0 : return false;
1160 : }
1161 0 : }
1162 : } else {
1163 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'paints' member of APZTestData");
1164 0 : return false;
1165 : }
1166 0 : mIsAnyMemberPresent = true;
1167 : }
1168 :
1169 0 : if (!isNull) {
1170 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->repaintRequests_id, temp.ptr())) {
1171 0 : return false;
1172 : }
1173 : }
1174 0 : if (!isNull && !temp->isUndefined()) {
1175 0 : mRepaintRequests.Construct();
1176 0 : if (temp.ref().isObject()) {
1177 0 : JS::ForOfIterator iter(cx);
1178 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
1179 0 : return false;
1180 : }
1181 0 : if (!iter.valueIsIterable()) {
1182 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'repaintRequests' member of APZTestData");
1183 0 : return false;
1184 : }
1185 0 : Sequence<APZBucket> &arr = (mRepaintRequests.Value());
1186 0 : JS::Rooted<JS::Value> temp(cx);
1187 : while (true) {
1188 : bool done;
1189 0 : if (!iter.next(&temp, &done)) {
1190 0 : return false;
1191 : }
1192 0 : if (done) {
1193 0 : break;
1194 : }
1195 0 : APZBucket* slotPtr = arr.AppendElement(mozilla::fallible);
1196 0 : if (!slotPtr) {
1197 0 : JS_ReportOutOfMemory(cx);
1198 0 : return false;
1199 : }
1200 0 : APZBucket& slot = *slotPtr;
1201 0 : if (!slot.Init(cx, temp, "Element of 'repaintRequests' member of APZTestData", passedToJSImpl)) {
1202 0 : return false;
1203 : }
1204 0 : }
1205 : } else {
1206 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'repaintRequests' member of APZTestData");
1207 0 : return false;
1208 : }
1209 0 : mIsAnyMemberPresent = true;
1210 : }
1211 0 : return true;
1212 : }
1213 :
1214 : bool
1215 0 : APZTestData::Init(const nsAString& aJSON)
1216 : {
1217 0 : AutoJSAPI jsapi;
1218 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
1219 0 : if (!cleanGlobal) {
1220 0 : return false;
1221 : }
1222 0 : if (!jsapi.Init(cleanGlobal)) {
1223 0 : return false;
1224 : }
1225 0 : JSContext* cx = jsapi.cx();
1226 0 : JS::Rooted<JS::Value> json(cx);
1227 0 : bool ok = ParseJSON(cx, aJSON, &json);
1228 0 : NS_ENSURE_TRUE(ok, false);
1229 0 : return Init(cx, json);
1230 : }
1231 :
1232 : bool
1233 0 : APZTestData::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
1234 : {
1235 0 : APZTestDataAtoms* atomsCache = GetAtomCache<APZTestDataAtoms>(cx);
1236 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1237 0 : return false;
1238 : }
1239 :
1240 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
1241 0 : if (!obj) {
1242 0 : return false;
1243 : }
1244 0 : rval.set(JS::ObjectValue(*obj));
1245 :
1246 0 : if (mPaints.WasPassed()) {
1247 : do {
1248 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1249 0 : JS::Rooted<JS::Value> temp(cx);
1250 0 : Sequence<APZBucket> const & currentValue = mPaints.InternalValue();
1251 :
1252 0 : uint32_t length = currentValue.Length();
1253 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1254 0 : if (!returnArray) {
1255 0 : return false;
1256 : }
1257 : // Scope for 'tmp'
1258 : {
1259 0 : JS::Rooted<JS::Value> tmp(cx);
1260 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1261 : // Control block to let us common up the JS_DefineElement calls when there
1262 : // are different ways to succeed at wrapping the object.
1263 : do {
1264 0 : if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
1265 0 : return false;
1266 : }
1267 0 : break;
1268 : } while (0);
1269 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1270 : JSPROP_ENUMERATE)) {
1271 0 : return false;
1272 : }
1273 : }
1274 : }
1275 0 : temp.setObject(*returnArray);
1276 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->paints_id, temp, JSPROP_ENUMERATE)) {
1277 0 : return false;
1278 : }
1279 0 : break;
1280 : } while(0);
1281 : }
1282 :
1283 0 : if (mRepaintRequests.WasPassed()) {
1284 : do {
1285 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1286 0 : JS::Rooted<JS::Value> temp(cx);
1287 0 : Sequence<APZBucket> const & currentValue = mRepaintRequests.InternalValue();
1288 :
1289 0 : uint32_t length = currentValue.Length();
1290 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1291 0 : if (!returnArray) {
1292 0 : return false;
1293 : }
1294 : // Scope for 'tmp'
1295 : {
1296 0 : JS::Rooted<JS::Value> tmp(cx);
1297 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1298 : // Control block to let us common up the JS_DefineElement calls when there
1299 : // are different ways to succeed at wrapping the object.
1300 : do {
1301 0 : if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
1302 0 : return false;
1303 : }
1304 0 : break;
1305 : } while (0);
1306 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1307 : JSPROP_ENUMERATE)) {
1308 0 : return false;
1309 : }
1310 : }
1311 : }
1312 0 : temp.setObject(*returnArray);
1313 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->repaintRequests_id, temp, JSPROP_ENUMERATE)) {
1314 0 : return false;
1315 : }
1316 0 : break;
1317 : } while(0);
1318 : }
1319 :
1320 0 : return true;
1321 : }
1322 :
1323 : bool
1324 0 : APZTestData::ToJSON(nsAString& aJSON) const
1325 : {
1326 0 : AutoJSAPI jsapi;
1327 0 : jsapi.Init();
1328 0 : JSContext *cx = jsapi.cx();
1329 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
1330 : // because we'll only be creating objects, in ways that have no
1331 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1332 : // which likewise guarantees no side-effects for the sorts of
1333 : // things we will pass it.
1334 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
1335 0 : JS::Rooted<JS::Value> val(cx);
1336 0 : if (!ToObjectInternal(cx, &val)) {
1337 0 : return false;
1338 : }
1339 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
1340 0 : return StringifyToJSON(cx, obj, aJSON);
1341 : }
1342 :
1343 : void
1344 0 : APZTestData::TraceDictionary(JSTracer* trc)
1345 : {
1346 0 : }
1347 :
1348 : APZTestData&
1349 0 : APZTestData::operator=(const APZTestData& aOther)
1350 : {
1351 0 : mPaints.Reset();
1352 0 : if (aOther.mPaints.WasPassed()) {
1353 0 : mPaints.Construct(aOther.mPaints.Value());
1354 : }
1355 0 : mRepaintRequests.Reset();
1356 0 : if (aOther.mRepaintRequests.WasPassed()) {
1357 0 : mRepaintRequests.Construct(aOther.mRepaintRequests.Value());
1358 : }
1359 0 : return *this;
1360 : }
1361 :
1362 : namespace binding_detail {
1363 : } // namespace binding_detail
1364 :
1365 :
1366 : } // namespace dom
1367 : } // namespace mozilla
|