Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM AppNotificationServiceOptions.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AppNotificationServiceOptionsBinding.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 :
16 0 : AppNotificationServiceOptions::AppNotificationServiceOptions()
17 0 : : mMozbehavior(FastDictionaryInitializer())
18 : {
19 : // Safe to pass a null context if we pass a null value
20 0 : Init(nullptr, JS::NullHandleValue);
21 0 : }
22 :
23 :
24 :
25 : bool
26 0 : AppNotificationServiceOptions::InitIds(JSContext* cx, AppNotificationServiceOptionsAtoms* atomsCache)
27 : {
28 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
29 :
30 : // Initialize these in reverse order so that any failure leaves the first one
31 : // uninitialized.
32 0 : if (!atomsCache->textClickable_id.init(cx, "textClickable") ||
33 0 : !atomsCache->tag_id.init(cx, "tag") ||
34 0 : !atomsCache->mozbehavior_id.init(cx, "mozbehavior") ||
35 0 : !atomsCache->manifestURL_id.init(cx, "manifestURL") ||
36 0 : !atomsCache->lang_id.init(cx, "lang") ||
37 0 : !atomsCache->id_id.init(cx, "id") ||
38 0 : !atomsCache->dir_id.init(cx, "dir") ||
39 0 : !atomsCache->dbId_id.init(cx, "dbId") ||
40 0 : !atomsCache->data_id.init(cx, "data")) {
41 0 : return false;
42 : }
43 0 : return true;
44 : }
45 :
46 : bool
47 0 : AppNotificationServiceOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
48 : {
49 : // Passing a null JSContext is OK only if we're initing from null,
50 : // Since in that case we will not have to do any property gets
51 : // Also evaluate isNullOrUndefined in order to avoid false-positive
52 : // checkers by static analysis tools
53 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
54 0 : AppNotificationServiceOptionsAtoms* atomsCache = nullptr;
55 0 : if (cx) {
56 0 : atomsCache = GetAtomCache<AppNotificationServiceOptionsAtoms>(cx);
57 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
58 0 : return false;
59 : }
60 : }
61 :
62 0 : if (!IsConvertibleToDictionary(val)) {
63 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
64 : }
65 :
66 0 : bool isNull = val.isNullOrUndefined();
67 : // We only need these if !isNull, in which case we have |cx|.
68 0 : Maybe<JS::Rooted<JSObject *> > object;
69 0 : Maybe<JS::Rooted<JS::Value> > temp;
70 0 : if (!isNull) {
71 0 : MOZ_ASSERT(cx);
72 0 : object.emplace(cx, &val.toObject());
73 0 : temp.emplace(cx);
74 : }
75 0 : if (!isNull) {
76 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) {
77 0 : return false;
78 : }
79 : }
80 0 : if (!isNull && !temp->isUndefined()) {
81 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mData)) {
82 0 : return false;
83 : }
84 : } else {
85 : static const char16_t data[] = { 0 };
86 0 : mData.Rebind(data, ArrayLength(data) - 1);
87 : }
88 0 : mIsAnyMemberPresent = true;
89 :
90 0 : if (!isNull) {
91 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->dbId_id, temp.ptr())) {
92 0 : return false;
93 : }
94 : }
95 0 : if (!isNull && !temp->isUndefined()) {
96 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDbId)) {
97 0 : return false;
98 : }
99 : } else {
100 : static const char16_t data[] = { 0 };
101 0 : mDbId.Rebind(data, ArrayLength(data) - 1);
102 : }
103 0 : mIsAnyMemberPresent = true;
104 :
105 0 : if (!isNull) {
106 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->dir_id, temp.ptr())) {
107 0 : return false;
108 : }
109 : }
110 0 : if (!isNull && !temp->isUndefined()) {
111 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDir)) {
112 0 : return false;
113 : }
114 : } else {
115 : static const char16_t data[] = { 0 };
116 0 : mDir.Rebind(data, ArrayLength(data) - 1);
117 : }
118 0 : mIsAnyMemberPresent = true;
119 :
120 0 : if (!isNull) {
121 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->id_id, temp.ptr())) {
122 0 : return false;
123 : }
124 : }
125 0 : if (!isNull && !temp->isUndefined()) {
126 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mId)) {
127 0 : return false;
128 : }
129 : } else {
130 : static const char16_t data[] = { 0 };
131 0 : mId.Rebind(data, ArrayLength(data) - 1);
132 : }
133 0 : mIsAnyMemberPresent = true;
134 :
135 0 : if (!isNull) {
136 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->lang_id, temp.ptr())) {
137 0 : return false;
138 : }
139 : }
140 0 : if (!isNull && !temp->isUndefined()) {
141 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mLang)) {
142 0 : return false;
143 : }
144 : } else {
145 : static const char16_t data[] = { 0 };
146 0 : mLang.Rebind(data, ArrayLength(data) - 1);
147 : }
148 0 : mIsAnyMemberPresent = true;
149 :
150 0 : if (!isNull) {
151 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->manifestURL_id, temp.ptr())) {
152 0 : return false;
153 : }
154 : }
155 0 : if (!isNull && !temp->isUndefined()) {
156 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mManifestURL)) {
157 0 : return false;
158 : }
159 : } else {
160 : static const char16_t data[] = { 0 };
161 0 : mManifestURL.Rebind(data, ArrayLength(data) - 1);
162 : }
163 0 : mIsAnyMemberPresent = true;
164 :
165 0 : if (!isNull) {
166 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->mozbehavior_id, temp.ptr())) {
167 0 : return false;
168 : }
169 : }
170 0 : if (!mMozbehavior.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'mozbehavior' member of AppNotificationServiceOptions", passedToJSImpl)) {
171 0 : return false;
172 : }
173 0 : mIsAnyMemberPresent = true;
174 :
175 0 : if (!isNull) {
176 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->tag_id, temp.ptr())) {
177 0 : return false;
178 : }
179 : }
180 0 : if (!isNull && !temp->isUndefined()) {
181 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mTag)) {
182 0 : return false;
183 : }
184 : } else {
185 : static const char16_t data[] = { 0 };
186 0 : mTag.Rebind(data, ArrayLength(data) - 1);
187 : }
188 0 : mIsAnyMemberPresent = true;
189 :
190 0 : if (!isNull) {
191 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->textClickable_id, temp.ptr())) {
192 0 : return false;
193 : }
194 : }
195 0 : if (!isNull && !temp->isUndefined()) {
196 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mTextClickable)) {
197 0 : return false;
198 : }
199 : } else {
200 0 : mTextClickable = false;
201 : }
202 0 : mIsAnyMemberPresent = true;
203 0 : return true;
204 : }
205 :
206 : bool
207 0 : AppNotificationServiceOptions::Init(const nsAString& aJSON)
208 : {
209 0 : AutoJSAPI jsapi;
210 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
211 0 : if (!cleanGlobal) {
212 0 : return false;
213 : }
214 0 : if (!jsapi.Init(cleanGlobal)) {
215 0 : return false;
216 : }
217 0 : JSContext* cx = jsapi.cx();
218 0 : JS::Rooted<JS::Value> json(cx);
219 0 : bool ok = ParseJSON(cx, aJSON, &json);
220 0 : NS_ENSURE_TRUE(ok, false);
221 0 : return Init(cx, json);
222 : }
223 :
224 : bool
225 0 : AppNotificationServiceOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
226 : {
227 0 : AppNotificationServiceOptionsAtoms* atomsCache = GetAtomCache<AppNotificationServiceOptionsAtoms>(cx);
228 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
229 0 : return false;
230 : }
231 :
232 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
233 0 : if (!obj) {
234 0 : return false;
235 : }
236 0 : rval.set(JS::ObjectValue(*obj));
237 :
238 : do {
239 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
240 0 : JS::Rooted<JS::Value> temp(cx);
241 0 : nsString const & currentValue = mData;
242 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
243 0 : return false;
244 : }
245 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) {
246 0 : return false;
247 : }
248 0 : break;
249 : } while(0);
250 :
251 : do {
252 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
253 0 : JS::Rooted<JS::Value> temp(cx);
254 0 : nsString const & currentValue = mDbId;
255 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
256 0 : return false;
257 : }
258 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->dbId_id, temp, JSPROP_ENUMERATE)) {
259 0 : return false;
260 : }
261 0 : break;
262 : } while(0);
263 :
264 : do {
265 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
266 0 : JS::Rooted<JS::Value> temp(cx);
267 0 : nsString const & currentValue = mDir;
268 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
269 0 : return false;
270 : }
271 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->dir_id, temp, JSPROP_ENUMERATE)) {
272 0 : return false;
273 : }
274 0 : break;
275 : } while(0);
276 :
277 : do {
278 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
279 0 : JS::Rooted<JS::Value> temp(cx);
280 0 : nsString const & currentValue = mId;
281 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
282 0 : return false;
283 : }
284 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) {
285 0 : return false;
286 : }
287 0 : break;
288 : } while(0);
289 :
290 : do {
291 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
292 0 : JS::Rooted<JS::Value> temp(cx);
293 0 : nsString const & currentValue = mLang;
294 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
295 0 : return false;
296 : }
297 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->lang_id, temp, JSPROP_ENUMERATE)) {
298 0 : return false;
299 : }
300 0 : break;
301 : } while(0);
302 :
303 : do {
304 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
305 0 : JS::Rooted<JS::Value> temp(cx);
306 0 : nsString const & currentValue = mManifestURL;
307 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
308 0 : return false;
309 : }
310 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->manifestURL_id, temp, JSPROP_ENUMERATE)) {
311 0 : return false;
312 : }
313 0 : break;
314 : } while(0);
315 :
316 : do {
317 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
318 0 : JS::Rooted<JS::Value> temp(cx);
319 0 : NotificationBehavior const & currentValue = mMozbehavior;
320 0 : if (!currentValue.ToObjectInternal(cx, &temp)) {
321 0 : return false;
322 : }
323 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->mozbehavior_id, temp, JSPROP_ENUMERATE)) {
324 0 : return false;
325 : }
326 0 : break;
327 : } while(0);
328 :
329 : do {
330 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
331 0 : JS::Rooted<JS::Value> temp(cx);
332 0 : nsString const & currentValue = mTag;
333 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
334 0 : return false;
335 : }
336 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->tag_id, temp, JSPROP_ENUMERATE)) {
337 0 : return false;
338 : }
339 0 : break;
340 : } while(0);
341 :
342 : do {
343 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
344 0 : JS::Rooted<JS::Value> temp(cx);
345 0 : bool const & currentValue = mTextClickable;
346 0 : temp.setBoolean(currentValue);
347 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->textClickable_id, temp, JSPROP_ENUMERATE)) {
348 0 : return false;
349 : }
350 0 : break;
351 : } while(0);
352 :
353 0 : return true;
354 : }
355 :
356 : bool
357 0 : AppNotificationServiceOptions::ToJSON(nsAString& aJSON) const
358 : {
359 0 : AutoJSAPI jsapi;
360 0 : jsapi.Init();
361 0 : JSContext *cx = jsapi.cx();
362 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
363 : // because we'll only be creating objects, in ways that have no
364 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
365 : // which likewise guarantees no side-effects for the sorts of
366 : // things we will pass it.
367 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
368 0 : JS::Rooted<JS::Value> val(cx);
369 0 : if (!ToObjectInternal(cx, &val)) {
370 0 : return false;
371 : }
372 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
373 0 : return StringifyToJSON(cx, obj, aJSON);
374 : }
375 :
376 : void
377 0 : AppNotificationServiceOptions::TraceDictionary(JSTracer* trc)
378 : {
379 0 : }
380 :
381 : AppNotificationServiceOptions&
382 0 : AppNotificationServiceOptions::operator=(const AppNotificationServiceOptions& aOther)
383 : {
384 0 : mData = aOther.mData;
385 0 : mDbId = aOther.mDbId;
386 0 : mDir = aOther.mDir;
387 0 : mId = aOther.mId;
388 0 : mLang = aOther.mLang;
389 0 : mManifestURL = aOther.mManifestURL;
390 0 : mMozbehavior = aOther.mMozbehavior;
391 0 : mTag = aOther.mTag;
392 0 : mTextClickable = aOther.mTextClickable;
393 0 : return *this;
394 : }
395 :
396 : namespace binding_detail {
397 : } // namespace binding_detail
398 :
399 :
400 : } // namespace dom
401 : } // namespace mozilla
|