/work/obj-fuzz/dom/bindings/SecurityPolicyViolationEventBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM SecurityPolicyViolationEvent.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "EventBinding.h" |
5 | | #include "SecurityPolicyViolationEventBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "jsapi.h" |
8 | | #include "mozilla/OwningNonNull.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/SecurityPolicyViolationEvent.h" |
15 | | #include "mozilla/dom/SimpleGlobalObject.h" |
16 | | #include "mozilla/dom/XrayExpandoClass.h" |
17 | | |
18 | | namespace mozilla { |
19 | | namespace dom { |
20 | | |
21 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
22 | | using namespace mozilla::dom::binding_detail; |
23 | | |
24 | | |
25 | | namespace SecurityPolicyViolationEventDispositionValues { |
26 | | extern const EnumEntry strings[3] = { |
27 | | {"enforce", 7}, |
28 | | {"report", 6}, |
29 | | { nullptr, 0 } |
30 | | }; |
31 | | } // namespace SecurityPolicyViolationEventDispositionValues |
32 | | |
33 | | bool |
34 | | ToJSValue(JSContext* aCx, SecurityPolicyViolationEventDisposition aArgument, JS::MutableHandle<JS::Value> aValue) |
35 | 0 | { |
36 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(SecurityPolicyViolationEventDispositionValues::strings)); |
37 | 0 | JSString* resultStr = |
38 | 0 | JS_NewStringCopyN(aCx, SecurityPolicyViolationEventDispositionValues::strings[uint32_t(aArgument)].value, |
39 | 0 | SecurityPolicyViolationEventDispositionValues::strings[uint32_t(aArgument)].length); |
40 | 0 | if (!resultStr) { |
41 | 0 | return false; |
42 | 0 | } |
43 | 0 | aValue.setString(resultStr); |
44 | 0 | return true; |
45 | 0 | } |
46 | | |
47 | | |
48 | | |
49 | | SecurityPolicyViolationEventInit::SecurityPolicyViolationEventInit() |
50 | | : EventInit(FastDictionaryInitializer()) |
51 | 0 | { |
52 | 0 | // Safe to pass a null context if we pass a null value |
53 | 0 | Init(nullptr, JS::NullHandleValue); |
54 | 0 | } |
55 | | |
56 | | |
57 | | |
58 | | bool |
59 | | SecurityPolicyViolationEventInit::InitIds(JSContext* cx, SecurityPolicyViolationEventInitAtoms* atomsCache) |
60 | 0 | { |
61 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
62 | 0 |
|
63 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
64 | 0 | // uninitialized. |
65 | 0 | if (!atomsCache->violatedDirective_id.init(cx, "violatedDirective") || |
66 | 0 | !atomsCache->statusCode_id.init(cx, "statusCode") || |
67 | 0 | !atomsCache->sourceFile_id.init(cx, "sourceFile") || |
68 | 0 | !atomsCache->sample_id.init(cx, "sample") || |
69 | 0 | !atomsCache->referrer_id.init(cx, "referrer") || |
70 | 0 | !atomsCache->originalPolicy_id.init(cx, "originalPolicy") || |
71 | 0 | !atomsCache->lineNumber_id.init(cx, "lineNumber") || |
72 | 0 | !atomsCache->effectiveDirective_id.init(cx, "effectiveDirective") || |
73 | 0 | !atomsCache->documentURI_id.init(cx, "documentURI") || |
74 | 0 | !atomsCache->disposition_id.init(cx, "disposition") || |
75 | 0 | !atomsCache->columnNumber_id.init(cx, "columnNumber") || |
76 | 0 | !atomsCache->blockedURI_id.init(cx, "blockedURI")) { |
77 | 0 | return false; |
78 | 0 | } |
79 | 0 | return true; |
80 | 0 | } |
81 | | |
82 | | bool |
83 | | SecurityPolicyViolationEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
84 | 0 | { |
85 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
86 | 0 | // Since in that case we will not have to do any property gets |
87 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
88 | 0 | // checkers by static analysis tools |
89 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
90 | 0 | SecurityPolicyViolationEventInitAtoms* atomsCache = nullptr; |
91 | 0 | if (cx) { |
92 | 0 | atomsCache = GetAtomCache<SecurityPolicyViolationEventInitAtoms>(cx); |
93 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
94 | 0 | return false; |
95 | 0 | } |
96 | 0 | } |
97 | 0 | |
98 | 0 | // Per spec, we init the parent's members first |
99 | 0 | if (!EventInit::Init(cx, val)) { |
100 | 0 | return false; |
101 | 0 | } |
102 | 0 | |
103 | 0 | bool isNull = val.isNullOrUndefined(); |
104 | 0 | // We only need these if !isNull, in which case we have |cx|. |
105 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
106 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
107 | 0 | if (!isNull) { |
108 | 0 | MOZ_ASSERT(cx); |
109 | 0 | object.emplace(cx, &val.toObject()); |
110 | 0 | temp.emplace(cx); |
111 | 0 | } |
112 | 0 | if (!isNull) { |
113 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->blockedURI_id, temp.ptr())) { |
114 | 0 | return false; |
115 | 0 | } |
116 | 0 | } |
117 | 0 | if (!isNull && !temp->isUndefined()) { |
118 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mBlockedURI)) { |
119 | 0 | return false; |
120 | 0 | } |
121 | 0 | } else { |
122 | 0 | static const char16_t data[] = { 0 }; |
123 | 0 | mBlockedURI.Rebind(data, ArrayLength(data) - 1); |
124 | 0 | } |
125 | 0 | mIsAnyMemberPresent = true; |
126 | 0 |
|
127 | 0 | if (!isNull) { |
128 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->columnNumber_id, temp.ptr())) { |
129 | 0 | return false; |
130 | 0 | } |
131 | 0 | } |
132 | 0 | if (!isNull && !temp->isUndefined()) { |
133 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mColumnNumber)) { |
134 | 0 | return false; |
135 | 0 | } |
136 | 0 | } else { |
137 | 0 | mColumnNumber = 0; |
138 | 0 | } |
139 | 0 | mIsAnyMemberPresent = true; |
140 | 0 |
|
141 | 0 | if (!isNull) { |
142 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->disposition_id, temp.ptr())) { |
143 | 0 | return false; |
144 | 0 | } |
145 | 0 | } |
146 | 0 | if (!isNull && !temp->isUndefined()) { |
147 | 0 | { |
148 | 0 | int index; |
149 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), SecurityPolicyViolationEventDispositionValues::strings, "SecurityPolicyViolationEventDisposition", "'disposition' member of SecurityPolicyViolationEventInit", &index)) { |
150 | 0 | return false; |
151 | 0 | } |
152 | 0 | MOZ_ASSERT(index >= 0); |
153 | 0 | mDisposition = static_cast<SecurityPolicyViolationEventDisposition>(index); |
154 | 0 | } |
155 | 0 | } else { |
156 | 0 | mDisposition = SecurityPolicyViolationEventDisposition::Report; |
157 | 0 | } |
158 | 0 | mIsAnyMemberPresent = true; |
159 | 0 |
|
160 | 0 | if (!isNull) { |
161 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->documentURI_id, temp.ptr())) { |
162 | 0 | return false; |
163 | 0 | } |
164 | 0 | } |
165 | 0 | if (!isNull && !temp->isUndefined()) { |
166 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDocumentURI)) { |
167 | 0 | return false; |
168 | 0 | } |
169 | 0 | } else { |
170 | 0 | static const char16_t data[] = { 0 }; |
171 | 0 | mDocumentURI.Rebind(data, ArrayLength(data) - 1); |
172 | 0 | } |
173 | 0 | mIsAnyMemberPresent = true; |
174 | 0 |
|
175 | 0 | if (!isNull) { |
176 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->effectiveDirective_id, temp.ptr())) { |
177 | 0 | return false; |
178 | 0 | } |
179 | 0 | } |
180 | 0 | if (!isNull && !temp->isUndefined()) { |
181 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mEffectiveDirective)) { |
182 | 0 | return false; |
183 | 0 | } |
184 | 0 | } else { |
185 | 0 | static const char16_t data[] = { 0 }; |
186 | 0 | mEffectiveDirective.Rebind(data, ArrayLength(data) - 1); |
187 | 0 | } |
188 | 0 | mIsAnyMemberPresent = true; |
189 | 0 |
|
190 | 0 | if (!isNull) { |
191 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->lineNumber_id, temp.ptr())) { |
192 | 0 | return false; |
193 | 0 | } |
194 | 0 | } |
195 | 0 | if (!isNull && !temp->isUndefined()) { |
196 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mLineNumber)) { |
197 | 0 | return false; |
198 | 0 | } |
199 | 0 | } else { |
200 | 0 | mLineNumber = 0; |
201 | 0 | } |
202 | 0 | mIsAnyMemberPresent = true; |
203 | 0 |
|
204 | 0 | if (!isNull) { |
205 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->originalPolicy_id, temp.ptr())) { |
206 | 0 | return false; |
207 | 0 | } |
208 | 0 | } |
209 | 0 | if (!isNull && !temp->isUndefined()) { |
210 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mOriginalPolicy)) { |
211 | 0 | return false; |
212 | 0 | } |
213 | 0 | } else { |
214 | 0 | static const char16_t data[] = { 0 }; |
215 | 0 | mOriginalPolicy.Rebind(data, ArrayLength(data) - 1); |
216 | 0 | } |
217 | 0 | mIsAnyMemberPresent = true; |
218 | 0 |
|
219 | 0 | if (!isNull) { |
220 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->referrer_id, temp.ptr())) { |
221 | 0 | return false; |
222 | 0 | } |
223 | 0 | } |
224 | 0 | if (!isNull && !temp->isUndefined()) { |
225 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mReferrer)) { |
226 | 0 | return false; |
227 | 0 | } |
228 | 0 | } else { |
229 | 0 | static const char16_t data[] = { 0 }; |
230 | 0 | mReferrer.Rebind(data, ArrayLength(data) - 1); |
231 | 0 | } |
232 | 0 | mIsAnyMemberPresent = true; |
233 | 0 |
|
234 | 0 | if (!isNull) { |
235 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->sample_id, temp.ptr())) { |
236 | 0 | return false; |
237 | 0 | } |
238 | 0 | } |
239 | 0 | if (!isNull && !temp->isUndefined()) { |
240 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mSample)) { |
241 | 0 | return false; |
242 | 0 | } |
243 | 0 | } else { |
244 | 0 | static const char16_t data[] = { 0 }; |
245 | 0 | mSample.Rebind(data, ArrayLength(data) - 1); |
246 | 0 | } |
247 | 0 | mIsAnyMemberPresent = true; |
248 | 0 |
|
249 | 0 | if (!isNull) { |
250 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->sourceFile_id, temp.ptr())) { |
251 | 0 | return false; |
252 | 0 | } |
253 | 0 | } |
254 | 0 | if (!isNull && !temp->isUndefined()) { |
255 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mSourceFile)) { |
256 | 0 | return false; |
257 | 0 | } |
258 | 0 | } else { |
259 | 0 | static const char16_t data[] = { 0 }; |
260 | 0 | mSourceFile.Rebind(data, ArrayLength(data) - 1); |
261 | 0 | } |
262 | 0 | mIsAnyMemberPresent = true; |
263 | 0 |
|
264 | 0 | if (!isNull) { |
265 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->statusCode_id, temp.ptr())) { |
266 | 0 | return false; |
267 | 0 | } |
268 | 0 | } |
269 | 0 | if (!isNull && !temp->isUndefined()) { |
270 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &mStatusCode)) { |
271 | 0 | return false; |
272 | 0 | } |
273 | 0 | } else { |
274 | 0 | mStatusCode = 0; |
275 | 0 | } |
276 | 0 | mIsAnyMemberPresent = true; |
277 | 0 |
|
278 | 0 | if (!isNull) { |
279 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->violatedDirective_id, temp.ptr())) { |
280 | 0 | return false; |
281 | 0 | } |
282 | 0 | } |
283 | 0 | if (!isNull && !temp->isUndefined()) { |
284 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mViolatedDirective)) { |
285 | 0 | return false; |
286 | 0 | } |
287 | 0 | } else { |
288 | 0 | static const char16_t data[] = { 0 }; |
289 | 0 | mViolatedDirective.Rebind(data, ArrayLength(data) - 1); |
290 | 0 | } |
291 | 0 | mIsAnyMemberPresent = true; |
292 | 0 | return true; |
293 | 0 | } |
294 | | |
295 | | bool |
296 | | SecurityPolicyViolationEventInit::Init(const nsAString& aJSON) |
297 | 0 | { |
298 | 0 | AutoJSAPI jsapi; |
299 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
300 | 0 | if (!cleanGlobal) { |
301 | 0 | return false; |
302 | 0 | } |
303 | 0 | if (!jsapi.Init(cleanGlobal)) { |
304 | 0 | return false; |
305 | 0 | } |
306 | 0 | JSContext* cx = jsapi.cx(); |
307 | 0 | JS::Rooted<JS::Value> json(cx); |
308 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
309 | 0 | NS_ENSURE_TRUE(ok, false); |
310 | 0 | return Init(cx, json); |
311 | 0 | } |
312 | | |
313 | | bool |
314 | | SecurityPolicyViolationEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
315 | 0 | { |
316 | 0 | SecurityPolicyViolationEventInitAtoms* atomsCache = GetAtomCache<SecurityPolicyViolationEventInitAtoms>(cx); |
317 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
318 | 0 | return false; |
319 | 0 | } |
320 | 0 | |
321 | 0 | // Per spec, we define the parent's members first |
322 | 0 | if (!EventInit::ToObjectInternal(cx, rval)) { |
323 | 0 | return false; |
324 | 0 | } |
325 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
326 | 0 |
|
327 | 0 | do { |
328 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
329 | 0 | JS::Rooted<JS::Value> temp(cx); |
330 | 0 | nsString const & currentValue = mBlockedURI; |
331 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
332 | 0 | return false; |
333 | 0 | } |
334 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->blockedURI_id, temp, JSPROP_ENUMERATE)) { |
335 | 0 | return false; |
336 | 0 | } |
337 | 0 | break; |
338 | 0 | } while(false); |
339 | 0 |
|
340 | 0 | do { |
341 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
342 | 0 | JS::Rooted<JS::Value> temp(cx); |
343 | 0 | int32_t const & currentValue = mColumnNumber; |
344 | 0 | temp.setInt32(int32_t(currentValue)); |
345 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->columnNumber_id, temp, JSPROP_ENUMERATE)) { |
346 | 0 | return false; |
347 | 0 | } |
348 | 0 | break; |
349 | 0 | } while(false); |
350 | 0 |
|
351 | 0 | do { |
352 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
353 | 0 | JS::Rooted<JS::Value> temp(cx); |
354 | 0 | SecurityPolicyViolationEventDisposition const & currentValue = mDisposition; |
355 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
356 | 0 | return false; |
357 | 0 | } |
358 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->disposition_id, temp, JSPROP_ENUMERATE)) { |
359 | 0 | return false; |
360 | 0 | } |
361 | 0 | break; |
362 | 0 | } while(false); |
363 | 0 |
|
364 | 0 | do { |
365 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
366 | 0 | JS::Rooted<JS::Value> temp(cx); |
367 | 0 | nsString const & currentValue = mDocumentURI; |
368 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
369 | 0 | return false; |
370 | 0 | } |
371 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->documentURI_id, temp, JSPROP_ENUMERATE)) { |
372 | 0 | return false; |
373 | 0 | } |
374 | 0 | break; |
375 | 0 | } while(false); |
376 | 0 |
|
377 | 0 | do { |
378 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
379 | 0 | JS::Rooted<JS::Value> temp(cx); |
380 | 0 | nsString const & currentValue = mEffectiveDirective; |
381 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
382 | 0 | return false; |
383 | 0 | } |
384 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->effectiveDirective_id, temp, JSPROP_ENUMERATE)) { |
385 | 0 | return false; |
386 | 0 | } |
387 | 0 | break; |
388 | 0 | } while(false); |
389 | 0 |
|
390 | 0 | do { |
391 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
392 | 0 | JS::Rooted<JS::Value> temp(cx); |
393 | 0 | int32_t const & currentValue = mLineNumber; |
394 | 0 | temp.setInt32(int32_t(currentValue)); |
395 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->lineNumber_id, temp, JSPROP_ENUMERATE)) { |
396 | 0 | return false; |
397 | 0 | } |
398 | 0 | break; |
399 | 0 | } while(false); |
400 | 0 |
|
401 | 0 | do { |
402 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
403 | 0 | JS::Rooted<JS::Value> temp(cx); |
404 | 0 | nsString const & currentValue = mOriginalPolicy; |
405 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
406 | 0 | return false; |
407 | 0 | } |
408 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->originalPolicy_id, temp, JSPROP_ENUMERATE)) { |
409 | 0 | return false; |
410 | 0 | } |
411 | 0 | break; |
412 | 0 | } while(false); |
413 | 0 |
|
414 | 0 | do { |
415 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
416 | 0 | JS::Rooted<JS::Value> temp(cx); |
417 | 0 | nsString const & currentValue = mReferrer; |
418 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
419 | 0 | return false; |
420 | 0 | } |
421 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->referrer_id, temp, JSPROP_ENUMERATE)) { |
422 | 0 | return false; |
423 | 0 | } |
424 | 0 | break; |
425 | 0 | } while(false); |
426 | 0 |
|
427 | 0 | do { |
428 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
429 | 0 | JS::Rooted<JS::Value> temp(cx); |
430 | 0 | nsString const & currentValue = mSample; |
431 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
432 | 0 | return false; |
433 | 0 | } |
434 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->sample_id, temp, JSPROP_ENUMERATE)) { |
435 | 0 | return false; |
436 | 0 | } |
437 | 0 | break; |
438 | 0 | } while(false); |
439 | 0 |
|
440 | 0 | do { |
441 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
442 | 0 | JS::Rooted<JS::Value> temp(cx); |
443 | 0 | nsString const & currentValue = mSourceFile; |
444 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
445 | 0 | return false; |
446 | 0 | } |
447 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->sourceFile_id, temp, JSPROP_ENUMERATE)) { |
448 | 0 | return false; |
449 | 0 | } |
450 | 0 | break; |
451 | 0 | } while(false); |
452 | 0 |
|
453 | 0 | do { |
454 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
455 | 0 | JS::Rooted<JS::Value> temp(cx); |
456 | 0 | uint16_t const & currentValue = mStatusCode; |
457 | 0 | temp.setInt32(int32_t(currentValue)); |
458 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->statusCode_id, temp, JSPROP_ENUMERATE)) { |
459 | 0 | return false; |
460 | 0 | } |
461 | 0 | break; |
462 | 0 | } while(false); |
463 | 0 |
|
464 | 0 | do { |
465 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
466 | 0 | JS::Rooted<JS::Value> temp(cx); |
467 | 0 | nsString const & currentValue = mViolatedDirective; |
468 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
469 | 0 | return false; |
470 | 0 | } |
471 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->violatedDirective_id, temp, JSPROP_ENUMERATE)) { |
472 | 0 | return false; |
473 | 0 | } |
474 | 0 | break; |
475 | 0 | } while(false); |
476 | 0 |
|
477 | 0 | return true; |
478 | 0 | } |
479 | | |
480 | | bool |
481 | | SecurityPolicyViolationEventInit::ToJSON(nsAString& aJSON) const |
482 | 0 | { |
483 | 0 | AutoJSAPI jsapi; |
484 | 0 | jsapi.Init(); |
485 | 0 | JSContext *cx = jsapi.cx(); |
486 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
487 | 0 | // because we'll only be creating objects, in ways that have no |
488 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
489 | 0 | // which likewise guarantees no side-effects for the sorts of |
490 | 0 | // things we will pass it. |
491 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
492 | 0 | JS::Rooted<JS::Value> val(cx); |
493 | 0 | if (!ToObjectInternal(cx, &val)) { |
494 | 0 | return false; |
495 | 0 | } |
496 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
497 | 0 | return StringifyToJSON(cx, obj, aJSON); |
498 | 0 | } |
499 | | |
500 | | void |
501 | | SecurityPolicyViolationEventInit::TraceDictionary(JSTracer* trc) |
502 | 0 | { |
503 | 0 | EventInit::TraceDictionary(trc); |
504 | 0 | } |
505 | | |
506 | | SecurityPolicyViolationEventInit& |
507 | | SecurityPolicyViolationEventInit::operator=(const SecurityPolicyViolationEventInit& aOther) |
508 | 0 | { |
509 | 0 | EventInit::operator=(aOther); |
510 | 0 | mBlockedURI = aOther.mBlockedURI; |
511 | 0 | mColumnNumber = aOther.mColumnNumber; |
512 | 0 | mDisposition = aOther.mDisposition; |
513 | 0 | mDocumentURI = aOther.mDocumentURI; |
514 | 0 | mEffectiveDirective = aOther.mEffectiveDirective; |
515 | 0 | mLineNumber = aOther.mLineNumber; |
516 | 0 | mOriginalPolicy = aOther.mOriginalPolicy; |
517 | 0 | mReferrer = aOther.mReferrer; |
518 | 0 | mSample = aOther.mSample; |
519 | 0 | mSourceFile = aOther.mSourceFile; |
520 | 0 | mStatusCode = aOther.mStatusCode; |
521 | 0 | mViolatedDirective = aOther.mViolatedDirective; |
522 | 0 | return *this; |
523 | 0 | } |
524 | | |
525 | | namespace binding_detail { |
526 | | } // namespace binding_detail |
527 | | |
528 | | |
529 | | namespace SecurityPolicyViolationEvent_Binding { |
530 | | |
531 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Event_Binding::NativeType>::value, |
532 | | "Can't inherit from an interface with a different ownership model."); |
533 | | |
534 | | MOZ_CAN_RUN_SCRIPT static bool |
535 | | get_documentURI(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
536 | 0 | { |
537 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.documentURI", DOM, cx); |
538 | 0 |
|
539 | 0 | DOMString result; |
540 | 0 | self->GetDocumentURI(result); |
541 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
542 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
543 | 0 | return false; |
544 | 0 | } |
545 | 0 | return true; |
546 | 0 | } |
547 | | |
548 | | static const JSJitInfo documentURI_getterinfo = { |
549 | | { (JSJitGetterOp)get_documentURI }, |
550 | | { prototypes::id::SecurityPolicyViolationEvent }, |
551 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
552 | | JSJitInfo::Getter, |
553 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
554 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
555 | | false, /* isInfallible. False in setters. */ |
556 | | false, /* isMovable. Not relevant for setters. */ |
557 | | false, /* isEliminatable. Not relevant for setters. */ |
558 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
559 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
560 | | false, /* isTypedMethod. Only relevant for methods. */ |
561 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
562 | | }; |
563 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
564 | | static_assert(0 < 1, "There is no slot for us"); |
565 | | |
566 | | MOZ_CAN_RUN_SCRIPT static bool |
567 | | get_referrer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
568 | 0 | { |
569 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.referrer", DOM, cx); |
570 | 0 |
|
571 | 0 | DOMString result; |
572 | 0 | self->GetReferrer(result); |
573 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
574 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
575 | 0 | return false; |
576 | 0 | } |
577 | 0 | return true; |
578 | 0 | } |
579 | | |
580 | | static const JSJitInfo referrer_getterinfo = { |
581 | | { (JSJitGetterOp)get_referrer }, |
582 | | { prototypes::id::SecurityPolicyViolationEvent }, |
583 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
584 | | JSJitInfo::Getter, |
585 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
586 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
587 | | false, /* isInfallible. False in setters. */ |
588 | | false, /* isMovable. Not relevant for setters. */ |
589 | | false, /* isEliminatable. Not relevant for setters. */ |
590 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
591 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
592 | | false, /* isTypedMethod. Only relevant for methods. */ |
593 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
594 | | }; |
595 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
596 | | static_assert(0 < 1, "There is no slot for us"); |
597 | | |
598 | | MOZ_CAN_RUN_SCRIPT static bool |
599 | | get_blockedURI(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
600 | 0 | { |
601 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.blockedURI", DOM, cx); |
602 | 0 |
|
603 | 0 | DOMString result; |
604 | 0 | self->GetBlockedURI(result); |
605 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
606 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
607 | 0 | return false; |
608 | 0 | } |
609 | 0 | return true; |
610 | 0 | } |
611 | | |
612 | | static const JSJitInfo blockedURI_getterinfo = { |
613 | | { (JSJitGetterOp)get_blockedURI }, |
614 | | { prototypes::id::SecurityPolicyViolationEvent }, |
615 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
616 | | JSJitInfo::Getter, |
617 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
618 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
619 | | false, /* isInfallible. False in setters. */ |
620 | | false, /* isMovable. Not relevant for setters. */ |
621 | | false, /* isEliminatable. Not relevant for setters. */ |
622 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
623 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
624 | | false, /* isTypedMethod. Only relevant for methods. */ |
625 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
626 | | }; |
627 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
628 | | static_assert(0 < 1, "There is no slot for us"); |
629 | | |
630 | | MOZ_CAN_RUN_SCRIPT static bool |
631 | | get_violatedDirective(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
632 | 0 | { |
633 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.violatedDirective", DOM, cx); |
634 | 0 |
|
635 | 0 | DOMString result; |
636 | 0 | self->GetViolatedDirective(result); |
637 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
638 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
639 | 0 | return false; |
640 | 0 | } |
641 | 0 | return true; |
642 | 0 | } |
643 | | |
644 | | static const JSJitInfo violatedDirective_getterinfo = { |
645 | | { (JSJitGetterOp)get_violatedDirective }, |
646 | | { prototypes::id::SecurityPolicyViolationEvent }, |
647 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
648 | | JSJitInfo::Getter, |
649 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
650 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
651 | | false, /* isInfallible. False in setters. */ |
652 | | false, /* isMovable. Not relevant for setters. */ |
653 | | false, /* isEliminatable. Not relevant for setters. */ |
654 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
655 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
656 | | false, /* isTypedMethod. Only relevant for methods. */ |
657 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
658 | | }; |
659 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
660 | | static_assert(0 < 1, "There is no slot for us"); |
661 | | |
662 | | MOZ_CAN_RUN_SCRIPT static bool |
663 | | get_effectiveDirective(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
664 | 0 | { |
665 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.effectiveDirective", DOM, cx); |
666 | 0 |
|
667 | 0 | DOMString result; |
668 | 0 | self->GetEffectiveDirective(result); |
669 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
670 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
671 | 0 | return false; |
672 | 0 | } |
673 | 0 | return true; |
674 | 0 | } |
675 | | |
676 | | static const JSJitInfo effectiveDirective_getterinfo = { |
677 | | { (JSJitGetterOp)get_effectiveDirective }, |
678 | | { prototypes::id::SecurityPolicyViolationEvent }, |
679 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
680 | | JSJitInfo::Getter, |
681 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
682 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
683 | | false, /* isInfallible. False in setters. */ |
684 | | false, /* isMovable. Not relevant for setters. */ |
685 | | false, /* isEliminatable. Not relevant for setters. */ |
686 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
687 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
688 | | false, /* isTypedMethod. Only relevant for methods. */ |
689 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
690 | | }; |
691 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
692 | | static_assert(0 < 1, "There is no slot for us"); |
693 | | |
694 | | MOZ_CAN_RUN_SCRIPT static bool |
695 | | get_originalPolicy(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
696 | 0 | { |
697 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.originalPolicy", DOM, cx); |
698 | 0 |
|
699 | 0 | DOMString result; |
700 | 0 | self->GetOriginalPolicy(result); |
701 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
702 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
703 | 0 | return false; |
704 | 0 | } |
705 | 0 | return true; |
706 | 0 | } |
707 | | |
708 | | static const JSJitInfo originalPolicy_getterinfo = { |
709 | | { (JSJitGetterOp)get_originalPolicy }, |
710 | | { prototypes::id::SecurityPolicyViolationEvent }, |
711 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
712 | | JSJitInfo::Getter, |
713 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
714 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
715 | | false, /* isInfallible. False in setters. */ |
716 | | false, /* isMovable. Not relevant for setters. */ |
717 | | false, /* isEliminatable. Not relevant for setters. */ |
718 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
719 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
720 | | false, /* isTypedMethod. Only relevant for methods. */ |
721 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
722 | | }; |
723 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
724 | | static_assert(0 < 1, "There is no slot for us"); |
725 | | |
726 | | MOZ_CAN_RUN_SCRIPT static bool |
727 | | get_sourceFile(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
728 | 0 | { |
729 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.sourceFile", DOM, cx); |
730 | 0 |
|
731 | 0 | DOMString result; |
732 | 0 | self->GetSourceFile(result); |
733 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
734 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
735 | 0 | return false; |
736 | 0 | } |
737 | 0 | return true; |
738 | 0 | } |
739 | | |
740 | | static const JSJitInfo sourceFile_getterinfo = { |
741 | | { (JSJitGetterOp)get_sourceFile }, |
742 | | { prototypes::id::SecurityPolicyViolationEvent }, |
743 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
744 | | JSJitInfo::Getter, |
745 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
746 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
747 | | false, /* isInfallible. False in setters. */ |
748 | | false, /* isMovable. Not relevant for setters. */ |
749 | | false, /* isEliminatable. Not relevant for setters. */ |
750 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
751 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
752 | | false, /* isTypedMethod. Only relevant for methods. */ |
753 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
754 | | }; |
755 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
756 | | static_assert(0 < 1, "There is no slot for us"); |
757 | | |
758 | | MOZ_CAN_RUN_SCRIPT static bool |
759 | | get_sample(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
760 | 0 | { |
761 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.sample", DOM, cx); |
762 | 0 |
|
763 | 0 | DOMString result; |
764 | 0 | self->GetSample(result); |
765 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
766 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
767 | 0 | return false; |
768 | 0 | } |
769 | 0 | return true; |
770 | 0 | } |
771 | | |
772 | | static const JSJitInfo sample_getterinfo = { |
773 | | { (JSJitGetterOp)get_sample }, |
774 | | { prototypes::id::SecurityPolicyViolationEvent }, |
775 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
776 | | JSJitInfo::Getter, |
777 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
778 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
779 | | false, /* isInfallible. False in setters. */ |
780 | | false, /* isMovable. Not relevant for setters. */ |
781 | | false, /* isEliminatable. Not relevant for setters. */ |
782 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
783 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
784 | | false, /* isTypedMethod. Only relevant for methods. */ |
785 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
786 | | }; |
787 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
788 | | static_assert(0 < 1, "There is no slot for us"); |
789 | | |
790 | | MOZ_CAN_RUN_SCRIPT static bool |
791 | | get_disposition(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
792 | 0 | { |
793 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.disposition", DOM, cx); |
794 | 0 |
|
795 | 0 | SecurityPolicyViolationEventDisposition result(self->Disposition()); |
796 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
797 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
798 | 0 | return false; |
799 | 0 | } |
800 | 0 | return true; |
801 | 0 | } |
802 | | |
803 | | static const JSJitInfo disposition_getterinfo = { |
804 | | { (JSJitGetterOp)get_disposition }, |
805 | | { prototypes::id::SecurityPolicyViolationEvent }, |
806 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
807 | | JSJitInfo::Getter, |
808 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
809 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
810 | | false, /* isInfallible. False in setters. */ |
811 | | false, /* isMovable. Not relevant for setters. */ |
812 | | false, /* isEliminatable. Not relevant for setters. */ |
813 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
814 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
815 | | false, /* isTypedMethod. Only relevant for methods. */ |
816 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
817 | | }; |
818 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
819 | | static_assert(0 < 1, "There is no slot for us"); |
820 | | |
821 | | MOZ_CAN_RUN_SCRIPT static bool |
822 | | get_statusCode(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
823 | 0 | { |
824 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.statusCode", DOM, cx); |
825 | 0 |
|
826 | 0 | uint16_t result(self->StatusCode()); |
827 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
828 | 0 | args.rval().setInt32(int32_t(result)); |
829 | 0 | return true; |
830 | 0 | } |
831 | | |
832 | | static const JSJitInfo statusCode_getterinfo = { |
833 | | { (JSJitGetterOp)get_statusCode }, |
834 | | { prototypes::id::SecurityPolicyViolationEvent }, |
835 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
836 | | JSJitInfo::Getter, |
837 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
838 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
839 | | true, /* isInfallible. False in setters. */ |
840 | | false, /* isMovable. Not relevant for setters. */ |
841 | | false, /* isEliminatable. Not relevant for setters. */ |
842 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
843 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
844 | | false, /* isTypedMethod. Only relevant for methods. */ |
845 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
846 | | }; |
847 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
848 | | static_assert(0 < 1, "There is no slot for us"); |
849 | | |
850 | | MOZ_CAN_RUN_SCRIPT static bool |
851 | | get_lineNumber(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
852 | 0 | { |
853 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.lineNumber", DOM, cx); |
854 | 0 |
|
855 | 0 | int32_t result(self->LineNumber()); |
856 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
857 | 0 | args.rval().setInt32(int32_t(result)); |
858 | 0 | return true; |
859 | 0 | } |
860 | | |
861 | | static const JSJitInfo lineNumber_getterinfo = { |
862 | | { (JSJitGetterOp)get_lineNumber }, |
863 | | { prototypes::id::SecurityPolicyViolationEvent }, |
864 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
865 | | JSJitInfo::Getter, |
866 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
867 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
868 | | true, /* isInfallible. False in setters. */ |
869 | | false, /* isMovable. Not relevant for setters. */ |
870 | | false, /* isEliminatable. Not relevant for setters. */ |
871 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
872 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
873 | | false, /* isTypedMethod. Only relevant for methods. */ |
874 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
875 | | }; |
876 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
877 | | static_assert(0 < 1, "There is no slot for us"); |
878 | | |
879 | | MOZ_CAN_RUN_SCRIPT static bool |
880 | | get_columnNumber(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
881 | 0 | { |
882 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.columnNumber", DOM, cx); |
883 | 0 |
|
884 | 0 | int32_t result(self->ColumnNumber()); |
885 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
886 | 0 | args.rval().setInt32(int32_t(result)); |
887 | 0 | return true; |
888 | 0 | } |
889 | | |
890 | | static const JSJitInfo columnNumber_getterinfo = { |
891 | | { (JSJitGetterOp)get_columnNumber }, |
892 | | { prototypes::id::SecurityPolicyViolationEvent }, |
893 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
894 | | JSJitInfo::Getter, |
895 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
896 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
897 | | true, /* isInfallible. False in setters. */ |
898 | | false, /* isMovable. Not relevant for setters. */ |
899 | | false, /* isEliminatable. Not relevant for setters. */ |
900 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
901 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
902 | | false, /* isTypedMethod. Only relevant for methods. */ |
903 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
904 | | }; |
905 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
906 | | static_assert(0 < 1, "There is no slot for us"); |
907 | | |
908 | | MOZ_CAN_RUN_SCRIPT static bool |
909 | | get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SecurityPolicyViolationEvent* self, JSJitGetterCallArgs args) |
910 | 0 | { |
911 | 0 | AUTO_PROFILER_LABEL_FAST("get SecurityPolicyViolationEvent.isTrusted", DOM, cx); |
912 | 0 |
|
913 | 0 | bool result(self->IsTrusted()); |
914 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
915 | 0 | args.rval().setBoolean(result); |
916 | 0 | return true; |
917 | 0 | } |
918 | | |
919 | | static const JSJitInfo isTrusted_getterinfo = { |
920 | | { (JSJitGetterOp)get_isTrusted }, |
921 | | { prototypes::id::SecurityPolicyViolationEvent }, |
922 | | { PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth }, |
923 | | JSJitInfo::Getter, |
924 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
925 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
926 | | true, /* isInfallible. False in setters. */ |
927 | | true, /* isMovable. Not relevant for setters. */ |
928 | | true, /* isEliminatable. Not relevant for setters. */ |
929 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
930 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
931 | | false, /* isTypedMethod. Only relevant for methods. */ |
932 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
933 | | }; |
934 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
935 | | static_assert(0 < 1, "There is no slot for us"); |
936 | | |
937 | | static bool |
938 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
939 | 0 | { |
940 | 0 | mozilla::dom::SecurityPolicyViolationEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SecurityPolicyViolationEvent>(obj); |
941 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
942 | 0 | // obviously can't preserve if we're not initialized. |
943 | 0 | if (self && self->GetWrapperPreserveColor()) { |
944 | 0 | PreserveWrapper(self); |
945 | 0 | } |
946 | 0 | return true; |
947 | 0 | } |
948 | | |
949 | | static void |
950 | | _finalize(js::FreeOp* fop, JSObject* obj) |
951 | 0 | { |
952 | 0 | mozilla::dom::SecurityPolicyViolationEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SecurityPolicyViolationEvent>(obj); |
953 | 0 | if (self) { |
954 | 0 | ClearWrapper(self, self, obj); |
955 | 0 | AddForDeferredFinalization<mozilla::dom::SecurityPolicyViolationEvent>(self); |
956 | 0 | } |
957 | 0 | } |
958 | | |
959 | | static size_t |
960 | | _objectMoved(JSObject* obj, JSObject* old) |
961 | 0 | { |
962 | 0 | mozilla::dom::SecurityPolicyViolationEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SecurityPolicyViolationEvent>(obj); |
963 | 0 | if (self) { |
964 | 0 | UpdateWrapper(self, self, obj, old); |
965 | 0 | } |
966 | 0 |
|
967 | 0 | return 0; |
968 | 0 | } |
969 | | |
970 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
971 | | #if defined(__clang__) |
972 | | #pragma clang diagnostic push |
973 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
974 | | #endif |
975 | | static const JSPropertySpec sAttributes_specs[] = { |
976 | | { "documentURI", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &documentURI_getterinfo, nullptr, nullptr }, |
977 | | { "referrer", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &referrer_getterinfo, nullptr, nullptr }, |
978 | | { "blockedURI", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &blockedURI_getterinfo, nullptr, nullptr }, |
979 | | { "violatedDirective", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &violatedDirective_getterinfo, nullptr, nullptr }, |
980 | | { "effectiveDirective", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &effectiveDirective_getterinfo, nullptr, nullptr }, |
981 | | { "originalPolicy", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &originalPolicy_getterinfo, nullptr, nullptr }, |
982 | | { "sourceFile", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &sourceFile_getterinfo, nullptr, nullptr }, |
983 | | { "sample", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &sample_getterinfo, nullptr, nullptr }, |
984 | | { "disposition", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &disposition_getterinfo, nullptr, nullptr }, |
985 | | { "statusCode", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &statusCode_getterinfo, nullptr, nullptr }, |
986 | | { "lineNumber", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &lineNumber_getterinfo, nullptr, nullptr }, |
987 | | { "columnNumber", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &columnNumber_getterinfo, nullptr, nullptr }, |
988 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
989 | | }; |
990 | | #if defined(__clang__) |
991 | | #pragma clang diagnostic pop |
992 | | #endif |
993 | | |
994 | | |
995 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
996 | | { nullptr, &sAttributes_specs[0] }, |
997 | | { nullptr, nullptr } |
998 | | }; |
999 | | |
1000 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1001 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1002 | | static_assert(12 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1003 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1004 | | |
1005 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1006 | | #if defined(__clang__) |
1007 | | #pragma clang diagnostic push |
1008 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1009 | | #endif |
1010 | | static const JSPropertySpec sUnforgeableAttributes_specs[] = { |
1011 | | { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr }, |
1012 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
1013 | | }; |
1014 | | #if defined(__clang__) |
1015 | | #pragma clang diagnostic pop |
1016 | | #endif |
1017 | | |
1018 | | |
1019 | | static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = { |
1020 | | { nullptr, &sUnforgeableAttributes_specs[0] }, |
1021 | | { nullptr, nullptr } |
1022 | | }; |
1023 | | |
1024 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1025 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1026 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1027 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1028 | | |
1029 | | |
1030 | | static uint16_t sNativeProperties_sortedPropertyIndices[13]; |
1031 | | static PropertyInfo sNativeProperties_propertyInfos[13]; |
1032 | | |
1033 | | static const NativePropertiesN<2> sNativeProperties = { |
1034 | | false, 0, |
1035 | | false, 0, |
1036 | | false, 0, |
1037 | | true, 0 /* sAttributes */, |
1038 | | false, 0, |
1039 | | true, 1 /* sUnforgeableAttributes */, |
1040 | | false, 0, |
1041 | | -1, |
1042 | | 13, |
1043 | | sNativeProperties_sortedPropertyIndices, |
1044 | | { |
1045 | | { sAttributes, &sNativeProperties_propertyInfos[0] }, |
1046 | | { sUnforgeableAttributes, &sNativeProperties_propertyInfos[12] } |
1047 | | } |
1048 | | }; |
1049 | | static_assert(13 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
1050 | | "We have a property info count that is oversized"); |
1051 | | |
1052 | | static bool |
1053 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
1054 | 0 | { |
1055 | 0 | AUTO_PROFILER_LABEL_FAST("SecurityPolicyViolationEvent constructor", DOM, cx); |
1056 | 0 |
|
1057 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
1058 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
1059 | 0 | if (!args.isConstructing()) { |
1060 | 0 | // XXXbz wish I could get the name from the callee instead of |
1061 | 0 | // Adding more relocations |
1062 | 0 | return ThrowConstructorWithoutNew(cx, "SecurityPolicyViolationEvent"); |
1063 | 0 | } |
1064 | 0 | |
1065 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
1066 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
1067 | 0 | return false; |
1068 | 0 | } |
1069 | 0 | |
1070 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
1071 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "SecurityPolicyViolationEvent"); |
1072 | 0 | } |
1073 | 0 | GlobalObject global(cx, obj); |
1074 | 0 | if (global.Failed()) { |
1075 | 0 | return false; |
1076 | 0 | } |
1077 | 0 | |
1078 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
1079 | 0 | binding_detail::FakeString arg0; |
1080 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
1081 | 0 | return false; |
1082 | 0 | } |
1083 | 0 | binding_detail::FastSecurityPolicyViolationEventInit arg1; |
1084 | 0 | if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of SecurityPolicyViolationEvent.constructor", false)) { |
1085 | 0 | return false; |
1086 | 0 | } |
1087 | 0 | Maybe<JSAutoRealm> ar; |
1088 | 0 | if (objIsXray) { |
1089 | 0 | obj = js::CheckedUnwrap(obj); |
1090 | 0 | if (!obj) { |
1091 | 0 | return false; |
1092 | 0 | } |
1093 | 0 | ar.emplace(cx, obj); |
1094 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
1095 | 0 | return false; |
1096 | 0 | } |
1097 | 0 | } |
1098 | 0 | FastErrorResult rv; |
1099 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SecurityPolicyViolationEvent>(mozilla::dom::SecurityPolicyViolationEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv))); |
1100 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1101 | 0 | return false; |
1102 | 0 | } |
1103 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1104 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
1105 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
1106 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
1107 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1108 | 0 | return false; |
1109 | 0 | } |
1110 | 0 | return true; |
1111 | 0 | } |
1112 | | |
1113 | | static const js::ClassOps sInterfaceObjectClassOps = { |
1114 | | nullptr, /* addProperty */ |
1115 | | nullptr, /* delProperty */ |
1116 | | nullptr, /* enumerate */ |
1117 | | nullptr, /* newEnumerate */ |
1118 | | nullptr, /* resolve */ |
1119 | | nullptr, /* mayResolve */ |
1120 | | nullptr, /* finalize */ |
1121 | | _constructor, /* call */ |
1122 | | nullptr, /* hasInstance */ |
1123 | | _constructor, /* construct */ |
1124 | | nullptr, /* trace */ |
1125 | | }; |
1126 | | |
1127 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
1128 | | { |
1129 | | "Function", |
1130 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
1131 | | &sInterfaceObjectClassOps, |
1132 | | JS_NULL_CLASS_SPEC, |
1133 | | JS_NULL_CLASS_EXT, |
1134 | | &sInterfaceObjectClassObjectOps |
1135 | | }, |
1136 | | eInterface, |
1137 | | true, |
1138 | | prototypes::id::SecurityPolicyViolationEvent, |
1139 | | PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth, |
1140 | | sNativePropertyHooks, |
1141 | | "function SecurityPolicyViolationEvent() {\n [native code]\n}", |
1142 | | Event_Binding::GetConstructorObject |
1143 | | }; |
1144 | | |
1145 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
1146 | | { |
1147 | | "SecurityPolicyViolationEventPrototype", |
1148 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */), |
1149 | | JS_NULL_CLASS_OPS, |
1150 | | JS_NULL_CLASS_SPEC, |
1151 | | JS_NULL_CLASS_EXT, |
1152 | | JS_NULL_OBJECT_OPS |
1153 | | }, |
1154 | | eInterfacePrototype, |
1155 | | false, |
1156 | | prototypes::id::SecurityPolicyViolationEvent, |
1157 | | PrototypeTraits<prototypes::id::SecurityPolicyViolationEvent>::Depth, |
1158 | | sNativePropertyHooks, |
1159 | | "[object SecurityPolicyViolationEventPrototype]", |
1160 | | Event_Binding::GetProtoObject |
1161 | | }; |
1162 | | |
1163 | | static const js::ClassOps sClassOps = { |
1164 | | _addProperty, /* addProperty */ |
1165 | | nullptr, /* delProperty */ |
1166 | | nullptr, /* enumerate */ |
1167 | | nullptr, /* newEnumerate */ |
1168 | | nullptr, /* resolve */ |
1169 | | nullptr, /* mayResolve */ |
1170 | | _finalize, /* finalize */ |
1171 | | nullptr, /* call */ |
1172 | | nullptr, /* hasInstance */ |
1173 | | nullptr, /* construct */ |
1174 | | nullptr, /* trace */ |
1175 | | }; |
1176 | | |
1177 | | static const js::ClassExtension sClassExtension = { |
1178 | | nullptr, /* weakmapKeyDelegateOp */ |
1179 | | _objectMoved /* objectMovedOp */ |
1180 | | }; |
1181 | | |
1182 | | static const DOMJSClass sClass = { |
1183 | | { "SecurityPolicyViolationEvent", |
1184 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE, |
1185 | | &sClassOps, |
1186 | | JS_NULL_CLASS_SPEC, |
1187 | | &sClassExtension, |
1188 | | JS_NULL_OBJECT_OPS |
1189 | | }, |
1190 | | { prototypes::id::Event, prototypes::id::SecurityPolicyViolationEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
1191 | | IsBaseOf<nsISupports, mozilla::dom::SecurityPolicyViolationEvent >::value, |
1192 | | sNativePropertyHooks, |
1193 | | FindAssociatedGlobalForNative<mozilla::dom::SecurityPolicyViolationEvent>::Get, |
1194 | | GetProtoObjectHandle, |
1195 | | GetCCParticipant<mozilla::dom::SecurityPolicyViolationEvent>::Get() |
1196 | | }; |
1197 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1198 | | "Must have the right minimal number of reserved slots."); |
1199 | | static_assert(1 >= 1, |
1200 | | "Must have enough reserved slots."); |
1201 | | |
1202 | | const JSClass* |
1203 | | GetJSClass() |
1204 | 0 | { |
1205 | 0 | return sClass.ToJSClass(); |
1206 | 0 | } |
1207 | | |
1208 | | bool |
1209 | | Wrap(JSContext* aCx, mozilla::dom::SecurityPolicyViolationEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1210 | 0 | { |
1211 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::SecurityPolicyViolationEvent>::value, |
1212 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1213 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::SecurityPolicyViolationEvent*>(aObject) == |
1214 | 0 | reinterpret_cast<mozilla::dom::SecurityPolicyViolationEvent*>(aObject), |
1215 | 0 | "Multiple inheritance for mozilla::dom::SecurityPolicyViolationEvent is broken."); |
1216 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) == |
1217 | 0 | reinterpret_cast<mozilla::dom::Event*>(aObject), |
1218 | 0 | "Multiple inheritance for mozilla::dom::Event is broken."); |
1219 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1220 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1221 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1222 | 0 | "You should probably not be using Wrap() directly; use " |
1223 | 0 | "GetOrCreateDOMReflector instead"); |
1224 | 0 |
|
1225 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1226 | 0 | "nsISupports must be on our primary inheritance chain"); |
1227 | 0 |
|
1228 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1229 | 0 | if (!global) { |
1230 | 0 | return false; |
1231 | 0 | } |
1232 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1233 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1234 | 0 |
|
1235 | 0 | // That might have ended up wrapping us already, due to the wonders |
1236 | 0 | // of XBL. Check for that, and bail out as needed. |
1237 | 0 | aReflector.set(aCache->GetWrapper()); |
1238 | 0 | if (aReflector) { |
1239 | | #ifdef DEBUG |
1240 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1241 | | #endif // DEBUG |
1242 | | return true; |
1243 | 0 | } |
1244 | 0 |
|
1245 | 0 | JSAutoRealm ar(aCx, global); |
1246 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1247 | 0 | if (!canonicalProto) { |
1248 | 0 | return false; |
1249 | 0 | } |
1250 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1251 | 0 | if (aGivenProto) { |
1252 | 0 | proto = aGivenProto; |
1253 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1254 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1255 | 0 | // to wrap the proto here. |
1256 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1257 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1258 | 0 | return false; |
1259 | 0 | } |
1260 | 0 | } |
1261 | 0 | } else { |
1262 | 0 | proto = canonicalProto; |
1263 | 0 | } |
1264 | 0 |
|
1265 | 0 | BindingJSObjectCreator<mozilla::dom::SecurityPolicyViolationEvent> creator(aCx); |
1266 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1267 | 0 | if (!aReflector) { |
1268 | 0 | return false; |
1269 | 0 | } |
1270 | 0 | |
1271 | 0 | aCache->SetWrapper(aReflector); |
1272 | 0 |
|
1273 | 0 | // Important: do unforgeable property setup after we have handed |
1274 | 0 | // over ownership of the C++ object to obj as needed, so that if |
1275 | 0 | // we fail and it ends up GCed it won't have problems in the |
1276 | 0 | // finalizer trying to drop its ownership of the C++ object. |
1277 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx, |
1278 | 0 | &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject()); |
1279 | 0 | if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) { |
1280 | 0 | aCache->ReleaseWrapper(aObject); |
1281 | 0 | aCache->ClearWrapper(); |
1282 | 0 | return false; |
1283 | 0 | } |
1284 | 0 | creator.InitializationSucceeded(); |
1285 | 0 |
|
1286 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1287 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1288 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1289 | 0 | // otherwise we won't be able to properly recreate it later, since |
1290 | 0 | // we won't know what proto to use. Note that we don't check |
1291 | 0 | // aGivenProto here, since it's entirely possible (and even |
1292 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1293 | 0 | // same as canonicalProto. |
1294 | 0 | if (proto != canonicalProto) { |
1295 | 0 | PreserveWrapper(aObject); |
1296 | 0 | } |
1297 | 0 |
|
1298 | 0 | return true; |
1299 | 0 | } |
1300 | | |
1301 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1302 | | nullptr, |
1303 | | nullptr, |
1304 | | nullptr, |
1305 | | { sNativeProperties.Upcast(), nullptr }, |
1306 | | prototypes::id::SecurityPolicyViolationEvent, |
1307 | | constructors::id::SecurityPolicyViolationEvent, |
1308 | | Event_Binding::sNativePropertyHooks, |
1309 | | &DefaultXrayExpandoObjectClass |
1310 | | } }; |
1311 | | |
1312 | | void |
1313 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1314 | 0 | { |
1315 | 0 | JS::Handle<JSObject*> parentProto(Event_Binding::GetProtoObjectHandle(aCx)); |
1316 | 0 | if (!parentProto) { |
1317 | 0 | return; |
1318 | 0 | } |
1319 | 0 | |
1320 | 0 | JS::Handle<JSObject*> constructorProto(Event_Binding::GetConstructorObjectHandle(aCx)); |
1321 | 0 | if (!constructorProto) { |
1322 | 0 | return; |
1323 | 0 | } |
1324 | 0 | |
1325 | 0 | static bool sIdsInited = false; |
1326 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1327 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1328 | 0 | return; |
1329 | 0 | } |
1330 | 0 | sIdsInited = true; |
1331 | 0 | } |
1332 | 0 |
|
1333 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::SecurityPolicyViolationEvent); |
1334 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::SecurityPolicyViolationEvent); |
1335 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1336 | 0 | &sPrototypeClass.mBase, protoCache, |
1337 | 0 | nullptr, |
1338 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr, |
1339 | 0 | interfaceCache, |
1340 | 0 | sNativeProperties.Upcast(), |
1341 | 0 | nullptr, |
1342 | 0 | "SecurityPolicyViolationEvent", aDefineOnGlobal, |
1343 | 0 | nullptr, |
1344 | 0 | false); |
1345 | 0 |
|
1346 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx); |
1347 | 0 | { |
1348 | 0 | JS::Rooted<JSObject*> holderProto(aCx, *protoCache); |
1349 | 0 | unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto); |
1350 | 0 | if (!unforgeableHolder) { |
1351 | 0 | *protoCache = nullptr; |
1352 | 0 | if (interfaceCache) { |
1353 | 0 | *interfaceCache = nullptr; |
1354 | 0 | } |
1355 | 0 | return; |
1356 | 0 | } |
1357 | 0 | } |
1358 | 0 |
|
1359 | 0 | if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) { |
1360 | 0 | *protoCache = nullptr; |
1361 | 0 | if (interfaceCache) { |
1362 | 0 | *interfaceCache = nullptr; |
1363 | 0 | } |
1364 | 0 | return; |
1365 | 0 | } |
1366 | 0 |
|
1367 | 0 | if (*protoCache) { |
1368 | 0 | js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE, |
1369 | 0 | JS::ObjectValue(*unforgeableHolder)); |
1370 | 0 | } |
1371 | 0 | } |
1372 | | |
1373 | | JSObject* |
1374 | | GetConstructorObject(JSContext* aCx) |
1375 | 0 | { |
1376 | 0 | return GetConstructorObjectHandle(aCx); |
1377 | 0 | } |
1378 | | |
1379 | | } // namespace SecurityPolicyViolationEvent_Binding |
1380 | | |
1381 | | |
1382 | | |
1383 | | } // namespace dom |
1384 | | } // namespace mozilla |