Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/AutocompleteInfoBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM AutocompleteInfo.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "AutocompleteInfoBinding.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
AutocompleteInfo::AutocompleteInfo()
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
AutocompleteInfo::InitIds(JSContext* cx, AutocompleteInfoAtoms* 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->section_id.init(cx, "section") ||
35
0
      !atomsCache->fieldName_id.init(cx, "fieldName") ||
36
0
      !atomsCache->contactType_id.init(cx, "contactType") ||
37
0
      !atomsCache->addressType_id.init(cx, "addressType")) {
38
0
    return false;
39
0
  }
40
0
  return true;
41
0
}
42
43
bool
44
AutocompleteInfo::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
45
0
{
46
0
  // Passing a null JSContext is OK only if we're initing from null,
47
0
  // Since in that case we will not have to do any property gets
48
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
49
0
  // checkers by static analysis tools
50
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
51
0
  AutocompleteInfoAtoms* atomsCache = nullptr;
52
0
  if (cx) {
53
0
    atomsCache = GetAtomCache<AutocompleteInfoAtoms>(cx);
54
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
55
0
      return false;
56
0
    }
57
0
  }
58
0
59
0
  if (!IsConvertibleToDictionary(val)) {
60
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
61
0
  }
62
0
63
0
  bool isNull = val.isNullOrUndefined();
64
0
  // We only need these if !isNull, in which case we have |cx|.
65
0
  Maybe<JS::Rooted<JSObject *> > object;
66
0
  Maybe<JS::Rooted<JS::Value> > temp;
67
0
  if (!isNull) {
68
0
    MOZ_ASSERT(cx);
69
0
    object.emplace(cx, &val.toObject());
70
0
    temp.emplace(cx);
71
0
  }
72
0
  if (!isNull) {
73
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->addressType_id, temp.ptr())) {
74
0
      return false;
75
0
    }
76
0
  }
77
0
  if (!isNull && !temp->isUndefined()) {
78
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mAddressType)) {
79
0
      return false;
80
0
    }
81
0
  } else {
82
0
    static const char16_t data[] = { 0 };
83
0
    mAddressType.Rebind(data, ArrayLength(data) - 1);
84
0
  }
85
0
  mIsAnyMemberPresent = true;
86
0
87
0
  if (!isNull) {
88
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->contactType_id, temp.ptr())) {
89
0
      return false;
90
0
    }
91
0
  }
92
0
  if (!isNull && !temp->isUndefined()) {
93
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mContactType)) {
94
0
      return false;
95
0
    }
96
0
  } else {
97
0
    static const char16_t data[] = { 0 };
98
0
    mContactType.Rebind(data, ArrayLength(data) - 1);
99
0
  }
100
0
  mIsAnyMemberPresent = true;
101
0
102
0
  if (!isNull) {
103
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->fieldName_id, temp.ptr())) {
104
0
      return false;
105
0
    }
106
0
  }
107
0
  if (!isNull && !temp->isUndefined()) {
108
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mFieldName)) {
109
0
      return false;
110
0
    }
111
0
  } else {
112
0
    static const char16_t data[] = { 0 };
113
0
    mFieldName.Rebind(data, ArrayLength(data) - 1);
114
0
  }
115
0
  mIsAnyMemberPresent = true;
116
0
117
0
  if (!isNull) {
118
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->section_id, temp.ptr())) {
119
0
      return false;
120
0
    }
121
0
  }
122
0
  if (!isNull && !temp->isUndefined()) {
123
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mSection)) {
124
0
      return false;
125
0
    }
126
0
  } else {
127
0
    static const char16_t data[] = { 0 };
128
0
    mSection.Rebind(data, ArrayLength(data) - 1);
129
0
  }
130
0
  mIsAnyMemberPresent = true;
131
0
  return true;
132
0
}
133
134
bool
135
AutocompleteInfo::Init(const nsAString& aJSON)
136
0
{
137
0
  AutoJSAPI jsapi;
138
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
139
0
  if (!cleanGlobal) {
140
0
    return false;
141
0
  }
142
0
  if (!jsapi.Init(cleanGlobal)) {
143
0
    return false;
144
0
  }
145
0
  JSContext* cx = jsapi.cx();
146
0
  JS::Rooted<JS::Value> json(cx);
147
0
  bool ok = ParseJSON(cx, aJSON, &json);
148
0
  NS_ENSURE_TRUE(ok, false);
149
0
  return Init(cx, json);
150
0
}
151
152
bool
153
AutocompleteInfo::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
154
0
{
155
0
  AutocompleteInfoAtoms* atomsCache = GetAtomCache<AutocompleteInfoAtoms>(cx);
156
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
157
0
    return false;
158
0
  }
159
0
160
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
161
0
  if (!obj) {
162
0
    return false;
163
0
  }
164
0
  rval.set(JS::ObjectValue(*obj));
165
0
166
0
  do {
167
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
168
0
    JS::Rooted<JS::Value> temp(cx);
169
0
    nsString const & currentValue = mAddressType;
170
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
171
0
      return false;
172
0
    }
173
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->addressType_id, temp, JSPROP_ENUMERATE)) {
174
0
      return false;
175
0
    }
176
0
    break;
177
0
  } while(false);
178
0
179
0
  do {
180
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
181
0
    JS::Rooted<JS::Value> temp(cx);
182
0
    nsString const & currentValue = mContactType;
183
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
184
0
      return false;
185
0
    }
186
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->contactType_id, temp, JSPROP_ENUMERATE)) {
187
0
      return false;
188
0
    }
189
0
    break;
190
0
  } while(false);
191
0
192
0
  do {
193
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
194
0
    JS::Rooted<JS::Value> temp(cx);
195
0
    nsString const & currentValue = mFieldName;
196
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
197
0
      return false;
198
0
    }
199
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->fieldName_id, temp, JSPROP_ENUMERATE)) {
200
0
      return false;
201
0
    }
202
0
    break;
203
0
  } while(false);
204
0
205
0
  do {
206
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
207
0
    JS::Rooted<JS::Value> temp(cx);
208
0
    nsString const & currentValue = mSection;
209
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
210
0
      return false;
211
0
    }
212
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->section_id, temp, JSPROP_ENUMERATE)) {
213
0
      return false;
214
0
    }
215
0
    break;
216
0
  } while(false);
217
0
218
0
  return true;
219
0
}
220
221
bool
222
AutocompleteInfo::ToJSON(nsAString& aJSON) const
223
0
{
224
0
  AutoJSAPI jsapi;
225
0
  jsapi.Init();
226
0
  JSContext *cx = jsapi.cx();
227
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
228
0
  // because we'll only be creating objects, in ways that have no
229
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
230
0
  // which likewise guarantees no side-effects for the sorts of
231
0
  // things we will pass it.
232
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
233
0
  JS::Rooted<JS::Value> val(cx);
234
0
  if (!ToObjectInternal(cx, &val)) {
235
0
    return false;
236
0
  }
237
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
238
0
  return StringifyToJSON(cx, obj, aJSON);
239
0
}
240
241
void
242
AutocompleteInfo::TraceDictionary(JSTracer* trc)
243
0
{
244
0
}
245
246
AutocompleteInfo&
247
AutocompleteInfo::operator=(const AutocompleteInfo& aOther)
248
0
{
249
0
  DictionaryBase::operator=(aOther);
250
0
  mAddressType = aOther.mAddressType;
251
0
  mContactType = aOther.mContactType;
252
0
  mFieldName = aOther.mFieldName;
253
0
  mSection = aOther.mSection;
254
0
  return *this;
255
0
}
256
257
namespace binding_detail {
258
} // namespace binding_detail
259
260
261
} // namespace dom
262
} // namespace mozilla