/work/obj-fuzz/dom/bindings/RTCIdentityProviderBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM RTCIdentityProvider.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "RTCIdentityProviderBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/DOMJSClass.h" |
9 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
10 | | #include "mozilla/dom/PrimitiveConversions.h" |
11 | | #include "mozilla/dom/Promise.h" |
12 | | #include "mozilla/dom/RTCIdentityProviderRegistrar.h" |
13 | | #include "mozilla/dom/ScriptSettings.h" |
14 | | #include "mozilla/dom/SimpleGlobalObject.h" |
15 | | #include "mozilla/dom/ToJSValue.h" |
16 | | #include "mozilla/dom/XrayExpandoClass.h" |
17 | | #include "nsContentUtils.h" |
18 | | |
19 | | namespace mozilla { |
20 | | namespace dom { |
21 | | |
22 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
23 | | using namespace mozilla::dom::binding_detail; |
24 | | |
25 | | |
26 | | |
27 | | RTCIdentityProvider::RTCIdentityProvider() |
28 | 0 | { |
29 | 0 | // Safe to pass a null context if we pass a null value |
30 | 0 | Init(nullptr, JS::NullHandleValue); |
31 | 0 | } |
32 | | |
33 | | |
34 | | bool |
35 | | RTCIdentityProvider::InitIds(JSContext* cx, RTCIdentityProviderAtoms* atomsCache) |
36 | 0 | { |
37 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
38 | 0 |
|
39 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
40 | 0 | // uninitialized. |
41 | 0 | if (!atomsCache->validateAssertion_id.init(cx, "validateAssertion") || |
42 | 0 | !atomsCache->generateAssertion_id.init(cx, "generateAssertion")) { |
43 | 0 | return false; |
44 | 0 | } |
45 | 0 | return true; |
46 | 0 | } |
47 | | |
48 | | bool |
49 | | RTCIdentityProvider::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
50 | 0 | { |
51 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
52 | 0 | // Since in that case we will not have to do any property gets |
53 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
54 | 0 | // checkers by static analysis tools |
55 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
56 | 0 | RTCIdentityProviderAtoms* atomsCache = nullptr; |
57 | 0 | if (cx) { |
58 | 0 | atomsCache = GetAtomCache<RTCIdentityProviderAtoms>(cx); |
59 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
60 | 0 | return false; |
61 | 0 | } |
62 | 0 | } |
63 | 0 | |
64 | 0 | if (!IsConvertibleToDictionary(val)) { |
65 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
66 | 0 | } |
67 | 0 | |
68 | 0 | bool isNull = val.isNullOrUndefined(); |
69 | 0 | // We only need these if !isNull, in which case we have |cx|. |
70 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
71 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
72 | 0 | if (!isNull) { |
73 | 0 | MOZ_ASSERT(cx); |
74 | 0 | object.emplace(cx, &val.toObject()); |
75 | 0 | temp.emplace(cx); |
76 | 0 | } |
77 | 0 | if (!isNull) { |
78 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->generateAssertion_id, temp.ptr())) { |
79 | 0 | return false; |
80 | 0 | } |
81 | 0 | } |
82 | 0 | if (!isNull && !temp->isUndefined()) { |
83 | 0 | if (temp.ref().isObject()) { |
84 | 0 | if (JS::IsCallable(&temp.ref().toObject())) { |
85 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
86 | 0 | JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject()); |
87 | 0 | JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx)); |
88 | 0 | mGenerateAssertion = new GenerateAssertionCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal()); |
89 | 0 | } |
90 | 0 | } else { |
91 | 0 | ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "'generateAssertion' member of RTCIdentityProvider"); |
92 | 0 | return false; |
93 | 0 | } |
94 | 0 | } else { |
95 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'generateAssertion' member of RTCIdentityProvider"); |
96 | 0 | return false; |
97 | 0 | } |
98 | 0 | mIsAnyMemberPresent = true; |
99 | 0 | } else if (cx) { |
100 | 0 | // Don't error out if we have no cx. In that |
101 | 0 | // situation the caller is default-constructing us and we'll |
102 | 0 | // just assume they know what they're doing. |
103 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
104 | 0 | "'generateAssertion' member of RTCIdentityProvider"); |
105 | 0 | } |
106 | 0 | |
107 | 0 | if (!isNull) { |
108 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->validateAssertion_id, temp.ptr())) { |
109 | 0 | return false; |
110 | 0 | } |
111 | 0 | } |
112 | 0 | if (!isNull && !temp->isUndefined()) { |
113 | 0 | if (temp.ref().isObject()) { |
114 | 0 | if (JS::IsCallable(&temp.ref().toObject())) { |
115 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
116 | 0 | JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject()); |
117 | 0 | JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx)); |
118 | 0 | mValidateAssertion = new ValidateAssertionCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal()); |
119 | 0 | } |
120 | 0 | } else { |
121 | 0 | ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "'validateAssertion' member of RTCIdentityProvider"); |
122 | 0 | return false; |
123 | 0 | } |
124 | 0 | } else { |
125 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'validateAssertion' member of RTCIdentityProvider"); |
126 | 0 | return false; |
127 | 0 | } |
128 | 0 | mIsAnyMemberPresent = true; |
129 | 0 | } else if (cx) { |
130 | 0 | // Don't error out if we have no cx. In that |
131 | 0 | // situation the caller is default-constructing us and we'll |
132 | 0 | // just assume they know what they're doing. |
133 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
134 | 0 | "'validateAssertion' member of RTCIdentityProvider"); |
135 | 0 | } |
136 | 0 | return true; |
137 | 0 | } |
138 | | |
139 | | bool |
140 | | RTCIdentityProvider::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
141 | 0 | { |
142 | 0 | RTCIdentityProviderAtoms* atomsCache = GetAtomCache<RTCIdentityProviderAtoms>(cx); |
143 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
144 | 0 | return false; |
145 | 0 | } |
146 | 0 | |
147 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
148 | 0 | if (!obj) { |
149 | 0 | return false; |
150 | 0 | } |
151 | 0 | rval.set(JS::ObjectValue(*obj)); |
152 | 0 |
|
153 | 0 | do { |
154 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
155 | 0 | JS::Rooted<JS::Value> temp(cx); |
156 | 0 | OwningNonNull<GenerateAssertionCallback> const & currentValue = mGenerateAssertion; |
157 | 0 | temp.setObjectOrNull(GetCallbackFromCallbackObject(cx, currentValue)); |
158 | 0 | if (!MaybeWrapObjectValue(cx, &temp)) { |
159 | 0 | return false; |
160 | 0 | } |
161 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->generateAssertion_id, temp, JSPROP_ENUMERATE)) { |
162 | 0 | return false; |
163 | 0 | } |
164 | 0 | break; |
165 | 0 | } while(false); |
166 | 0 |
|
167 | 0 | do { |
168 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
169 | 0 | JS::Rooted<JS::Value> temp(cx); |
170 | 0 | OwningNonNull<ValidateAssertionCallback> const & currentValue = mValidateAssertion; |
171 | 0 | temp.setObjectOrNull(GetCallbackFromCallbackObject(cx, currentValue)); |
172 | 0 | if (!MaybeWrapObjectValue(cx, &temp)) { |
173 | 0 | return false; |
174 | 0 | } |
175 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->validateAssertion_id, temp, JSPROP_ENUMERATE)) { |
176 | 0 | return false; |
177 | 0 | } |
178 | 0 | break; |
179 | 0 | } while(false); |
180 | 0 |
|
181 | 0 | return true; |
182 | 0 | } |
183 | | |
184 | | void |
185 | | RTCIdentityProvider::TraceDictionary(JSTracer* trc) |
186 | 0 | { |
187 | 0 | } |
188 | | |
189 | | |
190 | | |
191 | | namespace binding_detail { |
192 | | } // namespace binding_detail |
193 | | |
194 | | |
195 | | |
196 | | RTCIdentityProviderDetails::RTCIdentityProviderDetails() |
197 | 0 | { |
198 | 0 | // Safe to pass a null context if we pass a null value |
199 | 0 | Init(nullptr, JS::NullHandleValue); |
200 | 0 | } |
201 | | |
202 | | |
203 | | |
204 | | bool |
205 | | RTCIdentityProviderDetails::InitIds(JSContext* cx, RTCIdentityProviderDetailsAtoms* atomsCache) |
206 | 0 | { |
207 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
208 | 0 |
|
209 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
210 | 0 | // uninitialized. |
211 | 0 | if (!atomsCache->protocol_id.init(cx, "protocol") || |
212 | 0 | !atomsCache->domain_id.init(cx, "domain")) { |
213 | 0 | return false; |
214 | 0 | } |
215 | 0 | return true; |
216 | 0 | } |
217 | | |
218 | | bool |
219 | | RTCIdentityProviderDetails::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
220 | 0 | { |
221 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
222 | 0 | // Since in that case we will not have to do any property gets |
223 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
224 | 0 | // checkers by static analysis tools |
225 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
226 | 0 | RTCIdentityProviderDetailsAtoms* atomsCache = nullptr; |
227 | 0 | if (cx) { |
228 | 0 | atomsCache = GetAtomCache<RTCIdentityProviderDetailsAtoms>(cx); |
229 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
230 | 0 | return false; |
231 | 0 | } |
232 | 0 | } |
233 | 0 | |
234 | 0 | if (!IsConvertibleToDictionary(val)) { |
235 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
236 | 0 | } |
237 | 0 | |
238 | 0 | bool isNull = val.isNullOrUndefined(); |
239 | 0 | // We only need these if !isNull, in which case we have |cx|. |
240 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
241 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
242 | 0 | if (!isNull) { |
243 | 0 | MOZ_ASSERT(cx); |
244 | 0 | object.emplace(cx, &val.toObject()); |
245 | 0 | temp.emplace(cx); |
246 | 0 | } |
247 | 0 | if (!isNull) { |
248 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->domain_id, temp.ptr())) { |
249 | 0 | return false; |
250 | 0 | } |
251 | 0 | } |
252 | 0 | if (!isNull && !temp->isUndefined()) { |
253 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDomain)) { |
254 | 0 | return false; |
255 | 0 | } |
256 | 0 | mIsAnyMemberPresent = true; |
257 | 0 | } else if (cx) { |
258 | 0 | // Don't error out if we have no cx. In that |
259 | 0 | // situation the caller is default-constructing us and we'll |
260 | 0 | // just assume they know what they're doing. |
261 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
262 | 0 | "'domain' member of RTCIdentityProviderDetails"); |
263 | 0 | } |
264 | 0 | |
265 | 0 | if (!isNull) { |
266 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->protocol_id, temp.ptr())) { |
267 | 0 | return false; |
268 | 0 | } |
269 | 0 | } |
270 | 0 | if (!isNull && !temp->isUndefined()) { |
271 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mProtocol)) { |
272 | 0 | return false; |
273 | 0 | } |
274 | 0 | } else { |
275 | 0 | static const char16_t data[] = { 'd', 'e', 'f', 'a', 'u', 'l', 't', 0 }; |
276 | 0 | mProtocol.Rebind(data, ArrayLength(data) - 1); |
277 | 0 | } |
278 | 0 | mIsAnyMemberPresent = true; |
279 | 0 | return true; |
280 | 0 | } |
281 | | |
282 | | bool |
283 | | RTCIdentityProviderDetails::Init(const nsAString& aJSON) |
284 | 0 | { |
285 | 0 | AutoJSAPI jsapi; |
286 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
287 | 0 | if (!cleanGlobal) { |
288 | 0 | return false; |
289 | 0 | } |
290 | 0 | if (!jsapi.Init(cleanGlobal)) { |
291 | 0 | return false; |
292 | 0 | } |
293 | 0 | JSContext* cx = jsapi.cx(); |
294 | 0 | JS::Rooted<JS::Value> json(cx); |
295 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
296 | 0 | NS_ENSURE_TRUE(ok, false); |
297 | 0 | return Init(cx, json); |
298 | 0 | } |
299 | | |
300 | | bool |
301 | | RTCIdentityProviderDetails::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
302 | 0 | { |
303 | 0 | RTCIdentityProviderDetailsAtoms* atomsCache = GetAtomCache<RTCIdentityProviderDetailsAtoms>(cx); |
304 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
305 | 0 | return false; |
306 | 0 | } |
307 | 0 | |
308 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
309 | 0 | if (!obj) { |
310 | 0 | return false; |
311 | 0 | } |
312 | 0 | rval.set(JS::ObjectValue(*obj)); |
313 | 0 |
|
314 | 0 | do { |
315 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
316 | 0 | JS::Rooted<JS::Value> temp(cx); |
317 | 0 | nsString const & currentValue = mDomain; |
318 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
319 | 0 | return false; |
320 | 0 | } |
321 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->domain_id, temp, JSPROP_ENUMERATE)) { |
322 | 0 | return false; |
323 | 0 | } |
324 | 0 | break; |
325 | 0 | } while(false); |
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 = mProtocol; |
331 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
332 | 0 | return false; |
333 | 0 | } |
334 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->protocol_id, temp, JSPROP_ENUMERATE)) { |
335 | 0 | return false; |
336 | 0 | } |
337 | 0 | break; |
338 | 0 | } while(false); |
339 | 0 |
|
340 | 0 | return true; |
341 | 0 | } |
342 | | |
343 | | bool |
344 | | RTCIdentityProviderDetails::ToJSON(nsAString& aJSON) const |
345 | 0 | { |
346 | 0 | AutoJSAPI jsapi; |
347 | 0 | jsapi.Init(); |
348 | 0 | JSContext *cx = jsapi.cx(); |
349 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
350 | 0 | // because we'll only be creating objects, in ways that have no |
351 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
352 | 0 | // which likewise guarantees no side-effects for the sorts of |
353 | 0 | // things we will pass it. |
354 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
355 | 0 | JS::Rooted<JS::Value> val(cx); |
356 | 0 | if (!ToObjectInternal(cx, &val)) { |
357 | 0 | return false; |
358 | 0 | } |
359 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
360 | 0 | return StringifyToJSON(cx, obj, aJSON); |
361 | 0 | } |
362 | | |
363 | | void |
364 | | RTCIdentityProviderDetails::TraceDictionary(JSTracer* trc) |
365 | 0 | { |
366 | 0 | } |
367 | | |
368 | | RTCIdentityProviderDetails& |
369 | | RTCIdentityProviderDetails::operator=(const RTCIdentityProviderDetails& aOther) |
370 | 0 | { |
371 | 0 | DictionaryBase::operator=(aOther); |
372 | 0 | mDomain = aOther.mDomain; |
373 | 0 | mProtocol = aOther.mProtocol; |
374 | 0 | return *this; |
375 | 0 | } |
376 | | |
377 | | namespace binding_detail { |
378 | | } // namespace binding_detail |
379 | | |
380 | | |
381 | | |
382 | | RTCIdentityProviderOptions::RTCIdentityProviderOptions() |
383 | 0 | { |
384 | 0 | // Safe to pass a null context if we pass a null value |
385 | 0 | Init(nullptr, JS::NullHandleValue); |
386 | 0 | } |
387 | | |
388 | | |
389 | | |
390 | | bool |
391 | | RTCIdentityProviderOptions::InitIds(JSContext* cx, RTCIdentityProviderOptionsAtoms* atomsCache) |
392 | 0 | { |
393 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
394 | 0 |
|
395 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
396 | 0 | // uninitialized. |
397 | 0 | if (!atomsCache->usernameHint_id.init(cx, "usernameHint") || |
398 | 0 | !atomsCache->protocol_id.init(cx, "protocol") || |
399 | 0 | !atomsCache->peerIdentity_id.init(cx, "peerIdentity")) { |
400 | 0 | return false; |
401 | 0 | } |
402 | 0 | return true; |
403 | 0 | } |
404 | | |
405 | | bool |
406 | | RTCIdentityProviderOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
407 | 0 | { |
408 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
409 | 0 | // Since in that case we will not have to do any property gets |
410 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
411 | 0 | // checkers by static analysis tools |
412 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
413 | 0 | RTCIdentityProviderOptionsAtoms* atomsCache = nullptr; |
414 | 0 | if (cx) { |
415 | 0 | atomsCache = GetAtomCache<RTCIdentityProviderOptionsAtoms>(cx); |
416 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
417 | 0 | return false; |
418 | 0 | } |
419 | 0 | } |
420 | 0 | |
421 | 0 | if (!IsConvertibleToDictionary(val)) { |
422 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
423 | 0 | } |
424 | 0 | |
425 | 0 | bool isNull = val.isNullOrUndefined(); |
426 | 0 | // We only need these if !isNull, in which case we have |cx|. |
427 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
428 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
429 | 0 | if (!isNull) { |
430 | 0 | MOZ_ASSERT(cx); |
431 | 0 | object.emplace(cx, &val.toObject()); |
432 | 0 | temp.emplace(cx); |
433 | 0 | } |
434 | 0 | if (!isNull) { |
435 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->peerIdentity_id, temp.ptr())) { |
436 | 0 | return false; |
437 | 0 | } |
438 | 0 | } |
439 | 0 | if (!isNull && !temp->isUndefined()) { |
440 | 0 | mPeerIdentity.Construct(); |
441 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mPeerIdentity.Value()))) { |
442 | 0 | return false; |
443 | 0 | } |
444 | 0 | mIsAnyMemberPresent = true; |
445 | 0 | } |
446 | 0 |
|
447 | 0 | if (!isNull) { |
448 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->protocol_id, temp.ptr())) { |
449 | 0 | return false; |
450 | 0 | } |
451 | 0 | } |
452 | 0 | if (!isNull && !temp->isUndefined()) { |
453 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mProtocol)) { |
454 | 0 | return false; |
455 | 0 | } |
456 | 0 | } else { |
457 | 0 | static const char16_t data[] = { 'd', 'e', 'f', 'a', 'u', 'l', 't', 0 }; |
458 | 0 | mProtocol.Rebind(data, ArrayLength(data) - 1); |
459 | 0 | } |
460 | 0 | mIsAnyMemberPresent = true; |
461 | 0 |
|
462 | 0 | if (!isNull) { |
463 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->usernameHint_id, temp.ptr())) { |
464 | 0 | return false; |
465 | 0 | } |
466 | 0 | } |
467 | 0 | if (!isNull && !temp->isUndefined()) { |
468 | 0 | mUsernameHint.Construct(); |
469 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mUsernameHint.Value()))) { |
470 | 0 | return false; |
471 | 0 | } |
472 | 0 | mIsAnyMemberPresent = true; |
473 | 0 | } |
474 | 0 | return true; |
475 | 0 | } |
476 | | |
477 | | bool |
478 | | RTCIdentityProviderOptions::Init(const nsAString& aJSON) |
479 | 0 | { |
480 | 0 | AutoJSAPI jsapi; |
481 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
482 | 0 | if (!cleanGlobal) { |
483 | 0 | return false; |
484 | 0 | } |
485 | 0 | if (!jsapi.Init(cleanGlobal)) { |
486 | 0 | return false; |
487 | 0 | } |
488 | 0 | JSContext* cx = jsapi.cx(); |
489 | 0 | JS::Rooted<JS::Value> json(cx); |
490 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
491 | 0 | NS_ENSURE_TRUE(ok, false); |
492 | 0 | return Init(cx, json); |
493 | 0 | } |
494 | | |
495 | | bool |
496 | | RTCIdentityProviderOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
497 | 0 | { |
498 | 0 | RTCIdentityProviderOptionsAtoms* atomsCache = GetAtomCache<RTCIdentityProviderOptionsAtoms>(cx); |
499 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
500 | 0 | return false; |
501 | 0 | } |
502 | 0 | |
503 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
504 | 0 | if (!obj) { |
505 | 0 | return false; |
506 | 0 | } |
507 | 0 | rval.set(JS::ObjectValue(*obj)); |
508 | 0 |
|
509 | 0 | if (mPeerIdentity.WasPassed()) { |
510 | 0 | do { |
511 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
512 | 0 | JS::Rooted<JS::Value> temp(cx); |
513 | 0 | nsString const & currentValue = mPeerIdentity.InternalValue(); |
514 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
515 | 0 | return false; |
516 | 0 | } |
517 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->peerIdentity_id, temp, JSPROP_ENUMERATE)) { |
518 | 0 | return false; |
519 | 0 | } |
520 | 0 | break; |
521 | 0 | } while(false); |
522 | 0 | } |
523 | 0 |
|
524 | 0 | do { |
525 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
526 | 0 | JS::Rooted<JS::Value> temp(cx); |
527 | 0 | nsString const & currentValue = mProtocol; |
528 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
529 | 0 | return false; |
530 | 0 | } |
531 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->protocol_id, temp, JSPROP_ENUMERATE)) { |
532 | 0 | return false; |
533 | 0 | } |
534 | 0 | break; |
535 | 0 | } while(false); |
536 | 0 |
|
537 | 0 | if (mUsernameHint.WasPassed()) { |
538 | 0 | do { |
539 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
540 | 0 | JS::Rooted<JS::Value> temp(cx); |
541 | 0 | nsString const & currentValue = mUsernameHint.InternalValue(); |
542 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
543 | 0 | return false; |
544 | 0 | } |
545 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->usernameHint_id, temp, JSPROP_ENUMERATE)) { |
546 | 0 | return false; |
547 | 0 | } |
548 | 0 | break; |
549 | 0 | } while(false); |
550 | 0 | } |
551 | 0 |
|
552 | 0 | return true; |
553 | 0 | } |
554 | | |
555 | | bool |
556 | | RTCIdentityProviderOptions::ToJSON(nsAString& aJSON) const |
557 | 0 | { |
558 | 0 | AutoJSAPI jsapi; |
559 | 0 | jsapi.Init(); |
560 | 0 | JSContext *cx = jsapi.cx(); |
561 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
562 | 0 | // because we'll only be creating objects, in ways that have no |
563 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
564 | 0 | // which likewise guarantees no side-effects for the sorts of |
565 | 0 | // things we will pass it. |
566 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
567 | 0 | JS::Rooted<JS::Value> val(cx); |
568 | 0 | if (!ToObjectInternal(cx, &val)) { |
569 | 0 | return false; |
570 | 0 | } |
571 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
572 | 0 | return StringifyToJSON(cx, obj, aJSON); |
573 | 0 | } |
574 | | |
575 | | void |
576 | | RTCIdentityProviderOptions::TraceDictionary(JSTracer* trc) |
577 | 0 | { |
578 | 0 | } |
579 | | |
580 | | RTCIdentityProviderOptions& |
581 | | RTCIdentityProviderOptions::operator=(const RTCIdentityProviderOptions& aOther) |
582 | 0 | { |
583 | 0 | DictionaryBase::operator=(aOther); |
584 | 0 | mPeerIdentity.Reset(); |
585 | 0 | if (aOther.mPeerIdentity.WasPassed()) { |
586 | 0 | mPeerIdentity.Construct(aOther.mPeerIdentity.Value()); |
587 | 0 | } |
588 | 0 | mProtocol = aOther.mProtocol; |
589 | 0 | mUsernameHint.Reset(); |
590 | 0 | if (aOther.mUsernameHint.WasPassed()) { |
591 | 0 | mUsernameHint.Construct(aOther.mUsernameHint.Value()); |
592 | 0 | } |
593 | 0 | return *this; |
594 | 0 | } |
595 | | |
596 | | namespace binding_detail { |
597 | | } // namespace binding_detail |
598 | | |
599 | | |
600 | | |
601 | | RTCIdentityValidationResult::RTCIdentityValidationResult() |
602 | 0 | { |
603 | 0 | // Safe to pass a null context if we pass a null value |
604 | 0 | Init(nullptr, JS::NullHandleValue); |
605 | 0 | } |
606 | | |
607 | | |
608 | | |
609 | | bool |
610 | | RTCIdentityValidationResult::InitIds(JSContext* cx, RTCIdentityValidationResultAtoms* atomsCache) |
611 | 0 | { |
612 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
613 | 0 |
|
614 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
615 | 0 | // uninitialized. |
616 | 0 | if (!atomsCache->identity_id.init(cx, "identity") || |
617 | 0 | !atomsCache->contents_id.init(cx, "contents")) { |
618 | 0 | return false; |
619 | 0 | } |
620 | 0 | return true; |
621 | 0 | } |
622 | | |
623 | | bool |
624 | | RTCIdentityValidationResult::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
625 | 0 | { |
626 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
627 | 0 | // Since in that case we will not have to do any property gets |
628 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
629 | 0 | // checkers by static analysis tools |
630 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
631 | 0 | RTCIdentityValidationResultAtoms* atomsCache = nullptr; |
632 | 0 | if (cx) { |
633 | 0 | atomsCache = GetAtomCache<RTCIdentityValidationResultAtoms>(cx); |
634 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
635 | 0 | return false; |
636 | 0 | } |
637 | 0 | } |
638 | 0 | |
639 | 0 | if (!IsConvertibleToDictionary(val)) { |
640 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
641 | 0 | } |
642 | 0 | |
643 | 0 | bool isNull = val.isNullOrUndefined(); |
644 | 0 | // We only need these if !isNull, in which case we have |cx|. |
645 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
646 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
647 | 0 | if (!isNull) { |
648 | 0 | MOZ_ASSERT(cx); |
649 | 0 | object.emplace(cx, &val.toObject()); |
650 | 0 | temp.emplace(cx); |
651 | 0 | } |
652 | 0 | if (!isNull) { |
653 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->contents_id, temp.ptr())) { |
654 | 0 | return false; |
655 | 0 | } |
656 | 0 | } |
657 | 0 | if (!isNull && !temp->isUndefined()) { |
658 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mContents)) { |
659 | 0 | return false; |
660 | 0 | } |
661 | 0 | mIsAnyMemberPresent = true; |
662 | 0 | } else if (cx) { |
663 | 0 | // Don't error out if we have no cx. In that |
664 | 0 | // situation the caller is default-constructing us and we'll |
665 | 0 | // just assume they know what they're doing. |
666 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
667 | 0 | "'contents' member of RTCIdentityValidationResult"); |
668 | 0 | } |
669 | 0 | |
670 | 0 | if (!isNull) { |
671 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->identity_id, temp.ptr())) { |
672 | 0 | return false; |
673 | 0 | } |
674 | 0 | } |
675 | 0 | if (!isNull && !temp->isUndefined()) { |
676 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mIdentity)) { |
677 | 0 | return false; |
678 | 0 | } |
679 | 0 | mIsAnyMemberPresent = true; |
680 | 0 | } else if (cx) { |
681 | 0 | // Don't error out if we have no cx. In that |
682 | 0 | // situation the caller is default-constructing us and we'll |
683 | 0 | // just assume they know what they're doing. |
684 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
685 | 0 | "'identity' member of RTCIdentityValidationResult"); |
686 | 0 | } |
687 | 0 | return true; |
688 | 0 | } |
689 | | |
690 | | bool |
691 | | RTCIdentityValidationResult::Init(const nsAString& aJSON) |
692 | 0 | { |
693 | 0 | AutoJSAPI jsapi; |
694 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
695 | 0 | if (!cleanGlobal) { |
696 | 0 | return false; |
697 | 0 | } |
698 | 0 | if (!jsapi.Init(cleanGlobal)) { |
699 | 0 | return false; |
700 | 0 | } |
701 | 0 | JSContext* cx = jsapi.cx(); |
702 | 0 | JS::Rooted<JS::Value> json(cx); |
703 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
704 | 0 | NS_ENSURE_TRUE(ok, false); |
705 | 0 | return Init(cx, json); |
706 | 0 | } |
707 | | |
708 | | bool |
709 | | RTCIdentityValidationResult::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
710 | 0 | { |
711 | 0 | RTCIdentityValidationResultAtoms* atomsCache = GetAtomCache<RTCIdentityValidationResultAtoms>(cx); |
712 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
713 | 0 | return false; |
714 | 0 | } |
715 | 0 | |
716 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
717 | 0 | if (!obj) { |
718 | 0 | return false; |
719 | 0 | } |
720 | 0 | rval.set(JS::ObjectValue(*obj)); |
721 | 0 |
|
722 | 0 | do { |
723 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
724 | 0 | JS::Rooted<JS::Value> temp(cx); |
725 | 0 | nsString const & currentValue = mContents; |
726 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
727 | 0 | return false; |
728 | 0 | } |
729 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->contents_id, temp, JSPROP_ENUMERATE)) { |
730 | 0 | return false; |
731 | 0 | } |
732 | 0 | break; |
733 | 0 | } while(false); |
734 | 0 |
|
735 | 0 | do { |
736 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
737 | 0 | JS::Rooted<JS::Value> temp(cx); |
738 | 0 | nsString const & currentValue = mIdentity; |
739 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
740 | 0 | return false; |
741 | 0 | } |
742 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->identity_id, temp, JSPROP_ENUMERATE)) { |
743 | 0 | return false; |
744 | 0 | } |
745 | 0 | break; |
746 | 0 | } while(false); |
747 | 0 |
|
748 | 0 | return true; |
749 | 0 | } |
750 | | |
751 | | bool |
752 | | RTCIdentityValidationResult::ToJSON(nsAString& aJSON) const |
753 | 0 | { |
754 | 0 | AutoJSAPI jsapi; |
755 | 0 | jsapi.Init(); |
756 | 0 | JSContext *cx = jsapi.cx(); |
757 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
758 | 0 | // because we'll only be creating objects, in ways that have no |
759 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
760 | 0 | // which likewise guarantees no side-effects for the sorts of |
761 | 0 | // things we will pass it. |
762 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
763 | 0 | JS::Rooted<JS::Value> val(cx); |
764 | 0 | if (!ToObjectInternal(cx, &val)) { |
765 | 0 | return false; |
766 | 0 | } |
767 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
768 | 0 | return StringifyToJSON(cx, obj, aJSON); |
769 | 0 | } |
770 | | |
771 | | void |
772 | | RTCIdentityValidationResult::TraceDictionary(JSTracer* trc) |
773 | 0 | { |
774 | 0 | } |
775 | | |
776 | | RTCIdentityValidationResult& |
777 | | RTCIdentityValidationResult::operator=(const RTCIdentityValidationResult& aOther) |
778 | 0 | { |
779 | 0 | DictionaryBase::operator=(aOther); |
780 | 0 | mContents = aOther.mContents; |
781 | 0 | mIdentity = aOther.mIdentity; |
782 | 0 | return *this; |
783 | 0 | } |
784 | | |
785 | | namespace binding_detail { |
786 | | } // namespace binding_detail |
787 | | |
788 | | |
789 | | |
790 | | RTCIdentityAssertionResult::RTCIdentityAssertionResult() |
791 | | : mIdp(FastDictionaryInitializer()) |
792 | 0 | { |
793 | 0 | // Safe to pass a null context if we pass a null value |
794 | 0 | Init(nullptr, JS::NullHandleValue); |
795 | 0 | } |
796 | | |
797 | | |
798 | | |
799 | | bool |
800 | | RTCIdentityAssertionResult::InitIds(JSContext* cx, RTCIdentityAssertionResultAtoms* atomsCache) |
801 | 0 | { |
802 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
803 | 0 |
|
804 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
805 | 0 | // uninitialized. |
806 | 0 | if (!atomsCache->idp_id.init(cx, "idp") || |
807 | 0 | !atomsCache->assertion_id.init(cx, "assertion")) { |
808 | 0 | return false; |
809 | 0 | } |
810 | 0 | return true; |
811 | 0 | } |
812 | | |
813 | | bool |
814 | | RTCIdentityAssertionResult::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
815 | 0 | { |
816 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
817 | 0 | // Since in that case we will not have to do any property gets |
818 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
819 | 0 | // checkers by static analysis tools |
820 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
821 | 0 | RTCIdentityAssertionResultAtoms* atomsCache = nullptr; |
822 | 0 | if (cx) { |
823 | 0 | atomsCache = GetAtomCache<RTCIdentityAssertionResultAtoms>(cx); |
824 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
825 | 0 | return false; |
826 | 0 | } |
827 | 0 | } |
828 | 0 | |
829 | 0 | if (!IsConvertibleToDictionary(val)) { |
830 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
831 | 0 | } |
832 | 0 | |
833 | 0 | bool isNull = val.isNullOrUndefined(); |
834 | 0 | // We only need these if !isNull, in which case we have |cx|. |
835 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
836 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
837 | 0 | if (!isNull) { |
838 | 0 | MOZ_ASSERT(cx); |
839 | 0 | object.emplace(cx, &val.toObject()); |
840 | 0 | temp.emplace(cx); |
841 | 0 | } |
842 | 0 | if (!isNull) { |
843 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->assertion_id, temp.ptr())) { |
844 | 0 | return false; |
845 | 0 | } |
846 | 0 | } |
847 | 0 | if (!isNull && !temp->isUndefined()) { |
848 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mAssertion)) { |
849 | 0 | return false; |
850 | 0 | } |
851 | 0 | mIsAnyMemberPresent = true; |
852 | 0 | } else if (cx) { |
853 | 0 | // Don't error out if we have no cx. In that |
854 | 0 | // situation the caller is default-constructing us and we'll |
855 | 0 | // just assume they know what they're doing. |
856 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
857 | 0 | "'assertion' member of RTCIdentityAssertionResult"); |
858 | 0 | } |
859 | 0 | |
860 | 0 | if (!isNull) { |
861 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->idp_id, temp.ptr())) { |
862 | 0 | return false; |
863 | 0 | } |
864 | 0 | } |
865 | 0 | if (!isNull && !temp->isUndefined()) { |
866 | 0 | if (!mIdp.Init(cx, temp.ref(), "'idp' member of RTCIdentityAssertionResult", passedToJSImpl)) { |
867 | 0 | return false; |
868 | 0 | } |
869 | 0 | mIsAnyMemberPresent = true; |
870 | 0 | } else if (cx) { |
871 | 0 | // Don't error out if we have no cx. In that |
872 | 0 | // situation the caller is default-constructing us and we'll |
873 | 0 | // just assume they know what they're doing. |
874 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
875 | 0 | "'idp' member of RTCIdentityAssertionResult"); |
876 | 0 | } |
877 | 0 | return true; |
878 | 0 | } |
879 | | |
880 | | bool |
881 | | RTCIdentityAssertionResult::Init(const nsAString& aJSON) |
882 | 0 | { |
883 | 0 | AutoJSAPI jsapi; |
884 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
885 | 0 | if (!cleanGlobal) { |
886 | 0 | return false; |
887 | 0 | } |
888 | 0 | if (!jsapi.Init(cleanGlobal)) { |
889 | 0 | return false; |
890 | 0 | } |
891 | 0 | JSContext* cx = jsapi.cx(); |
892 | 0 | JS::Rooted<JS::Value> json(cx); |
893 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
894 | 0 | NS_ENSURE_TRUE(ok, false); |
895 | 0 | return Init(cx, json); |
896 | 0 | } |
897 | | |
898 | | bool |
899 | | RTCIdentityAssertionResult::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
900 | 0 | { |
901 | 0 | RTCIdentityAssertionResultAtoms* atomsCache = GetAtomCache<RTCIdentityAssertionResultAtoms>(cx); |
902 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
903 | 0 | return false; |
904 | 0 | } |
905 | 0 | |
906 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
907 | 0 | if (!obj) { |
908 | 0 | return false; |
909 | 0 | } |
910 | 0 | rval.set(JS::ObjectValue(*obj)); |
911 | 0 |
|
912 | 0 | do { |
913 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
914 | 0 | JS::Rooted<JS::Value> temp(cx); |
915 | 0 | nsString const & currentValue = mAssertion; |
916 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
917 | 0 | return false; |
918 | 0 | } |
919 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->assertion_id, temp, JSPROP_ENUMERATE)) { |
920 | 0 | return false; |
921 | 0 | } |
922 | 0 | break; |
923 | 0 | } while(false); |
924 | 0 |
|
925 | 0 | do { |
926 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
927 | 0 | JS::Rooted<JS::Value> temp(cx); |
928 | 0 | RTCIdentityProviderDetails const & currentValue = mIdp; |
929 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
930 | 0 | return false; |
931 | 0 | } |
932 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->idp_id, temp, JSPROP_ENUMERATE)) { |
933 | 0 | return false; |
934 | 0 | } |
935 | 0 | break; |
936 | 0 | } while(false); |
937 | 0 |
|
938 | 0 | return true; |
939 | 0 | } |
940 | | |
941 | | bool |
942 | | RTCIdentityAssertionResult::ToJSON(nsAString& aJSON) const |
943 | 0 | { |
944 | 0 | AutoJSAPI jsapi; |
945 | 0 | jsapi.Init(); |
946 | 0 | JSContext *cx = jsapi.cx(); |
947 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
948 | 0 | // because we'll only be creating objects, in ways that have no |
949 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
950 | 0 | // which likewise guarantees no side-effects for the sorts of |
951 | 0 | // things we will pass it. |
952 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
953 | 0 | JS::Rooted<JS::Value> val(cx); |
954 | 0 | if (!ToObjectInternal(cx, &val)) { |
955 | 0 | return false; |
956 | 0 | } |
957 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
958 | 0 | return StringifyToJSON(cx, obj, aJSON); |
959 | 0 | } |
960 | | |
961 | | void |
962 | | RTCIdentityAssertionResult::TraceDictionary(JSTracer* trc) |
963 | 0 | { |
964 | 0 | } |
965 | | |
966 | | RTCIdentityAssertionResult& |
967 | | RTCIdentityAssertionResult::operator=(const RTCIdentityAssertionResult& aOther) |
968 | 0 | { |
969 | 0 | DictionaryBase::operator=(aOther); |
970 | 0 | mAssertion = aOther.mAssertion; |
971 | 0 | mIdp = aOther.mIdp; |
972 | 0 | return *this; |
973 | 0 | } |
974 | | |
975 | | namespace binding_detail { |
976 | | } // namespace binding_detail |
977 | | |
978 | | |
979 | | already_AddRefed<Promise> |
980 | | GenerateAssertionCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const nsAString& contents, const nsAString& origin, const RTCIdentityProviderOptions& options, ErrorResult& aRv) |
981 | 0 | { |
982 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
983 | 0 | JS::AutoValueVector argv(cx); |
984 | 0 | if (!argv.resize(3)) { |
985 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
986 | 0 | return nullptr; |
987 | 0 | } |
988 | 0 | unsigned argc = 3; |
989 | 0 |
|
990 | 0 | do { |
991 | 0 | if (!options.ToObjectInternal(cx, argv[2])) { |
992 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
993 | 0 | return nullptr; |
994 | 0 | } |
995 | 0 | break; |
996 | 0 | } while (false); |
997 | 0 |
|
998 | 0 | do { |
999 | 0 | nsString mutableStr(origin); |
1000 | 0 | if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[1])) { |
1001 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1002 | 0 | return nullptr; |
1003 | 0 | } |
1004 | 0 | break; |
1005 | 0 | } while (false); |
1006 | 0 |
|
1007 | 0 | do { |
1008 | 0 | nsString mutableStr(contents); |
1009 | 0 | if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) { |
1010 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1011 | 0 | return nullptr; |
1012 | 0 | } |
1013 | 0 | break; |
1014 | 0 | } while (false); |
1015 | 0 |
|
1016 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
1017 | 0 | if (!JS::Call(cx, aThisVal, callable, |
1018 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
1019 | 0 | aRv.NoteJSContextException(cx); |
1020 | 0 | return nullptr; |
1021 | 0 | } |
1022 | 0 | RefPtr<Promise> rvalDecl; |
1023 | 0 | { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm, |
1024 | 0 | // etc. |
1025 | 0 |
|
1026 | 0 | JS::Rooted<JSObject*> globalObj(cx); |
1027 | 0 | // We basically want our entry global here. Play it safe |
1028 | 0 | // and use GetEntryGlobal() to get it, with whatever |
1029 | 0 | // principal-clamping it ends up doing. |
1030 | 0 | globalObj = GetEntryGlobal()->GetGlobalJSObject(); |
1031 | 0 | JSAutoRealm ar(cx, globalObj); |
1032 | 0 | GlobalObject promiseGlobal(cx, globalObj); |
1033 | 0 | if (promiseGlobal.Failed()) { |
1034 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1035 | 0 | return nullptr; |
1036 | 0 | } |
1037 | 0 | |
1038 | 0 | JS::Rooted<JS::Value> valueToResolve(cx, rval); |
1039 | 0 | if (!JS_WrapValue(cx, &valueToResolve)) { |
1040 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1041 | 0 | return nullptr; |
1042 | 0 | } |
1043 | 0 | binding_detail::FastErrorResult promiseRv; |
1044 | 0 | nsCOMPtr<nsIGlobalObject> global = |
1045 | 0 | do_QueryInterface(promiseGlobal.GetAsSupports()); |
1046 | 0 | if (!global) { |
1047 | 0 | promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED); |
1048 | 0 | MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx)); |
1049 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1050 | 0 | return nullptr; |
1051 | 0 | } |
1052 | 0 | rvalDecl = Promise::Resolve(global, cx, valueToResolve, |
1053 | 0 | promiseRv); |
1054 | 0 | if (promiseRv.MaybeSetPendingException(cx)) { |
1055 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1056 | 0 | return nullptr; |
1057 | 0 | } |
1058 | 0 | } |
1059 | 0 | return rvalDecl.forget(); |
1060 | 0 | } |
1061 | | |
1062 | | |
1063 | | |
1064 | | already_AddRefed<Promise> |
1065 | | ValidateAssertionCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const nsAString& assertion, const nsAString& origin, ErrorResult& aRv) |
1066 | 0 | { |
1067 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
1068 | 0 | JS::AutoValueVector argv(cx); |
1069 | 0 | if (!argv.resize(2)) { |
1070 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
1071 | 0 | return nullptr; |
1072 | 0 | } |
1073 | 0 | unsigned argc = 2; |
1074 | 0 |
|
1075 | 0 | do { |
1076 | 0 | nsString mutableStr(origin); |
1077 | 0 | if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[1])) { |
1078 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1079 | 0 | return nullptr; |
1080 | 0 | } |
1081 | 0 | break; |
1082 | 0 | } while (false); |
1083 | 0 |
|
1084 | 0 | do { |
1085 | 0 | nsString mutableStr(assertion); |
1086 | 0 | if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) { |
1087 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1088 | 0 | return nullptr; |
1089 | 0 | } |
1090 | 0 | break; |
1091 | 0 | } while (false); |
1092 | 0 |
|
1093 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
1094 | 0 | if (!JS::Call(cx, aThisVal, callable, |
1095 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
1096 | 0 | aRv.NoteJSContextException(cx); |
1097 | 0 | return nullptr; |
1098 | 0 | } |
1099 | 0 | RefPtr<Promise> rvalDecl; |
1100 | 0 | { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm, |
1101 | 0 | // etc. |
1102 | 0 |
|
1103 | 0 | JS::Rooted<JSObject*> globalObj(cx); |
1104 | 0 | // We basically want our entry global here. Play it safe |
1105 | 0 | // and use GetEntryGlobal() to get it, with whatever |
1106 | 0 | // principal-clamping it ends up doing. |
1107 | 0 | globalObj = GetEntryGlobal()->GetGlobalJSObject(); |
1108 | 0 | JSAutoRealm ar(cx, globalObj); |
1109 | 0 | GlobalObject promiseGlobal(cx, globalObj); |
1110 | 0 | if (promiseGlobal.Failed()) { |
1111 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1112 | 0 | return nullptr; |
1113 | 0 | } |
1114 | 0 | |
1115 | 0 | JS::Rooted<JS::Value> valueToResolve(cx, rval); |
1116 | 0 | if (!JS_WrapValue(cx, &valueToResolve)) { |
1117 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1118 | 0 | return nullptr; |
1119 | 0 | } |
1120 | 0 | binding_detail::FastErrorResult promiseRv; |
1121 | 0 | nsCOMPtr<nsIGlobalObject> global = |
1122 | 0 | do_QueryInterface(promiseGlobal.GetAsSupports()); |
1123 | 0 | if (!global) { |
1124 | 0 | promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED); |
1125 | 0 | MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx)); |
1126 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1127 | 0 | return nullptr; |
1128 | 0 | } |
1129 | 0 | rvalDecl = Promise::Resolve(global, cx, valueToResolve, |
1130 | 0 | promiseRv); |
1131 | 0 | if (promiseRv.MaybeSetPendingException(cx)) { |
1132 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1133 | 0 | return nullptr; |
1134 | 0 | } |
1135 | 0 | } |
1136 | 0 | return rvalDecl.forget(); |
1137 | 0 | } |
1138 | | |
1139 | | |
1140 | | |
1141 | | namespace binding_detail { |
1142 | | } // namespace binding_detail |
1143 | | |
1144 | | |
1145 | | namespace binding_detail { |
1146 | | } // namespace binding_detail |
1147 | | |
1148 | | |
1149 | | namespace RTCIdentityProviderRegistrar_Binding { |
1150 | | |
1151 | | MOZ_CAN_RUN_SCRIPT static bool |
1152 | | _register_(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCIdentityProviderRegistrar* self, const JSJitMethodCallArgs& args) |
1153 | 0 | { |
1154 | 0 | AUTO_PROFILER_LABEL_FAST("RTCIdentityProviderRegistrar.register", DOM, cx); |
1155 | 0 |
|
1156 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
1157 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCIdentityProviderRegistrar.register"); |
1158 | 0 | } |
1159 | 0 | binding_detail::FastRTCIdentityProvider arg0; |
1160 | 0 | if (!arg0.Init(cx, args[0], "Argument 1 of RTCIdentityProviderRegistrar.register", false)) { |
1161 | 0 | return false; |
1162 | 0 | } |
1163 | 0 | self->Register(Constify(arg0)); |
1164 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1165 | 0 | args.rval().setUndefined(); |
1166 | 0 | return true; |
1167 | 0 | } |
1168 | | |
1169 | | static const JSJitInfo register_methodinfo = { |
1170 | | { (JSJitGetterOp)_register_ }, |
1171 | | { prototypes::id::RTCIdentityProviderRegistrar }, |
1172 | | { PrototypeTraits<prototypes::id::RTCIdentityProviderRegistrar>::Depth }, |
1173 | | JSJitInfo::Method, |
1174 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1175 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
1176 | | false, /* isInfallible. False in setters. */ |
1177 | | false, /* isMovable. Not relevant for setters. */ |
1178 | | false, /* isEliminatable. Not relevant for setters. */ |
1179 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1180 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1181 | | false, /* isTypedMethod. Only relevant for methods. */ |
1182 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1183 | | }; |
1184 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1185 | | static_assert(0 < 1, "There is no slot for us"); |
1186 | | |
1187 | | MOZ_CAN_RUN_SCRIPT static bool |
1188 | | get_hasIdp(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCIdentityProviderRegistrar* self, JSJitGetterCallArgs args) |
1189 | 0 | { |
1190 | 0 | AUTO_PROFILER_LABEL_FAST("get RTCIdentityProviderRegistrar.hasIdp", DOM, cx); |
1191 | 0 |
|
1192 | 0 | bool result(self->HasIdp()); |
1193 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1194 | 0 | args.rval().setBoolean(result); |
1195 | 0 | return true; |
1196 | 0 | } |
1197 | | |
1198 | | static const JSJitInfo hasIdp_getterinfo = { |
1199 | | { (JSJitGetterOp)get_hasIdp }, |
1200 | | { prototypes::id::RTCIdentityProviderRegistrar }, |
1201 | | { PrototypeTraits<prototypes::id::RTCIdentityProviderRegistrar>::Depth }, |
1202 | | JSJitInfo::Getter, |
1203 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1204 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
1205 | | true, /* isInfallible. False in setters. */ |
1206 | | false, /* isMovable. Not relevant for setters. */ |
1207 | | false, /* isEliminatable. Not relevant for setters. */ |
1208 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1209 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1210 | | false, /* isTypedMethod. Only relevant for methods. */ |
1211 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1212 | | }; |
1213 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1214 | | static_assert(0 < 1, "There is no slot for us"); |
1215 | | |
1216 | | MOZ_CAN_RUN_SCRIPT static bool |
1217 | | generateAssertion(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCIdentityProviderRegistrar* self, const JSJitMethodCallArgs& args) |
1218 | 0 | { |
1219 | 0 | AUTO_PROFILER_LABEL_FAST("RTCIdentityProviderRegistrar.generateAssertion", DOM, cx); |
1220 | 0 |
|
1221 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
1222 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCIdentityProviderRegistrar.generateAssertion"); |
1223 | 0 | } |
1224 | 0 | binding_detail::FakeString arg0; |
1225 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
1226 | 0 | return false; |
1227 | 0 | } |
1228 | 0 | binding_detail::FakeString arg1; |
1229 | 0 | if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) { |
1230 | 0 | return false; |
1231 | 0 | } |
1232 | 0 | binding_detail::FastRTCIdentityProviderOptions arg2; |
1233 | 0 | if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue, "Argument 3 of RTCIdentityProviderRegistrar.generateAssertion", false)) { |
1234 | 0 | return false; |
1235 | 0 | } |
1236 | 0 | FastErrorResult rv; |
1237 | 0 | auto result(StrongOrRawPtr<Promise>(self->GenerateAssertion(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), Constify(arg2), rv))); |
1238 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1239 | 0 | return false; |
1240 | 0 | } |
1241 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1242 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
1243 | 0 | return false; |
1244 | 0 | } |
1245 | 0 | return true; |
1246 | 0 | } |
1247 | | |
1248 | | MOZ_CAN_RUN_SCRIPT static bool |
1249 | | generateAssertion_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCIdentityProviderRegistrar* self, const JSJitMethodCallArgs& args) |
1250 | 0 | { |
1251 | 0 | bool ok = generateAssertion(cx, obj, self, args); |
1252 | 0 | if (ok) { |
1253 | 0 | return true; |
1254 | 0 | } |
1255 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
1256 | 0 | } |
1257 | | |
1258 | | static const JSJitInfo generateAssertion_methodinfo = { |
1259 | | { (JSJitGetterOp)generateAssertion_promiseWrapper }, |
1260 | | { prototypes::id::RTCIdentityProviderRegistrar }, |
1261 | | { PrototypeTraits<prototypes::id::RTCIdentityProviderRegistrar>::Depth }, |
1262 | | JSJitInfo::Method, |
1263 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1264 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
1265 | | false, /* isInfallible. False in setters. */ |
1266 | | false, /* isMovable. Not relevant for setters. */ |
1267 | | false, /* isEliminatable. Not relevant for setters. */ |
1268 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1269 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1270 | | false, /* isTypedMethod. Only relevant for methods. */ |
1271 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1272 | | }; |
1273 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1274 | | static_assert(0 < 1, "There is no slot for us"); |
1275 | | |
1276 | | MOZ_CAN_RUN_SCRIPT static bool |
1277 | | validateAssertion(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCIdentityProviderRegistrar* self, const JSJitMethodCallArgs& args) |
1278 | 0 | { |
1279 | 0 | AUTO_PROFILER_LABEL_FAST("RTCIdentityProviderRegistrar.validateAssertion", DOM, cx); |
1280 | 0 |
|
1281 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
1282 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCIdentityProviderRegistrar.validateAssertion"); |
1283 | 0 | } |
1284 | 0 | binding_detail::FakeString arg0; |
1285 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
1286 | 0 | return false; |
1287 | 0 | } |
1288 | 0 | binding_detail::FakeString arg1; |
1289 | 0 | if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) { |
1290 | 0 | return false; |
1291 | 0 | } |
1292 | 0 | FastErrorResult rv; |
1293 | 0 | auto result(StrongOrRawPtr<Promise>(self->ValidateAssertion(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), rv))); |
1294 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1295 | 0 | return false; |
1296 | 0 | } |
1297 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1298 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
1299 | 0 | return false; |
1300 | 0 | } |
1301 | 0 | return true; |
1302 | 0 | } |
1303 | | |
1304 | | MOZ_CAN_RUN_SCRIPT static bool |
1305 | | validateAssertion_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCIdentityProviderRegistrar* self, const JSJitMethodCallArgs& args) |
1306 | 0 | { |
1307 | 0 | bool ok = validateAssertion(cx, obj, self, args); |
1308 | 0 | if (ok) { |
1309 | 0 | return true; |
1310 | 0 | } |
1311 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
1312 | 0 | } |
1313 | | |
1314 | | static const JSJitInfo validateAssertion_methodinfo = { |
1315 | | { (JSJitGetterOp)validateAssertion_promiseWrapper }, |
1316 | | { prototypes::id::RTCIdentityProviderRegistrar }, |
1317 | | { PrototypeTraits<prototypes::id::RTCIdentityProviderRegistrar>::Depth }, |
1318 | | JSJitInfo::Method, |
1319 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1320 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
1321 | | false, /* isInfallible. False in setters. */ |
1322 | | false, /* isMovable. Not relevant for setters. */ |
1323 | | false, /* isEliminatable. Not relevant for setters. */ |
1324 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1325 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1326 | | false, /* isTypedMethod. Only relevant for methods. */ |
1327 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1328 | | }; |
1329 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1330 | | static_assert(0 < 1, "There is no slot for us"); |
1331 | | |
1332 | | static bool |
1333 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
1334 | 0 | { |
1335 | 0 | mozilla::dom::RTCIdentityProviderRegistrar* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCIdentityProviderRegistrar>(obj); |
1336 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
1337 | 0 | // obviously can't preserve if we're not initialized. |
1338 | 0 | if (self && self->GetWrapperPreserveColor()) { |
1339 | 0 | PreserveWrapper(self); |
1340 | 0 | } |
1341 | 0 | return true; |
1342 | 0 | } |
1343 | | |
1344 | | static void |
1345 | | _finalize(js::FreeOp* fop, JSObject* obj) |
1346 | 0 | { |
1347 | 0 | mozilla::dom::RTCIdentityProviderRegistrar* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCIdentityProviderRegistrar>(obj); |
1348 | 0 | if (self) { |
1349 | 0 | ClearWrapper(self, self, obj); |
1350 | 0 | AddForDeferredFinalization<mozilla::dom::RTCIdentityProviderRegistrar>(self); |
1351 | 0 | } |
1352 | 0 | } |
1353 | | |
1354 | | static size_t |
1355 | | _objectMoved(JSObject* obj, JSObject* old) |
1356 | 0 | { |
1357 | 0 | mozilla::dom::RTCIdentityProviderRegistrar* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCIdentityProviderRegistrar>(obj); |
1358 | 0 | if (self) { |
1359 | 0 | UpdateWrapper(self, self, obj, old); |
1360 | 0 | } |
1361 | 0 |
|
1362 | 0 | return 0; |
1363 | 0 | } |
1364 | | |
1365 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1366 | | #if defined(__clang__) |
1367 | | #pragma clang diagnostic push |
1368 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1369 | | #endif |
1370 | | static const JSFunctionSpec sMethods_specs[] = { |
1371 | | JS_FNSPEC("register", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(®ister_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
1372 | | JS_FS_END |
1373 | | }; |
1374 | | #if defined(__clang__) |
1375 | | #pragma clang diagnostic pop |
1376 | | #endif |
1377 | | |
1378 | | |
1379 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
1380 | | { nullptr, &sMethods_specs[0] }, |
1381 | | { nullptr, nullptr } |
1382 | | }; |
1383 | | |
1384 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1385 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1386 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1387 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1388 | | |
1389 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1390 | | #if defined(__clang__) |
1391 | | #pragma clang diagnostic push |
1392 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1393 | | #endif |
1394 | | static const JSFunctionSpec sChromeMethods_specs[] = { |
1395 | | JS_FNSPEC("generateAssertion", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&generateAssertion_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
1396 | | JS_FNSPEC("validateAssertion", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&validateAssertion_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
1397 | | JS_FS_END |
1398 | | }; |
1399 | | #if defined(__clang__) |
1400 | | #pragma clang diagnostic pop |
1401 | | #endif |
1402 | | |
1403 | | |
1404 | | static const Prefable<const JSFunctionSpec> sChromeMethods[] = { |
1405 | | { nullptr, &sChromeMethods_specs[0] }, |
1406 | | { nullptr, nullptr } |
1407 | | }; |
1408 | | |
1409 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1410 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1411 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1412 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1413 | | |
1414 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1415 | | #if defined(__clang__) |
1416 | | #pragma clang diagnostic push |
1417 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1418 | | #endif |
1419 | | static const JSPropertySpec sChromeAttributes_specs[] = { |
1420 | | { "hasIdp", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &hasIdp_getterinfo, nullptr, nullptr }, |
1421 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
1422 | | }; |
1423 | | #if defined(__clang__) |
1424 | | #pragma clang diagnostic pop |
1425 | | #endif |
1426 | | |
1427 | | |
1428 | | static const Prefable<const JSPropertySpec> sChromeAttributes[] = { |
1429 | | { nullptr, &sChromeAttributes_specs[0] }, |
1430 | | { nullptr, nullptr } |
1431 | | }; |
1432 | | |
1433 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1434 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1435 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1436 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1437 | | |
1438 | | |
1439 | | static uint16_t sNativeProperties_sortedPropertyIndices[1]; |
1440 | | static PropertyInfo sNativeProperties_propertyInfos[1]; |
1441 | | |
1442 | | static const NativePropertiesN<1> sNativeProperties = { |
1443 | | false, 0, |
1444 | | false, 0, |
1445 | | true, 0 /* sMethods */, |
1446 | | false, 0, |
1447 | | false, 0, |
1448 | | false, 0, |
1449 | | false, 0, |
1450 | | -1, |
1451 | | 1, |
1452 | | sNativeProperties_sortedPropertyIndices, |
1453 | | { |
1454 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
1455 | | } |
1456 | | }; |
1457 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
1458 | | "We have a property info count that is oversized"); |
1459 | | |
1460 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[3]; |
1461 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[3]; |
1462 | | |
1463 | | static const NativePropertiesN<2> sChromeOnlyNativeProperties = { |
1464 | | false, 0, |
1465 | | false, 0, |
1466 | | true, 0 /* sChromeMethods */, |
1467 | | true, 1 /* sChromeAttributes */, |
1468 | | false, 0, |
1469 | | false, 0, |
1470 | | false, 0, |
1471 | | -1, |
1472 | | 3, |
1473 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
1474 | | { |
1475 | | { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }, |
1476 | | { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[2] } |
1477 | | } |
1478 | | }; |
1479 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
1480 | | "We have a property info count that is oversized"); |
1481 | | |
1482 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
1483 | | { |
1484 | | "RTCIdentityProviderRegistrarPrototype", |
1485 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
1486 | | JS_NULL_CLASS_OPS, |
1487 | | JS_NULL_CLASS_SPEC, |
1488 | | JS_NULL_CLASS_EXT, |
1489 | | JS_NULL_OBJECT_OPS |
1490 | | }, |
1491 | | eInterfacePrototype, |
1492 | | false, |
1493 | | prototypes::id::RTCIdentityProviderRegistrar, |
1494 | | PrototypeTraits<prototypes::id::RTCIdentityProviderRegistrar>::Depth, |
1495 | | sNativePropertyHooks, |
1496 | | "[object RTCIdentityProviderRegistrarPrototype]", |
1497 | | JS::GetRealmObjectPrototype |
1498 | | }; |
1499 | | |
1500 | | static const js::ClassOps sClassOps = { |
1501 | | _addProperty, /* addProperty */ |
1502 | | nullptr, /* delProperty */ |
1503 | | nullptr, /* enumerate */ |
1504 | | nullptr, /* newEnumerate */ |
1505 | | nullptr, /* resolve */ |
1506 | | nullptr, /* mayResolve */ |
1507 | | _finalize, /* finalize */ |
1508 | | nullptr, /* call */ |
1509 | | nullptr, /* hasInstance */ |
1510 | | nullptr, /* construct */ |
1511 | | nullptr, /* trace */ |
1512 | | }; |
1513 | | |
1514 | | static const js::ClassExtension sClassExtension = { |
1515 | | nullptr, /* weakmapKeyDelegateOp */ |
1516 | | _objectMoved /* objectMovedOp */ |
1517 | | }; |
1518 | | |
1519 | | static const DOMJSClass sClass = { |
1520 | | { "RTCIdentityProviderRegistrar", |
1521 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
1522 | | &sClassOps, |
1523 | | JS_NULL_CLASS_SPEC, |
1524 | | &sClassExtension, |
1525 | | JS_NULL_OBJECT_OPS |
1526 | | }, |
1527 | | { prototypes::id::RTCIdentityProviderRegistrar, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
1528 | | IsBaseOf<nsISupports, mozilla::dom::RTCIdentityProviderRegistrar >::value, |
1529 | | sNativePropertyHooks, |
1530 | | FindAssociatedGlobalForNative<mozilla::dom::RTCIdentityProviderRegistrar>::Get, |
1531 | | GetProtoObjectHandle, |
1532 | | GetCCParticipant<mozilla::dom::RTCIdentityProviderRegistrar>::Get() |
1533 | | }; |
1534 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1535 | | "Must have the right minimal number of reserved slots."); |
1536 | | static_assert(1 >= 1, |
1537 | | "Must have enough reserved slots."); |
1538 | | |
1539 | | const JSClass* |
1540 | | GetJSClass() |
1541 | 0 | { |
1542 | 0 | return sClass.ToJSClass(); |
1543 | 0 | } |
1544 | | |
1545 | | bool |
1546 | | Wrap(JSContext* aCx, mozilla::dom::RTCIdentityProviderRegistrar* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1547 | 0 | { |
1548 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::RTCIdentityProviderRegistrar>::value, |
1549 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1550 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::RTCIdentityProviderRegistrar*>(aObject) == |
1551 | 0 | reinterpret_cast<mozilla::dom::RTCIdentityProviderRegistrar*>(aObject), |
1552 | 0 | "Multiple inheritance for mozilla::dom::RTCIdentityProviderRegistrar is broken."); |
1553 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1554 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1555 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1556 | 0 | "You should probably not be using Wrap() directly; use " |
1557 | 0 | "GetOrCreateDOMReflector instead"); |
1558 | 0 |
|
1559 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1560 | 0 | "nsISupports must be on our primary inheritance chain"); |
1561 | 0 |
|
1562 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1563 | 0 | if (!global) { |
1564 | 0 | return false; |
1565 | 0 | } |
1566 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1567 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1568 | 0 |
|
1569 | 0 | // That might have ended up wrapping us already, due to the wonders |
1570 | 0 | // of XBL. Check for that, and bail out as needed. |
1571 | 0 | aReflector.set(aCache->GetWrapper()); |
1572 | 0 | if (aReflector) { |
1573 | | #ifdef DEBUG |
1574 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1575 | | #endif // DEBUG |
1576 | | return true; |
1577 | 0 | } |
1578 | 0 |
|
1579 | 0 | JSAutoRealm ar(aCx, global); |
1580 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1581 | 0 | if (!canonicalProto) { |
1582 | 0 | return false; |
1583 | 0 | } |
1584 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1585 | 0 | if (aGivenProto) { |
1586 | 0 | proto = aGivenProto; |
1587 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1588 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1589 | 0 | // to wrap the proto here. |
1590 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1591 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1592 | 0 | return false; |
1593 | 0 | } |
1594 | 0 | } |
1595 | 0 | } else { |
1596 | 0 | proto = canonicalProto; |
1597 | 0 | } |
1598 | 0 |
|
1599 | 0 | BindingJSObjectCreator<mozilla::dom::RTCIdentityProviderRegistrar> creator(aCx); |
1600 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1601 | 0 | if (!aReflector) { |
1602 | 0 | return false; |
1603 | 0 | } |
1604 | 0 | |
1605 | 0 | aCache->SetWrapper(aReflector); |
1606 | 0 | creator.InitializationSucceeded(); |
1607 | 0 |
|
1608 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1609 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1610 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1611 | 0 | // otherwise we won't be able to properly recreate it later, since |
1612 | 0 | // we won't know what proto to use. Note that we don't check |
1613 | 0 | // aGivenProto here, since it's entirely possible (and even |
1614 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1615 | 0 | // same as canonicalProto. |
1616 | 0 | if (proto != canonicalProto) { |
1617 | 0 | PreserveWrapper(aObject); |
1618 | 0 | } |
1619 | 0 |
|
1620 | 0 | return true; |
1621 | 0 | } |
1622 | | |
1623 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1624 | | nullptr, |
1625 | | nullptr, |
1626 | | nullptr, |
1627 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
1628 | | prototypes::id::RTCIdentityProviderRegistrar, |
1629 | | constructors::id::_ID_Count, |
1630 | | nullptr, |
1631 | | &DefaultXrayExpandoObjectClass |
1632 | | } }; |
1633 | | |
1634 | | void |
1635 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1636 | 0 | { |
1637 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
1638 | 0 | if (!parentProto) { |
1639 | 0 | return; |
1640 | 0 | } |
1641 | 0 | |
1642 | 0 | static bool sIdsInited = false; |
1643 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1644 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1645 | 0 | return; |
1646 | 0 | } |
1647 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
1648 | 0 | return; |
1649 | 0 | } |
1650 | 0 | sIdsInited = true; |
1651 | 0 | } |
1652 | 0 |
|
1653 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::RTCIdentityProviderRegistrar); |
1654 | 0 | JS::Heap<JSObject*>* interfaceCache = nullptr; |
1655 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1656 | 0 | &sPrototypeClass.mBase, protoCache, |
1657 | 0 | nullptr, |
1658 | 0 | nullptr, nullptr, 0, nullptr, |
1659 | 0 | interfaceCache, |
1660 | 0 | sNativeProperties.Upcast(), |
1661 | 0 | sChromeOnlyNativeProperties.Upcast(), |
1662 | 0 | nullptr, aDefineOnGlobal, |
1663 | 0 | nullptr, |
1664 | 0 | false); |
1665 | 0 | } |
1666 | | |
1667 | | } // namespace RTCIdentityProviderRegistrar_Binding |
1668 | | |
1669 | | |
1670 | | |
1671 | | } // namespace dom |
1672 | | } // namespace mozilla |