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