/work/obj-fuzz/dom/bindings/RTCIdentityAssertionBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM RTCIdentityAssertion.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "RTCIdentityAssertionBinding.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/dom/BindingUtils.h" |
7 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
8 | | #include "mozilla/dom/ScriptSettings.h" |
9 | | #include "mozilla/dom/SimpleGlobalObject.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace dom { |
13 | | |
14 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
15 | | using namespace mozilla::dom::binding_detail; |
16 | | |
17 | | |
18 | | |
19 | | RTCIdentityAssertion::RTCIdentityAssertion() |
20 | 0 | { |
21 | 0 | // Safe to pass a null context if we pass a null value |
22 | 0 | Init(nullptr, JS::NullHandleValue); |
23 | 0 | } |
24 | | |
25 | | |
26 | | |
27 | | bool |
28 | | RTCIdentityAssertion::InitIds(JSContext* cx, RTCIdentityAssertionAtoms* atomsCache) |
29 | 0 | { |
30 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
31 | 0 |
|
32 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
33 | 0 | // uninitialized. |
34 | 0 | if (!atomsCache->name_id.init(cx, "name") || |
35 | 0 | !atomsCache->idp_id.init(cx, "idp")) { |
36 | 0 | return false; |
37 | 0 | } |
38 | 0 | return true; |
39 | 0 | } |
40 | | |
41 | | bool |
42 | | RTCIdentityAssertion::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
43 | 0 | { |
44 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
45 | 0 | // Since in that case we will not have to do any property gets |
46 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
47 | 0 | // checkers by static analysis tools |
48 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
49 | 0 | RTCIdentityAssertionAtoms* atomsCache = nullptr; |
50 | 0 | if (cx) { |
51 | 0 | atomsCache = GetAtomCache<RTCIdentityAssertionAtoms>(cx); |
52 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
53 | 0 | return false; |
54 | 0 | } |
55 | 0 | } |
56 | 0 | |
57 | 0 | if (!IsConvertibleToDictionary(val)) { |
58 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
59 | 0 | } |
60 | 0 | |
61 | 0 | bool isNull = val.isNullOrUndefined(); |
62 | 0 | // We only need these if !isNull, in which case we have |cx|. |
63 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
64 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
65 | 0 | if (!isNull) { |
66 | 0 | MOZ_ASSERT(cx); |
67 | 0 | object.emplace(cx, &val.toObject()); |
68 | 0 | temp.emplace(cx); |
69 | 0 | } |
70 | 0 | if (!isNull) { |
71 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->idp_id, temp.ptr())) { |
72 | 0 | return false; |
73 | 0 | } |
74 | 0 | } |
75 | 0 | if (!isNull && !temp->isUndefined()) { |
76 | 0 | mIdp.Construct(); |
77 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mIdp.Value()))) { |
78 | 0 | return false; |
79 | 0 | } |
80 | 0 | mIsAnyMemberPresent = true; |
81 | 0 | } |
82 | 0 |
|
83 | 0 | if (!isNull) { |
84 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) { |
85 | 0 | return false; |
86 | 0 | } |
87 | 0 | } |
88 | 0 | if (!isNull && !temp->isUndefined()) { |
89 | 0 | mName.Construct(); |
90 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mName.Value()))) { |
91 | 0 | return false; |
92 | 0 | } |
93 | 0 | mIsAnyMemberPresent = true; |
94 | 0 | } |
95 | 0 | return true; |
96 | 0 | } |
97 | | |
98 | | bool |
99 | | RTCIdentityAssertion::Init(const nsAString& aJSON) |
100 | 0 | { |
101 | 0 | AutoJSAPI jsapi; |
102 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
103 | 0 | if (!cleanGlobal) { |
104 | 0 | return false; |
105 | 0 | } |
106 | 0 | if (!jsapi.Init(cleanGlobal)) { |
107 | 0 | return false; |
108 | 0 | } |
109 | 0 | JSContext* cx = jsapi.cx(); |
110 | 0 | JS::Rooted<JS::Value> json(cx); |
111 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
112 | 0 | NS_ENSURE_TRUE(ok, false); |
113 | 0 | return Init(cx, json); |
114 | 0 | } |
115 | | |
116 | | bool |
117 | | RTCIdentityAssertion::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
118 | 0 | { |
119 | 0 | RTCIdentityAssertionAtoms* atomsCache = GetAtomCache<RTCIdentityAssertionAtoms>(cx); |
120 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
121 | 0 | return false; |
122 | 0 | } |
123 | 0 | |
124 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
125 | 0 | if (!obj) { |
126 | 0 | return false; |
127 | 0 | } |
128 | 0 | rval.set(JS::ObjectValue(*obj)); |
129 | 0 |
|
130 | 0 | if (mIdp.WasPassed()) { |
131 | 0 | do { |
132 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
133 | 0 | JS::Rooted<JS::Value> temp(cx); |
134 | 0 | nsString const & currentValue = mIdp.InternalValue(); |
135 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
136 | 0 | return false; |
137 | 0 | } |
138 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->idp_id, temp, JSPROP_ENUMERATE)) { |
139 | 0 | return false; |
140 | 0 | } |
141 | 0 | break; |
142 | 0 | } while(false); |
143 | 0 | } |
144 | 0 |
|
145 | 0 | if (mName.WasPassed()) { |
146 | 0 | do { |
147 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
148 | 0 | JS::Rooted<JS::Value> temp(cx); |
149 | 0 | nsString const & currentValue = mName.InternalValue(); |
150 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
151 | 0 | return false; |
152 | 0 | } |
153 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) { |
154 | 0 | return false; |
155 | 0 | } |
156 | 0 | break; |
157 | 0 | } while(false); |
158 | 0 | } |
159 | 0 |
|
160 | 0 | return true; |
161 | 0 | } |
162 | | |
163 | | bool |
164 | | RTCIdentityAssertion::ToJSON(nsAString& aJSON) const |
165 | 0 | { |
166 | 0 | AutoJSAPI jsapi; |
167 | 0 | jsapi.Init(); |
168 | 0 | JSContext *cx = jsapi.cx(); |
169 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
170 | 0 | // because we'll only be creating objects, in ways that have no |
171 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
172 | 0 | // which likewise guarantees no side-effects for the sorts of |
173 | 0 | // things we will pass it. |
174 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
175 | 0 | JS::Rooted<JS::Value> val(cx); |
176 | 0 | if (!ToObjectInternal(cx, &val)) { |
177 | 0 | return false; |
178 | 0 | } |
179 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
180 | 0 | return StringifyToJSON(cx, obj, aJSON); |
181 | 0 | } |
182 | | |
183 | | void |
184 | | RTCIdentityAssertion::TraceDictionary(JSTracer* trc) |
185 | 0 | { |
186 | 0 | } |
187 | | |
188 | | RTCIdentityAssertion& |
189 | | RTCIdentityAssertion::operator=(const RTCIdentityAssertion& aOther) |
190 | 0 | { |
191 | 0 | DictionaryBase::operator=(aOther); |
192 | 0 | mIdp.Reset(); |
193 | 0 | if (aOther.mIdp.WasPassed()) { |
194 | 0 | mIdp.Construct(aOther.mIdp.Value()); |
195 | 0 | } |
196 | 0 | mName.Reset(); |
197 | 0 | if (aOther.mName.WasPassed()) { |
198 | 0 | mName.Construct(aOther.mName.Value()); |
199 | 0 | } |
200 | 0 | return *this; |
201 | 0 | } |
202 | | |
203 | | namespace binding_detail { |
204 | | } // namespace binding_detail |
205 | | |
206 | | |
207 | | } // namespace dom |
208 | | } // namespace mozilla |