/work/obj-fuzz/dom/bindings/IteratorResultBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM IteratorResult.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "IteratorResultBinding.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 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
15 | | using namespace mozilla::dom::binding_detail; |
16 | | |
17 | | |
18 | | |
19 | | IteratorResult::IteratorResult() |
20 | | : mValue(JS::UndefinedValue()) |
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 | | bool |
28 | | IteratorResult::InitIds(JSContext* cx, IteratorResultAtoms* 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->value_id.init(cx, "value") || |
35 | 0 | !atomsCache->done_id.init(cx, "done")) { |
36 | 0 | return false; |
37 | 0 | } |
38 | 0 | return true; |
39 | 0 | } |
40 | | |
41 | | bool |
42 | | IteratorResult::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
43 | 0 | { |
44 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
45 | 0 | // Since in that case we will not have to do any property gets |
46 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
47 | 0 | // checkers by static analysis tools |
48 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
49 | 0 | IteratorResultAtoms* atomsCache = nullptr; |
50 | 0 | if (cx) { |
51 | 0 | atomsCache = GetAtomCache<IteratorResultAtoms>(cx); |
52 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
53 | 0 | return false; |
54 | 0 | } |
55 | 0 | } |
56 | 0 | |
57 | 0 | if (!IsConvertibleToDictionary(val)) { |
58 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
59 | 0 | } |
60 | 0 | |
61 | 0 | bool isNull = val.isNullOrUndefined(); |
62 | 0 | // We only need these if !isNull, in which case we have |cx|. |
63 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
64 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
65 | 0 | if (!isNull) { |
66 | 0 | MOZ_ASSERT(cx); |
67 | 0 | object.emplace(cx, &val.toObject()); |
68 | 0 | temp.emplace(cx); |
69 | 0 | } |
70 | 0 | if (!isNull) { |
71 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->done_id, temp.ptr())) { |
72 | 0 | return false; |
73 | 0 | } |
74 | 0 | } |
75 | 0 | if (!isNull && !temp->isUndefined()) { |
76 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mDone)) { |
77 | 0 | return false; |
78 | 0 | } |
79 | 0 | mIsAnyMemberPresent = true; |
80 | 0 | } else if (cx) { |
81 | 0 | // Don't error out if we have no cx. In that |
82 | 0 | // situation the caller is default-constructing us and we'll |
83 | 0 | // just assume they know what they're doing. |
84 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
85 | 0 | "'done' member of IteratorResult"); |
86 | 0 | } |
87 | 0 | |
88 | 0 | if (!isNull) { |
89 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->value_id, temp.ptr())) { |
90 | 0 | return false; |
91 | 0 | } |
92 | 0 | } |
93 | 0 | if (!isNull && !temp->isUndefined()) { |
94 | 0 | #ifdef __clang__ |
95 | 0 | #pragma clang diagnostic push |
96 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
97 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
98 | 0 | #endif // __clang__ |
99 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
100 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'value' member of IteratorResult"); |
101 | 0 | return false; |
102 | 0 | } |
103 | 0 | #ifdef __clang__ |
104 | 0 | #pragma clang diagnostic pop |
105 | 0 | #endif // __clang__ |
106 | 0 | mValue = temp.ref(); |
107 | 0 | } else { |
108 | 0 | mValue = JS::UndefinedValue(); |
109 | 0 | } |
110 | 0 | mIsAnyMemberPresent = true; |
111 | 0 | return true; |
112 | 0 | } |
113 | | |
114 | | bool |
115 | | IteratorResult::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
116 | 0 | { |
117 | 0 | IteratorResultAtoms* atomsCache = GetAtomCache<IteratorResultAtoms>(cx); |
118 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
119 | 0 | return false; |
120 | 0 | } |
121 | 0 | |
122 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
123 | 0 | if (!obj) { |
124 | 0 | return false; |
125 | 0 | } |
126 | 0 | rval.set(JS::ObjectValue(*obj)); |
127 | 0 |
|
128 | 0 | do { |
129 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
130 | 0 | JS::Rooted<JS::Value> temp(cx); |
131 | 0 | bool const & currentValue = mDone; |
132 | 0 | temp.setBoolean(currentValue); |
133 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->done_id, temp, JSPROP_ENUMERATE)) { |
134 | 0 | return false; |
135 | 0 | } |
136 | 0 | break; |
137 | 0 | } while(false); |
138 | 0 |
|
139 | 0 | do { |
140 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
141 | 0 | JS::Rooted<JS::Value> temp(cx); |
142 | 0 | JS::Value const & currentValue = mValue; |
143 | 0 | JS::ExposeValueToActiveJS(currentValue); |
144 | 0 | temp.set(currentValue); |
145 | 0 | if (!MaybeWrapValue(cx, &temp)) { |
146 | 0 | return false; |
147 | 0 | } |
148 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->value_id, temp, JSPROP_ENUMERATE)) { |
149 | 0 | return false; |
150 | 0 | } |
151 | 0 | break; |
152 | 0 | } while(false); |
153 | 0 |
|
154 | 0 | return true; |
155 | 0 | } |
156 | | |
157 | | void |
158 | | IteratorResult::TraceDictionary(JSTracer* trc) |
159 | 0 | { |
160 | 0 | JS::UnsafeTraceRoot(trc, &mValue, "IteratorResult.mValue"); |
161 | 0 | } |
162 | | |
163 | | namespace binding_detail { |
164 | | } // namespace binding_detail |
165 | | |
166 | | |
167 | | } // namespace dom |
168 | | } // namespace mozilla |