/work/obj-fuzz/dom/bindings/APZTestDataBinding.cpp
Line | Count | Source (jump to first uncovered line) |
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 "WrapperFactory.h" |
6 | | #include "mozilla/FloatingPoint.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/Preferences.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/DOMJSClass.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/PrimitiveConversions.h" |
13 | | #include "mozilla/dom/ScriptSettings.h" |
14 | | #include "mozilla/dom/SimpleGlobalObject.h" |
15 | | #include "mozilla/dom/XrayExpandoClass.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | |
20 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
21 | | using namespace mozilla::dom::binding_detail; |
22 | | |
23 | | |
24 | | |
25 | | APZHitResult::APZHitResult() |
26 | 0 | { |
27 | 0 | // Safe to pass a null context if we pass a null value |
28 | 0 | Init(nullptr, JS::NullHandleValue); |
29 | 0 | } |
30 | | |
31 | | |
32 | | |
33 | | bool |
34 | | APZHitResult::InitIds(JSContext* cx, APZHitResultAtoms* atomsCache) |
35 | 0 | { |
36 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
37 | 0 |
|
38 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
39 | 0 | // uninitialized. |
40 | 0 | if (!atomsCache->scrollId_id.init(cx, "scrollId") || |
41 | 0 | !atomsCache->screenY_id.init(cx, "screenY") || |
42 | 0 | !atomsCache->screenX_id.init(cx, "screenX") || |
43 | 0 | !atomsCache->hitResult_id.init(cx, "hitResult")) { |
44 | 0 | return false; |
45 | 0 | } |
46 | 0 | return true; |
47 | 0 | } |
48 | | |
49 | | bool |
50 | | APZHitResult::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
51 | 0 | { |
52 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
53 | 0 | // Since in that case we will not have to do any property gets |
54 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
55 | 0 | // checkers by static analysis tools |
56 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
57 | 0 | APZHitResultAtoms* atomsCache = nullptr; |
58 | 0 | if (cx) { |
59 | 0 | atomsCache = GetAtomCache<APZHitResultAtoms>(cx); |
60 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
61 | 0 | return false; |
62 | 0 | } |
63 | 0 | } |
64 | 0 | |
65 | 0 | if (!IsConvertibleToDictionary(val)) { |
66 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
67 | 0 | } |
68 | 0 | |
69 | 0 | bool isNull = val.isNullOrUndefined(); |
70 | 0 | // We only need these if !isNull, in which case we have |cx|. |
71 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
72 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
73 | 0 | if (!isNull) { |
74 | 0 | MOZ_ASSERT(cx); |
75 | 0 | object.emplace(cx, &val.toObject()); |
76 | 0 | temp.emplace(cx); |
77 | 0 | } |
78 | 0 | if (!isNull) { |
79 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->hitResult_id, temp.ptr())) { |
80 | 0 | return false; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | if (!isNull && !temp->isUndefined()) { |
84 | 0 | mHitResult.Construct(); |
85 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mHitResult.Value()))) { |
86 | 0 | return false; |
87 | 0 | } |
88 | 0 | mIsAnyMemberPresent = true; |
89 | 0 | } |
90 | 0 |
|
91 | 0 | if (!isNull) { |
92 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->screenX_id, temp.ptr())) { |
93 | 0 | return false; |
94 | 0 | } |
95 | 0 | } |
96 | 0 | if (!isNull && !temp->isUndefined()) { |
97 | 0 | mScreenX.Construct(); |
98 | 0 | if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &(mScreenX.Value()))) { |
99 | 0 | return false; |
100 | 0 | } else if (!mozilla::IsFinite((mScreenX.Value()))) { |
101 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "'screenX' member of APZHitResult"); |
102 | 0 | return false; |
103 | 0 | } |
104 | 0 | mIsAnyMemberPresent = true; |
105 | 0 | } |
106 | 0 |
|
107 | 0 | if (!isNull) { |
108 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->screenY_id, temp.ptr())) { |
109 | 0 | return false; |
110 | 0 | } |
111 | 0 | } |
112 | 0 | if (!isNull && !temp->isUndefined()) { |
113 | 0 | mScreenY.Construct(); |
114 | 0 | if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &(mScreenY.Value()))) { |
115 | 0 | return false; |
116 | 0 | } else if (!mozilla::IsFinite((mScreenY.Value()))) { |
117 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "'screenY' member of APZHitResult"); |
118 | 0 | return false; |
119 | 0 | } |
120 | 0 | mIsAnyMemberPresent = true; |
121 | 0 | } |
122 | 0 |
|
123 | 0 | if (!isNull) { |
124 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->scrollId_id, temp.ptr())) { |
125 | 0 | return false; |
126 | 0 | } |
127 | 0 | } |
128 | 0 | if (!isNull && !temp->isUndefined()) { |
129 | 0 | mScrollId.Construct(); |
130 | 0 | if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mScrollId.Value()))) { |
131 | 0 | return false; |
132 | 0 | } |
133 | 0 | mIsAnyMemberPresent = true; |
134 | 0 | } |
135 | 0 | return true; |
136 | 0 | } |
137 | | |
138 | | bool |
139 | | APZHitResult::Init(const nsAString& aJSON) |
140 | 0 | { |
141 | 0 | AutoJSAPI jsapi; |
142 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
143 | 0 | if (!cleanGlobal) { |
144 | 0 | return false; |
145 | 0 | } |
146 | 0 | if (!jsapi.Init(cleanGlobal)) { |
147 | 0 | return false; |
148 | 0 | } |
149 | 0 | JSContext* cx = jsapi.cx(); |
150 | 0 | JS::Rooted<JS::Value> json(cx); |
151 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
152 | 0 | NS_ENSURE_TRUE(ok, false); |
153 | 0 | return Init(cx, json); |
154 | 0 | } |
155 | | |
156 | | bool |
157 | | APZHitResult::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
158 | 0 | { |
159 | 0 | APZHitResultAtoms* atomsCache = GetAtomCache<APZHitResultAtoms>(cx); |
160 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
161 | 0 | return false; |
162 | 0 | } |
163 | 0 | |
164 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
165 | 0 | if (!obj) { |
166 | 0 | return false; |
167 | 0 | } |
168 | 0 | rval.set(JS::ObjectValue(*obj)); |
169 | 0 |
|
170 | 0 | if (mHitResult.WasPassed()) { |
171 | 0 | do { |
172 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
173 | 0 | JS::Rooted<JS::Value> temp(cx); |
174 | 0 | uint16_t const & currentValue = mHitResult.InternalValue(); |
175 | 0 | temp.setInt32(int32_t(currentValue)); |
176 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->hitResult_id, temp, JSPROP_ENUMERATE)) { |
177 | 0 | return false; |
178 | 0 | } |
179 | 0 | break; |
180 | 0 | } while(false); |
181 | 0 | } |
182 | 0 |
|
183 | 0 | if (mScreenX.WasPassed()) { |
184 | 0 | do { |
185 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
186 | 0 | JS::Rooted<JS::Value> temp(cx); |
187 | 0 | float const & currentValue = mScreenX.InternalValue(); |
188 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
189 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->screenX_id, temp, JSPROP_ENUMERATE)) { |
190 | 0 | return false; |
191 | 0 | } |
192 | 0 | break; |
193 | 0 | } while(false); |
194 | 0 | } |
195 | 0 |
|
196 | 0 | if (mScreenY.WasPassed()) { |
197 | 0 | do { |
198 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
199 | 0 | JS::Rooted<JS::Value> temp(cx); |
200 | 0 | float const & currentValue = mScreenY.InternalValue(); |
201 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
202 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->screenY_id, temp, JSPROP_ENUMERATE)) { |
203 | 0 | return false; |
204 | 0 | } |
205 | 0 | break; |
206 | 0 | } while(false); |
207 | 0 | } |
208 | 0 |
|
209 | 0 | if (mScrollId.WasPassed()) { |
210 | 0 | do { |
211 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
212 | 0 | JS::Rooted<JS::Value> temp(cx); |
213 | 0 | uint64_t const & currentValue = mScrollId.InternalValue(); |
214 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
215 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->scrollId_id, temp, JSPROP_ENUMERATE)) { |
216 | 0 | return false; |
217 | 0 | } |
218 | 0 | break; |
219 | 0 | } while(false); |
220 | 0 | } |
221 | 0 |
|
222 | 0 | return true; |
223 | 0 | } |
224 | | |
225 | | bool |
226 | | APZHitResult::ToJSON(nsAString& aJSON) const |
227 | 0 | { |
228 | 0 | AutoJSAPI jsapi; |
229 | 0 | jsapi.Init(); |
230 | 0 | JSContext *cx = jsapi.cx(); |
231 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
232 | 0 | // because we'll only be creating objects, in ways that have no |
233 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
234 | 0 | // which likewise guarantees no side-effects for the sorts of |
235 | 0 | // things we will pass it. |
236 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
237 | 0 | JS::Rooted<JS::Value> val(cx); |
238 | 0 | if (!ToObjectInternal(cx, &val)) { |
239 | 0 | return false; |
240 | 0 | } |
241 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
242 | 0 | return StringifyToJSON(cx, obj, aJSON); |
243 | 0 | } |
244 | | |
245 | | void |
246 | | APZHitResult::TraceDictionary(JSTracer* trc) |
247 | 0 | { |
248 | 0 | } |
249 | | |
250 | | APZHitResult& |
251 | | APZHitResult::operator=(const APZHitResult& aOther) |
252 | 0 | { |
253 | 0 | DictionaryBase::operator=(aOther); |
254 | 0 | mHitResult.Reset(); |
255 | 0 | if (aOther.mHitResult.WasPassed()) { |
256 | 0 | mHitResult.Construct(aOther.mHitResult.Value()); |
257 | 0 | } |
258 | 0 | mScreenX.Reset(); |
259 | 0 | if (aOther.mScreenX.WasPassed()) { |
260 | 0 | mScreenX.Construct(aOther.mScreenX.Value()); |
261 | 0 | } |
262 | 0 | mScreenY.Reset(); |
263 | 0 | if (aOther.mScreenY.WasPassed()) { |
264 | 0 | mScreenY.Construct(aOther.mScreenY.Value()); |
265 | 0 | } |
266 | 0 | mScrollId.Reset(); |
267 | 0 | if (aOther.mScrollId.WasPassed()) { |
268 | 0 | mScrollId.Construct(aOther.mScrollId.Value()); |
269 | 0 | } |
270 | 0 | return *this; |
271 | 0 | } |
272 | | |
273 | | namespace binding_detail { |
274 | | } // namespace binding_detail |
275 | | |
276 | | |
277 | | |
278 | | FrameUniformity::FrameUniformity() |
279 | 0 | { |
280 | 0 | // Safe to pass a null context if we pass a null value |
281 | 0 | Init(nullptr, JS::NullHandleValue); |
282 | 0 | } |
283 | | |
284 | | |
285 | | |
286 | | bool |
287 | | FrameUniformity::InitIds(JSContext* cx, FrameUniformityAtoms* atomsCache) |
288 | 0 | { |
289 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
290 | 0 |
|
291 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
292 | 0 | // uninitialized. |
293 | 0 | if (!atomsCache->layerAddress_id.init(cx, "layerAddress") || |
294 | 0 | !atomsCache->frameUniformity_id.init(cx, "frameUniformity")) { |
295 | 0 | return false; |
296 | 0 | } |
297 | 0 | return true; |
298 | 0 | } |
299 | | |
300 | | bool |
301 | | FrameUniformity::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
302 | 0 | { |
303 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
304 | 0 | // Since in that case we will not have to do any property gets |
305 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
306 | 0 | // checkers by static analysis tools |
307 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
308 | 0 | FrameUniformityAtoms* atomsCache = nullptr; |
309 | 0 | if (cx) { |
310 | 0 | atomsCache = GetAtomCache<FrameUniformityAtoms>(cx); |
311 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
312 | 0 | return false; |
313 | 0 | } |
314 | 0 | } |
315 | 0 | |
316 | 0 | if (!IsConvertibleToDictionary(val)) { |
317 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
318 | 0 | } |
319 | 0 | |
320 | 0 | bool isNull = val.isNullOrUndefined(); |
321 | 0 | // We only need these if !isNull, in which case we have |cx|. |
322 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
323 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
324 | 0 | if (!isNull) { |
325 | 0 | MOZ_ASSERT(cx); |
326 | 0 | object.emplace(cx, &val.toObject()); |
327 | 0 | temp.emplace(cx); |
328 | 0 | } |
329 | 0 | if (!isNull) { |
330 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->frameUniformity_id, temp.ptr())) { |
331 | 0 | return false; |
332 | 0 | } |
333 | 0 | } |
334 | 0 | if (!isNull && !temp->isUndefined()) { |
335 | 0 | mFrameUniformity.Construct(); |
336 | 0 | if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &(mFrameUniformity.Value()))) { |
337 | 0 | return false; |
338 | 0 | } else if (!mozilla::IsFinite((mFrameUniformity.Value()))) { |
339 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "'frameUniformity' member of FrameUniformity"); |
340 | 0 | return false; |
341 | 0 | } |
342 | 0 | mIsAnyMemberPresent = true; |
343 | 0 | } |
344 | 0 |
|
345 | 0 | if (!isNull) { |
346 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->layerAddress_id, temp.ptr())) { |
347 | 0 | return false; |
348 | 0 | } |
349 | 0 | } |
350 | 0 | if (!isNull && !temp->isUndefined()) { |
351 | 0 | mLayerAddress.Construct(); |
352 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mLayerAddress.Value()))) { |
353 | 0 | return false; |
354 | 0 | } |
355 | 0 | mIsAnyMemberPresent = true; |
356 | 0 | } |
357 | 0 | return true; |
358 | 0 | } |
359 | | |
360 | | bool |
361 | | FrameUniformity::Init(const nsAString& aJSON) |
362 | 0 | { |
363 | 0 | AutoJSAPI jsapi; |
364 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
365 | 0 | if (!cleanGlobal) { |
366 | 0 | return false; |
367 | 0 | } |
368 | 0 | if (!jsapi.Init(cleanGlobal)) { |
369 | 0 | return false; |
370 | 0 | } |
371 | 0 | JSContext* cx = jsapi.cx(); |
372 | 0 | JS::Rooted<JS::Value> json(cx); |
373 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
374 | 0 | NS_ENSURE_TRUE(ok, false); |
375 | 0 | return Init(cx, json); |
376 | 0 | } |
377 | | |
378 | | bool |
379 | | FrameUniformity::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
380 | 0 | { |
381 | 0 | FrameUniformityAtoms* atomsCache = GetAtomCache<FrameUniformityAtoms>(cx); |
382 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
383 | 0 | return false; |
384 | 0 | } |
385 | 0 | |
386 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
387 | 0 | if (!obj) { |
388 | 0 | return false; |
389 | 0 | } |
390 | 0 | rval.set(JS::ObjectValue(*obj)); |
391 | 0 |
|
392 | 0 | if (mFrameUniformity.WasPassed()) { |
393 | 0 | do { |
394 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
395 | 0 | JS::Rooted<JS::Value> temp(cx); |
396 | 0 | float const & currentValue = mFrameUniformity.InternalValue(); |
397 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
398 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->frameUniformity_id, temp, JSPROP_ENUMERATE)) { |
399 | 0 | return false; |
400 | 0 | } |
401 | 0 | break; |
402 | 0 | } while(false); |
403 | 0 | } |
404 | 0 |
|
405 | 0 | if (mLayerAddress.WasPassed()) { |
406 | 0 | do { |
407 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
408 | 0 | JS::Rooted<JS::Value> temp(cx); |
409 | 0 | uint32_t const & currentValue = mLayerAddress.InternalValue(); |
410 | 0 | temp.setNumber(currentValue); |
411 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->layerAddress_id, temp, JSPROP_ENUMERATE)) { |
412 | 0 | return false; |
413 | 0 | } |
414 | 0 | break; |
415 | 0 | } while(false); |
416 | 0 | } |
417 | 0 |
|
418 | 0 | return true; |
419 | 0 | } |
420 | | |
421 | | bool |
422 | | FrameUniformity::ToJSON(nsAString& aJSON) const |
423 | 0 | { |
424 | 0 | AutoJSAPI jsapi; |
425 | 0 | jsapi.Init(); |
426 | 0 | JSContext *cx = jsapi.cx(); |
427 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
428 | 0 | // because we'll only be creating objects, in ways that have no |
429 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
430 | 0 | // which likewise guarantees no side-effects for the sorts of |
431 | 0 | // things we will pass it. |
432 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
433 | 0 | JS::Rooted<JS::Value> val(cx); |
434 | 0 | if (!ToObjectInternal(cx, &val)) { |
435 | 0 | return false; |
436 | 0 | } |
437 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
438 | 0 | return StringifyToJSON(cx, obj, aJSON); |
439 | 0 | } |
440 | | |
441 | | void |
442 | | FrameUniformity::TraceDictionary(JSTracer* trc) |
443 | 0 | { |
444 | 0 | } |
445 | | |
446 | | FrameUniformity& |
447 | | FrameUniformity::operator=(const FrameUniformity& aOther) |
448 | 0 | { |
449 | 0 | DictionaryBase::operator=(aOther); |
450 | 0 | mFrameUniformity.Reset(); |
451 | 0 | if (aOther.mFrameUniformity.WasPassed()) { |
452 | 0 | mFrameUniformity.Construct(aOther.mFrameUniformity.Value()); |
453 | 0 | } |
454 | 0 | mLayerAddress.Reset(); |
455 | 0 | if (aOther.mLayerAddress.WasPassed()) { |
456 | 0 | mLayerAddress.Construct(aOther.mLayerAddress.Value()); |
457 | 0 | } |
458 | 0 | return *this; |
459 | 0 | } |
460 | | |
461 | | namespace binding_detail { |
462 | | } // namespace binding_detail |
463 | | |
464 | | |
465 | | |
466 | | ScrollFrameDataEntry::ScrollFrameDataEntry() |
467 | 0 | { |
468 | 0 | // Safe to pass a null context if we pass a null value |
469 | 0 | Init(nullptr, JS::NullHandleValue); |
470 | 0 | } |
471 | | |
472 | | |
473 | | |
474 | | bool |
475 | | ScrollFrameDataEntry::InitIds(JSContext* cx, ScrollFrameDataEntryAtoms* atomsCache) |
476 | 0 | { |
477 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
478 | 0 |
|
479 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
480 | 0 | // uninitialized. |
481 | 0 | if (!atomsCache->value_id.init(cx, "value") || |
482 | 0 | !atomsCache->key_id.init(cx, "key")) { |
483 | 0 | return false; |
484 | 0 | } |
485 | 0 | return true; |
486 | 0 | } |
487 | | |
488 | | bool |
489 | | ScrollFrameDataEntry::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
490 | 0 | { |
491 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
492 | 0 | // Since in that case we will not have to do any property gets |
493 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
494 | 0 | // checkers by static analysis tools |
495 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
496 | 0 | ScrollFrameDataEntryAtoms* atomsCache = nullptr; |
497 | 0 | if (cx) { |
498 | 0 | atomsCache = GetAtomCache<ScrollFrameDataEntryAtoms>(cx); |
499 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
500 | 0 | return false; |
501 | 0 | } |
502 | 0 | } |
503 | 0 | |
504 | 0 | if (!IsConvertibleToDictionary(val)) { |
505 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
506 | 0 | } |
507 | 0 | |
508 | 0 | bool isNull = val.isNullOrUndefined(); |
509 | 0 | // We only need these if !isNull, in which case we have |cx|. |
510 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
511 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
512 | 0 | if (!isNull) { |
513 | 0 | MOZ_ASSERT(cx); |
514 | 0 | object.emplace(cx, &val.toObject()); |
515 | 0 | temp.emplace(cx); |
516 | 0 | } |
517 | 0 | if (!isNull) { |
518 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->key_id, temp.ptr())) { |
519 | 0 | return false; |
520 | 0 | } |
521 | 0 | } |
522 | 0 | if (!isNull && !temp->isUndefined()) { |
523 | 0 | mKey.Construct(); |
524 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mKey.Value()))) { |
525 | 0 | return false; |
526 | 0 | } |
527 | 0 | mIsAnyMemberPresent = true; |
528 | 0 | } |
529 | 0 |
|
530 | 0 | if (!isNull) { |
531 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->value_id, temp.ptr())) { |
532 | 0 | return false; |
533 | 0 | } |
534 | 0 | } |
535 | 0 | if (!isNull && !temp->isUndefined()) { |
536 | 0 | mValue.Construct(); |
537 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mValue.Value()))) { |
538 | 0 | return false; |
539 | 0 | } |
540 | 0 | mIsAnyMemberPresent = true; |
541 | 0 | } |
542 | 0 | return true; |
543 | 0 | } |
544 | | |
545 | | bool |
546 | | ScrollFrameDataEntry::Init(const nsAString& aJSON) |
547 | 0 | { |
548 | 0 | AutoJSAPI jsapi; |
549 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
550 | 0 | if (!cleanGlobal) { |
551 | 0 | return false; |
552 | 0 | } |
553 | 0 | if (!jsapi.Init(cleanGlobal)) { |
554 | 0 | return false; |
555 | 0 | } |
556 | 0 | JSContext* cx = jsapi.cx(); |
557 | 0 | JS::Rooted<JS::Value> json(cx); |
558 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
559 | 0 | NS_ENSURE_TRUE(ok, false); |
560 | 0 | return Init(cx, json); |
561 | 0 | } |
562 | | |
563 | | bool |
564 | | ScrollFrameDataEntry::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
565 | 0 | { |
566 | 0 | ScrollFrameDataEntryAtoms* atomsCache = GetAtomCache<ScrollFrameDataEntryAtoms>(cx); |
567 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
568 | 0 | return false; |
569 | 0 | } |
570 | 0 | |
571 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
572 | 0 | if (!obj) { |
573 | 0 | return false; |
574 | 0 | } |
575 | 0 | rval.set(JS::ObjectValue(*obj)); |
576 | 0 |
|
577 | 0 | if (mKey.WasPassed()) { |
578 | 0 | do { |
579 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
580 | 0 | JS::Rooted<JS::Value> temp(cx); |
581 | 0 | nsString const & currentValue = mKey.InternalValue(); |
582 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
583 | 0 | return false; |
584 | 0 | } |
585 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->key_id, temp, JSPROP_ENUMERATE)) { |
586 | 0 | return false; |
587 | 0 | } |
588 | 0 | break; |
589 | 0 | } while(false); |
590 | 0 | } |
591 | 0 |
|
592 | 0 | if (mValue.WasPassed()) { |
593 | 0 | do { |
594 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
595 | 0 | JS::Rooted<JS::Value> temp(cx); |
596 | 0 | nsString const & currentValue = mValue.InternalValue(); |
597 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
598 | 0 | return false; |
599 | 0 | } |
600 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->value_id, temp, JSPROP_ENUMERATE)) { |
601 | 0 | return false; |
602 | 0 | } |
603 | 0 | break; |
604 | 0 | } while(false); |
605 | 0 | } |
606 | 0 |
|
607 | 0 | return true; |
608 | 0 | } |
609 | | |
610 | | bool |
611 | | ScrollFrameDataEntry::ToJSON(nsAString& aJSON) const |
612 | 0 | { |
613 | 0 | AutoJSAPI jsapi; |
614 | 0 | jsapi.Init(); |
615 | 0 | JSContext *cx = jsapi.cx(); |
616 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
617 | 0 | // because we'll only be creating objects, in ways that have no |
618 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
619 | 0 | // which likewise guarantees no side-effects for the sorts of |
620 | 0 | // things we will pass it. |
621 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
622 | 0 | JS::Rooted<JS::Value> val(cx); |
623 | 0 | if (!ToObjectInternal(cx, &val)) { |
624 | 0 | return false; |
625 | 0 | } |
626 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
627 | 0 | return StringifyToJSON(cx, obj, aJSON); |
628 | 0 | } |
629 | | |
630 | | void |
631 | | ScrollFrameDataEntry::TraceDictionary(JSTracer* trc) |
632 | 0 | { |
633 | 0 | } |
634 | | |
635 | | ScrollFrameDataEntry& |
636 | | ScrollFrameDataEntry::operator=(const ScrollFrameDataEntry& aOther) |
637 | 0 | { |
638 | 0 | DictionaryBase::operator=(aOther); |
639 | 0 | mKey.Reset(); |
640 | 0 | if (aOther.mKey.WasPassed()) { |
641 | 0 | mKey.Construct(aOther.mKey.Value()); |
642 | 0 | } |
643 | 0 | mValue.Reset(); |
644 | 0 | if (aOther.mValue.WasPassed()) { |
645 | 0 | mValue.Construct(aOther.mValue.Value()); |
646 | 0 | } |
647 | 0 | return *this; |
648 | 0 | } |
649 | | |
650 | | namespace binding_detail { |
651 | | } // namespace binding_detail |
652 | | |
653 | | |
654 | | |
655 | | FrameUniformityResults::FrameUniformityResults() |
656 | 0 | { |
657 | 0 | // Safe to pass a null context if we pass a null value |
658 | 0 | Init(nullptr, JS::NullHandleValue); |
659 | 0 | } |
660 | | |
661 | | |
662 | | |
663 | | bool |
664 | | FrameUniformityResults::InitIds(JSContext* cx, FrameUniformityResultsAtoms* atomsCache) |
665 | 0 | { |
666 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
667 | 0 |
|
668 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
669 | 0 | // uninitialized. |
670 | 0 | if (!atomsCache->layerUniformities_id.init(cx, "layerUniformities")) { |
671 | 0 | return false; |
672 | 0 | } |
673 | 0 | return true; |
674 | 0 | } |
675 | | |
676 | | bool |
677 | | FrameUniformityResults::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
678 | 0 | { |
679 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
680 | 0 | // Since in that case we will not have to do any property gets |
681 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
682 | 0 | // checkers by static analysis tools |
683 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
684 | 0 | FrameUniformityResultsAtoms* atomsCache = nullptr; |
685 | 0 | if (cx) { |
686 | 0 | atomsCache = GetAtomCache<FrameUniformityResultsAtoms>(cx); |
687 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
688 | 0 | return false; |
689 | 0 | } |
690 | 0 | } |
691 | 0 | |
692 | 0 | if (!IsConvertibleToDictionary(val)) { |
693 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
694 | 0 | } |
695 | 0 | |
696 | 0 | bool isNull = val.isNullOrUndefined(); |
697 | 0 | // We only need these if !isNull, in which case we have |cx|. |
698 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
699 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
700 | 0 | if (!isNull) { |
701 | 0 | MOZ_ASSERT(cx); |
702 | 0 | object.emplace(cx, &val.toObject()); |
703 | 0 | temp.emplace(cx); |
704 | 0 | } |
705 | 0 | if (!isNull) { |
706 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->layerUniformities_id, temp.ptr())) { |
707 | 0 | return false; |
708 | 0 | } |
709 | 0 | } |
710 | 0 | if (!isNull && !temp->isUndefined()) { |
711 | 0 | mLayerUniformities.Construct(); |
712 | 0 | if (temp.ref().isObject()) { |
713 | 0 | JS::ForOfIterator iter(cx); |
714 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
715 | 0 | return false; |
716 | 0 | } |
717 | 0 | if (!iter.valueIsIterable()) { |
718 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'layerUniformities' member of FrameUniformityResults"); |
719 | 0 | return false; |
720 | 0 | } |
721 | 0 | Sequence<FrameUniformity> &arr = (mLayerUniformities.Value()); |
722 | 0 | JS::Rooted<JS::Value> temp(cx); |
723 | 0 | while (true) { |
724 | 0 | bool done; |
725 | 0 | if (!iter.next(&temp, &done)) { |
726 | 0 | return false; |
727 | 0 | } |
728 | 0 | if (done) { |
729 | 0 | break; |
730 | 0 | } |
731 | 0 | FrameUniformity* slotPtr = arr.AppendElement(mozilla::fallible); |
732 | 0 | if (!slotPtr) { |
733 | 0 | JS_ReportOutOfMemory(cx); |
734 | 0 | return false; |
735 | 0 | } |
736 | 0 | FrameUniformity& slot = *slotPtr; |
737 | 0 | if (!slot.Init(cx, temp, "Element of 'layerUniformities' member of FrameUniformityResults", passedToJSImpl)) { |
738 | 0 | return false; |
739 | 0 | } |
740 | 0 | } |
741 | 0 | } else { |
742 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'layerUniformities' member of FrameUniformityResults"); |
743 | 0 | return false; |
744 | 0 | } |
745 | 0 | mIsAnyMemberPresent = true; |
746 | 0 | } |
747 | 0 | return true; |
748 | 0 | } |
749 | | |
750 | | bool |
751 | | FrameUniformityResults::Init(const nsAString& aJSON) |
752 | 0 | { |
753 | 0 | AutoJSAPI jsapi; |
754 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
755 | 0 | if (!cleanGlobal) { |
756 | 0 | return false; |
757 | 0 | } |
758 | 0 | if (!jsapi.Init(cleanGlobal)) { |
759 | 0 | return false; |
760 | 0 | } |
761 | 0 | JSContext* cx = jsapi.cx(); |
762 | 0 | JS::Rooted<JS::Value> json(cx); |
763 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
764 | 0 | NS_ENSURE_TRUE(ok, false); |
765 | 0 | return Init(cx, json); |
766 | 0 | } |
767 | | |
768 | | bool |
769 | | FrameUniformityResults::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
770 | 0 | { |
771 | 0 | FrameUniformityResultsAtoms* atomsCache = GetAtomCache<FrameUniformityResultsAtoms>(cx); |
772 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
773 | 0 | return false; |
774 | 0 | } |
775 | 0 | |
776 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
777 | 0 | if (!obj) { |
778 | 0 | return false; |
779 | 0 | } |
780 | 0 | rval.set(JS::ObjectValue(*obj)); |
781 | 0 |
|
782 | 0 | if (mLayerUniformities.WasPassed()) { |
783 | 0 | do { |
784 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
785 | 0 | JS::Rooted<JS::Value> temp(cx); |
786 | 0 | Sequence<FrameUniformity> const & currentValue = mLayerUniformities.InternalValue(); |
787 | 0 |
|
788 | 0 | uint32_t length = currentValue.Length(); |
789 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
790 | 0 | if (!returnArray) { |
791 | 0 | return false; |
792 | 0 | } |
793 | 0 | // Scope for 'tmp' |
794 | 0 | { |
795 | 0 | JS::Rooted<JS::Value> tmp(cx); |
796 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
797 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
798 | 0 | // are different ways to succeed at wrapping the object. |
799 | 0 | do { |
800 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
801 | 0 | return false; |
802 | 0 | } |
803 | 0 | break; |
804 | 0 | } while (false); |
805 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
806 | 0 | JSPROP_ENUMERATE)) { |
807 | 0 | return false; |
808 | 0 | } |
809 | 0 | } |
810 | 0 | } |
811 | 0 | temp.setObject(*returnArray); |
812 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->layerUniformities_id, temp, JSPROP_ENUMERATE)) { |
813 | 0 | return false; |
814 | 0 | } |
815 | 0 | break; |
816 | 0 | } while(false); |
817 | 0 | } |
818 | 0 |
|
819 | 0 | return true; |
820 | 0 | } |
821 | | |
822 | | bool |
823 | | FrameUniformityResults::ToJSON(nsAString& aJSON) const |
824 | 0 | { |
825 | 0 | AutoJSAPI jsapi; |
826 | 0 | jsapi.Init(); |
827 | 0 | JSContext *cx = jsapi.cx(); |
828 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
829 | 0 | // because we'll only be creating objects, in ways that have no |
830 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
831 | 0 | // which likewise guarantees no side-effects for the sorts of |
832 | 0 | // things we will pass it. |
833 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
834 | 0 | JS::Rooted<JS::Value> val(cx); |
835 | 0 | if (!ToObjectInternal(cx, &val)) { |
836 | 0 | return false; |
837 | 0 | } |
838 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
839 | 0 | return StringifyToJSON(cx, obj, aJSON); |
840 | 0 | } |
841 | | |
842 | | void |
843 | | FrameUniformityResults::TraceDictionary(JSTracer* trc) |
844 | 0 | { |
845 | 0 | } |
846 | | |
847 | | FrameUniformityResults& |
848 | | FrameUniformityResults::operator=(const FrameUniformityResults& aOther) |
849 | 0 | { |
850 | 0 | DictionaryBase::operator=(aOther); |
851 | 0 | mLayerUniformities.Reset(); |
852 | 0 | if (aOther.mLayerUniformities.WasPassed()) { |
853 | 0 | mLayerUniformities.Construct(aOther.mLayerUniformities.Value()); |
854 | 0 | } |
855 | 0 | return *this; |
856 | 0 | } |
857 | | |
858 | | namespace binding_detail { |
859 | | } // namespace binding_detail |
860 | | |
861 | | |
862 | | |
863 | | ScrollFrameData::ScrollFrameData() |
864 | 0 | { |
865 | 0 | // Safe to pass a null context if we pass a null value |
866 | 0 | Init(nullptr, JS::NullHandleValue); |
867 | 0 | } |
868 | | |
869 | | |
870 | | |
871 | | bool |
872 | | ScrollFrameData::InitIds(JSContext* cx, ScrollFrameDataAtoms* atomsCache) |
873 | 0 | { |
874 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
875 | 0 |
|
876 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
877 | 0 | // uninitialized. |
878 | 0 | if (!atomsCache->scrollId_id.init(cx, "scrollId") || |
879 | 0 | !atomsCache->entries_id.init(cx, "entries")) { |
880 | 0 | return false; |
881 | 0 | } |
882 | 0 | return true; |
883 | 0 | } |
884 | | |
885 | | bool |
886 | | ScrollFrameData::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
887 | 0 | { |
888 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
889 | 0 | // Since in that case we will not have to do any property gets |
890 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
891 | 0 | // checkers by static analysis tools |
892 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
893 | 0 | ScrollFrameDataAtoms* atomsCache = nullptr; |
894 | 0 | if (cx) { |
895 | 0 | atomsCache = GetAtomCache<ScrollFrameDataAtoms>(cx); |
896 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
897 | 0 | return false; |
898 | 0 | } |
899 | 0 | } |
900 | 0 | |
901 | 0 | if (!IsConvertibleToDictionary(val)) { |
902 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
903 | 0 | } |
904 | 0 | |
905 | 0 | bool isNull = val.isNullOrUndefined(); |
906 | 0 | // We only need these if !isNull, in which case we have |cx|. |
907 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
908 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
909 | 0 | if (!isNull) { |
910 | 0 | MOZ_ASSERT(cx); |
911 | 0 | object.emplace(cx, &val.toObject()); |
912 | 0 | temp.emplace(cx); |
913 | 0 | } |
914 | 0 | if (!isNull) { |
915 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->entries_id, temp.ptr())) { |
916 | 0 | return false; |
917 | 0 | } |
918 | 0 | } |
919 | 0 | if (!isNull && !temp->isUndefined()) { |
920 | 0 | mEntries.Construct(); |
921 | 0 | if (temp.ref().isObject()) { |
922 | 0 | JS::ForOfIterator iter(cx); |
923 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
924 | 0 | return false; |
925 | 0 | } |
926 | 0 | if (!iter.valueIsIterable()) { |
927 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'entries' member of ScrollFrameData"); |
928 | 0 | return false; |
929 | 0 | } |
930 | 0 | Sequence<ScrollFrameDataEntry> &arr = (mEntries.Value()); |
931 | 0 | JS::Rooted<JS::Value> temp(cx); |
932 | 0 | while (true) { |
933 | 0 | bool done; |
934 | 0 | if (!iter.next(&temp, &done)) { |
935 | 0 | return false; |
936 | 0 | } |
937 | 0 | if (done) { |
938 | 0 | break; |
939 | 0 | } |
940 | 0 | ScrollFrameDataEntry* slotPtr = arr.AppendElement(mozilla::fallible); |
941 | 0 | if (!slotPtr) { |
942 | 0 | JS_ReportOutOfMemory(cx); |
943 | 0 | return false; |
944 | 0 | } |
945 | 0 | ScrollFrameDataEntry& slot = *slotPtr; |
946 | 0 | if (!slot.Init(cx, temp, "Element of 'entries' member of ScrollFrameData", passedToJSImpl)) { |
947 | 0 | return false; |
948 | 0 | } |
949 | 0 | } |
950 | 0 | } else { |
951 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'entries' member of ScrollFrameData"); |
952 | 0 | return false; |
953 | 0 | } |
954 | 0 | mIsAnyMemberPresent = true; |
955 | 0 | } |
956 | 0 |
|
957 | 0 | if (!isNull) { |
958 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->scrollId_id, temp.ptr())) { |
959 | 0 | return false; |
960 | 0 | } |
961 | 0 | } |
962 | 0 | if (!isNull && !temp->isUndefined()) { |
963 | 0 | mScrollId.Construct(); |
964 | 0 | if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mScrollId.Value()))) { |
965 | 0 | return false; |
966 | 0 | } |
967 | 0 | mIsAnyMemberPresent = true; |
968 | 0 | } |
969 | 0 | return true; |
970 | 0 | } |
971 | | |
972 | | bool |
973 | | ScrollFrameData::Init(const nsAString& aJSON) |
974 | 0 | { |
975 | 0 | AutoJSAPI jsapi; |
976 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
977 | 0 | if (!cleanGlobal) { |
978 | 0 | return false; |
979 | 0 | } |
980 | 0 | if (!jsapi.Init(cleanGlobal)) { |
981 | 0 | return false; |
982 | 0 | } |
983 | 0 | JSContext* cx = jsapi.cx(); |
984 | 0 | JS::Rooted<JS::Value> json(cx); |
985 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
986 | 0 | NS_ENSURE_TRUE(ok, false); |
987 | 0 | return Init(cx, json); |
988 | 0 | } |
989 | | |
990 | | bool |
991 | | ScrollFrameData::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
992 | 0 | { |
993 | 0 | ScrollFrameDataAtoms* atomsCache = GetAtomCache<ScrollFrameDataAtoms>(cx); |
994 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
995 | 0 | return false; |
996 | 0 | } |
997 | 0 | |
998 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
999 | 0 | if (!obj) { |
1000 | 0 | return false; |
1001 | 0 | } |
1002 | 0 | rval.set(JS::ObjectValue(*obj)); |
1003 | 0 |
|
1004 | 0 | if (mEntries.WasPassed()) { |
1005 | 0 | do { |
1006 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1007 | 0 | JS::Rooted<JS::Value> temp(cx); |
1008 | 0 | Sequence<ScrollFrameDataEntry> const & currentValue = mEntries.InternalValue(); |
1009 | 0 |
|
1010 | 0 | uint32_t length = currentValue.Length(); |
1011 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
1012 | 0 | if (!returnArray) { |
1013 | 0 | return false; |
1014 | 0 | } |
1015 | 0 | // Scope for 'tmp' |
1016 | 0 | { |
1017 | 0 | JS::Rooted<JS::Value> tmp(cx); |
1018 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
1019 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
1020 | 0 | // are different ways to succeed at wrapping the object. |
1021 | 0 | do { |
1022 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
1023 | 0 | return false; |
1024 | 0 | } |
1025 | 0 | break; |
1026 | 0 | } while (false); |
1027 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
1028 | 0 | JSPROP_ENUMERATE)) { |
1029 | 0 | return false; |
1030 | 0 | } |
1031 | 0 | } |
1032 | 0 | } |
1033 | 0 | temp.setObject(*returnArray); |
1034 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->entries_id, temp, JSPROP_ENUMERATE)) { |
1035 | 0 | return false; |
1036 | 0 | } |
1037 | 0 | break; |
1038 | 0 | } while(false); |
1039 | 0 | } |
1040 | 0 |
|
1041 | 0 | if (mScrollId.WasPassed()) { |
1042 | 0 | do { |
1043 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1044 | 0 | JS::Rooted<JS::Value> temp(cx); |
1045 | 0 | uint64_t const & currentValue = mScrollId.InternalValue(); |
1046 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
1047 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->scrollId_id, temp, JSPROP_ENUMERATE)) { |
1048 | 0 | return false; |
1049 | 0 | } |
1050 | 0 | break; |
1051 | 0 | } while(false); |
1052 | 0 | } |
1053 | 0 |
|
1054 | 0 | return true; |
1055 | 0 | } |
1056 | | |
1057 | | bool |
1058 | | ScrollFrameData::ToJSON(nsAString& aJSON) const |
1059 | 0 | { |
1060 | 0 | AutoJSAPI jsapi; |
1061 | 0 | jsapi.Init(); |
1062 | 0 | JSContext *cx = jsapi.cx(); |
1063 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
1064 | 0 | // because we'll only be creating objects, in ways that have no |
1065 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
1066 | 0 | // which likewise guarantees no side-effects for the sorts of |
1067 | 0 | // things we will pass it. |
1068 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
1069 | 0 | JS::Rooted<JS::Value> val(cx); |
1070 | 0 | if (!ToObjectInternal(cx, &val)) { |
1071 | 0 | return false; |
1072 | 0 | } |
1073 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
1074 | 0 | return StringifyToJSON(cx, obj, aJSON); |
1075 | 0 | } |
1076 | | |
1077 | | void |
1078 | | ScrollFrameData::TraceDictionary(JSTracer* trc) |
1079 | 0 | { |
1080 | 0 | } |
1081 | | |
1082 | | ScrollFrameData& |
1083 | | ScrollFrameData::operator=(const ScrollFrameData& aOther) |
1084 | 0 | { |
1085 | 0 | DictionaryBase::operator=(aOther); |
1086 | 0 | mEntries.Reset(); |
1087 | 0 | if (aOther.mEntries.WasPassed()) { |
1088 | 0 | mEntries.Construct(aOther.mEntries.Value()); |
1089 | 0 | } |
1090 | 0 | mScrollId.Reset(); |
1091 | 0 | if (aOther.mScrollId.WasPassed()) { |
1092 | 0 | mScrollId.Construct(aOther.mScrollId.Value()); |
1093 | 0 | } |
1094 | 0 | return *this; |
1095 | 0 | } |
1096 | | |
1097 | | namespace binding_detail { |
1098 | | } // namespace binding_detail |
1099 | | |
1100 | | |
1101 | | |
1102 | | APZBucket::APZBucket() |
1103 | 0 | { |
1104 | 0 | // Safe to pass a null context if we pass a null value |
1105 | 0 | Init(nullptr, JS::NullHandleValue); |
1106 | 0 | } |
1107 | | |
1108 | | |
1109 | | |
1110 | | bool |
1111 | | APZBucket::InitIds(JSContext* cx, APZBucketAtoms* atomsCache) |
1112 | 0 | { |
1113 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1114 | 0 |
|
1115 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1116 | 0 | // uninitialized. |
1117 | 0 | if (!atomsCache->sequenceNumber_id.init(cx, "sequenceNumber") || |
1118 | 0 | !atomsCache->scrollFrames_id.init(cx, "scrollFrames")) { |
1119 | 0 | return false; |
1120 | 0 | } |
1121 | 0 | return true; |
1122 | 0 | } |
1123 | | |
1124 | | bool |
1125 | | APZBucket::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1126 | 0 | { |
1127 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1128 | 0 | // Since in that case we will not have to do any property gets |
1129 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1130 | 0 | // checkers by static analysis tools |
1131 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1132 | 0 | APZBucketAtoms* atomsCache = nullptr; |
1133 | 0 | if (cx) { |
1134 | 0 | atomsCache = GetAtomCache<APZBucketAtoms>(cx); |
1135 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1136 | 0 | return false; |
1137 | 0 | } |
1138 | 0 | } |
1139 | 0 | |
1140 | 0 | if (!IsConvertibleToDictionary(val)) { |
1141 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1142 | 0 | } |
1143 | 0 | |
1144 | 0 | bool isNull = val.isNullOrUndefined(); |
1145 | 0 | // We only need these if !isNull, in which case we have |cx|. |
1146 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
1147 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
1148 | 0 | if (!isNull) { |
1149 | 0 | MOZ_ASSERT(cx); |
1150 | 0 | object.emplace(cx, &val.toObject()); |
1151 | 0 | temp.emplace(cx); |
1152 | 0 | } |
1153 | 0 | if (!isNull) { |
1154 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->scrollFrames_id, temp.ptr())) { |
1155 | 0 | return false; |
1156 | 0 | } |
1157 | 0 | } |
1158 | 0 | if (!isNull && !temp->isUndefined()) { |
1159 | 0 | mScrollFrames.Construct(); |
1160 | 0 | if (temp.ref().isObject()) { |
1161 | 0 | JS::ForOfIterator iter(cx); |
1162 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
1163 | 0 | return false; |
1164 | 0 | } |
1165 | 0 | if (!iter.valueIsIterable()) { |
1166 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'scrollFrames' member of APZBucket"); |
1167 | 0 | return false; |
1168 | 0 | } |
1169 | 0 | Sequence<ScrollFrameData> &arr = (mScrollFrames.Value()); |
1170 | 0 | JS::Rooted<JS::Value> temp(cx); |
1171 | 0 | while (true) { |
1172 | 0 | bool done; |
1173 | 0 | if (!iter.next(&temp, &done)) { |
1174 | 0 | return false; |
1175 | 0 | } |
1176 | 0 | if (done) { |
1177 | 0 | break; |
1178 | 0 | } |
1179 | 0 | ScrollFrameData* slotPtr = arr.AppendElement(mozilla::fallible); |
1180 | 0 | if (!slotPtr) { |
1181 | 0 | JS_ReportOutOfMemory(cx); |
1182 | 0 | return false; |
1183 | 0 | } |
1184 | 0 | ScrollFrameData& slot = *slotPtr; |
1185 | 0 | if (!slot.Init(cx, temp, "Element of 'scrollFrames' member of APZBucket", passedToJSImpl)) { |
1186 | 0 | return false; |
1187 | 0 | } |
1188 | 0 | } |
1189 | 0 | } else { |
1190 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'scrollFrames' member of APZBucket"); |
1191 | 0 | return false; |
1192 | 0 | } |
1193 | 0 | mIsAnyMemberPresent = true; |
1194 | 0 | } |
1195 | 0 |
|
1196 | 0 | if (!isNull) { |
1197 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->sequenceNumber_id, temp.ptr())) { |
1198 | 0 | return false; |
1199 | 0 | } |
1200 | 0 | } |
1201 | 0 | if (!isNull && !temp->isUndefined()) { |
1202 | 0 | mSequenceNumber.Construct(); |
1203 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mSequenceNumber.Value()))) { |
1204 | 0 | return false; |
1205 | 0 | } |
1206 | 0 | mIsAnyMemberPresent = true; |
1207 | 0 | } |
1208 | 0 | return true; |
1209 | 0 | } |
1210 | | |
1211 | | bool |
1212 | | APZBucket::Init(const nsAString& aJSON) |
1213 | 0 | { |
1214 | 0 | AutoJSAPI jsapi; |
1215 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
1216 | 0 | if (!cleanGlobal) { |
1217 | 0 | return false; |
1218 | 0 | } |
1219 | 0 | if (!jsapi.Init(cleanGlobal)) { |
1220 | 0 | return false; |
1221 | 0 | } |
1222 | 0 | JSContext* cx = jsapi.cx(); |
1223 | 0 | JS::Rooted<JS::Value> json(cx); |
1224 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
1225 | 0 | NS_ENSURE_TRUE(ok, false); |
1226 | 0 | return Init(cx, json); |
1227 | 0 | } |
1228 | | |
1229 | | bool |
1230 | | APZBucket::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
1231 | 0 | { |
1232 | 0 | APZBucketAtoms* atomsCache = GetAtomCache<APZBucketAtoms>(cx); |
1233 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1234 | 0 | return false; |
1235 | 0 | } |
1236 | 0 | |
1237 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
1238 | 0 | if (!obj) { |
1239 | 0 | return false; |
1240 | 0 | } |
1241 | 0 | rval.set(JS::ObjectValue(*obj)); |
1242 | 0 |
|
1243 | 0 | if (mScrollFrames.WasPassed()) { |
1244 | 0 | do { |
1245 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1246 | 0 | JS::Rooted<JS::Value> temp(cx); |
1247 | 0 | Sequence<ScrollFrameData> const & currentValue = mScrollFrames.InternalValue(); |
1248 | 0 |
|
1249 | 0 | uint32_t length = currentValue.Length(); |
1250 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
1251 | 0 | if (!returnArray) { |
1252 | 0 | return false; |
1253 | 0 | } |
1254 | 0 | // Scope for 'tmp' |
1255 | 0 | { |
1256 | 0 | JS::Rooted<JS::Value> tmp(cx); |
1257 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
1258 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
1259 | 0 | // are different ways to succeed at wrapping the object. |
1260 | 0 | do { |
1261 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
1262 | 0 | return false; |
1263 | 0 | } |
1264 | 0 | break; |
1265 | 0 | } while (false); |
1266 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
1267 | 0 | JSPROP_ENUMERATE)) { |
1268 | 0 | return false; |
1269 | 0 | } |
1270 | 0 | } |
1271 | 0 | } |
1272 | 0 | temp.setObject(*returnArray); |
1273 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->scrollFrames_id, temp, JSPROP_ENUMERATE)) { |
1274 | 0 | return false; |
1275 | 0 | } |
1276 | 0 | break; |
1277 | 0 | } while(false); |
1278 | 0 | } |
1279 | 0 |
|
1280 | 0 | if (mSequenceNumber.WasPassed()) { |
1281 | 0 | do { |
1282 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1283 | 0 | JS::Rooted<JS::Value> temp(cx); |
1284 | 0 | uint32_t const & currentValue = mSequenceNumber.InternalValue(); |
1285 | 0 | temp.setNumber(currentValue); |
1286 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->sequenceNumber_id, temp, JSPROP_ENUMERATE)) { |
1287 | 0 | return false; |
1288 | 0 | } |
1289 | 0 | break; |
1290 | 0 | } while(false); |
1291 | 0 | } |
1292 | 0 |
|
1293 | 0 | return true; |
1294 | 0 | } |
1295 | | |
1296 | | bool |
1297 | | APZBucket::ToJSON(nsAString& aJSON) const |
1298 | 0 | { |
1299 | 0 | AutoJSAPI jsapi; |
1300 | 0 | jsapi.Init(); |
1301 | 0 | JSContext *cx = jsapi.cx(); |
1302 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
1303 | 0 | // because we'll only be creating objects, in ways that have no |
1304 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
1305 | 0 | // which likewise guarantees no side-effects for the sorts of |
1306 | 0 | // things we will pass it. |
1307 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
1308 | 0 | JS::Rooted<JS::Value> val(cx); |
1309 | 0 | if (!ToObjectInternal(cx, &val)) { |
1310 | 0 | return false; |
1311 | 0 | } |
1312 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
1313 | 0 | return StringifyToJSON(cx, obj, aJSON); |
1314 | 0 | } |
1315 | | |
1316 | | void |
1317 | | APZBucket::TraceDictionary(JSTracer* trc) |
1318 | 0 | { |
1319 | 0 | } |
1320 | | |
1321 | | APZBucket& |
1322 | | APZBucket::operator=(const APZBucket& aOther) |
1323 | 0 | { |
1324 | 0 | DictionaryBase::operator=(aOther); |
1325 | 0 | mScrollFrames.Reset(); |
1326 | 0 | if (aOther.mScrollFrames.WasPassed()) { |
1327 | 0 | mScrollFrames.Construct(aOther.mScrollFrames.Value()); |
1328 | 0 | } |
1329 | 0 | mSequenceNumber.Reset(); |
1330 | 0 | if (aOther.mSequenceNumber.WasPassed()) { |
1331 | 0 | mSequenceNumber.Construct(aOther.mSequenceNumber.Value()); |
1332 | 0 | } |
1333 | 0 | return *this; |
1334 | 0 | } |
1335 | | |
1336 | | namespace binding_detail { |
1337 | | } // namespace binding_detail |
1338 | | |
1339 | | |
1340 | | |
1341 | | APZTestData::APZTestData() |
1342 | 0 | { |
1343 | 0 | // Safe to pass a null context if we pass a null value |
1344 | 0 | Init(nullptr, JS::NullHandleValue); |
1345 | 0 | } |
1346 | | |
1347 | | |
1348 | | |
1349 | | bool |
1350 | | APZTestData::InitIds(JSContext* cx, APZTestDataAtoms* atomsCache) |
1351 | 0 | { |
1352 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1353 | 0 |
|
1354 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1355 | 0 | // uninitialized. |
1356 | 0 | if (!atomsCache->repaintRequests_id.init(cx, "repaintRequests") || |
1357 | 0 | !atomsCache->paints_id.init(cx, "paints") || |
1358 | 0 | !atomsCache->hitResults_id.init(cx, "hitResults")) { |
1359 | 0 | return false; |
1360 | 0 | } |
1361 | 0 | return true; |
1362 | 0 | } |
1363 | | |
1364 | | bool |
1365 | | APZTestData::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1366 | 0 | { |
1367 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1368 | 0 | // Since in that case we will not have to do any property gets |
1369 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1370 | 0 | // checkers by static analysis tools |
1371 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1372 | 0 | APZTestDataAtoms* atomsCache = nullptr; |
1373 | 0 | if (cx) { |
1374 | 0 | atomsCache = GetAtomCache<APZTestDataAtoms>(cx); |
1375 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1376 | 0 | return false; |
1377 | 0 | } |
1378 | 0 | } |
1379 | 0 | |
1380 | 0 | if (!IsConvertibleToDictionary(val)) { |
1381 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1382 | 0 | } |
1383 | 0 | |
1384 | 0 | bool isNull = val.isNullOrUndefined(); |
1385 | 0 | // We only need these if !isNull, in which case we have |cx|. |
1386 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
1387 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
1388 | 0 | if (!isNull) { |
1389 | 0 | MOZ_ASSERT(cx); |
1390 | 0 | object.emplace(cx, &val.toObject()); |
1391 | 0 | temp.emplace(cx); |
1392 | 0 | } |
1393 | 0 | if (!isNull) { |
1394 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->hitResults_id, temp.ptr())) { |
1395 | 0 | return false; |
1396 | 0 | } |
1397 | 0 | } |
1398 | 0 | if (!isNull && !temp->isUndefined()) { |
1399 | 0 | mHitResults.Construct(); |
1400 | 0 | if (temp.ref().isObject()) { |
1401 | 0 | JS::ForOfIterator iter(cx); |
1402 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
1403 | 0 | return false; |
1404 | 0 | } |
1405 | 0 | if (!iter.valueIsIterable()) { |
1406 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'hitResults' member of APZTestData"); |
1407 | 0 | return false; |
1408 | 0 | } |
1409 | 0 | Sequence<APZHitResult> &arr = (mHitResults.Value()); |
1410 | 0 | JS::Rooted<JS::Value> temp(cx); |
1411 | 0 | while (true) { |
1412 | 0 | bool done; |
1413 | 0 | if (!iter.next(&temp, &done)) { |
1414 | 0 | return false; |
1415 | 0 | } |
1416 | 0 | if (done) { |
1417 | 0 | break; |
1418 | 0 | } |
1419 | 0 | APZHitResult* slotPtr = arr.AppendElement(mozilla::fallible); |
1420 | 0 | if (!slotPtr) { |
1421 | 0 | JS_ReportOutOfMemory(cx); |
1422 | 0 | return false; |
1423 | 0 | } |
1424 | 0 | APZHitResult& slot = *slotPtr; |
1425 | 0 | if (!slot.Init(cx, temp, "Element of 'hitResults' member of APZTestData", passedToJSImpl)) { |
1426 | 0 | return false; |
1427 | 0 | } |
1428 | 0 | } |
1429 | 0 | } else { |
1430 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'hitResults' member of APZTestData"); |
1431 | 0 | return false; |
1432 | 0 | } |
1433 | 0 | mIsAnyMemberPresent = true; |
1434 | 0 | } |
1435 | 0 |
|
1436 | 0 | if (!isNull) { |
1437 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->paints_id, temp.ptr())) { |
1438 | 0 | return false; |
1439 | 0 | } |
1440 | 0 | } |
1441 | 0 | if (!isNull && !temp->isUndefined()) { |
1442 | 0 | mPaints.Construct(); |
1443 | 0 | if (temp.ref().isObject()) { |
1444 | 0 | JS::ForOfIterator iter(cx); |
1445 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
1446 | 0 | return false; |
1447 | 0 | } |
1448 | 0 | if (!iter.valueIsIterable()) { |
1449 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'paints' member of APZTestData"); |
1450 | 0 | return false; |
1451 | 0 | } |
1452 | 0 | Sequence<APZBucket> &arr = (mPaints.Value()); |
1453 | 0 | JS::Rooted<JS::Value> temp(cx); |
1454 | 0 | while (true) { |
1455 | 0 | bool done; |
1456 | 0 | if (!iter.next(&temp, &done)) { |
1457 | 0 | return false; |
1458 | 0 | } |
1459 | 0 | if (done) { |
1460 | 0 | break; |
1461 | 0 | } |
1462 | 0 | APZBucket* slotPtr = arr.AppendElement(mozilla::fallible); |
1463 | 0 | if (!slotPtr) { |
1464 | 0 | JS_ReportOutOfMemory(cx); |
1465 | 0 | return false; |
1466 | 0 | } |
1467 | 0 | APZBucket& slot = *slotPtr; |
1468 | 0 | if (!slot.Init(cx, temp, "Element of 'paints' member of APZTestData", passedToJSImpl)) { |
1469 | 0 | return false; |
1470 | 0 | } |
1471 | 0 | } |
1472 | 0 | } else { |
1473 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'paints' member of APZTestData"); |
1474 | 0 | return false; |
1475 | 0 | } |
1476 | 0 | mIsAnyMemberPresent = true; |
1477 | 0 | } |
1478 | 0 |
|
1479 | 0 | if (!isNull) { |
1480 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->repaintRequests_id, temp.ptr())) { |
1481 | 0 | return false; |
1482 | 0 | } |
1483 | 0 | } |
1484 | 0 | if (!isNull && !temp->isUndefined()) { |
1485 | 0 | mRepaintRequests.Construct(); |
1486 | 0 | if (temp.ref().isObject()) { |
1487 | 0 | JS::ForOfIterator iter(cx); |
1488 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
1489 | 0 | return false; |
1490 | 0 | } |
1491 | 0 | if (!iter.valueIsIterable()) { |
1492 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'repaintRequests' member of APZTestData"); |
1493 | 0 | return false; |
1494 | 0 | } |
1495 | 0 | Sequence<APZBucket> &arr = (mRepaintRequests.Value()); |
1496 | 0 | JS::Rooted<JS::Value> temp(cx); |
1497 | 0 | while (true) { |
1498 | 0 | bool done; |
1499 | 0 | if (!iter.next(&temp, &done)) { |
1500 | 0 | return false; |
1501 | 0 | } |
1502 | 0 | if (done) { |
1503 | 0 | break; |
1504 | 0 | } |
1505 | 0 | APZBucket* slotPtr = arr.AppendElement(mozilla::fallible); |
1506 | 0 | if (!slotPtr) { |
1507 | 0 | JS_ReportOutOfMemory(cx); |
1508 | 0 | return false; |
1509 | 0 | } |
1510 | 0 | APZBucket& slot = *slotPtr; |
1511 | 0 | if (!slot.Init(cx, temp, "Element of 'repaintRequests' member of APZTestData", passedToJSImpl)) { |
1512 | 0 | return false; |
1513 | 0 | } |
1514 | 0 | } |
1515 | 0 | } else { |
1516 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'repaintRequests' member of APZTestData"); |
1517 | 0 | return false; |
1518 | 0 | } |
1519 | 0 | mIsAnyMemberPresent = true; |
1520 | 0 | } |
1521 | 0 | return true; |
1522 | 0 | } |
1523 | | |
1524 | | bool |
1525 | | APZTestData::Init(const nsAString& aJSON) |
1526 | 0 | { |
1527 | 0 | AutoJSAPI jsapi; |
1528 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
1529 | 0 | if (!cleanGlobal) { |
1530 | 0 | return false; |
1531 | 0 | } |
1532 | 0 | if (!jsapi.Init(cleanGlobal)) { |
1533 | 0 | return false; |
1534 | 0 | } |
1535 | 0 | JSContext* cx = jsapi.cx(); |
1536 | 0 | JS::Rooted<JS::Value> json(cx); |
1537 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
1538 | 0 | NS_ENSURE_TRUE(ok, false); |
1539 | 0 | return Init(cx, json); |
1540 | 0 | } |
1541 | | |
1542 | | bool |
1543 | | APZTestData::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
1544 | 0 | { |
1545 | 0 | APZTestDataAtoms* atomsCache = GetAtomCache<APZTestDataAtoms>(cx); |
1546 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1547 | 0 | return false; |
1548 | 0 | } |
1549 | 0 | |
1550 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
1551 | 0 | if (!obj) { |
1552 | 0 | return false; |
1553 | 0 | } |
1554 | 0 | rval.set(JS::ObjectValue(*obj)); |
1555 | 0 |
|
1556 | 0 | if (mHitResults.WasPassed()) { |
1557 | 0 | do { |
1558 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1559 | 0 | JS::Rooted<JS::Value> temp(cx); |
1560 | 0 | Sequence<APZHitResult> const & currentValue = mHitResults.InternalValue(); |
1561 | 0 |
|
1562 | 0 | uint32_t length = currentValue.Length(); |
1563 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
1564 | 0 | if (!returnArray) { |
1565 | 0 | return false; |
1566 | 0 | } |
1567 | 0 | // Scope for 'tmp' |
1568 | 0 | { |
1569 | 0 | JS::Rooted<JS::Value> tmp(cx); |
1570 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
1571 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
1572 | 0 | // are different ways to succeed at wrapping the object. |
1573 | 0 | do { |
1574 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
1575 | 0 | return false; |
1576 | 0 | } |
1577 | 0 | break; |
1578 | 0 | } while (false); |
1579 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
1580 | 0 | JSPROP_ENUMERATE)) { |
1581 | 0 | return false; |
1582 | 0 | } |
1583 | 0 | } |
1584 | 0 | } |
1585 | 0 | temp.setObject(*returnArray); |
1586 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->hitResults_id, temp, JSPROP_ENUMERATE)) { |
1587 | 0 | return false; |
1588 | 0 | } |
1589 | 0 | break; |
1590 | 0 | } while(false); |
1591 | 0 | } |
1592 | 0 |
|
1593 | 0 | if (mPaints.WasPassed()) { |
1594 | 0 | do { |
1595 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1596 | 0 | JS::Rooted<JS::Value> temp(cx); |
1597 | 0 | Sequence<APZBucket> const & currentValue = mPaints.InternalValue(); |
1598 | 0 |
|
1599 | 0 | uint32_t length = currentValue.Length(); |
1600 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
1601 | 0 | if (!returnArray) { |
1602 | 0 | return false; |
1603 | 0 | } |
1604 | 0 | // Scope for 'tmp' |
1605 | 0 | { |
1606 | 0 | JS::Rooted<JS::Value> tmp(cx); |
1607 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
1608 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
1609 | 0 | // are different ways to succeed at wrapping the object. |
1610 | 0 | do { |
1611 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
1612 | 0 | return false; |
1613 | 0 | } |
1614 | 0 | break; |
1615 | 0 | } while (false); |
1616 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
1617 | 0 | JSPROP_ENUMERATE)) { |
1618 | 0 | return false; |
1619 | 0 | } |
1620 | 0 | } |
1621 | 0 | } |
1622 | 0 | temp.setObject(*returnArray); |
1623 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->paints_id, temp, JSPROP_ENUMERATE)) { |
1624 | 0 | return false; |
1625 | 0 | } |
1626 | 0 | break; |
1627 | 0 | } while(false); |
1628 | 0 | } |
1629 | 0 |
|
1630 | 0 | if (mRepaintRequests.WasPassed()) { |
1631 | 0 | do { |
1632 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1633 | 0 | JS::Rooted<JS::Value> temp(cx); |
1634 | 0 | Sequence<APZBucket> const & currentValue = mRepaintRequests.InternalValue(); |
1635 | 0 |
|
1636 | 0 | uint32_t length = currentValue.Length(); |
1637 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
1638 | 0 | if (!returnArray) { |
1639 | 0 | return false; |
1640 | 0 | } |
1641 | 0 | // Scope for 'tmp' |
1642 | 0 | { |
1643 | 0 | JS::Rooted<JS::Value> tmp(cx); |
1644 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
1645 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
1646 | 0 | // are different ways to succeed at wrapping the object. |
1647 | 0 | do { |
1648 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
1649 | 0 | return false; |
1650 | 0 | } |
1651 | 0 | break; |
1652 | 0 | } while (false); |
1653 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
1654 | 0 | JSPROP_ENUMERATE)) { |
1655 | 0 | return false; |
1656 | 0 | } |
1657 | 0 | } |
1658 | 0 | } |
1659 | 0 | temp.setObject(*returnArray); |
1660 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->repaintRequests_id, temp, JSPROP_ENUMERATE)) { |
1661 | 0 | return false; |
1662 | 0 | } |
1663 | 0 | break; |
1664 | 0 | } while(false); |
1665 | 0 | } |
1666 | 0 |
|
1667 | 0 | return true; |
1668 | 0 | } |
1669 | | |
1670 | | bool |
1671 | | APZTestData::ToJSON(nsAString& aJSON) const |
1672 | 0 | { |
1673 | 0 | AutoJSAPI jsapi; |
1674 | 0 | jsapi.Init(); |
1675 | 0 | JSContext *cx = jsapi.cx(); |
1676 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
1677 | 0 | // because we'll only be creating objects, in ways that have no |
1678 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
1679 | 0 | // which likewise guarantees no side-effects for the sorts of |
1680 | 0 | // things we will pass it. |
1681 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
1682 | 0 | JS::Rooted<JS::Value> val(cx); |
1683 | 0 | if (!ToObjectInternal(cx, &val)) { |
1684 | 0 | return false; |
1685 | 0 | } |
1686 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
1687 | 0 | return StringifyToJSON(cx, obj, aJSON); |
1688 | 0 | } |
1689 | | |
1690 | | void |
1691 | | APZTestData::TraceDictionary(JSTracer* trc) |
1692 | 0 | { |
1693 | 0 | } |
1694 | | |
1695 | | APZTestData& |
1696 | | APZTestData::operator=(const APZTestData& aOther) |
1697 | 0 | { |
1698 | 0 | DictionaryBase::operator=(aOther); |
1699 | 0 | mHitResults.Reset(); |
1700 | 0 | if (aOther.mHitResults.WasPassed()) { |
1701 | 0 | mHitResults.Construct(aOther.mHitResults.Value()); |
1702 | 0 | } |
1703 | 0 | mPaints.Reset(); |
1704 | 0 | if (aOther.mPaints.WasPassed()) { |
1705 | 0 | mPaints.Construct(aOther.mPaints.Value()); |
1706 | 0 | } |
1707 | 0 | mRepaintRequests.Reset(); |
1708 | 0 | if (aOther.mRepaintRequests.WasPassed()) { |
1709 | 0 | mRepaintRequests.Construct(aOther.mRepaintRequests.Value()); |
1710 | 0 | } |
1711 | 0 | return *this; |
1712 | 0 | } |
1713 | | |
1714 | | namespace binding_detail { |
1715 | | } // namespace binding_detail |
1716 | | |
1717 | | |
1718 | | namespace APZHitResultFlags_Binding { |
1719 | | |
1720 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1721 | | #if defined(__clang__) |
1722 | | #pragma clang diagnostic push |
1723 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1724 | | #endif |
1725 | | static const ConstantSpec sConstants_specs[] = { |
1726 | | { "INVISIBLE", JS::Int32Value(0) }, |
1727 | | { "VISIBLE", JS::Int32Value(1) }, |
1728 | | { "DISPATCH_TO_CONTENT", JS::Int32Value(2) }, |
1729 | | { "PAN_X_DISABLED", JS::Int32Value(4) }, |
1730 | | { "PAN_Y_DISABLED", JS::Int32Value(8) }, |
1731 | | { "PINCH_ZOOM_DISABLED", JS::Int32Value(16) }, |
1732 | | { "DOUBLE_TAP_ZOOM_DISABLED", JS::Int32Value(32) }, |
1733 | | { "SCROLLBAR", JS::Int32Value(64) }, |
1734 | | { "SCROLLBAR_THUMB", JS::Int32Value(128) }, |
1735 | | { "SCROLLBAR_VERTICAL", JS::Int32Value(256) }, |
1736 | | { 0, JS::UndefinedValue() } |
1737 | | }; |
1738 | | #if defined(__clang__) |
1739 | | #pragma clang diagnostic pop |
1740 | | #endif |
1741 | | |
1742 | | |
1743 | | static const Prefable<const ConstantSpec> sConstants[] = { |
1744 | | { nullptr, &sConstants_specs[0] }, |
1745 | | { nullptr, nullptr } |
1746 | | }; |
1747 | | |
1748 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1749 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1750 | | static_assert(10 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1751 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1752 | | |
1753 | | |
1754 | | static uint16_t sNativeProperties_sortedPropertyIndices[10]; |
1755 | | static PropertyInfo sNativeProperties_propertyInfos[10]; |
1756 | | |
1757 | | static const NativePropertiesN<1> sNativeProperties = { |
1758 | | false, 0, |
1759 | | false, 0, |
1760 | | false, 0, |
1761 | | false, 0, |
1762 | | false, 0, |
1763 | | false, 0, |
1764 | | true, 0 /* sConstants */, |
1765 | | -1, |
1766 | | 10, |
1767 | | sNativeProperties_sortedPropertyIndices, |
1768 | | { |
1769 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
1770 | | } |
1771 | | }; |
1772 | | static_assert(10 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
1773 | | "We have a property info count that is oversized"); |
1774 | | |
1775 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
1776 | | { |
1777 | | "Object", |
1778 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
1779 | | JS_NULL_CLASS_OPS, |
1780 | | JS_NULL_CLASS_SPEC, |
1781 | | JS_NULL_CLASS_EXT, |
1782 | | JS_NULL_OBJECT_OPS |
1783 | | }, |
1784 | | eInterface, |
1785 | | false, |
1786 | | prototypes::id::_ID_Count, |
1787 | | 0, |
1788 | | sNativePropertyHooks, |
1789 | | "[object Object]", |
1790 | | JS::GetRealmObjectPrototype |
1791 | | }; |
1792 | | |
1793 | | bool |
1794 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
1795 | 0 | { |
1796 | 0 | static bool sPrefValue; |
1797 | 0 | static bool sPrefCacheSetUp = false; |
1798 | 0 | if (!sPrefCacheSetUp) { |
1799 | 0 | sPrefCacheSetUp = true; |
1800 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "apz.test.logging_enabled"); |
1801 | 0 | } |
1802 | 0 |
|
1803 | 0 | return sPrefValue; |
1804 | 0 | } |
1805 | | |
1806 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1807 | | nullptr, |
1808 | | nullptr, |
1809 | | nullptr, |
1810 | | { sNativeProperties.Upcast(), nullptr }, |
1811 | | prototypes::id::_ID_Count, |
1812 | | constructors::id::APZHitResultFlags, |
1813 | | nullptr, |
1814 | | &DefaultXrayExpandoObjectClass |
1815 | | } }; |
1816 | | |
1817 | | void |
1818 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1819 | 0 | { |
1820 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
1821 | 0 | if (!constructorProto) { |
1822 | 0 | return; |
1823 | 0 | } |
1824 | 0 | |
1825 | 0 | static bool sIdsInited = false; |
1826 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1827 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1828 | 0 | return; |
1829 | 0 | } |
1830 | 0 | sIdsInited = true; |
1831 | 0 | } |
1832 | 0 |
|
1833 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
1834 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::APZHitResultFlags); |
1835 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
1836 | 0 | nullptr, protoCache, |
1837 | 0 | nullptr, |
1838 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1839 | 0 | interfaceCache, |
1840 | 0 | sNativeProperties.Upcast(), |
1841 | 0 | nullptr, |
1842 | 0 | "APZHitResultFlags", aDefineOnGlobal, |
1843 | 0 | nullptr, |
1844 | 0 | false); |
1845 | 0 | } |
1846 | | |
1847 | | JSObject* |
1848 | | GetConstructorObject(JSContext* aCx) |
1849 | 0 | { |
1850 | 0 | return GetConstructorObjectHandle(aCx); |
1851 | 0 | } |
1852 | | |
1853 | | } // namespace APZHitResultFlags_Binding |
1854 | | |
1855 | | |
1856 | | |
1857 | | } // namespace dom |
1858 | | } // namespace mozilla |