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