Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM IterableIterator.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "IterableIteratorBinding.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 :
11 : namespace mozilla {
12 : namespace dom {
13 :
14 :
15 0 : IterableKeyAndValueResult::IterableKeyAndValueResult()
16 : {
17 : // Safe to pass a null context if we pass a null value
18 0 : Init(nullptr, JS::NullHandleValue);
19 0 : }
20 :
21 :
22 : bool
23 0 : IterableKeyAndValueResult::InitIds(JSContext* cx, IterableKeyAndValueResultAtoms* atomsCache)
24 : {
25 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
26 :
27 : // Initialize these in reverse order so that any failure leaves the first one
28 : // uninitialized.
29 0 : if (!atomsCache->value_id.init(cx, "value") ||
30 0 : !atomsCache->done_id.init(cx, "done")) {
31 0 : return false;
32 : }
33 0 : return true;
34 : }
35 :
36 : bool
37 0 : IterableKeyAndValueResult::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
38 : {
39 : // Passing a null JSContext is OK only if we're initing from null,
40 : // Since in that case we will not have to do any property gets
41 : // Also evaluate isNullOrUndefined in order to avoid false-positive
42 : // checkers by static analysis tools
43 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
44 0 : IterableKeyAndValueResultAtoms* atomsCache = nullptr;
45 0 : if (cx) {
46 0 : atomsCache = GetAtomCache<IterableKeyAndValueResultAtoms>(cx);
47 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
48 0 : return false;
49 : }
50 : }
51 :
52 0 : if (!IsConvertibleToDictionary(val)) {
53 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
54 : }
55 :
56 0 : bool isNull = val.isNullOrUndefined();
57 : // We only need these if !isNull, in which case we have |cx|.
58 0 : Maybe<JS::Rooted<JSObject *> > object;
59 0 : Maybe<JS::Rooted<JS::Value> > temp;
60 0 : if (!isNull) {
61 0 : MOZ_ASSERT(cx);
62 0 : object.emplace(cx, &val.toObject());
63 0 : temp.emplace(cx);
64 : }
65 0 : if (!isNull) {
66 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->done_id, temp.ptr())) {
67 0 : return false;
68 : }
69 : }
70 0 : if (!isNull && !temp->isUndefined()) {
71 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mDone)) {
72 0 : return false;
73 : }
74 : } else {
75 0 : mDone = false;
76 : }
77 0 : mIsAnyMemberPresent = true;
78 :
79 0 : if (!isNull) {
80 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->value_id, temp.ptr())) {
81 0 : return false;
82 : }
83 : }
84 0 : if (!isNull && !temp->isUndefined()) {
85 0 : if (temp.ref().isObject()) {
86 0 : JS::ForOfIterator iter(cx);
87 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
88 0 : return false;
89 : }
90 0 : if (!iter.valueIsIterable()) {
91 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'value' member of IterableKeyAndValueResult");
92 0 : return false;
93 : }
94 0 : Sequence<JS::Value> &arr = mValue;
95 0 : JS::Rooted<JS::Value> temp(cx);
96 : while (true) {
97 : bool done;
98 0 : if (!iter.next(&temp, &done)) {
99 0 : return false;
100 : }
101 0 : if (done) {
102 0 : break;
103 : }
104 0 : JS::Value* slotPtr = arr.AppendElement(mozilla::fallible);
105 0 : if (!slotPtr) {
106 0 : JS_ReportOutOfMemory(cx);
107 0 : return false;
108 : }
109 0 : JS::Value& slot = *slotPtr;
110 : #ifdef __clang__
111 : #pragma clang diagnostic push
112 : #pragma clang diagnostic ignored "-Wunreachable-code"
113 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
114 : #endif // __clang__
115 0 : if ((passedToJSImpl) && !CallerSubsumes(temp)) {
116 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "element of 'value' member of IterableKeyAndValueResult");
117 0 : return false;
118 : }
119 : #ifdef __clang__
120 : #pragma clang diagnostic pop
121 : #endif // __clang__
122 0 : slot = temp;
123 0 : }
124 : } else {
125 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'value' member of IterableKeyAndValueResult");
126 0 : return false;
127 : }
128 : } else {
129 : /* Array is already empty; nothing to do */
130 : }
131 0 : mIsAnyMemberPresent = true;
132 0 : return true;
133 : }
134 :
135 : bool
136 0 : IterableKeyAndValueResult::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
137 : {
138 0 : IterableKeyAndValueResultAtoms* atomsCache = GetAtomCache<IterableKeyAndValueResultAtoms>(cx);
139 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
140 0 : return false;
141 : }
142 :
143 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
144 0 : if (!obj) {
145 0 : return false;
146 : }
147 0 : rval.set(JS::ObjectValue(*obj));
148 :
149 : do {
150 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
151 0 : JS::Rooted<JS::Value> temp(cx);
152 0 : bool const & currentValue = mDone;
153 0 : temp.setBoolean(currentValue);
154 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->done_id, temp, JSPROP_ENUMERATE)) {
155 0 : return false;
156 : }
157 0 : break;
158 : } while(0);
159 :
160 : do {
161 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
162 0 : JS::Rooted<JS::Value> temp(cx);
163 0 : Sequence<JS::Value> const & currentValue = mValue;
164 :
165 0 : uint32_t length = currentValue.Length();
166 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
167 0 : if (!returnArray) {
168 0 : return false;
169 : }
170 : // Scope for 'tmp'
171 : {
172 0 : JS::Rooted<JS::Value> tmp(cx);
173 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
174 : // Control block to let us common up the JS_DefineElement calls when there
175 : // are different ways to succeed at wrapping the object.
176 : do {
177 0 : JS::ExposeValueToActiveJS(currentValue[sequenceIdx0]);
178 0 : tmp.set(currentValue[sequenceIdx0]);
179 0 : if (!MaybeWrapValue(cx, &tmp)) {
180 0 : return false;
181 : }
182 0 : break;
183 : } while (0);
184 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
185 : JSPROP_ENUMERATE)) {
186 0 : return false;
187 : }
188 : }
189 : }
190 0 : temp.setObject(*returnArray);
191 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->value_id, temp, JSPROP_ENUMERATE)) {
192 0 : return false;
193 : }
194 0 : break;
195 : } while(0);
196 :
197 0 : return true;
198 : }
199 :
200 : void
201 0 : IterableKeyAndValueResult::TraceDictionary(JSTracer* trc)
202 : {
203 0 : DoTraceSequence(trc, mValue);
204 0 : }
205 :
206 : namespace binding_detail {
207 : } // namespace binding_detail
208 :
209 :
210 :
211 0 : IterableKeyOrValueResult::IterableKeyOrValueResult()
212 0 : : mValue(JS::UndefinedValue())
213 : {
214 : // Safe to pass a null context if we pass a null value
215 0 : Init(nullptr, JS::NullHandleValue);
216 0 : }
217 :
218 :
219 : bool
220 0 : IterableKeyOrValueResult::InitIds(JSContext* cx, IterableKeyOrValueResultAtoms* atomsCache)
221 : {
222 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
223 :
224 : // Initialize these in reverse order so that any failure leaves the first one
225 : // uninitialized.
226 0 : if (!atomsCache->value_id.init(cx, "value") ||
227 0 : !atomsCache->done_id.init(cx, "done")) {
228 0 : return false;
229 : }
230 0 : return true;
231 : }
232 :
233 : bool
234 0 : IterableKeyOrValueResult::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
235 : {
236 : // Passing a null JSContext is OK only if we're initing from null,
237 : // Since in that case we will not have to do any property gets
238 : // Also evaluate isNullOrUndefined in order to avoid false-positive
239 : // checkers by static analysis tools
240 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
241 0 : IterableKeyOrValueResultAtoms* atomsCache = nullptr;
242 0 : if (cx) {
243 0 : atomsCache = GetAtomCache<IterableKeyOrValueResultAtoms>(cx);
244 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
245 0 : return false;
246 : }
247 : }
248 :
249 0 : if (!IsConvertibleToDictionary(val)) {
250 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
251 : }
252 :
253 0 : bool isNull = val.isNullOrUndefined();
254 : // We only need these if !isNull, in which case we have |cx|.
255 0 : Maybe<JS::Rooted<JSObject *> > object;
256 0 : Maybe<JS::Rooted<JS::Value> > temp;
257 0 : if (!isNull) {
258 0 : MOZ_ASSERT(cx);
259 0 : object.emplace(cx, &val.toObject());
260 0 : temp.emplace(cx);
261 : }
262 0 : if (!isNull) {
263 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->done_id, temp.ptr())) {
264 0 : return false;
265 : }
266 : }
267 0 : if (!isNull && !temp->isUndefined()) {
268 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mDone)) {
269 0 : return false;
270 : }
271 : } else {
272 0 : mDone = false;
273 : }
274 0 : mIsAnyMemberPresent = true;
275 :
276 0 : if (!isNull) {
277 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->value_id, temp.ptr())) {
278 0 : return false;
279 : }
280 : }
281 0 : if (!isNull && !temp->isUndefined()) {
282 : #ifdef __clang__
283 : #pragma clang diagnostic push
284 : #pragma clang diagnostic ignored "-Wunreachable-code"
285 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
286 : #endif // __clang__
287 0 : if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
288 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'value' member of IterableKeyOrValueResult");
289 0 : return false;
290 : }
291 : #ifdef __clang__
292 : #pragma clang diagnostic pop
293 : #endif // __clang__
294 0 : mValue = temp.ref();
295 : } else {
296 0 : mValue = JS::UndefinedValue();
297 : }
298 0 : mIsAnyMemberPresent = true;
299 0 : return true;
300 : }
301 :
302 : bool
303 0 : IterableKeyOrValueResult::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
304 : {
305 0 : IterableKeyOrValueResultAtoms* atomsCache = GetAtomCache<IterableKeyOrValueResultAtoms>(cx);
306 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
307 0 : return false;
308 : }
309 :
310 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
311 0 : if (!obj) {
312 0 : return false;
313 : }
314 0 : rval.set(JS::ObjectValue(*obj));
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 : bool const & currentValue = mDone;
320 0 : temp.setBoolean(currentValue);
321 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->done_id, temp, JSPROP_ENUMERATE)) {
322 0 : return false;
323 : }
324 0 : break;
325 : } while(0);
326 :
327 : do {
328 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
329 0 : JS::Rooted<JS::Value> temp(cx);
330 0 : JS::Value const & currentValue = mValue;
331 0 : JS::ExposeValueToActiveJS(currentValue);
332 0 : temp.set(currentValue);
333 0 : if (!MaybeWrapValue(cx, &temp)) {
334 0 : return false;
335 : }
336 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->value_id, temp, JSPROP_ENUMERATE)) {
337 0 : return false;
338 : }
339 0 : break;
340 : } while(0);
341 :
342 0 : return true;
343 : }
344 :
345 : void
346 0 : IterableKeyOrValueResult::TraceDictionary(JSTracer* trc)
347 : {
348 0 : JS::UnsafeTraceRoot(trc, &mValue, "IterableKeyOrValueResult.mValue");
349 0 : }
350 :
351 : namespace binding_detail {
352 : } // namespace binding_detail
353 :
354 :
355 : } // namespace dom
356 : } // namespace mozilla
|