/work/obj-fuzz/dom/bindings/MIDIOptionsBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM MIDIOptions.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "MIDIOptionsBinding.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 | | MIDIOptions::MIDIOptions() |
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 | | MIDIOptions::InitIds(JSContext* cx, MIDIOptionsAtoms* 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->sysex_id.init(cx, "sysex") || |
36 | 0 | !atomsCache->software_id.init(cx, "software")) { |
37 | 0 | return false; |
38 | 0 | } |
39 | 0 | return true; |
40 | 0 | } |
41 | | |
42 | | bool |
43 | | MIDIOptions::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 | MIDIOptionsAtoms* atomsCache = nullptr; |
51 | 0 | if (cx) { |
52 | 0 | atomsCache = GetAtomCache<MIDIOptionsAtoms>(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->software_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(), &mSoftware)) { |
78 | 0 | return false; |
79 | 0 | } |
80 | 0 | } else { |
81 | 0 | mSoftware = false; |
82 | 0 | } |
83 | 0 | mIsAnyMemberPresent = true; |
84 | 0 |
|
85 | 0 | if (!isNull) { |
86 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->sysex_id, temp.ptr())) { |
87 | 0 | return false; |
88 | 0 | } |
89 | 0 | } |
90 | 0 | if (!isNull && !temp->isUndefined()) { |
91 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mSysex)) { |
92 | 0 | return false; |
93 | 0 | } |
94 | 0 | } else { |
95 | 0 | mSysex = false; |
96 | 0 | } |
97 | 0 | mIsAnyMemberPresent = true; |
98 | 0 | return true; |
99 | 0 | } |
100 | | |
101 | | bool |
102 | | MIDIOptions::Init(const nsAString& aJSON) |
103 | 0 | { |
104 | 0 | AutoJSAPI jsapi; |
105 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
106 | 0 | if (!cleanGlobal) { |
107 | 0 | return false; |
108 | 0 | } |
109 | 0 | if (!jsapi.Init(cleanGlobal)) { |
110 | 0 | return false; |
111 | 0 | } |
112 | 0 | JSContext* cx = jsapi.cx(); |
113 | 0 | JS::Rooted<JS::Value> json(cx); |
114 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
115 | 0 | NS_ENSURE_TRUE(ok, false); |
116 | 0 | return Init(cx, json); |
117 | 0 | } |
118 | | |
119 | | bool |
120 | | MIDIOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
121 | 0 | { |
122 | 0 | MIDIOptionsAtoms* atomsCache = GetAtomCache<MIDIOptionsAtoms>(cx); |
123 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
124 | 0 | return false; |
125 | 0 | } |
126 | 0 | |
127 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
128 | 0 | if (!obj) { |
129 | 0 | return false; |
130 | 0 | } |
131 | 0 | rval.set(JS::ObjectValue(*obj)); |
132 | 0 |
|
133 | 0 | do { |
134 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
135 | 0 | JS::Rooted<JS::Value> temp(cx); |
136 | 0 | bool const & currentValue = mSoftware; |
137 | 0 | temp.setBoolean(currentValue); |
138 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->software_id, temp, JSPROP_ENUMERATE)) { |
139 | 0 | return false; |
140 | 0 | } |
141 | 0 | break; |
142 | 0 | } while(false); |
143 | 0 |
|
144 | 0 | do { |
145 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
146 | 0 | JS::Rooted<JS::Value> temp(cx); |
147 | 0 | bool const & currentValue = mSysex; |
148 | 0 | temp.setBoolean(currentValue); |
149 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->sysex_id, temp, JSPROP_ENUMERATE)) { |
150 | 0 | return false; |
151 | 0 | } |
152 | 0 | break; |
153 | 0 | } while(false); |
154 | 0 |
|
155 | 0 | return true; |
156 | 0 | } |
157 | | |
158 | | bool |
159 | | MIDIOptions::ToJSON(nsAString& aJSON) const |
160 | 0 | { |
161 | 0 | AutoJSAPI jsapi; |
162 | 0 | jsapi.Init(); |
163 | 0 | JSContext *cx = jsapi.cx(); |
164 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
165 | 0 | // because we'll only be creating objects, in ways that have no |
166 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
167 | 0 | // which likewise guarantees no side-effects for the sorts of |
168 | 0 | // things we will pass it. |
169 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
170 | 0 | JS::Rooted<JS::Value> val(cx); |
171 | 0 | if (!ToObjectInternal(cx, &val)) { |
172 | 0 | return false; |
173 | 0 | } |
174 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
175 | 0 | return StringifyToJSON(cx, obj, aJSON); |
176 | 0 | } |
177 | | |
178 | | void |
179 | | MIDIOptions::TraceDictionary(JSTracer* trc) |
180 | 0 | { |
181 | 0 | } |
182 | | |
183 | | MIDIOptions& |
184 | | MIDIOptions::operator=(const MIDIOptions& aOther) |
185 | 0 | { |
186 | 0 | DictionaryBase::operator=(aOther); |
187 | 0 | mSoftware = aOther.mSoftware; |
188 | 0 | mSysex = aOther.mSysex; |
189 | 0 | return *this; |
190 | 0 | } |
191 | | |
192 | | namespace binding_detail { |
193 | | } // namespace binding_detail |
194 | | |
195 | | |
196 | | } // namespace dom |
197 | | } // namespace mozilla |