/work/obj-fuzz/dom/bindings/ProfileTimelineMarkerBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM ProfileTimelineMarker.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "ProfileTimelineMarkerBinding.h" |
5 | | #include "jsapi.h" |
6 | | #include "mozilla/FloatingPoint.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/dom/BindingUtils.h" |
9 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
10 | | #include "mozilla/dom/PrimitiveConversions.h" |
11 | | #include "mozilla/dom/ScriptSettings.h" |
12 | | #include "mozilla/dom/SimpleGlobalObject.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
18 | | using namespace mozilla::dom::binding_detail; |
19 | | |
20 | | |
21 | | namespace ProfileTimelineMessagePortOperationTypeValues { |
22 | | extern const EnumEntry strings[3] = { |
23 | | {"serializeData", 13}, |
24 | | {"deserializeData", 15}, |
25 | | { nullptr, 0 } |
26 | | }; |
27 | | } // namespace ProfileTimelineMessagePortOperationTypeValues |
28 | | |
29 | | bool |
30 | | ToJSValue(JSContext* aCx, ProfileTimelineMessagePortOperationType aArgument, JS::MutableHandle<JS::Value> aValue) |
31 | 0 | { |
32 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(ProfileTimelineMessagePortOperationTypeValues::strings)); |
33 | 0 | JSString* resultStr = |
34 | 0 | JS_NewStringCopyN(aCx, ProfileTimelineMessagePortOperationTypeValues::strings[uint32_t(aArgument)].value, |
35 | 0 | ProfileTimelineMessagePortOperationTypeValues::strings[uint32_t(aArgument)].length); |
36 | 0 | if (!resultStr) { |
37 | 0 | return false; |
38 | 0 | } |
39 | 0 | aValue.setString(resultStr); |
40 | 0 | return true; |
41 | 0 | } |
42 | | |
43 | | |
44 | | namespace ProfileTimelineWorkerOperationTypeValues { |
45 | | extern const EnumEntry strings[5] = { |
46 | | {"serializeDataOffMainThread", 26}, |
47 | | {"serializeDataOnMainThread", 25}, |
48 | | {"deserializeDataOffMainThread", 28}, |
49 | | {"deserializeDataOnMainThread", 27}, |
50 | | { nullptr, 0 } |
51 | | }; |
52 | | } // namespace ProfileTimelineWorkerOperationTypeValues |
53 | | |
54 | | bool |
55 | | ToJSValue(JSContext* aCx, ProfileTimelineWorkerOperationType aArgument, JS::MutableHandle<JS::Value> aValue) |
56 | 0 | { |
57 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(ProfileTimelineWorkerOperationTypeValues::strings)); |
58 | 0 | JSString* resultStr = |
59 | 0 | JS_NewStringCopyN(aCx, ProfileTimelineWorkerOperationTypeValues::strings[uint32_t(aArgument)].value, |
60 | 0 | ProfileTimelineWorkerOperationTypeValues::strings[uint32_t(aArgument)].length); |
61 | 0 | if (!resultStr) { |
62 | 0 | return false; |
63 | 0 | } |
64 | 0 | aValue.setString(resultStr); |
65 | 0 | return true; |
66 | 0 | } |
67 | | |
68 | | |
69 | | |
70 | | ProfileTimelineLayerRect::ProfileTimelineLayerRect() |
71 | 0 | { |
72 | 0 | // Safe to pass a null context if we pass a null value |
73 | 0 | Init(nullptr, JS::NullHandleValue); |
74 | 0 | } |
75 | | |
76 | | |
77 | | |
78 | | bool |
79 | | ProfileTimelineLayerRect::InitIds(JSContext* cx, ProfileTimelineLayerRectAtoms* atomsCache) |
80 | 0 | { |
81 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
82 | 0 |
|
83 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
84 | 0 | // uninitialized. |
85 | 0 | if (!atomsCache->y_id.init(cx, "y") || |
86 | 0 | !atomsCache->x_id.init(cx, "x") || |
87 | 0 | !atomsCache->width_id.init(cx, "width") || |
88 | 0 | !atomsCache->height_id.init(cx, "height")) { |
89 | 0 | return false; |
90 | 0 | } |
91 | 0 | return true; |
92 | 0 | } |
93 | | |
94 | | bool |
95 | | ProfileTimelineLayerRect::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
96 | 0 | { |
97 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
98 | 0 | // Since in that case we will not have to do any property gets |
99 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
100 | 0 | // checkers by static analysis tools |
101 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
102 | 0 | ProfileTimelineLayerRectAtoms* atomsCache = nullptr; |
103 | 0 | if (cx) { |
104 | 0 | atomsCache = GetAtomCache<ProfileTimelineLayerRectAtoms>(cx); |
105 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
106 | 0 | return false; |
107 | 0 | } |
108 | 0 | } |
109 | 0 | |
110 | 0 | if (!IsConvertibleToDictionary(val)) { |
111 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
112 | 0 | } |
113 | 0 | |
114 | 0 | bool isNull = val.isNullOrUndefined(); |
115 | 0 | // We only need these if !isNull, in which case we have |cx|. |
116 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
117 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
118 | 0 | if (!isNull) { |
119 | 0 | MOZ_ASSERT(cx); |
120 | 0 | object.emplace(cx, &val.toObject()); |
121 | 0 | temp.emplace(cx); |
122 | 0 | } |
123 | 0 | if (!isNull) { |
124 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->height_id, temp.ptr())) { |
125 | 0 | return false; |
126 | 0 | } |
127 | 0 | } |
128 | 0 | if (!isNull && !temp->isUndefined()) { |
129 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mHeight)) { |
130 | 0 | return false; |
131 | 0 | } |
132 | 0 | } else { |
133 | 0 | mHeight = 0; |
134 | 0 | } |
135 | 0 | mIsAnyMemberPresent = true; |
136 | 0 |
|
137 | 0 | if (!isNull) { |
138 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->width_id, temp.ptr())) { |
139 | 0 | return false; |
140 | 0 | } |
141 | 0 | } |
142 | 0 | if (!isNull && !temp->isUndefined()) { |
143 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mWidth)) { |
144 | 0 | return false; |
145 | 0 | } |
146 | 0 | } else { |
147 | 0 | mWidth = 0; |
148 | 0 | } |
149 | 0 | mIsAnyMemberPresent = true; |
150 | 0 |
|
151 | 0 | if (!isNull) { |
152 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->x_id, temp.ptr())) { |
153 | 0 | return false; |
154 | 0 | } |
155 | 0 | } |
156 | 0 | if (!isNull && !temp->isUndefined()) { |
157 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mX)) { |
158 | 0 | return false; |
159 | 0 | } |
160 | 0 | } else { |
161 | 0 | mX = 0; |
162 | 0 | } |
163 | 0 | mIsAnyMemberPresent = true; |
164 | 0 |
|
165 | 0 | if (!isNull) { |
166 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->y_id, temp.ptr())) { |
167 | 0 | return false; |
168 | 0 | } |
169 | 0 | } |
170 | 0 | if (!isNull && !temp->isUndefined()) { |
171 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mY)) { |
172 | 0 | return false; |
173 | 0 | } |
174 | 0 | } else { |
175 | 0 | mY = 0; |
176 | 0 | } |
177 | 0 | mIsAnyMemberPresent = true; |
178 | 0 | return true; |
179 | 0 | } |
180 | | |
181 | | bool |
182 | | ProfileTimelineLayerRect::Init(const nsAString& aJSON) |
183 | 0 | { |
184 | 0 | AutoJSAPI jsapi; |
185 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
186 | 0 | if (!cleanGlobal) { |
187 | 0 | return false; |
188 | 0 | } |
189 | 0 | if (!jsapi.Init(cleanGlobal)) { |
190 | 0 | return false; |
191 | 0 | } |
192 | 0 | JSContext* cx = jsapi.cx(); |
193 | 0 | JS::Rooted<JS::Value> json(cx); |
194 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
195 | 0 | NS_ENSURE_TRUE(ok, false); |
196 | 0 | return Init(cx, json); |
197 | 0 | } |
198 | | |
199 | | bool |
200 | | ProfileTimelineLayerRect::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
201 | 0 | { |
202 | 0 | ProfileTimelineLayerRectAtoms* atomsCache = GetAtomCache<ProfileTimelineLayerRectAtoms>(cx); |
203 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
204 | 0 | return false; |
205 | 0 | } |
206 | 0 | |
207 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
208 | 0 | if (!obj) { |
209 | 0 | return false; |
210 | 0 | } |
211 | 0 | rval.set(JS::ObjectValue(*obj)); |
212 | 0 |
|
213 | 0 | do { |
214 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
215 | 0 | JS::Rooted<JS::Value> temp(cx); |
216 | 0 | int32_t const & currentValue = mHeight; |
217 | 0 | temp.setInt32(int32_t(currentValue)); |
218 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->height_id, temp, JSPROP_ENUMERATE)) { |
219 | 0 | return false; |
220 | 0 | } |
221 | 0 | break; |
222 | 0 | } while(false); |
223 | 0 |
|
224 | 0 | do { |
225 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
226 | 0 | JS::Rooted<JS::Value> temp(cx); |
227 | 0 | int32_t const & currentValue = mWidth; |
228 | 0 | temp.setInt32(int32_t(currentValue)); |
229 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->width_id, temp, JSPROP_ENUMERATE)) { |
230 | 0 | return false; |
231 | 0 | } |
232 | 0 | break; |
233 | 0 | } while(false); |
234 | 0 |
|
235 | 0 | do { |
236 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
237 | 0 | JS::Rooted<JS::Value> temp(cx); |
238 | 0 | int32_t const & currentValue = mX; |
239 | 0 | temp.setInt32(int32_t(currentValue)); |
240 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->x_id, temp, JSPROP_ENUMERATE)) { |
241 | 0 | return false; |
242 | 0 | } |
243 | 0 | break; |
244 | 0 | } while(false); |
245 | 0 |
|
246 | 0 | do { |
247 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
248 | 0 | JS::Rooted<JS::Value> temp(cx); |
249 | 0 | int32_t const & currentValue = mY; |
250 | 0 | temp.setInt32(int32_t(currentValue)); |
251 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->y_id, temp, JSPROP_ENUMERATE)) { |
252 | 0 | return false; |
253 | 0 | } |
254 | 0 | break; |
255 | 0 | } while(false); |
256 | 0 |
|
257 | 0 | return true; |
258 | 0 | } |
259 | | |
260 | | bool |
261 | | ProfileTimelineLayerRect::ToJSON(nsAString& aJSON) const |
262 | 0 | { |
263 | 0 | AutoJSAPI jsapi; |
264 | 0 | jsapi.Init(); |
265 | 0 | JSContext *cx = jsapi.cx(); |
266 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
267 | 0 | // because we'll only be creating objects, in ways that have no |
268 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
269 | 0 | // which likewise guarantees no side-effects for the sorts of |
270 | 0 | // things we will pass it. |
271 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
272 | 0 | JS::Rooted<JS::Value> val(cx); |
273 | 0 | if (!ToObjectInternal(cx, &val)) { |
274 | 0 | return false; |
275 | 0 | } |
276 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
277 | 0 | return StringifyToJSON(cx, obj, aJSON); |
278 | 0 | } |
279 | | |
280 | | void |
281 | | ProfileTimelineLayerRect::TraceDictionary(JSTracer* trc) |
282 | 0 | { |
283 | 0 | } |
284 | | |
285 | | ProfileTimelineLayerRect& |
286 | | ProfileTimelineLayerRect::operator=(const ProfileTimelineLayerRect& aOther) |
287 | 0 | { |
288 | 0 | DictionaryBase::operator=(aOther); |
289 | 0 | mHeight = aOther.mHeight; |
290 | 0 | mWidth = aOther.mWidth; |
291 | 0 | mX = aOther.mX; |
292 | 0 | mY = aOther.mY; |
293 | 0 | return *this; |
294 | 0 | } |
295 | | |
296 | | namespace binding_detail { |
297 | | } // namespace binding_detail |
298 | | |
299 | | |
300 | | |
301 | | ProfileTimelineStackFrame::ProfileTimelineStackFrame() |
302 | | : mAsyncParent(nullptr), |
303 | | mParent(nullptr) |
304 | 0 | { |
305 | 0 | // Safe to pass a null context if we pass a null value |
306 | 0 | Init(nullptr, JS::NullHandleValue); |
307 | 0 | } |
308 | | |
309 | | |
310 | | bool |
311 | | ProfileTimelineStackFrame::InitIds(JSContext* cx, ProfileTimelineStackFrameAtoms* atomsCache) |
312 | 0 | { |
313 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
314 | 0 |
|
315 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
316 | 0 | // uninitialized. |
317 | 0 | if (!atomsCache->source_id.init(cx, "source") || |
318 | 0 | !atomsCache->parent_id.init(cx, "parent") || |
319 | 0 | !atomsCache->line_id.init(cx, "line") || |
320 | 0 | !atomsCache->functionDisplayName_id.init(cx, "functionDisplayName") || |
321 | 0 | !atomsCache->column_id.init(cx, "column") || |
322 | 0 | !atomsCache->asyncParent_id.init(cx, "asyncParent") || |
323 | 0 | !atomsCache->asyncCause_id.init(cx, "asyncCause")) { |
324 | 0 | return false; |
325 | 0 | } |
326 | 0 | return true; |
327 | 0 | } |
328 | | |
329 | | bool |
330 | | ProfileTimelineStackFrame::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
331 | 0 | { |
332 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
333 | 0 | // Since in that case we will not have to do any property gets |
334 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
335 | 0 | // checkers by static analysis tools |
336 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
337 | 0 | ProfileTimelineStackFrameAtoms* atomsCache = nullptr; |
338 | 0 | if (cx) { |
339 | 0 | atomsCache = GetAtomCache<ProfileTimelineStackFrameAtoms>(cx); |
340 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
341 | 0 | return false; |
342 | 0 | } |
343 | 0 | } |
344 | 0 | |
345 | 0 | if (!IsConvertibleToDictionary(val)) { |
346 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
347 | 0 | } |
348 | 0 | |
349 | 0 | bool isNull = val.isNullOrUndefined(); |
350 | 0 | // We only need these if !isNull, in which case we have |cx|. |
351 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
352 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
353 | 0 | if (!isNull) { |
354 | 0 | MOZ_ASSERT(cx); |
355 | 0 | object.emplace(cx, &val.toObject()); |
356 | 0 | temp.emplace(cx); |
357 | 0 | } |
358 | 0 | if (!isNull) { |
359 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->asyncCause_id, temp.ptr())) { |
360 | 0 | return false; |
361 | 0 | } |
362 | 0 | } |
363 | 0 | if (!isNull && !temp->isUndefined()) { |
364 | 0 | mAsyncCause.Construct(); |
365 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mAsyncCause.Value()))) { |
366 | 0 | return false; |
367 | 0 | } |
368 | 0 | mIsAnyMemberPresent = true; |
369 | 0 | } |
370 | 0 |
|
371 | 0 | if (!isNull) { |
372 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->asyncParent_id, temp.ptr())) { |
373 | 0 | return false; |
374 | 0 | } |
375 | 0 | } |
376 | 0 | if (!isNull && !temp->isUndefined()) { |
377 | 0 | if (temp.ref().isObject()) { |
378 | 0 | #ifdef __clang__ |
379 | 0 | #pragma clang diagnostic push |
380 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
381 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
382 | 0 | #endif // __clang__ |
383 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
384 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'asyncParent' member of ProfileTimelineStackFrame"); |
385 | 0 | return false; |
386 | 0 | } |
387 | 0 | #ifdef __clang__ |
388 | 0 | #pragma clang diagnostic pop |
389 | 0 | #endif // __clang__ |
390 | 0 | mAsyncParent = &temp.ref().toObject(); |
391 | 0 | } else if (temp.ref().isNullOrUndefined()) { |
392 | 0 | mAsyncParent = nullptr; |
393 | 0 | } else { |
394 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'asyncParent' member of ProfileTimelineStackFrame"); |
395 | 0 | return false; |
396 | 0 | } |
397 | 0 | } else { |
398 | 0 | mAsyncParent = nullptr; |
399 | 0 | } |
400 | 0 | mIsAnyMemberPresent = true; |
401 | 0 |
|
402 | 0 | if (!isNull) { |
403 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->column_id, temp.ptr())) { |
404 | 0 | return false; |
405 | 0 | } |
406 | 0 | } |
407 | 0 | if (!isNull && !temp->isUndefined()) { |
408 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mColumn)) { |
409 | 0 | return false; |
410 | 0 | } |
411 | 0 | } else { |
412 | 0 | mColumn = 0; |
413 | 0 | } |
414 | 0 | mIsAnyMemberPresent = true; |
415 | 0 |
|
416 | 0 | if (!isNull) { |
417 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->functionDisplayName_id, temp.ptr())) { |
418 | 0 | return false; |
419 | 0 | } |
420 | 0 | } |
421 | 0 | if (!isNull && !temp->isUndefined()) { |
422 | 0 | mFunctionDisplayName.Construct(); |
423 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mFunctionDisplayName.Value()))) { |
424 | 0 | return false; |
425 | 0 | } |
426 | 0 | mIsAnyMemberPresent = true; |
427 | 0 | } |
428 | 0 |
|
429 | 0 | if (!isNull) { |
430 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->line_id, temp.ptr())) { |
431 | 0 | return false; |
432 | 0 | } |
433 | 0 | } |
434 | 0 | if (!isNull && !temp->isUndefined()) { |
435 | 0 | mLine.Construct(); |
436 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &(mLine.Value()))) { |
437 | 0 | return false; |
438 | 0 | } |
439 | 0 | mIsAnyMemberPresent = true; |
440 | 0 | } |
441 | 0 |
|
442 | 0 | if (!isNull) { |
443 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->parent_id, temp.ptr())) { |
444 | 0 | return false; |
445 | 0 | } |
446 | 0 | } |
447 | 0 | if (!isNull && !temp->isUndefined()) { |
448 | 0 | if (temp.ref().isObject()) { |
449 | 0 | #ifdef __clang__ |
450 | 0 | #pragma clang diagnostic push |
451 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
452 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
453 | 0 | #endif // __clang__ |
454 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
455 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'parent' member of ProfileTimelineStackFrame"); |
456 | 0 | return false; |
457 | 0 | } |
458 | 0 | #ifdef __clang__ |
459 | 0 | #pragma clang diagnostic pop |
460 | 0 | #endif // __clang__ |
461 | 0 | mParent = &temp.ref().toObject(); |
462 | 0 | } else if (temp.ref().isNullOrUndefined()) { |
463 | 0 | mParent = nullptr; |
464 | 0 | } else { |
465 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'parent' member of ProfileTimelineStackFrame"); |
466 | 0 | return false; |
467 | 0 | } |
468 | 0 | } else { |
469 | 0 | mParent = nullptr; |
470 | 0 | } |
471 | 0 | mIsAnyMemberPresent = true; |
472 | 0 |
|
473 | 0 | if (!isNull) { |
474 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->source_id, temp.ptr())) { |
475 | 0 | return false; |
476 | 0 | } |
477 | 0 | } |
478 | 0 | if (!isNull && !temp->isUndefined()) { |
479 | 0 | mSource.Construct(); |
480 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mSource.Value()))) { |
481 | 0 | return false; |
482 | 0 | } |
483 | 0 | mIsAnyMemberPresent = true; |
484 | 0 | } |
485 | 0 | return true; |
486 | 0 | } |
487 | | |
488 | | bool |
489 | | ProfileTimelineStackFrame::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
490 | 0 | { |
491 | 0 | ProfileTimelineStackFrameAtoms* atomsCache = GetAtomCache<ProfileTimelineStackFrameAtoms>(cx); |
492 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
493 | 0 | return false; |
494 | 0 | } |
495 | 0 | |
496 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
497 | 0 | if (!obj) { |
498 | 0 | return false; |
499 | 0 | } |
500 | 0 | rval.set(JS::ObjectValue(*obj)); |
501 | 0 |
|
502 | 0 | if (mAsyncCause.WasPassed()) { |
503 | 0 | do { |
504 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
505 | 0 | JS::Rooted<JS::Value> temp(cx); |
506 | 0 | nsString const & currentValue = mAsyncCause.InternalValue(); |
507 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
508 | 0 | return false; |
509 | 0 | } |
510 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->asyncCause_id, temp, JSPROP_ENUMERATE)) { |
511 | 0 | return false; |
512 | 0 | } |
513 | 0 | break; |
514 | 0 | } while(false); |
515 | 0 | } |
516 | 0 |
|
517 | 0 | do { |
518 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
519 | 0 | JS::Rooted<JS::Value> temp(cx); |
520 | 0 | JSObject* const & currentValue = mAsyncParent; |
521 | 0 | if (currentValue) { |
522 | 0 | JS::ExposeObjectToActiveJS(currentValue); |
523 | 0 | } |
524 | 0 | temp.setObjectOrNull(currentValue); |
525 | 0 | if (!MaybeWrapObjectOrNullValue(cx, &temp)) { |
526 | 0 | return false; |
527 | 0 | } |
528 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->asyncParent_id, temp, JSPROP_ENUMERATE)) { |
529 | 0 | return false; |
530 | 0 | } |
531 | 0 | break; |
532 | 0 | } while(false); |
533 | 0 |
|
534 | 0 | do { |
535 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
536 | 0 | JS::Rooted<JS::Value> temp(cx); |
537 | 0 | int32_t const & currentValue = mColumn; |
538 | 0 | temp.setInt32(int32_t(currentValue)); |
539 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->column_id, temp, JSPROP_ENUMERATE)) { |
540 | 0 | return false; |
541 | 0 | } |
542 | 0 | break; |
543 | 0 | } while(false); |
544 | 0 |
|
545 | 0 | if (mFunctionDisplayName.WasPassed()) { |
546 | 0 | do { |
547 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
548 | 0 | JS::Rooted<JS::Value> temp(cx); |
549 | 0 | nsString const & currentValue = mFunctionDisplayName.InternalValue(); |
550 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
551 | 0 | return false; |
552 | 0 | } |
553 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->functionDisplayName_id, temp, JSPROP_ENUMERATE)) { |
554 | 0 | return false; |
555 | 0 | } |
556 | 0 | break; |
557 | 0 | } while(false); |
558 | 0 | } |
559 | 0 |
|
560 | 0 | if (mLine.WasPassed()) { |
561 | 0 | do { |
562 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
563 | 0 | JS::Rooted<JS::Value> temp(cx); |
564 | 0 | int32_t const & currentValue = mLine.InternalValue(); |
565 | 0 | temp.setInt32(int32_t(currentValue)); |
566 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->line_id, temp, JSPROP_ENUMERATE)) { |
567 | 0 | return false; |
568 | 0 | } |
569 | 0 | break; |
570 | 0 | } while(false); |
571 | 0 | } |
572 | 0 |
|
573 | 0 | do { |
574 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
575 | 0 | JS::Rooted<JS::Value> temp(cx); |
576 | 0 | JSObject* const & currentValue = mParent; |
577 | 0 | if (currentValue) { |
578 | 0 | JS::ExposeObjectToActiveJS(currentValue); |
579 | 0 | } |
580 | 0 | temp.setObjectOrNull(currentValue); |
581 | 0 | if (!MaybeWrapObjectOrNullValue(cx, &temp)) { |
582 | 0 | return false; |
583 | 0 | } |
584 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->parent_id, temp, JSPROP_ENUMERATE)) { |
585 | 0 | return false; |
586 | 0 | } |
587 | 0 | break; |
588 | 0 | } while(false); |
589 | 0 |
|
590 | 0 | if (mSource.WasPassed()) { |
591 | 0 | do { |
592 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
593 | 0 | JS::Rooted<JS::Value> temp(cx); |
594 | 0 | nsString const & currentValue = mSource.InternalValue(); |
595 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
596 | 0 | return false; |
597 | 0 | } |
598 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->source_id, temp, JSPROP_ENUMERATE)) { |
599 | 0 | return false; |
600 | 0 | } |
601 | 0 | break; |
602 | 0 | } while(false); |
603 | 0 | } |
604 | 0 |
|
605 | 0 | return true; |
606 | 0 | } |
607 | | |
608 | | void |
609 | | ProfileTimelineStackFrame::TraceDictionary(JSTracer* trc) |
610 | 0 | { |
611 | 0 | if (mAsyncParent) { |
612 | 0 | JS::UnsafeTraceRoot(trc, &mAsyncParent, "ProfileTimelineStackFrame.mAsyncParent"); |
613 | 0 | } |
614 | 0 |
|
615 | 0 | if (mParent) { |
616 | 0 | JS::UnsafeTraceRoot(trc, &mParent, "ProfileTimelineStackFrame.mParent"); |
617 | 0 | } |
618 | 0 | } |
619 | | |
620 | | namespace binding_detail { |
621 | | } // namespace binding_detail |
622 | | |
623 | | |
624 | | |
625 | | ProfileTimelineMarker::ProfileTimelineMarker() |
626 | | : mEndStack(nullptr), |
627 | | mStack(nullptr) |
628 | 0 | { |
629 | 0 | // Safe to pass a null context if we pass a null value |
630 | 0 | Init(nullptr, JS::NullHandleValue); |
631 | 0 | } |
632 | | |
633 | | |
634 | | bool |
635 | | ProfileTimelineMarker::InitIds(JSContext* cx, ProfileTimelineMarkerAtoms* atomsCache) |
636 | 0 | { |
637 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
638 | 0 |
|
639 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
640 | 0 | // uninitialized. |
641 | 0 | if (!atomsCache->workerOperation_id.init(cx, "workerOperation") || |
642 | 0 | !atomsCache->unixTime_id.init(cx, "unixTime") || |
643 | 0 | !atomsCache->type_id.init(cx, "type") || |
644 | 0 | !atomsCache->start_id.init(cx, "start") || |
645 | 0 | !atomsCache->stack_id.init(cx, "stack") || |
646 | 0 | !atomsCache->rectangles_id.init(cx, "rectangles") || |
647 | 0 | !atomsCache->processType_id.init(cx, "processType") || |
648 | 0 | !atomsCache->name_id.init(cx, "name") || |
649 | 0 | !atomsCache->messagePortOperation_id.init(cx, "messagePortOperation") || |
650 | 0 | !atomsCache->isOffMainThread_id.init(cx, "isOffMainThread") || |
651 | 0 | !atomsCache->isAnimationOnly_id.init(cx, "isAnimationOnly") || |
652 | 0 | !atomsCache->eventPhase_id.init(cx, "eventPhase") || |
653 | 0 | !atomsCache->endStack_id.init(cx, "endStack") || |
654 | 0 | !atomsCache->end_id.init(cx, "end") || |
655 | 0 | !atomsCache->causeName_id.init(cx, "causeName")) { |
656 | 0 | return false; |
657 | 0 | } |
658 | 0 | return true; |
659 | 0 | } |
660 | | |
661 | | bool |
662 | | ProfileTimelineMarker::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
663 | 0 | { |
664 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
665 | 0 | // Since in that case we will not have to do any property gets |
666 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
667 | 0 | // checkers by static analysis tools |
668 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
669 | 0 | ProfileTimelineMarkerAtoms* atomsCache = nullptr; |
670 | 0 | if (cx) { |
671 | 0 | atomsCache = GetAtomCache<ProfileTimelineMarkerAtoms>(cx); |
672 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
673 | 0 | return false; |
674 | 0 | } |
675 | 0 | } |
676 | 0 | |
677 | 0 | if (!IsConvertibleToDictionary(val)) { |
678 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
679 | 0 | } |
680 | 0 | |
681 | 0 | bool isNull = val.isNullOrUndefined(); |
682 | 0 | // We only need these if !isNull, in which case we have |cx|. |
683 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
684 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
685 | 0 | if (!isNull) { |
686 | 0 | MOZ_ASSERT(cx); |
687 | 0 | object.emplace(cx, &val.toObject()); |
688 | 0 | temp.emplace(cx); |
689 | 0 | } |
690 | 0 | if (!isNull) { |
691 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->causeName_id, temp.ptr())) { |
692 | 0 | return false; |
693 | 0 | } |
694 | 0 | } |
695 | 0 | if (!isNull && !temp->isUndefined()) { |
696 | 0 | mCauseName.Construct(); |
697 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mCauseName.Value()))) { |
698 | 0 | return false; |
699 | 0 | } |
700 | 0 | mIsAnyMemberPresent = true; |
701 | 0 | } |
702 | 0 |
|
703 | 0 | if (!isNull) { |
704 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->end_id, temp.ptr())) { |
705 | 0 | return false; |
706 | 0 | } |
707 | 0 | } |
708 | 0 | if (!isNull && !temp->isUndefined()) { |
709 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mEnd)) { |
710 | 0 | return false; |
711 | 0 | } else if (!mozilla::IsFinite(mEnd)) { |
712 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "'end' member of ProfileTimelineMarker"); |
713 | 0 | return false; |
714 | 0 | } |
715 | 0 | } else { |
716 | 0 | mEnd = 0.0; |
717 | 0 | } |
718 | 0 | mIsAnyMemberPresent = true; |
719 | 0 |
|
720 | 0 | if (!isNull) { |
721 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->endStack_id, temp.ptr())) { |
722 | 0 | return false; |
723 | 0 | } |
724 | 0 | } |
725 | 0 | if (!isNull && !temp->isUndefined()) { |
726 | 0 | if (temp.ref().isObject()) { |
727 | 0 | #ifdef __clang__ |
728 | 0 | #pragma clang diagnostic push |
729 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
730 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
731 | 0 | #endif // __clang__ |
732 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
733 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'endStack' member of ProfileTimelineMarker"); |
734 | 0 | return false; |
735 | 0 | } |
736 | 0 | #ifdef __clang__ |
737 | 0 | #pragma clang diagnostic pop |
738 | 0 | #endif // __clang__ |
739 | 0 | mEndStack = &temp.ref().toObject(); |
740 | 0 | } else if (temp.ref().isNullOrUndefined()) { |
741 | 0 | mEndStack = nullptr; |
742 | 0 | } else { |
743 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'endStack' member of ProfileTimelineMarker"); |
744 | 0 | return false; |
745 | 0 | } |
746 | 0 | } else { |
747 | 0 | mEndStack = nullptr; |
748 | 0 | } |
749 | 0 | mIsAnyMemberPresent = true; |
750 | 0 |
|
751 | 0 | if (!isNull) { |
752 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->eventPhase_id, temp.ptr())) { |
753 | 0 | return false; |
754 | 0 | } |
755 | 0 | } |
756 | 0 | if (!isNull && !temp->isUndefined()) { |
757 | 0 | mEventPhase.Construct(); |
758 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mEventPhase.Value()))) { |
759 | 0 | return false; |
760 | 0 | } |
761 | 0 | mIsAnyMemberPresent = true; |
762 | 0 | } |
763 | 0 |
|
764 | 0 | if (!isNull) { |
765 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->isAnimationOnly_id, temp.ptr())) { |
766 | 0 | return false; |
767 | 0 | } |
768 | 0 | } |
769 | 0 | if (!isNull && !temp->isUndefined()) { |
770 | 0 | mIsAnimationOnly.Construct(); |
771 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mIsAnimationOnly.Value()))) { |
772 | 0 | return false; |
773 | 0 | } |
774 | 0 | mIsAnyMemberPresent = true; |
775 | 0 | } |
776 | 0 |
|
777 | 0 | if (!isNull) { |
778 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->isOffMainThread_id, temp.ptr())) { |
779 | 0 | return false; |
780 | 0 | } |
781 | 0 | } |
782 | 0 | if (!isNull && !temp->isUndefined()) { |
783 | 0 | mIsOffMainThread.Construct(); |
784 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mIsOffMainThread.Value()))) { |
785 | 0 | return false; |
786 | 0 | } |
787 | 0 | mIsAnyMemberPresent = true; |
788 | 0 | } |
789 | 0 |
|
790 | 0 | if (!isNull) { |
791 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->messagePortOperation_id, temp.ptr())) { |
792 | 0 | return false; |
793 | 0 | } |
794 | 0 | } |
795 | 0 | if (!isNull && !temp->isUndefined()) { |
796 | 0 | mMessagePortOperation.Construct(); |
797 | 0 | { |
798 | 0 | int index; |
799 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), ProfileTimelineMessagePortOperationTypeValues::strings, "ProfileTimelineMessagePortOperationType", "'messagePortOperation' member of ProfileTimelineMarker", &index)) { |
800 | 0 | return false; |
801 | 0 | } |
802 | 0 | MOZ_ASSERT(index >= 0); |
803 | 0 | (mMessagePortOperation.Value()) = static_cast<ProfileTimelineMessagePortOperationType>(index); |
804 | 0 | } |
805 | 0 | mIsAnyMemberPresent = true; |
806 | 0 | } |
807 | 0 |
|
808 | 0 | if (!isNull) { |
809 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) { |
810 | 0 | return false; |
811 | 0 | } |
812 | 0 | } |
813 | 0 | if (!isNull && !temp->isUndefined()) { |
814 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) { |
815 | 0 | return false; |
816 | 0 | } |
817 | 0 | } else { |
818 | 0 | static const char16_t data[] = { 0 }; |
819 | 0 | mName.Rebind(data, ArrayLength(data) - 1); |
820 | 0 | } |
821 | 0 | mIsAnyMemberPresent = true; |
822 | 0 |
|
823 | 0 | if (!isNull) { |
824 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->processType_id, temp.ptr())) { |
825 | 0 | return false; |
826 | 0 | } |
827 | 0 | } |
828 | 0 | if (!isNull && !temp->isUndefined()) { |
829 | 0 | mProcessType.Construct(); |
830 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mProcessType.Value()))) { |
831 | 0 | return false; |
832 | 0 | } |
833 | 0 | mIsAnyMemberPresent = true; |
834 | 0 | } |
835 | 0 |
|
836 | 0 | if (!isNull) { |
837 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->rectangles_id, temp.ptr())) { |
838 | 0 | return false; |
839 | 0 | } |
840 | 0 | } |
841 | 0 | if (!isNull && !temp->isUndefined()) { |
842 | 0 | mRectangles.Construct(); |
843 | 0 | if (temp.ref().isObject()) { |
844 | 0 | JS::ForOfIterator iter(cx); |
845 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
846 | 0 | return false; |
847 | 0 | } |
848 | 0 | if (!iter.valueIsIterable()) { |
849 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'rectangles' member of ProfileTimelineMarker"); |
850 | 0 | return false; |
851 | 0 | } |
852 | 0 | Sequence<ProfileTimelineLayerRect> &arr = (mRectangles.Value()); |
853 | 0 | JS::Rooted<JS::Value> temp(cx); |
854 | 0 | while (true) { |
855 | 0 | bool done; |
856 | 0 | if (!iter.next(&temp, &done)) { |
857 | 0 | return false; |
858 | 0 | } |
859 | 0 | if (done) { |
860 | 0 | break; |
861 | 0 | } |
862 | 0 | ProfileTimelineLayerRect* slotPtr = arr.AppendElement(mozilla::fallible); |
863 | 0 | if (!slotPtr) { |
864 | 0 | JS_ReportOutOfMemory(cx); |
865 | 0 | return false; |
866 | 0 | } |
867 | 0 | ProfileTimelineLayerRect& slot = *slotPtr; |
868 | 0 | if (!slot.Init(cx, temp, "Element of 'rectangles' member of ProfileTimelineMarker", passedToJSImpl)) { |
869 | 0 | return false; |
870 | 0 | } |
871 | 0 | } |
872 | 0 | } else { |
873 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'rectangles' member of ProfileTimelineMarker"); |
874 | 0 | return false; |
875 | 0 | } |
876 | 0 | mIsAnyMemberPresent = true; |
877 | 0 | } |
878 | 0 |
|
879 | 0 | if (!isNull) { |
880 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->stack_id, temp.ptr())) { |
881 | 0 | return false; |
882 | 0 | } |
883 | 0 | } |
884 | 0 | if (!isNull && !temp->isUndefined()) { |
885 | 0 | if (temp.ref().isObject()) { |
886 | 0 | #ifdef __clang__ |
887 | 0 | #pragma clang diagnostic push |
888 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
889 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
890 | 0 | #endif // __clang__ |
891 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
892 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'stack' member of ProfileTimelineMarker"); |
893 | 0 | return false; |
894 | 0 | } |
895 | 0 | #ifdef __clang__ |
896 | 0 | #pragma clang diagnostic pop |
897 | 0 | #endif // __clang__ |
898 | 0 | mStack = &temp.ref().toObject(); |
899 | 0 | } else if (temp.ref().isNullOrUndefined()) { |
900 | 0 | mStack = nullptr; |
901 | 0 | } else { |
902 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'stack' member of ProfileTimelineMarker"); |
903 | 0 | return false; |
904 | 0 | } |
905 | 0 | } else { |
906 | 0 | mStack = nullptr; |
907 | 0 | } |
908 | 0 | mIsAnyMemberPresent = true; |
909 | 0 |
|
910 | 0 | if (!isNull) { |
911 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->start_id, temp.ptr())) { |
912 | 0 | return false; |
913 | 0 | } |
914 | 0 | } |
915 | 0 | if (!isNull && !temp->isUndefined()) { |
916 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mStart)) { |
917 | 0 | return false; |
918 | 0 | } else if (!mozilla::IsFinite(mStart)) { |
919 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "'start' member of ProfileTimelineMarker"); |
920 | 0 | return false; |
921 | 0 | } |
922 | 0 | } else { |
923 | 0 | mStart = 0.0; |
924 | 0 | } |
925 | 0 | mIsAnyMemberPresent = true; |
926 | 0 |
|
927 | 0 | if (!isNull) { |
928 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) { |
929 | 0 | return false; |
930 | 0 | } |
931 | 0 | } |
932 | 0 | if (!isNull && !temp->isUndefined()) { |
933 | 0 | mType.Construct(); |
934 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mType.Value()))) { |
935 | 0 | return false; |
936 | 0 | } |
937 | 0 | mIsAnyMemberPresent = true; |
938 | 0 | } |
939 | 0 |
|
940 | 0 | if (!isNull) { |
941 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->unixTime_id, temp.ptr())) { |
942 | 0 | return false; |
943 | 0 | } |
944 | 0 | } |
945 | 0 | if (!isNull && !temp->isUndefined()) { |
946 | 0 | mUnixTime.Construct(); |
947 | 0 | if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mUnixTime.Value()))) { |
948 | 0 | return false; |
949 | 0 | } |
950 | 0 | mIsAnyMemberPresent = true; |
951 | 0 | } |
952 | 0 |
|
953 | 0 | if (!isNull) { |
954 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->workerOperation_id, temp.ptr())) { |
955 | 0 | return false; |
956 | 0 | } |
957 | 0 | } |
958 | 0 | if (!isNull && !temp->isUndefined()) { |
959 | 0 | mWorkerOperation.Construct(); |
960 | 0 | { |
961 | 0 | int index; |
962 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), ProfileTimelineWorkerOperationTypeValues::strings, "ProfileTimelineWorkerOperationType", "'workerOperation' member of ProfileTimelineMarker", &index)) { |
963 | 0 | return false; |
964 | 0 | } |
965 | 0 | MOZ_ASSERT(index >= 0); |
966 | 0 | (mWorkerOperation.Value()) = static_cast<ProfileTimelineWorkerOperationType>(index); |
967 | 0 | } |
968 | 0 | mIsAnyMemberPresent = true; |
969 | 0 | } |
970 | 0 | return true; |
971 | 0 | } |
972 | | |
973 | | bool |
974 | | ProfileTimelineMarker::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
975 | 0 | { |
976 | 0 | ProfileTimelineMarkerAtoms* atomsCache = GetAtomCache<ProfileTimelineMarkerAtoms>(cx); |
977 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
978 | 0 | return false; |
979 | 0 | } |
980 | 0 | |
981 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
982 | 0 | if (!obj) { |
983 | 0 | return false; |
984 | 0 | } |
985 | 0 | rval.set(JS::ObjectValue(*obj)); |
986 | 0 |
|
987 | 0 | if (mCauseName.WasPassed()) { |
988 | 0 | do { |
989 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
990 | 0 | JS::Rooted<JS::Value> temp(cx); |
991 | 0 | nsString const & currentValue = mCauseName.InternalValue(); |
992 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
993 | 0 | return false; |
994 | 0 | } |
995 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->causeName_id, temp, JSPROP_ENUMERATE)) { |
996 | 0 | return false; |
997 | 0 | } |
998 | 0 | break; |
999 | 0 | } while(false); |
1000 | 0 | } |
1001 | 0 |
|
1002 | 0 | do { |
1003 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1004 | 0 | JS::Rooted<JS::Value> temp(cx); |
1005 | 0 | double const & currentValue = mEnd; |
1006 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
1007 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->end_id, temp, JSPROP_ENUMERATE)) { |
1008 | 0 | return false; |
1009 | 0 | } |
1010 | 0 | break; |
1011 | 0 | } while(false); |
1012 | 0 |
|
1013 | 0 | do { |
1014 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1015 | 0 | JS::Rooted<JS::Value> temp(cx); |
1016 | 0 | JSObject* const & currentValue = mEndStack; |
1017 | 0 | if (currentValue) { |
1018 | 0 | JS::ExposeObjectToActiveJS(currentValue); |
1019 | 0 | } |
1020 | 0 | temp.setObjectOrNull(currentValue); |
1021 | 0 | if (!MaybeWrapObjectOrNullValue(cx, &temp)) { |
1022 | 0 | return false; |
1023 | 0 | } |
1024 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->endStack_id, temp, JSPROP_ENUMERATE)) { |
1025 | 0 | return false; |
1026 | 0 | } |
1027 | 0 | break; |
1028 | 0 | } while(false); |
1029 | 0 |
|
1030 | 0 | if (mEventPhase.WasPassed()) { |
1031 | 0 | do { |
1032 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1033 | 0 | JS::Rooted<JS::Value> temp(cx); |
1034 | 0 | uint16_t const & currentValue = mEventPhase.InternalValue(); |
1035 | 0 | temp.setInt32(int32_t(currentValue)); |
1036 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->eventPhase_id, temp, JSPROP_ENUMERATE)) { |
1037 | 0 | return false; |
1038 | 0 | } |
1039 | 0 | break; |
1040 | 0 | } while(false); |
1041 | 0 | } |
1042 | 0 |
|
1043 | 0 | if (mIsAnimationOnly.WasPassed()) { |
1044 | 0 | do { |
1045 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1046 | 0 | JS::Rooted<JS::Value> temp(cx); |
1047 | 0 | bool const & currentValue = mIsAnimationOnly.InternalValue(); |
1048 | 0 | temp.setBoolean(currentValue); |
1049 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->isAnimationOnly_id, temp, JSPROP_ENUMERATE)) { |
1050 | 0 | return false; |
1051 | 0 | } |
1052 | 0 | break; |
1053 | 0 | } while(false); |
1054 | 0 | } |
1055 | 0 |
|
1056 | 0 | if (mIsOffMainThread.WasPassed()) { |
1057 | 0 | do { |
1058 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1059 | 0 | JS::Rooted<JS::Value> temp(cx); |
1060 | 0 | bool const & currentValue = mIsOffMainThread.InternalValue(); |
1061 | 0 | temp.setBoolean(currentValue); |
1062 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->isOffMainThread_id, temp, JSPROP_ENUMERATE)) { |
1063 | 0 | return false; |
1064 | 0 | } |
1065 | 0 | break; |
1066 | 0 | } while(false); |
1067 | 0 | } |
1068 | 0 |
|
1069 | 0 | if (mMessagePortOperation.WasPassed()) { |
1070 | 0 | do { |
1071 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1072 | 0 | JS::Rooted<JS::Value> temp(cx); |
1073 | 0 | ProfileTimelineMessagePortOperationType const & currentValue = mMessagePortOperation.InternalValue(); |
1074 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
1075 | 0 | return false; |
1076 | 0 | } |
1077 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->messagePortOperation_id, temp, JSPROP_ENUMERATE)) { |
1078 | 0 | return false; |
1079 | 0 | } |
1080 | 0 | break; |
1081 | 0 | } while(false); |
1082 | 0 | } |
1083 | 0 |
|
1084 | 0 | do { |
1085 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1086 | 0 | JS::Rooted<JS::Value> temp(cx); |
1087 | 0 | nsString const & currentValue = mName; |
1088 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
1089 | 0 | return false; |
1090 | 0 | } |
1091 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) { |
1092 | 0 | return false; |
1093 | 0 | } |
1094 | 0 | break; |
1095 | 0 | } while(false); |
1096 | 0 |
|
1097 | 0 | if (mProcessType.WasPassed()) { |
1098 | 0 | do { |
1099 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1100 | 0 | JS::Rooted<JS::Value> temp(cx); |
1101 | 0 | uint16_t const & currentValue = mProcessType.InternalValue(); |
1102 | 0 | temp.setInt32(int32_t(currentValue)); |
1103 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->processType_id, temp, JSPROP_ENUMERATE)) { |
1104 | 0 | return false; |
1105 | 0 | } |
1106 | 0 | break; |
1107 | 0 | } while(false); |
1108 | 0 | } |
1109 | 0 |
|
1110 | 0 | if (mRectangles.WasPassed()) { |
1111 | 0 | do { |
1112 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1113 | 0 | JS::Rooted<JS::Value> temp(cx); |
1114 | 0 | Sequence<ProfileTimelineLayerRect> const & currentValue = mRectangles.InternalValue(); |
1115 | 0 |
|
1116 | 0 | uint32_t length = currentValue.Length(); |
1117 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
1118 | 0 | if (!returnArray) { |
1119 | 0 | return false; |
1120 | 0 | } |
1121 | 0 | // Scope for 'tmp' |
1122 | 0 | { |
1123 | 0 | JS::Rooted<JS::Value> tmp(cx); |
1124 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
1125 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
1126 | 0 | // are different ways to succeed at wrapping the object. |
1127 | 0 | do { |
1128 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
1129 | 0 | return false; |
1130 | 0 | } |
1131 | 0 | break; |
1132 | 0 | } while (false); |
1133 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
1134 | 0 | JSPROP_ENUMERATE)) { |
1135 | 0 | return false; |
1136 | 0 | } |
1137 | 0 | } |
1138 | 0 | } |
1139 | 0 | temp.setObject(*returnArray); |
1140 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->rectangles_id, temp, JSPROP_ENUMERATE)) { |
1141 | 0 | return false; |
1142 | 0 | } |
1143 | 0 | break; |
1144 | 0 | } while(false); |
1145 | 0 | } |
1146 | 0 |
|
1147 | 0 | do { |
1148 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1149 | 0 | JS::Rooted<JS::Value> temp(cx); |
1150 | 0 | JSObject* const & currentValue = mStack; |
1151 | 0 | if (currentValue) { |
1152 | 0 | JS::ExposeObjectToActiveJS(currentValue); |
1153 | 0 | } |
1154 | 0 | temp.setObjectOrNull(currentValue); |
1155 | 0 | if (!MaybeWrapObjectOrNullValue(cx, &temp)) { |
1156 | 0 | return false; |
1157 | 0 | } |
1158 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->stack_id, temp, JSPROP_ENUMERATE)) { |
1159 | 0 | return false; |
1160 | 0 | } |
1161 | 0 | break; |
1162 | 0 | } while(false); |
1163 | 0 |
|
1164 | 0 | do { |
1165 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1166 | 0 | JS::Rooted<JS::Value> temp(cx); |
1167 | 0 | double const & currentValue = mStart; |
1168 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
1169 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->start_id, temp, JSPROP_ENUMERATE)) { |
1170 | 0 | return false; |
1171 | 0 | } |
1172 | 0 | break; |
1173 | 0 | } while(false); |
1174 | 0 |
|
1175 | 0 | if (mType.WasPassed()) { |
1176 | 0 | do { |
1177 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1178 | 0 | JS::Rooted<JS::Value> temp(cx); |
1179 | 0 | nsString const & currentValue = mType.InternalValue(); |
1180 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
1181 | 0 | return false; |
1182 | 0 | } |
1183 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) { |
1184 | 0 | return false; |
1185 | 0 | } |
1186 | 0 | break; |
1187 | 0 | } while(false); |
1188 | 0 | } |
1189 | 0 |
|
1190 | 0 | if (mUnixTime.WasPassed()) { |
1191 | 0 | do { |
1192 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1193 | 0 | JS::Rooted<JS::Value> temp(cx); |
1194 | 0 | uint64_t const & currentValue = mUnixTime.InternalValue(); |
1195 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
1196 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->unixTime_id, temp, JSPROP_ENUMERATE)) { |
1197 | 0 | return false; |
1198 | 0 | } |
1199 | 0 | break; |
1200 | 0 | } while(false); |
1201 | 0 | } |
1202 | 0 |
|
1203 | 0 | if (mWorkerOperation.WasPassed()) { |
1204 | 0 | do { |
1205 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1206 | 0 | JS::Rooted<JS::Value> temp(cx); |
1207 | 0 | ProfileTimelineWorkerOperationType const & currentValue = mWorkerOperation.InternalValue(); |
1208 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
1209 | 0 | return false; |
1210 | 0 | } |
1211 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->workerOperation_id, temp, JSPROP_ENUMERATE)) { |
1212 | 0 | return false; |
1213 | 0 | } |
1214 | 0 | break; |
1215 | 0 | } while(false); |
1216 | 0 | } |
1217 | 0 |
|
1218 | 0 | return true; |
1219 | 0 | } |
1220 | | |
1221 | | void |
1222 | | ProfileTimelineMarker::TraceDictionary(JSTracer* trc) |
1223 | 0 | { |
1224 | 0 | if (mEndStack) { |
1225 | 0 | JS::UnsafeTraceRoot(trc, &mEndStack, "ProfileTimelineMarker.mEndStack"); |
1226 | 0 | } |
1227 | 0 |
|
1228 | 0 | if (mStack) { |
1229 | 0 | JS::UnsafeTraceRoot(trc, &mStack, "ProfileTimelineMarker.mStack"); |
1230 | 0 | } |
1231 | 0 | } |
1232 | | |
1233 | | namespace binding_detail { |
1234 | | } // namespace binding_detail |
1235 | | |
1236 | | |
1237 | | } // namespace dom |
1238 | | } // namespace mozilla |