/work/obj-fuzz/dom/bindings/CSPReportBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM CSPReport.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "CSPReportBinding.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/dom/BindingUtils.h" |
7 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
8 | | #include "mozilla/dom/PrimitiveConversions.h" |
9 | | #include "mozilla/dom/ScriptSettings.h" |
10 | | #include "mozilla/dom/SimpleGlobalObject.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace dom { |
14 | | |
15 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
16 | | using namespace mozilla::dom::binding_detail; |
17 | | |
18 | | |
19 | | |
20 | | CSPReportProperties::CSPReportProperties() |
21 | 0 | { |
22 | 0 | // Safe to pass a null context if we pass a null value |
23 | 0 | Init(nullptr, JS::NullHandleValue); |
24 | 0 | } |
25 | | |
26 | | |
27 | | |
28 | | bool |
29 | | CSPReportProperties::InitIds(JSContext* cx, CSPReportPropertiesAtoms* atomsCache) |
30 | 0 | { |
31 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
32 | 0 |
|
33 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
34 | 0 | // uninitialized. |
35 | 0 | if (!atomsCache->violated_directive_id.init(cx, "violated-directive") || |
36 | 0 | !atomsCache->source_file_id.init(cx, "source-file") || |
37 | 0 | !atomsCache->script_sample_id.init(cx, "script-sample") || |
38 | 0 | !atomsCache->referrer_id.init(cx, "referrer") || |
39 | 0 | !atomsCache->original_policy_id.init(cx, "original-policy") || |
40 | 0 | !atomsCache->line_number_id.init(cx, "line-number") || |
41 | 0 | !atomsCache->document_uri_id.init(cx, "document-uri") || |
42 | 0 | !atomsCache->column_number_id.init(cx, "column-number") || |
43 | 0 | !atomsCache->blocked_uri_id.init(cx, "blocked-uri")) { |
44 | 0 | return false; |
45 | 0 | } |
46 | 0 | return true; |
47 | 0 | } |
48 | | |
49 | | bool |
50 | | CSPReportProperties::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 | CSPReportPropertiesAtoms* atomsCache = nullptr; |
58 | 0 | if (cx) { |
59 | 0 | atomsCache = GetAtomCache<CSPReportPropertiesAtoms>(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->blocked_uri_id, temp.ptr())) { |
80 | 0 | return false; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | if (!isNull && !temp->isUndefined()) { |
84 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mBlocked_uri)) { |
85 | 0 | return false; |
86 | 0 | } |
87 | 0 | } else { |
88 | 0 | static const char16_t data[] = { 0 }; |
89 | 0 | mBlocked_uri.Rebind(data, ArrayLength(data) - 1); |
90 | 0 | } |
91 | 0 | mIsAnyMemberPresent = true; |
92 | 0 |
|
93 | 0 | if (!isNull) { |
94 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->column_number_id, temp.ptr())) { |
95 | 0 | return false; |
96 | 0 | } |
97 | 0 | } |
98 | 0 | if (!isNull && !temp->isUndefined()) { |
99 | 0 | mColumn_number.Construct(); |
100 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &(mColumn_number.Value()))) { |
101 | 0 | return false; |
102 | 0 | } |
103 | 0 | mIsAnyMemberPresent = true; |
104 | 0 | } |
105 | 0 |
|
106 | 0 | if (!isNull) { |
107 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->document_uri_id, temp.ptr())) { |
108 | 0 | return false; |
109 | 0 | } |
110 | 0 | } |
111 | 0 | if (!isNull && !temp->isUndefined()) { |
112 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDocument_uri)) { |
113 | 0 | return false; |
114 | 0 | } |
115 | 0 | } else { |
116 | 0 | static const char16_t data[] = { 0 }; |
117 | 0 | mDocument_uri.Rebind(data, ArrayLength(data) - 1); |
118 | 0 | } |
119 | 0 | mIsAnyMemberPresent = true; |
120 | 0 |
|
121 | 0 | if (!isNull) { |
122 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->line_number_id, temp.ptr())) { |
123 | 0 | return false; |
124 | 0 | } |
125 | 0 | } |
126 | 0 | if (!isNull && !temp->isUndefined()) { |
127 | 0 | mLine_number.Construct(); |
128 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &(mLine_number.Value()))) { |
129 | 0 | return false; |
130 | 0 | } |
131 | 0 | mIsAnyMemberPresent = true; |
132 | 0 | } |
133 | 0 |
|
134 | 0 | if (!isNull) { |
135 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->original_policy_id, temp.ptr())) { |
136 | 0 | return false; |
137 | 0 | } |
138 | 0 | } |
139 | 0 | if (!isNull && !temp->isUndefined()) { |
140 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mOriginal_policy)) { |
141 | 0 | return false; |
142 | 0 | } |
143 | 0 | } else { |
144 | 0 | static const char16_t data[] = { 0 }; |
145 | 0 | mOriginal_policy.Rebind(data, ArrayLength(data) - 1); |
146 | 0 | } |
147 | 0 | mIsAnyMemberPresent = true; |
148 | 0 |
|
149 | 0 | if (!isNull) { |
150 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->referrer_id, temp.ptr())) { |
151 | 0 | return false; |
152 | 0 | } |
153 | 0 | } |
154 | 0 | if (!isNull && !temp->isUndefined()) { |
155 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mReferrer)) { |
156 | 0 | return false; |
157 | 0 | } |
158 | 0 | } else { |
159 | 0 | static const char16_t data[] = { 0 }; |
160 | 0 | mReferrer.Rebind(data, ArrayLength(data) - 1); |
161 | 0 | } |
162 | 0 | mIsAnyMemberPresent = true; |
163 | 0 |
|
164 | 0 | if (!isNull) { |
165 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->script_sample_id, temp.ptr())) { |
166 | 0 | return false; |
167 | 0 | } |
168 | 0 | } |
169 | 0 | if (!isNull && !temp->isUndefined()) { |
170 | 0 | mScript_sample.Construct(); |
171 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mScript_sample.Value()))) { |
172 | 0 | return false; |
173 | 0 | } |
174 | 0 | mIsAnyMemberPresent = true; |
175 | 0 | } |
176 | 0 |
|
177 | 0 | if (!isNull) { |
178 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->source_file_id, temp.ptr())) { |
179 | 0 | return false; |
180 | 0 | } |
181 | 0 | } |
182 | 0 | if (!isNull && !temp->isUndefined()) { |
183 | 0 | mSource_file.Construct(); |
184 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mSource_file.Value()))) { |
185 | 0 | return false; |
186 | 0 | } |
187 | 0 | mIsAnyMemberPresent = true; |
188 | 0 | } |
189 | 0 |
|
190 | 0 | if (!isNull) { |
191 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->violated_directive_id, temp.ptr())) { |
192 | 0 | return false; |
193 | 0 | } |
194 | 0 | } |
195 | 0 | if (!isNull && !temp->isUndefined()) { |
196 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mViolated_directive)) { |
197 | 0 | return false; |
198 | 0 | } |
199 | 0 | } else { |
200 | 0 | static const char16_t data[] = { 0 }; |
201 | 0 | mViolated_directive.Rebind(data, ArrayLength(data) - 1); |
202 | 0 | } |
203 | 0 | mIsAnyMemberPresent = true; |
204 | 0 | return true; |
205 | 0 | } |
206 | | |
207 | | bool |
208 | | CSPReportProperties::Init(const nsAString& aJSON) |
209 | 0 | { |
210 | 0 | AutoJSAPI jsapi; |
211 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
212 | 0 | if (!cleanGlobal) { |
213 | 0 | return false; |
214 | 0 | } |
215 | 0 | if (!jsapi.Init(cleanGlobal)) { |
216 | 0 | return false; |
217 | 0 | } |
218 | 0 | JSContext* cx = jsapi.cx(); |
219 | 0 | JS::Rooted<JS::Value> json(cx); |
220 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
221 | 0 | NS_ENSURE_TRUE(ok, false); |
222 | 0 | return Init(cx, json); |
223 | 0 | } |
224 | | |
225 | | bool |
226 | | CSPReportProperties::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
227 | 0 | { |
228 | 0 | CSPReportPropertiesAtoms* atomsCache = GetAtomCache<CSPReportPropertiesAtoms>(cx); |
229 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
230 | 0 | return false; |
231 | 0 | } |
232 | 0 | |
233 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
234 | 0 | if (!obj) { |
235 | 0 | return false; |
236 | 0 | } |
237 | 0 | rval.set(JS::ObjectValue(*obj)); |
238 | 0 |
|
239 | 0 | do { |
240 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
241 | 0 | JS::Rooted<JS::Value> temp(cx); |
242 | 0 | nsString const & currentValue = mBlocked_uri; |
243 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
244 | 0 | return false; |
245 | 0 | } |
246 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->blocked_uri_id, temp, JSPROP_ENUMERATE)) { |
247 | 0 | return false; |
248 | 0 | } |
249 | 0 | break; |
250 | 0 | } while(false); |
251 | 0 |
|
252 | 0 | if (mColumn_number.WasPassed()) { |
253 | 0 | do { |
254 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
255 | 0 | JS::Rooted<JS::Value> temp(cx); |
256 | 0 | int32_t const & currentValue = mColumn_number.InternalValue(); |
257 | 0 | temp.setInt32(int32_t(currentValue)); |
258 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->column_number_id, temp, JSPROP_ENUMERATE)) { |
259 | 0 | return false; |
260 | 0 | } |
261 | 0 | break; |
262 | 0 | } while(false); |
263 | 0 | } |
264 | 0 |
|
265 | 0 | do { |
266 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
267 | 0 | JS::Rooted<JS::Value> temp(cx); |
268 | 0 | nsString const & currentValue = mDocument_uri; |
269 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
270 | 0 | return false; |
271 | 0 | } |
272 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->document_uri_id, temp, JSPROP_ENUMERATE)) { |
273 | 0 | return false; |
274 | 0 | } |
275 | 0 | break; |
276 | 0 | } while(false); |
277 | 0 |
|
278 | 0 | if (mLine_number.WasPassed()) { |
279 | 0 | do { |
280 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
281 | 0 | JS::Rooted<JS::Value> temp(cx); |
282 | 0 | int32_t const & currentValue = mLine_number.InternalValue(); |
283 | 0 | temp.setInt32(int32_t(currentValue)); |
284 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->line_number_id, temp, JSPROP_ENUMERATE)) { |
285 | 0 | return false; |
286 | 0 | } |
287 | 0 | break; |
288 | 0 | } while(false); |
289 | 0 | } |
290 | 0 |
|
291 | 0 | do { |
292 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
293 | 0 | JS::Rooted<JS::Value> temp(cx); |
294 | 0 | nsString const & currentValue = mOriginal_policy; |
295 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
296 | 0 | return false; |
297 | 0 | } |
298 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->original_policy_id, temp, JSPROP_ENUMERATE)) { |
299 | 0 | return false; |
300 | 0 | } |
301 | 0 | break; |
302 | 0 | } while(false); |
303 | 0 |
|
304 | 0 | do { |
305 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
306 | 0 | JS::Rooted<JS::Value> temp(cx); |
307 | 0 | nsString const & currentValue = mReferrer; |
308 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
309 | 0 | return false; |
310 | 0 | } |
311 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->referrer_id, temp, JSPROP_ENUMERATE)) { |
312 | 0 | return false; |
313 | 0 | } |
314 | 0 | break; |
315 | 0 | } while(false); |
316 | 0 |
|
317 | 0 | if (mScript_sample.WasPassed()) { |
318 | 0 | do { |
319 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
320 | 0 | JS::Rooted<JS::Value> temp(cx); |
321 | 0 | nsString const & currentValue = mScript_sample.InternalValue(); |
322 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
323 | 0 | return false; |
324 | 0 | } |
325 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->script_sample_id, temp, JSPROP_ENUMERATE)) { |
326 | 0 | return false; |
327 | 0 | } |
328 | 0 | break; |
329 | 0 | } while(false); |
330 | 0 | } |
331 | 0 |
|
332 | 0 | if (mSource_file.WasPassed()) { |
333 | 0 | do { |
334 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
335 | 0 | JS::Rooted<JS::Value> temp(cx); |
336 | 0 | nsString const & currentValue = mSource_file.InternalValue(); |
337 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
338 | 0 | return false; |
339 | 0 | } |
340 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->source_file_id, temp, JSPROP_ENUMERATE)) { |
341 | 0 | return false; |
342 | 0 | } |
343 | 0 | break; |
344 | 0 | } while(false); |
345 | 0 | } |
346 | 0 |
|
347 | 0 | do { |
348 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
349 | 0 | JS::Rooted<JS::Value> temp(cx); |
350 | 0 | nsString const & currentValue = mViolated_directive; |
351 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
352 | 0 | return false; |
353 | 0 | } |
354 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->violated_directive_id, temp, JSPROP_ENUMERATE)) { |
355 | 0 | return false; |
356 | 0 | } |
357 | 0 | break; |
358 | 0 | } while(false); |
359 | 0 |
|
360 | 0 | return true; |
361 | 0 | } |
362 | | |
363 | | bool |
364 | | CSPReportProperties::ToJSON(nsAString& aJSON) const |
365 | 0 | { |
366 | 0 | AutoJSAPI jsapi; |
367 | 0 | jsapi.Init(); |
368 | 0 | JSContext *cx = jsapi.cx(); |
369 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
370 | 0 | // because we'll only be creating objects, in ways that have no |
371 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
372 | 0 | // which likewise guarantees no side-effects for the sorts of |
373 | 0 | // things we will pass it. |
374 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
375 | 0 | JS::Rooted<JS::Value> val(cx); |
376 | 0 | if (!ToObjectInternal(cx, &val)) { |
377 | 0 | return false; |
378 | 0 | } |
379 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
380 | 0 | return StringifyToJSON(cx, obj, aJSON); |
381 | 0 | } |
382 | | |
383 | | void |
384 | | CSPReportProperties::TraceDictionary(JSTracer* trc) |
385 | 0 | { |
386 | 0 | } |
387 | | |
388 | | CSPReportProperties& |
389 | | CSPReportProperties::operator=(const CSPReportProperties& aOther) |
390 | 0 | { |
391 | 0 | DictionaryBase::operator=(aOther); |
392 | 0 | mBlocked_uri = aOther.mBlocked_uri; |
393 | 0 | mColumn_number.Reset(); |
394 | 0 | if (aOther.mColumn_number.WasPassed()) { |
395 | 0 | mColumn_number.Construct(aOther.mColumn_number.Value()); |
396 | 0 | } |
397 | 0 | mDocument_uri = aOther.mDocument_uri; |
398 | 0 | mLine_number.Reset(); |
399 | 0 | if (aOther.mLine_number.WasPassed()) { |
400 | 0 | mLine_number.Construct(aOther.mLine_number.Value()); |
401 | 0 | } |
402 | 0 | mOriginal_policy = aOther.mOriginal_policy; |
403 | 0 | mReferrer = aOther.mReferrer; |
404 | 0 | mScript_sample.Reset(); |
405 | 0 | if (aOther.mScript_sample.WasPassed()) { |
406 | 0 | mScript_sample.Construct(aOther.mScript_sample.Value()); |
407 | 0 | } |
408 | 0 | mSource_file.Reset(); |
409 | 0 | if (aOther.mSource_file.WasPassed()) { |
410 | 0 | mSource_file.Construct(aOther.mSource_file.Value()); |
411 | 0 | } |
412 | 0 | mViolated_directive = aOther.mViolated_directive; |
413 | 0 | return *this; |
414 | 0 | } |
415 | | |
416 | | namespace binding_detail { |
417 | | } // namespace binding_detail |
418 | | |
419 | | |
420 | | |
421 | | CSPReport::CSPReport() |
422 | | : mCsp_report(FastDictionaryInitializer()) |
423 | 0 | { |
424 | 0 | // Safe to pass a null context if we pass a null value |
425 | 0 | Init(nullptr, JS::NullHandleValue); |
426 | 0 | } |
427 | | |
428 | | |
429 | | |
430 | | bool |
431 | | CSPReport::InitIds(JSContext* cx, CSPReportAtoms* atomsCache) |
432 | 0 | { |
433 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
434 | 0 |
|
435 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
436 | 0 | // uninitialized. |
437 | 0 | if (!atomsCache->csp_report_id.init(cx, "csp-report")) { |
438 | 0 | return false; |
439 | 0 | } |
440 | 0 | return true; |
441 | 0 | } |
442 | | |
443 | | bool |
444 | | CSPReport::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
445 | 0 | { |
446 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
447 | 0 | // Since in that case we will not have to do any property gets |
448 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
449 | 0 | // checkers by static analysis tools |
450 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
451 | 0 | CSPReportAtoms* atomsCache = nullptr; |
452 | 0 | if (cx) { |
453 | 0 | atomsCache = GetAtomCache<CSPReportAtoms>(cx); |
454 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
455 | 0 | return false; |
456 | 0 | } |
457 | 0 | } |
458 | 0 | |
459 | 0 | if (!IsConvertibleToDictionary(val)) { |
460 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
461 | 0 | } |
462 | 0 | |
463 | 0 | bool isNull = val.isNullOrUndefined(); |
464 | 0 | // We only need these if !isNull, in which case we have |cx|. |
465 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
466 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
467 | 0 | if (!isNull) { |
468 | 0 | MOZ_ASSERT(cx); |
469 | 0 | object.emplace(cx, &val.toObject()); |
470 | 0 | temp.emplace(cx); |
471 | 0 | } |
472 | 0 | if (!isNull) { |
473 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->csp_report_id, temp.ptr())) { |
474 | 0 | return false; |
475 | 0 | } |
476 | 0 | } |
477 | 0 | if (!mCsp_report.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'csp-report' member of CSPReport", passedToJSImpl)) { |
478 | 0 | return false; |
479 | 0 | } |
480 | 0 | mIsAnyMemberPresent = true; |
481 | 0 | return true; |
482 | 0 | } |
483 | | |
484 | | bool |
485 | | CSPReport::Init(const nsAString& aJSON) |
486 | 0 | { |
487 | 0 | AutoJSAPI jsapi; |
488 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
489 | 0 | if (!cleanGlobal) { |
490 | 0 | return false; |
491 | 0 | } |
492 | 0 | if (!jsapi.Init(cleanGlobal)) { |
493 | 0 | return false; |
494 | 0 | } |
495 | 0 | JSContext* cx = jsapi.cx(); |
496 | 0 | JS::Rooted<JS::Value> json(cx); |
497 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
498 | 0 | NS_ENSURE_TRUE(ok, false); |
499 | 0 | return Init(cx, json); |
500 | 0 | } |
501 | | |
502 | | bool |
503 | | CSPReport::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
504 | 0 | { |
505 | 0 | CSPReportAtoms* atomsCache = GetAtomCache<CSPReportAtoms>(cx); |
506 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
507 | 0 | return false; |
508 | 0 | } |
509 | 0 | |
510 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
511 | 0 | if (!obj) { |
512 | 0 | return false; |
513 | 0 | } |
514 | 0 | rval.set(JS::ObjectValue(*obj)); |
515 | 0 |
|
516 | 0 | do { |
517 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
518 | 0 | JS::Rooted<JS::Value> temp(cx); |
519 | 0 | CSPReportProperties const & currentValue = mCsp_report; |
520 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
521 | 0 | return false; |
522 | 0 | } |
523 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->csp_report_id, temp, JSPROP_ENUMERATE)) { |
524 | 0 | return false; |
525 | 0 | } |
526 | 0 | break; |
527 | 0 | } while(false); |
528 | 0 |
|
529 | 0 | return true; |
530 | 0 | } |
531 | | |
532 | | bool |
533 | | CSPReport::ToJSON(nsAString& aJSON) const |
534 | 0 | { |
535 | 0 | AutoJSAPI jsapi; |
536 | 0 | jsapi.Init(); |
537 | 0 | JSContext *cx = jsapi.cx(); |
538 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
539 | 0 | // because we'll only be creating objects, in ways that have no |
540 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
541 | 0 | // which likewise guarantees no side-effects for the sorts of |
542 | 0 | // things we will pass it. |
543 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
544 | 0 | JS::Rooted<JS::Value> val(cx); |
545 | 0 | if (!ToObjectInternal(cx, &val)) { |
546 | 0 | return false; |
547 | 0 | } |
548 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
549 | 0 | return StringifyToJSON(cx, obj, aJSON); |
550 | 0 | } |
551 | | |
552 | | void |
553 | | CSPReport::TraceDictionary(JSTracer* trc) |
554 | 0 | { |
555 | 0 | } |
556 | | |
557 | | CSPReport& |
558 | | CSPReport::operator=(const CSPReport& aOther) |
559 | 0 | { |
560 | 0 | DictionaryBase::operator=(aOther); |
561 | 0 | mCsp_report = aOther.mCsp_report; |
562 | 0 | return *this; |
563 | 0 | } |
564 | | |
565 | | namespace binding_detail { |
566 | | } // namespace binding_detail |
567 | | |
568 | | |
569 | | } // namespace dom |
570 | | } // namespace mozilla |