/work/obj-fuzz/dom/bindings/PaymentRequestBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM PaymentRequest.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "EventHandlerBinding.h" |
5 | | #include "EventTargetBinding.h" |
6 | | #include "PaymentRequestBinding.h" |
7 | | #include "WrapperFactory.h" |
8 | | #include "jsapi.h" |
9 | | #include "mozilla/OwningNonNull.h" |
10 | | #include "mozilla/dom/BindingUtils.h" |
11 | | #include "mozilla/dom/DOMJSClass.h" |
12 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
13 | | #include "mozilla/dom/Nullable.h" |
14 | | #include "mozilla/dom/PaymentAddress.h" |
15 | | #include "mozilla/dom/PaymentRequest.h" |
16 | | #include "mozilla/dom/PrimitiveConversions.h" |
17 | | #include "mozilla/dom/Promise.h" |
18 | | #include "mozilla/dom/ScriptSettings.h" |
19 | | #include "mozilla/dom/SimpleGlobalObject.h" |
20 | | #include "mozilla/dom/ToJSValue.h" |
21 | | #include "mozilla/dom/XrayExpandoClass.h" |
22 | | |
23 | | namespace mozilla { |
24 | | namespace dom { |
25 | | |
26 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
27 | | using namespace mozilla::dom::binding_detail; |
28 | | |
29 | | |
30 | | namespace PaymentItemTypeValues { |
31 | | extern const EnumEntry strings[2] = { |
32 | | {"tax", 3}, |
33 | | { nullptr, 0 } |
34 | | }; |
35 | | } // namespace PaymentItemTypeValues |
36 | | |
37 | | bool |
38 | | ToJSValue(JSContext* aCx, PaymentItemType aArgument, JS::MutableHandle<JS::Value> aValue) |
39 | 0 | { |
40 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(PaymentItemTypeValues::strings)); |
41 | 0 | JSString* resultStr = |
42 | 0 | JS_NewStringCopyN(aCx, PaymentItemTypeValues::strings[uint32_t(aArgument)].value, |
43 | 0 | PaymentItemTypeValues::strings[uint32_t(aArgument)].length); |
44 | 0 | if (!resultStr) { |
45 | 0 | return false; |
46 | 0 | } |
47 | 0 | aValue.setString(resultStr); |
48 | 0 | return true; |
49 | 0 | } |
50 | | |
51 | | |
52 | | namespace PaymentShippingTypeValues { |
53 | | extern const EnumEntry strings[4] = { |
54 | | {"shipping", 8}, |
55 | | {"delivery", 8}, |
56 | | {"pickup", 6}, |
57 | | { nullptr, 0 } |
58 | | }; |
59 | | } // namespace PaymentShippingTypeValues |
60 | | |
61 | | bool |
62 | | ToJSValue(JSContext* aCx, PaymentShippingType aArgument, JS::MutableHandle<JS::Value> aValue) |
63 | 0 | { |
64 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(PaymentShippingTypeValues::strings)); |
65 | 0 | JSString* resultStr = |
66 | 0 | JS_NewStringCopyN(aCx, PaymentShippingTypeValues::strings[uint32_t(aArgument)].value, |
67 | 0 | PaymentShippingTypeValues::strings[uint32_t(aArgument)].length); |
68 | 0 | if (!resultStr) { |
69 | 0 | return false; |
70 | 0 | } |
71 | 0 | aValue.setString(resultStr); |
72 | 0 | return true; |
73 | 0 | } |
74 | | |
75 | | |
76 | | |
77 | | AddressErrors::AddressErrors() |
78 | 0 | { |
79 | 0 | // Safe to pass a null context if we pass a null value |
80 | 0 | Init(nullptr, JS::NullHandleValue); |
81 | 0 | } |
82 | | |
83 | | |
84 | | |
85 | | bool |
86 | | AddressErrors::InitIds(JSContext* cx, AddressErrorsAtoms* atomsCache) |
87 | 0 | { |
88 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
89 | 0 |
|
90 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
91 | 0 | // uninitialized. |
92 | 0 | if (!atomsCache->sortingCode_id.init(cx, "sortingCode") || |
93 | 0 | !atomsCache->regionCode_id.init(cx, "regionCode") || |
94 | 0 | !atomsCache->region_id.init(cx, "region") || |
95 | 0 | !atomsCache->recipient_id.init(cx, "recipient") || |
96 | 0 | !atomsCache->postalCode_id.init(cx, "postalCode") || |
97 | 0 | !atomsCache->phone_id.init(cx, "phone") || |
98 | 0 | !atomsCache->organization_id.init(cx, "organization") || |
99 | 0 | !atomsCache->dependentLocality_id.init(cx, "dependentLocality") || |
100 | 0 | !atomsCache->country_id.init(cx, "country") || |
101 | 0 | !atomsCache->city_id.init(cx, "city") || |
102 | 0 | !atomsCache->addressLine_id.init(cx, "addressLine")) { |
103 | 0 | return false; |
104 | 0 | } |
105 | 0 | return true; |
106 | 0 | } |
107 | | |
108 | | bool |
109 | | AddressErrors::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
110 | 0 | { |
111 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
112 | 0 | // Since in that case we will not have to do any property gets |
113 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
114 | 0 | // checkers by static analysis tools |
115 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
116 | 0 | AddressErrorsAtoms* atomsCache = nullptr; |
117 | 0 | if (cx) { |
118 | 0 | atomsCache = GetAtomCache<AddressErrorsAtoms>(cx); |
119 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
120 | 0 | return false; |
121 | 0 | } |
122 | 0 | } |
123 | 0 | |
124 | 0 | if (!IsConvertibleToDictionary(val)) { |
125 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
126 | 0 | } |
127 | 0 | |
128 | 0 | bool isNull = val.isNullOrUndefined(); |
129 | 0 | // We only need these if !isNull, in which case we have |cx|. |
130 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
131 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
132 | 0 | if (!isNull) { |
133 | 0 | MOZ_ASSERT(cx); |
134 | 0 | object.emplace(cx, &val.toObject()); |
135 | 0 | temp.emplace(cx); |
136 | 0 | } |
137 | 0 | if (!isNull) { |
138 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->addressLine_id, temp.ptr())) { |
139 | 0 | return false; |
140 | 0 | } |
141 | 0 | } |
142 | 0 | if (!isNull && !temp->isUndefined()) { |
143 | 0 | mAddressLine.Construct(); |
144 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mAddressLine.Value()))) { |
145 | 0 | return false; |
146 | 0 | } |
147 | 0 | mIsAnyMemberPresent = true; |
148 | 0 | } |
149 | 0 |
|
150 | 0 | if (!isNull) { |
151 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->city_id, temp.ptr())) { |
152 | 0 | return false; |
153 | 0 | } |
154 | 0 | } |
155 | 0 | if (!isNull && !temp->isUndefined()) { |
156 | 0 | mCity.Construct(); |
157 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mCity.Value()))) { |
158 | 0 | return false; |
159 | 0 | } |
160 | 0 | mIsAnyMemberPresent = true; |
161 | 0 | } |
162 | 0 |
|
163 | 0 | if (!isNull) { |
164 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->country_id, temp.ptr())) { |
165 | 0 | return false; |
166 | 0 | } |
167 | 0 | } |
168 | 0 | if (!isNull && !temp->isUndefined()) { |
169 | 0 | mCountry.Construct(); |
170 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mCountry.Value()))) { |
171 | 0 | return false; |
172 | 0 | } |
173 | 0 | mIsAnyMemberPresent = true; |
174 | 0 | } |
175 | 0 |
|
176 | 0 | if (!isNull) { |
177 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->dependentLocality_id, temp.ptr())) { |
178 | 0 | return false; |
179 | 0 | } |
180 | 0 | } |
181 | 0 | if (!isNull && !temp->isUndefined()) { |
182 | 0 | mDependentLocality.Construct(); |
183 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mDependentLocality.Value()))) { |
184 | 0 | return false; |
185 | 0 | } |
186 | 0 | mIsAnyMemberPresent = true; |
187 | 0 | } |
188 | 0 |
|
189 | 0 | if (!isNull) { |
190 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->organization_id, temp.ptr())) { |
191 | 0 | return false; |
192 | 0 | } |
193 | 0 | } |
194 | 0 | if (!isNull && !temp->isUndefined()) { |
195 | 0 | mOrganization.Construct(); |
196 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mOrganization.Value()))) { |
197 | 0 | return false; |
198 | 0 | } |
199 | 0 | mIsAnyMemberPresent = true; |
200 | 0 | } |
201 | 0 |
|
202 | 0 | if (!isNull) { |
203 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->phone_id, temp.ptr())) { |
204 | 0 | return false; |
205 | 0 | } |
206 | 0 | } |
207 | 0 | if (!isNull && !temp->isUndefined()) { |
208 | 0 | mPhone.Construct(); |
209 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mPhone.Value()))) { |
210 | 0 | return false; |
211 | 0 | } |
212 | 0 | mIsAnyMemberPresent = true; |
213 | 0 | } |
214 | 0 |
|
215 | 0 | if (!isNull) { |
216 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->postalCode_id, temp.ptr())) { |
217 | 0 | return false; |
218 | 0 | } |
219 | 0 | } |
220 | 0 | if (!isNull && !temp->isUndefined()) { |
221 | 0 | mPostalCode.Construct(); |
222 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mPostalCode.Value()))) { |
223 | 0 | return false; |
224 | 0 | } |
225 | 0 | mIsAnyMemberPresent = true; |
226 | 0 | } |
227 | 0 |
|
228 | 0 | if (!isNull) { |
229 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->recipient_id, temp.ptr())) { |
230 | 0 | return false; |
231 | 0 | } |
232 | 0 | } |
233 | 0 | if (!isNull && !temp->isUndefined()) { |
234 | 0 | mRecipient.Construct(); |
235 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mRecipient.Value()))) { |
236 | 0 | return false; |
237 | 0 | } |
238 | 0 | mIsAnyMemberPresent = true; |
239 | 0 | } |
240 | 0 |
|
241 | 0 | if (!isNull) { |
242 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->region_id, temp.ptr())) { |
243 | 0 | return false; |
244 | 0 | } |
245 | 0 | } |
246 | 0 | if (!isNull && !temp->isUndefined()) { |
247 | 0 | mRegion.Construct(); |
248 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mRegion.Value()))) { |
249 | 0 | return false; |
250 | 0 | } |
251 | 0 | mIsAnyMemberPresent = true; |
252 | 0 | } |
253 | 0 |
|
254 | 0 | if (!isNull) { |
255 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->regionCode_id, temp.ptr())) { |
256 | 0 | return false; |
257 | 0 | } |
258 | 0 | } |
259 | 0 | if (!isNull && !temp->isUndefined()) { |
260 | 0 | mRegionCode.Construct(); |
261 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mRegionCode.Value()))) { |
262 | 0 | return false; |
263 | 0 | } |
264 | 0 | mIsAnyMemberPresent = true; |
265 | 0 | } |
266 | 0 |
|
267 | 0 | if (!isNull) { |
268 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->sortingCode_id, temp.ptr())) { |
269 | 0 | return false; |
270 | 0 | } |
271 | 0 | } |
272 | 0 | if (!isNull && !temp->isUndefined()) { |
273 | 0 | mSortingCode.Construct(); |
274 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mSortingCode.Value()))) { |
275 | 0 | return false; |
276 | 0 | } |
277 | 0 | mIsAnyMemberPresent = true; |
278 | 0 | } |
279 | 0 | return true; |
280 | 0 | } |
281 | | |
282 | | bool |
283 | | AddressErrors::Init(const nsAString& aJSON) |
284 | 0 | { |
285 | 0 | AutoJSAPI jsapi; |
286 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
287 | 0 | if (!cleanGlobal) { |
288 | 0 | return false; |
289 | 0 | } |
290 | 0 | if (!jsapi.Init(cleanGlobal)) { |
291 | 0 | return false; |
292 | 0 | } |
293 | 0 | JSContext* cx = jsapi.cx(); |
294 | 0 | JS::Rooted<JS::Value> json(cx); |
295 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
296 | 0 | NS_ENSURE_TRUE(ok, false); |
297 | 0 | return Init(cx, json); |
298 | 0 | } |
299 | | |
300 | | bool |
301 | | AddressErrors::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
302 | 0 | { |
303 | 0 | AddressErrorsAtoms* atomsCache = GetAtomCache<AddressErrorsAtoms>(cx); |
304 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
305 | 0 | return false; |
306 | 0 | } |
307 | 0 | |
308 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
309 | 0 | if (!obj) { |
310 | 0 | return false; |
311 | 0 | } |
312 | 0 | rval.set(JS::ObjectValue(*obj)); |
313 | 0 |
|
314 | 0 | if (mAddressLine.WasPassed()) { |
315 | 0 | do { |
316 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
317 | 0 | JS::Rooted<JS::Value> temp(cx); |
318 | 0 | nsString const & currentValue = mAddressLine.InternalValue(); |
319 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
320 | 0 | return false; |
321 | 0 | } |
322 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->addressLine_id, temp, JSPROP_ENUMERATE)) { |
323 | 0 | return false; |
324 | 0 | } |
325 | 0 | break; |
326 | 0 | } while(false); |
327 | 0 | } |
328 | 0 |
|
329 | 0 | if (mCity.WasPassed()) { |
330 | 0 | do { |
331 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
332 | 0 | JS::Rooted<JS::Value> temp(cx); |
333 | 0 | nsString const & currentValue = mCity.InternalValue(); |
334 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
335 | 0 | return false; |
336 | 0 | } |
337 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->city_id, temp, JSPROP_ENUMERATE)) { |
338 | 0 | return false; |
339 | 0 | } |
340 | 0 | break; |
341 | 0 | } while(false); |
342 | 0 | } |
343 | 0 |
|
344 | 0 | if (mCountry.WasPassed()) { |
345 | 0 | do { |
346 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
347 | 0 | JS::Rooted<JS::Value> temp(cx); |
348 | 0 | nsString const & currentValue = mCountry.InternalValue(); |
349 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
350 | 0 | return false; |
351 | 0 | } |
352 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->country_id, temp, JSPROP_ENUMERATE)) { |
353 | 0 | return false; |
354 | 0 | } |
355 | 0 | break; |
356 | 0 | } while(false); |
357 | 0 | } |
358 | 0 |
|
359 | 0 | if (mDependentLocality.WasPassed()) { |
360 | 0 | do { |
361 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
362 | 0 | JS::Rooted<JS::Value> temp(cx); |
363 | 0 | nsString const & currentValue = mDependentLocality.InternalValue(); |
364 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
365 | 0 | return false; |
366 | 0 | } |
367 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->dependentLocality_id, temp, JSPROP_ENUMERATE)) { |
368 | 0 | return false; |
369 | 0 | } |
370 | 0 | break; |
371 | 0 | } while(false); |
372 | 0 | } |
373 | 0 |
|
374 | 0 | if (mOrganization.WasPassed()) { |
375 | 0 | do { |
376 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
377 | 0 | JS::Rooted<JS::Value> temp(cx); |
378 | 0 | nsString const & currentValue = mOrganization.InternalValue(); |
379 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
380 | 0 | return false; |
381 | 0 | } |
382 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->organization_id, temp, JSPROP_ENUMERATE)) { |
383 | 0 | return false; |
384 | 0 | } |
385 | 0 | break; |
386 | 0 | } while(false); |
387 | 0 | } |
388 | 0 |
|
389 | 0 | if (mPhone.WasPassed()) { |
390 | 0 | do { |
391 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
392 | 0 | JS::Rooted<JS::Value> temp(cx); |
393 | 0 | nsString const & currentValue = mPhone.InternalValue(); |
394 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
395 | 0 | return false; |
396 | 0 | } |
397 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->phone_id, temp, JSPROP_ENUMERATE)) { |
398 | 0 | return false; |
399 | 0 | } |
400 | 0 | break; |
401 | 0 | } while(false); |
402 | 0 | } |
403 | 0 |
|
404 | 0 | if (mPostalCode.WasPassed()) { |
405 | 0 | do { |
406 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
407 | 0 | JS::Rooted<JS::Value> temp(cx); |
408 | 0 | nsString const & currentValue = mPostalCode.InternalValue(); |
409 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
410 | 0 | return false; |
411 | 0 | } |
412 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->postalCode_id, temp, JSPROP_ENUMERATE)) { |
413 | 0 | return false; |
414 | 0 | } |
415 | 0 | break; |
416 | 0 | } while(false); |
417 | 0 | } |
418 | 0 |
|
419 | 0 | if (mRecipient.WasPassed()) { |
420 | 0 | do { |
421 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
422 | 0 | JS::Rooted<JS::Value> temp(cx); |
423 | 0 | nsString const & currentValue = mRecipient.InternalValue(); |
424 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
425 | 0 | return false; |
426 | 0 | } |
427 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->recipient_id, temp, JSPROP_ENUMERATE)) { |
428 | 0 | return false; |
429 | 0 | } |
430 | 0 | break; |
431 | 0 | } while(false); |
432 | 0 | } |
433 | 0 |
|
434 | 0 | if (mRegion.WasPassed()) { |
435 | 0 | do { |
436 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
437 | 0 | JS::Rooted<JS::Value> temp(cx); |
438 | 0 | nsString const & currentValue = mRegion.InternalValue(); |
439 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
440 | 0 | return false; |
441 | 0 | } |
442 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->region_id, temp, JSPROP_ENUMERATE)) { |
443 | 0 | return false; |
444 | 0 | } |
445 | 0 | break; |
446 | 0 | } while(false); |
447 | 0 | } |
448 | 0 |
|
449 | 0 | if (mRegionCode.WasPassed()) { |
450 | 0 | do { |
451 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
452 | 0 | JS::Rooted<JS::Value> temp(cx); |
453 | 0 | nsString const & currentValue = mRegionCode.InternalValue(); |
454 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
455 | 0 | return false; |
456 | 0 | } |
457 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->regionCode_id, temp, JSPROP_ENUMERATE)) { |
458 | 0 | return false; |
459 | 0 | } |
460 | 0 | break; |
461 | 0 | } while(false); |
462 | 0 | } |
463 | 0 |
|
464 | 0 | if (mSortingCode.WasPassed()) { |
465 | 0 | do { |
466 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
467 | 0 | JS::Rooted<JS::Value> temp(cx); |
468 | 0 | nsString const & currentValue = mSortingCode.InternalValue(); |
469 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
470 | 0 | return false; |
471 | 0 | } |
472 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->sortingCode_id, temp, JSPROP_ENUMERATE)) { |
473 | 0 | return false; |
474 | 0 | } |
475 | 0 | break; |
476 | 0 | } while(false); |
477 | 0 | } |
478 | 0 |
|
479 | 0 | return true; |
480 | 0 | } |
481 | | |
482 | | bool |
483 | | AddressErrors::ToJSON(nsAString& aJSON) const |
484 | 0 | { |
485 | 0 | AutoJSAPI jsapi; |
486 | 0 | jsapi.Init(); |
487 | 0 | JSContext *cx = jsapi.cx(); |
488 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
489 | 0 | // because we'll only be creating objects, in ways that have no |
490 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
491 | 0 | // which likewise guarantees no side-effects for the sorts of |
492 | 0 | // things we will pass it. |
493 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
494 | 0 | JS::Rooted<JS::Value> val(cx); |
495 | 0 | if (!ToObjectInternal(cx, &val)) { |
496 | 0 | return false; |
497 | 0 | } |
498 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
499 | 0 | return StringifyToJSON(cx, obj, aJSON); |
500 | 0 | } |
501 | | |
502 | | void |
503 | | AddressErrors::TraceDictionary(JSTracer* trc) |
504 | 0 | { |
505 | 0 | } |
506 | | |
507 | | AddressErrors& |
508 | | AddressErrors::operator=(const AddressErrors& aOther) |
509 | 0 | { |
510 | 0 | DictionaryBase::operator=(aOther); |
511 | 0 | mAddressLine.Reset(); |
512 | 0 | if (aOther.mAddressLine.WasPassed()) { |
513 | 0 | mAddressLine.Construct(aOther.mAddressLine.Value()); |
514 | 0 | } |
515 | 0 | mCity.Reset(); |
516 | 0 | if (aOther.mCity.WasPassed()) { |
517 | 0 | mCity.Construct(aOther.mCity.Value()); |
518 | 0 | } |
519 | 0 | mCountry.Reset(); |
520 | 0 | if (aOther.mCountry.WasPassed()) { |
521 | 0 | mCountry.Construct(aOther.mCountry.Value()); |
522 | 0 | } |
523 | 0 | mDependentLocality.Reset(); |
524 | 0 | if (aOther.mDependentLocality.WasPassed()) { |
525 | 0 | mDependentLocality.Construct(aOther.mDependentLocality.Value()); |
526 | 0 | } |
527 | 0 | mOrganization.Reset(); |
528 | 0 | if (aOther.mOrganization.WasPassed()) { |
529 | 0 | mOrganization.Construct(aOther.mOrganization.Value()); |
530 | 0 | } |
531 | 0 | mPhone.Reset(); |
532 | 0 | if (aOther.mPhone.WasPassed()) { |
533 | 0 | mPhone.Construct(aOther.mPhone.Value()); |
534 | 0 | } |
535 | 0 | mPostalCode.Reset(); |
536 | 0 | if (aOther.mPostalCode.WasPassed()) { |
537 | 0 | mPostalCode.Construct(aOther.mPostalCode.Value()); |
538 | 0 | } |
539 | 0 | mRecipient.Reset(); |
540 | 0 | if (aOther.mRecipient.WasPassed()) { |
541 | 0 | mRecipient.Construct(aOther.mRecipient.Value()); |
542 | 0 | } |
543 | 0 | mRegion.Reset(); |
544 | 0 | if (aOther.mRegion.WasPassed()) { |
545 | 0 | mRegion.Construct(aOther.mRegion.Value()); |
546 | 0 | } |
547 | 0 | mRegionCode.Reset(); |
548 | 0 | if (aOther.mRegionCode.WasPassed()) { |
549 | 0 | mRegionCode.Construct(aOther.mRegionCode.Value()); |
550 | 0 | } |
551 | 0 | mSortingCode.Reset(); |
552 | 0 | if (aOther.mSortingCode.WasPassed()) { |
553 | 0 | mSortingCode.Construct(aOther.mSortingCode.Value()); |
554 | 0 | } |
555 | 0 | return *this; |
556 | 0 | } |
557 | | |
558 | | namespace binding_detail { |
559 | | } // namespace binding_detail |
560 | | |
561 | | |
562 | | |
563 | | PayerErrorFields::PayerErrorFields() |
564 | 0 | { |
565 | 0 | // Safe to pass a null context if we pass a null value |
566 | 0 | Init(nullptr, JS::NullHandleValue); |
567 | 0 | } |
568 | | |
569 | | |
570 | | |
571 | | bool |
572 | | PayerErrorFields::InitIds(JSContext* cx, PayerErrorFieldsAtoms* atomsCache) |
573 | 0 | { |
574 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
575 | 0 |
|
576 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
577 | 0 | // uninitialized. |
578 | 0 | if (!atomsCache->phone_id.init(cx, "phone") || |
579 | 0 | !atomsCache->name_id.init(cx, "name") || |
580 | 0 | !atomsCache->email_id.init(cx, "email")) { |
581 | 0 | return false; |
582 | 0 | } |
583 | 0 | return true; |
584 | 0 | } |
585 | | |
586 | | bool |
587 | | PayerErrorFields::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
588 | 0 | { |
589 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
590 | 0 | // Since in that case we will not have to do any property gets |
591 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
592 | 0 | // checkers by static analysis tools |
593 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
594 | 0 | PayerErrorFieldsAtoms* atomsCache = nullptr; |
595 | 0 | if (cx) { |
596 | 0 | atomsCache = GetAtomCache<PayerErrorFieldsAtoms>(cx); |
597 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
598 | 0 | return false; |
599 | 0 | } |
600 | 0 | } |
601 | 0 | |
602 | 0 | if (!IsConvertibleToDictionary(val)) { |
603 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
604 | 0 | } |
605 | 0 | |
606 | 0 | bool isNull = val.isNullOrUndefined(); |
607 | 0 | // We only need these if !isNull, in which case we have |cx|. |
608 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
609 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
610 | 0 | if (!isNull) { |
611 | 0 | MOZ_ASSERT(cx); |
612 | 0 | object.emplace(cx, &val.toObject()); |
613 | 0 | temp.emplace(cx); |
614 | 0 | } |
615 | 0 | if (!isNull) { |
616 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->email_id, temp.ptr())) { |
617 | 0 | return false; |
618 | 0 | } |
619 | 0 | } |
620 | 0 | if (!isNull && !temp->isUndefined()) { |
621 | 0 | mEmail.Construct(); |
622 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mEmail.Value()))) { |
623 | 0 | return false; |
624 | 0 | } |
625 | 0 | mIsAnyMemberPresent = true; |
626 | 0 | } |
627 | 0 |
|
628 | 0 | if (!isNull) { |
629 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) { |
630 | 0 | return false; |
631 | 0 | } |
632 | 0 | } |
633 | 0 | if (!isNull && !temp->isUndefined()) { |
634 | 0 | mName.Construct(); |
635 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mName.Value()))) { |
636 | 0 | return false; |
637 | 0 | } |
638 | 0 | mIsAnyMemberPresent = true; |
639 | 0 | } |
640 | 0 |
|
641 | 0 | if (!isNull) { |
642 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->phone_id, temp.ptr())) { |
643 | 0 | return false; |
644 | 0 | } |
645 | 0 | } |
646 | 0 | if (!isNull && !temp->isUndefined()) { |
647 | 0 | mPhone.Construct(); |
648 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mPhone.Value()))) { |
649 | 0 | return false; |
650 | 0 | } |
651 | 0 | mIsAnyMemberPresent = true; |
652 | 0 | } |
653 | 0 | return true; |
654 | 0 | } |
655 | | |
656 | | bool |
657 | | PayerErrorFields::Init(const nsAString& aJSON) |
658 | 0 | { |
659 | 0 | AutoJSAPI jsapi; |
660 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
661 | 0 | if (!cleanGlobal) { |
662 | 0 | return false; |
663 | 0 | } |
664 | 0 | if (!jsapi.Init(cleanGlobal)) { |
665 | 0 | return false; |
666 | 0 | } |
667 | 0 | JSContext* cx = jsapi.cx(); |
668 | 0 | JS::Rooted<JS::Value> json(cx); |
669 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
670 | 0 | NS_ENSURE_TRUE(ok, false); |
671 | 0 | return Init(cx, json); |
672 | 0 | } |
673 | | |
674 | | bool |
675 | | PayerErrorFields::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
676 | 0 | { |
677 | 0 | PayerErrorFieldsAtoms* atomsCache = GetAtomCache<PayerErrorFieldsAtoms>(cx); |
678 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
679 | 0 | return false; |
680 | 0 | } |
681 | 0 | |
682 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
683 | 0 | if (!obj) { |
684 | 0 | return false; |
685 | 0 | } |
686 | 0 | rval.set(JS::ObjectValue(*obj)); |
687 | 0 |
|
688 | 0 | if (mEmail.WasPassed()) { |
689 | 0 | do { |
690 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
691 | 0 | JS::Rooted<JS::Value> temp(cx); |
692 | 0 | nsString const & currentValue = mEmail.InternalValue(); |
693 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
694 | 0 | return false; |
695 | 0 | } |
696 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->email_id, temp, JSPROP_ENUMERATE)) { |
697 | 0 | return false; |
698 | 0 | } |
699 | 0 | break; |
700 | 0 | } while(false); |
701 | 0 | } |
702 | 0 |
|
703 | 0 | if (mName.WasPassed()) { |
704 | 0 | do { |
705 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
706 | 0 | JS::Rooted<JS::Value> temp(cx); |
707 | 0 | nsString const & currentValue = mName.InternalValue(); |
708 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
709 | 0 | return false; |
710 | 0 | } |
711 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) { |
712 | 0 | return false; |
713 | 0 | } |
714 | 0 | break; |
715 | 0 | } while(false); |
716 | 0 | } |
717 | 0 |
|
718 | 0 | if (mPhone.WasPassed()) { |
719 | 0 | do { |
720 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
721 | 0 | JS::Rooted<JS::Value> temp(cx); |
722 | 0 | nsString const & currentValue = mPhone.InternalValue(); |
723 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
724 | 0 | return false; |
725 | 0 | } |
726 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->phone_id, temp, JSPROP_ENUMERATE)) { |
727 | 0 | return false; |
728 | 0 | } |
729 | 0 | break; |
730 | 0 | } while(false); |
731 | 0 | } |
732 | 0 |
|
733 | 0 | return true; |
734 | 0 | } |
735 | | |
736 | | bool |
737 | | PayerErrorFields::ToJSON(nsAString& aJSON) const |
738 | 0 | { |
739 | 0 | AutoJSAPI jsapi; |
740 | 0 | jsapi.Init(); |
741 | 0 | JSContext *cx = jsapi.cx(); |
742 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
743 | 0 | // because we'll only be creating objects, in ways that have no |
744 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
745 | 0 | // which likewise guarantees no side-effects for the sorts of |
746 | 0 | // things we will pass it. |
747 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
748 | 0 | JS::Rooted<JS::Value> val(cx); |
749 | 0 | if (!ToObjectInternal(cx, &val)) { |
750 | 0 | return false; |
751 | 0 | } |
752 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
753 | 0 | return StringifyToJSON(cx, obj, aJSON); |
754 | 0 | } |
755 | | |
756 | | void |
757 | | PayerErrorFields::TraceDictionary(JSTracer* trc) |
758 | 0 | { |
759 | 0 | } |
760 | | |
761 | | PayerErrorFields& |
762 | | PayerErrorFields::operator=(const PayerErrorFields& aOther) |
763 | 0 | { |
764 | 0 | DictionaryBase::operator=(aOther); |
765 | 0 | mEmail.Reset(); |
766 | 0 | if (aOther.mEmail.WasPassed()) { |
767 | 0 | mEmail.Construct(aOther.mEmail.Value()); |
768 | 0 | } |
769 | 0 | mName.Reset(); |
770 | 0 | if (aOther.mName.WasPassed()) { |
771 | 0 | mName.Construct(aOther.mName.Value()); |
772 | 0 | } |
773 | 0 | mPhone.Reset(); |
774 | 0 | if (aOther.mPhone.WasPassed()) { |
775 | 0 | mPhone.Construct(aOther.mPhone.Value()); |
776 | 0 | } |
777 | 0 | return *this; |
778 | 0 | } |
779 | | |
780 | | namespace binding_detail { |
781 | | } // namespace binding_detail |
782 | | |
783 | | |
784 | | |
785 | | PaymentCurrencyAmount::PaymentCurrencyAmount() |
786 | 0 | { |
787 | 0 | // Safe to pass a null context if we pass a null value |
788 | 0 | Init(nullptr, JS::NullHandleValue); |
789 | 0 | } |
790 | | |
791 | | |
792 | | |
793 | | bool |
794 | | PaymentCurrencyAmount::InitIds(JSContext* cx, PaymentCurrencyAmountAtoms* atomsCache) |
795 | 0 | { |
796 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
797 | 0 |
|
798 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
799 | 0 | // uninitialized. |
800 | 0 | if (!atomsCache->value_id.init(cx, "value") || |
801 | 0 | !atomsCache->currencySystem_id.init(cx, "currencySystem") || |
802 | 0 | !atomsCache->currency_id.init(cx, "currency")) { |
803 | 0 | return false; |
804 | 0 | } |
805 | 0 | return true; |
806 | 0 | } |
807 | | |
808 | | bool |
809 | | PaymentCurrencyAmount::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
810 | 0 | { |
811 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
812 | 0 | // Since in that case we will not have to do any property gets |
813 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
814 | 0 | // checkers by static analysis tools |
815 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
816 | 0 | PaymentCurrencyAmountAtoms* atomsCache = nullptr; |
817 | 0 | if (cx) { |
818 | 0 | atomsCache = GetAtomCache<PaymentCurrencyAmountAtoms>(cx); |
819 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
820 | 0 | return false; |
821 | 0 | } |
822 | 0 | } |
823 | 0 | |
824 | 0 | if (!IsConvertibleToDictionary(val)) { |
825 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
826 | 0 | } |
827 | 0 | |
828 | 0 | bool isNull = val.isNullOrUndefined(); |
829 | 0 | // We only need these if !isNull, in which case we have |cx|. |
830 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
831 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
832 | 0 | if (!isNull) { |
833 | 0 | MOZ_ASSERT(cx); |
834 | 0 | object.emplace(cx, &val.toObject()); |
835 | 0 | temp.emplace(cx); |
836 | 0 | } |
837 | 0 | if (!isNull) { |
838 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->currency_id, temp.ptr())) { |
839 | 0 | return false; |
840 | 0 | } |
841 | 0 | } |
842 | 0 | if (!isNull && !temp->isUndefined()) { |
843 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mCurrency)) { |
844 | 0 | return false; |
845 | 0 | } |
846 | 0 | mIsAnyMemberPresent = true; |
847 | 0 | } else if (cx) { |
848 | 0 | // Don't error out if we have no cx. In that |
849 | 0 | // situation the caller is default-constructing us and we'll |
850 | 0 | // just assume they know what they're doing. |
851 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
852 | 0 | "'currency' member of PaymentCurrencyAmount"); |
853 | 0 | } |
854 | 0 | |
855 | 0 | if (!isNull) { |
856 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->currencySystem_id, temp.ptr())) { |
857 | 0 | return false; |
858 | 0 | } |
859 | 0 | } |
860 | 0 | if (!isNull && !temp->isUndefined()) { |
861 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mCurrencySystem)) { |
862 | 0 | return false; |
863 | 0 | } |
864 | 0 | } else { |
865 | 0 | static const char16_t data[] = { 'u', 'r', 'n', ':', 'i', 's', 'o', ':', 's', 't', 'd', ':', 'i', 's', 'o', ':', '4', '2', '1', '7', 0 }; |
866 | 0 | mCurrencySystem.Rebind(data, ArrayLength(data) - 1); |
867 | 0 | } |
868 | 0 | mIsAnyMemberPresent = true; |
869 | 0 |
|
870 | 0 | if (!isNull) { |
871 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->value_id, temp.ptr())) { |
872 | 0 | return false; |
873 | 0 | } |
874 | 0 | } |
875 | 0 | if (!isNull && !temp->isUndefined()) { |
876 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mValue)) { |
877 | 0 | return false; |
878 | 0 | } |
879 | 0 | mIsAnyMemberPresent = true; |
880 | 0 | } else if (cx) { |
881 | 0 | // Don't error out if we have no cx. In that |
882 | 0 | // situation the caller is default-constructing us and we'll |
883 | 0 | // just assume they know what they're doing. |
884 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
885 | 0 | "'value' member of PaymentCurrencyAmount"); |
886 | 0 | } |
887 | 0 | return true; |
888 | 0 | } |
889 | | |
890 | | bool |
891 | | PaymentCurrencyAmount::Init(const nsAString& aJSON) |
892 | 0 | { |
893 | 0 | AutoJSAPI jsapi; |
894 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
895 | 0 | if (!cleanGlobal) { |
896 | 0 | return false; |
897 | 0 | } |
898 | 0 | if (!jsapi.Init(cleanGlobal)) { |
899 | 0 | return false; |
900 | 0 | } |
901 | 0 | JSContext* cx = jsapi.cx(); |
902 | 0 | JS::Rooted<JS::Value> json(cx); |
903 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
904 | 0 | NS_ENSURE_TRUE(ok, false); |
905 | 0 | return Init(cx, json); |
906 | 0 | } |
907 | | |
908 | | bool |
909 | | PaymentCurrencyAmount::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
910 | 0 | { |
911 | 0 | PaymentCurrencyAmountAtoms* atomsCache = GetAtomCache<PaymentCurrencyAmountAtoms>(cx); |
912 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
913 | 0 | return false; |
914 | 0 | } |
915 | 0 | |
916 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
917 | 0 | if (!obj) { |
918 | 0 | return false; |
919 | 0 | } |
920 | 0 | rval.set(JS::ObjectValue(*obj)); |
921 | 0 |
|
922 | 0 | do { |
923 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
924 | 0 | JS::Rooted<JS::Value> temp(cx); |
925 | 0 | nsString const & currentValue = mCurrency; |
926 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
927 | 0 | return false; |
928 | 0 | } |
929 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->currency_id, temp, JSPROP_ENUMERATE)) { |
930 | 0 | return false; |
931 | 0 | } |
932 | 0 | break; |
933 | 0 | } while(false); |
934 | 0 |
|
935 | 0 | do { |
936 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
937 | 0 | JS::Rooted<JS::Value> temp(cx); |
938 | 0 | nsString const & currentValue = mCurrencySystem; |
939 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
940 | 0 | return false; |
941 | 0 | } |
942 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->currencySystem_id, temp, JSPROP_ENUMERATE)) { |
943 | 0 | return false; |
944 | 0 | } |
945 | 0 | break; |
946 | 0 | } while(false); |
947 | 0 |
|
948 | 0 | do { |
949 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
950 | 0 | JS::Rooted<JS::Value> temp(cx); |
951 | 0 | nsString const & currentValue = mValue; |
952 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
953 | 0 | return false; |
954 | 0 | } |
955 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->value_id, temp, JSPROP_ENUMERATE)) { |
956 | 0 | return false; |
957 | 0 | } |
958 | 0 | break; |
959 | 0 | } while(false); |
960 | 0 |
|
961 | 0 | return true; |
962 | 0 | } |
963 | | |
964 | | bool |
965 | | PaymentCurrencyAmount::ToJSON(nsAString& aJSON) const |
966 | 0 | { |
967 | 0 | AutoJSAPI jsapi; |
968 | 0 | jsapi.Init(); |
969 | 0 | JSContext *cx = jsapi.cx(); |
970 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
971 | 0 | // because we'll only be creating objects, in ways that have no |
972 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
973 | 0 | // which likewise guarantees no side-effects for the sorts of |
974 | 0 | // things we will pass it. |
975 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
976 | 0 | JS::Rooted<JS::Value> val(cx); |
977 | 0 | if (!ToObjectInternal(cx, &val)) { |
978 | 0 | return false; |
979 | 0 | } |
980 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
981 | 0 | return StringifyToJSON(cx, obj, aJSON); |
982 | 0 | } |
983 | | |
984 | | void |
985 | | PaymentCurrencyAmount::TraceDictionary(JSTracer* trc) |
986 | 0 | { |
987 | 0 | } |
988 | | |
989 | | PaymentCurrencyAmount& |
990 | | PaymentCurrencyAmount::operator=(const PaymentCurrencyAmount& aOther) |
991 | 0 | { |
992 | 0 | DictionaryBase::operator=(aOther); |
993 | 0 | mCurrency = aOther.mCurrency; |
994 | 0 | mCurrencySystem = aOther.mCurrencySystem; |
995 | 0 | mValue = aOther.mValue; |
996 | 0 | return *this; |
997 | 0 | } |
998 | | |
999 | | namespace binding_detail { |
1000 | | } // namespace binding_detail |
1001 | | |
1002 | | |
1003 | | |
1004 | | PaymentMethodData::PaymentMethodData() |
1005 | 0 | { |
1006 | 0 | // Safe to pass a null context if we pass a null value |
1007 | 0 | Init(nullptr, JS::NullHandleValue); |
1008 | 0 | } |
1009 | | |
1010 | | |
1011 | | bool |
1012 | | PaymentMethodData::InitIds(JSContext* cx, PaymentMethodDataAtoms* atomsCache) |
1013 | 0 | { |
1014 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1015 | 0 |
|
1016 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1017 | 0 | // uninitialized. |
1018 | 0 | if (!atomsCache->supportedMethods_id.init(cx, "supportedMethods") || |
1019 | 0 | !atomsCache->data_id.init(cx, "data")) { |
1020 | 0 | return false; |
1021 | 0 | } |
1022 | 0 | return true; |
1023 | 0 | } |
1024 | | |
1025 | | bool |
1026 | | PaymentMethodData::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1027 | 0 | { |
1028 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1029 | 0 | // Since in that case we will not have to do any property gets |
1030 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1031 | 0 | // checkers by static analysis tools |
1032 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1033 | 0 | PaymentMethodDataAtoms* atomsCache = nullptr; |
1034 | 0 | if (cx) { |
1035 | 0 | atomsCache = GetAtomCache<PaymentMethodDataAtoms>(cx); |
1036 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1037 | 0 | return false; |
1038 | 0 | } |
1039 | 0 | } |
1040 | 0 | |
1041 | 0 | if (!IsConvertibleToDictionary(val)) { |
1042 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1043 | 0 | } |
1044 | 0 | |
1045 | 0 | bool isNull = val.isNullOrUndefined(); |
1046 | 0 | // We only need these if !isNull, in which case we have |cx|. |
1047 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
1048 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
1049 | 0 | if (!isNull) { |
1050 | 0 | MOZ_ASSERT(cx); |
1051 | 0 | object.emplace(cx, &val.toObject()); |
1052 | 0 | temp.emplace(cx); |
1053 | 0 | } |
1054 | 0 | if (!isNull) { |
1055 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) { |
1056 | 0 | return false; |
1057 | 0 | } |
1058 | 0 | } |
1059 | 0 | if (!isNull && !temp->isUndefined()) { |
1060 | 0 | mData.Construct(); |
1061 | 0 | if (temp.ref().isObject()) { |
1062 | 0 | #ifdef __clang__ |
1063 | 0 | #pragma clang diagnostic push |
1064 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
1065 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
1066 | 0 | #endif // __clang__ |
1067 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
1068 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'data' member of PaymentMethodData"); |
1069 | 0 | return false; |
1070 | 0 | } |
1071 | 0 | #ifdef __clang__ |
1072 | 0 | #pragma clang diagnostic pop |
1073 | 0 | #endif // __clang__ |
1074 | 0 | (mData.Value()) = &temp.ref().toObject(); |
1075 | 0 | } else { |
1076 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'data' member of PaymentMethodData"); |
1077 | 0 | return false; |
1078 | 0 | } |
1079 | 0 | mIsAnyMemberPresent = true; |
1080 | 0 | } |
1081 | 0 |
|
1082 | 0 | if (!isNull) { |
1083 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->supportedMethods_id, temp.ptr())) { |
1084 | 0 | return false; |
1085 | 0 | } |
1086 | 0 | } |
1087 | 0 | if (!isNull && !temp->isUndefined()) { |
1088 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mSupportedMethods)) { |
1089 | 0 | return false; |
1090 | 0 | } |
1091 | 0 | mIsAnyMemberPresent = true; |
1092 | 0 | } else if (cx) { |
1093 | 0 | // Don't error out if we have no cx. In that |
1094 | 0 | // situation the caller is default-constructing us and we'll |
1095 | 0 | // just assume they know what they're doing. |
1096 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
1097 | 0 | "'supportedMethods' member of PaymentMethodData"); |
1098 | 0 | } |
1099 | 0 | return true; |
1100 | 0 | } |
1101 | | |
1102 | | bool |
1103 | | PaymentMethodData::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
1104 | 0 | { |
1105 | 0 | PaymentMethodDataAtoms* atomsCache = GetAtomCache<PaymentMethodDataAtoms>(cx); |
1106 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1107 | 0 | return false; |
1108 | 0 | } |
1109 | 0 | |
1110 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
1111 | 0 | if (!obj) { |
1112 | 0 | return false; |
1113 | 0 | } |
1114 | 0 | rval.set(JS::ObjectValue(*obj)); |
1115 | 0 |
|
1116 | 0 | if (mData.WasPassed()) { |
1117 | 0 | do { |
1118 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1119 | 0 | JS::Rooted<JS::Value> temp(cx); |
1120 | 0 | JSObject* const & currentValue = mData.InternalValue(); |
1121 | 0 | JS::ExposeObjectToActiveJS(currentValue); |
1122 | 0 | temp.setObject(*currentValue); |
1123 | 0 | if (!MaybeWrapObjectValue(cx, &temp)) { |
1124 | 0 | return false; |
1125 | 0 | } |
1126 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) { |
1127 | 0 | return false; |
1128 | 0 | } |
1129 | 0 | break; |
1130 | 0 | } while(false); |
1131 | 0 | } |
1132 | 0 |
|
1133 | 0 | do { |
1134 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1135 | 0 | JS::Rooted<JS::Value> temp(cx); |
1136 | 0 | nsString const & currentValue = mSupportedMethods; |
1137 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
1138 | 0 | return false; |
1139 | 0 | } |
1140 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->supportedMethods_id, temp, JSPROP_ENUMERATE)) { |
1141 | 0 | return false; |
1142 | 0 | } |
1143 | 0 | break; |
1144 | 0 | } while(false); |
1145 | 0 |
|
1146 | 0 | return true; |
1147 | 0 | } |
1148 | | |
1149 | | void |
1150 | | PaymentMethodData::TraceDictionary(JSTracer* trc) |
1151 | 0 | { |
1152 | 0 | if (mData.WasPassed()) { |
1153 | 0 | JS::UnsafeTraceRoot(trc, &mData.Value(), "PaymentMethodData.mData"); |
1154 | 0 | } |
1155 | 0 | } |
1156 | | |
1157 | | namespace binding_detail { |
1158 | | } // namespace binding_detail |
1159 | | |
1160 | | |
1161 | | |
1162 | | PaymentOptions::PaymentOptions() |
1163 | 0 | { |
1164 | 0 | // Safe to pass a null context if we pass a null value |
1165 | 0 | Init(nullptr, JS::NullHandleValue); |
1166 | 0 | } |
1167 | | |
1168 | | |
1169 | | |
1170 | | bool |
1171 | | PaymentOptions::InitIds(JSContext* cx, PaymentOptionsAtoms* atomsCache) |
1172 | 0 | { |
1173 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1174 | 0 |
|
1175 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1176 | 0 | // uninitialized. |
1177 | 0 | if (!atomsCache->shippingType_id.init(cx, "shippingType") || |
1178 | 0 | !atomsCache->requestShipping_id.init(cx, "requestShipping") || |
1179 | 0 | !atomsCache->requestPayerPhone_id.init(cx, "requestPayerPhone") || |
1180 | 0 | !atomsCache->requestPayerName_id.init(cx, "requestPayerName") || |
1181 | 0 | !atomsCache->requestPayerEmail_id.init(cx, "requestPayerEmail")) { |
1182 | 0 | return false; |
1183 | 0 | } |
1184 | 0 | return true; |
1185 | 0 | } |
1186 | | |
1187 | | bool |
1188 | | PaymentOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1189 | 0 | { |
1190 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1191 | 0 | // Since in that case we will not have to do any property gets |
1192 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1193 | 0 | // checkers by static analysis tools |
1194 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1195 | 0 | PaymentOptionsAtoms* atomsCache = nullptr; |
1196 | 0 | if (cx) { |
1197 | 0 | atomsCache = GetAtomCache<PaymentOptionsAtoms>(cx); |
1198 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1199 | 0 | return false; |
1200 | 0 | } |
1201 | 0 | } |
1202 | 0 | |
1203 | 0 | if (!IsConvertibleToDictionary(val)) { |
1204 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1205 | 0 | } |
1206 | 0 | |
1207 | 0 | bool isNull = val.isNullOrUndefined(); |
1208 | 0 | // We only need these if !isNull, in which case we have |cx|. |
1209 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
1210 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
1211 | 0 | if (!isNull) { |
1212 | 0 | MOZ_ASSERT(cx); |
1213 | 0 | object.emplace(cx, &val.toObject()); |
1214 | 0 | temp.emplace(cx); |
1215 | 0 | } |
1216 | 0 | if (!isNull) { |
1217 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->requestPayerEmail_id, temp.ptr())) { |
1218 | 0 | return false; |
1219 | 0 | } |
1220 | 0 | } |
1221 | 0 | if (!isNull && !temp->isUndefined()) { |
1222 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mRequestPayerEmail)) { |
1223 | 0 | return false; |
1224 | 0 | } |
1225 | 0 | } else { |
1226 | 0 | mRequestPayerEmail = false; |
1227 | 0 | } |
1228 | 0 | mIsAnyMemberPresent = true; |
1229 | 0 |
|
1230 | 0 | if (!isNull) { |
1231 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->requestPayerName_id, temp.ptr())) { |
1232 | 0 | return false; |
1233 | 0 | } |
1234 | 0 | } |
1235 | 0 | if (!isNull && !temp->isUndefined()) { |
1236 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mRequestPayerName)) { |
1237 | 0 | return false; |
1238 | 0 | } |
1239 | 0 | } else { |
1240 | 0 | mRequestPayerName = false; |
1241 | 0 | } |
1242 | 0 | mIsAnyMemberPresent = true; |
1243 | 0 |
|
1244 | 0 | if (!isNull) { |
1245 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->requestPayerPhone_id, temp.ptr())) { |
1246 | 0 | return false; |
1247 | 0 | } |
1248 | 0 | } |
1249 | 0 | if (!isNull && !temp->isUndefined()) { |
1250 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mRequestPayerPhone)) { |
1251 | 0 | return false; |
1252 | 0 | } |
1253 | 0 | } else { |
1254 | 0 | mRequestPayerPhone = false; |
1255 | 0 | } |
1256 | 0 | mIsAnyMemberPresent = true; |
1257 | 0 |
|
1258 | 0 | if (!isNull) { |
1259 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->requestShipping_id, temp.ptr())) { |
1260 | 0 | return false; |
1261 | 0 | } |
1262 | 0 | } |
1263 | 0 | if (!isNull && !temp->isUndefined()) { |
1264 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mRequestShipping)) { |
1265 | 0 | return false; |
1266 | 0 | } |
1267 | 0 | } else { |
1268 | 0 | mRequestShipping = false; |
1269 | 0 | } |
1270 | 0 | mIsAnyMemberPresent = true; |
1271 | 0 |
|
1272 | 0 | if (!isNull) { |
1273 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->shippingType_id, temp.ptr())) { |
1274 | 0 | return false; |
1275 | 0 | } |
1276 | 0 | } |
1277 | 0 | if (!isNull && !temp->isUndefined()) { |
1278 | 0 | { |
1279 | 0 | int index; |
1280 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), PaymentShippingTypeValues::strings, "PaymentShippingType", "'shippingType' member of PaymentOptions", &index)) { |
1281 | 0 | return false; |
1282 | 0 | } |
1283 | 0 | MOZ_ASSERT(index >= 0); |
1284 | 0 | mShippingType = static_cast<PaymentShippingType>(index); |
1285 | 0 | } |
1286 | 0 | } else { |
1287 | 0 | mShippingType = PaymentShippingType::Shipping; |
1288 | 0 | } |
1289 | 0 | mIsAnyMemberPresent = true; |
1290 | 0 | return true; |
1291 | 0 | } |
1292 | | |
1293 | | bool |
1294 | | PaymentOptions::Init(const nsAString& aJSON) |
1295 | 0 | { |
1296 | 0 | AutoJSAPI jsapi; |
1297 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
1298 | 0 | if (!cleanGlobal) { |
1299 | 0 | return false; |
1300 | 0 | } |
1301 | 0 | if (!jsapi.Init(cleanGlobal)) { |
1302 | 0 | return false; |
1303 | 0 | } |
1304 | 0 | JSContext* cx = jsapi.cx(); |
1305 | 0 | JS::Rooted<JS::Value> json(cx); |
1306 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
1307 | 0 | NS_ENSURE_TRUE(ok, false); |
1308 | 0 | return Init(cx, json); |
1309 | 0 | } |
1310 | | |
1311 | | bool |
1312 | | PaymentOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
1313 | 0 | { |
1314 | 0 | PaymentOptionsAtoms* atomsCache = GetAtomCache<PaymentOptionsAtoms>(cx); |
1315 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1316 | 0 | return false; |
1317 | 0 | } |
1318 | 0 | |
1319 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
1320 | 0 | if (!obj) { |
1321 | 0 | return false; |
1322 | 0 | } |
1323 | 0 | rval.set(JS::ObjectValue(*obj)); |
1324 | 0 |
|
1325 | 0 | do { |
1326 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1327 | 0 | JS::Rooted<JS::Value> temp(cx); |
1328 | 0 | bool const & currentValue = mRequestPayerEmail; |
1329 | 0 | temp.setBoolean(currentValue); |
1330 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->requestPayerEmail_id, temp, JSPROP_ENUMERATE)) { |
1331 | 0 | return false; |
1332 | 0 | } |
1333 | 0 | break; |
1334 | 0 | } while(false); |
1335 | 0 |
|
1336 | 0 | do { |
1337 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1338 | 0 | JS::Rooted<JS::Value> temp(cx); |
1339 | 0 | bool const & currentValue = mRequestPayerName; |
1340 | 0 | temp.setBoolean(currentValue); |
1341 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->requestPayerName_id, temp, JSPROP_ENUMERATE)) { |
1342 | 0 | return false; |
1343 | 0 | } |
1344 | 0 | break; |
1345 | 0 | } while(false); |
1346 | 0 |
|
1347 | 0 | do { |
1348 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1349 | 0 | JS::Rooted<JS::Value> temp(cx); |
1350 | 0 | bool const & currentValue = mRequestPayerPhone; |
1351 | 0 | temp.setBoolean(currentValue); |
1352 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->requestPayerPhone_id, temp, JSPROP_ENUMERATE)) { |
1353 | 0 | return false; |
1354 | 0 | } |
1355 | 0 | break; |
1356 | 0 | } while(false); |
1357 | 0 |
|
1358 | 0 | do { |
1359 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1360 | 0 | JS::Rooted<JS::Value> temp(cx); |
1361 | 0 | bool const & currentValue = mRequestShipping; |
1362 | 0 | temp.setBoolean(currentValue); |
1363 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->requestShipping_id, temp, JSPROP_ENUMERATE)) { |
1364 | 0 | return false; |
1365 | 0 | } |
1366 | 0 | break; |
1367 | 0 | } while(false); |
1368 | 0 |
|
1369 | 0 | do { |
1370 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1371 | 0 | JS::Rooted<JS::Value> temp(cx); |
1372 | 0 | PaymentShippingType const & currentValue = mShippingType; |
1373 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
1374 | 0 | return false; |
1375 | 0 | } |
1376 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->shippingType_id, temp, JSPROP_ENUMERATE)) { |
1377 | 0 | return false; |
1378 | 0 | } |
1379 | 0 | break; |
1380 | 0 | } while(false); |
1381 | 0 |
|
1382 | 0 | return true; |
1383 | 0 | } |
1384 | | |
1385 | | bool |
1386 | | PaymentOptions::ToJSON(nsAString& aJSON) const |
1387 | 0 | { |
1388 | 0 | AutoJSAPI jsapi; |
1389 | 0 | jsapi.Init(); |
1390 | 0 | JSContext *cx = jsapi.cx(); |
1391 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
1392 | 0 | // because we'll only be creating objects, in ways that have no |
1393 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
1394 | 0 | // which likewise guarantees no side-effects for the sorts of |
1395 | 0 | // things we will pass it. |
1396 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
1397 | 0 | JS::Rooted<JS::Value> val(cx); |
1398 | 0 | if (!ToObjectInternal(cx, &val)) { |
1399 | 0 | return false; |
1400 | 0 | } |
1401 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
1402 | 0 | return StringifyToJSON(cx, obj, aJSON); |
1403 | 0 | } |
1404 | | |
1405 | | void |
1406 | | PaymentOptions::TraceDictionary(JSTracer* trc) |
1407 | 0 | { |
1408 | 0 | } |
1409 | | |
1410 | | PaymentOptions& |
1411 | | PaymentOptions::operator=(const PaymentOptions& aOther) |
1412 | 0 | { |
1413 | 0 | DictionaryBase::operator=(aOther); |
1414 | 0 | mRequestPayerEmail = aOther.mRequestPayerEmail; |
1415 | 0 | mRequestPayerName = aOther.mRequestPayerName; |
1416 | 0 | mRequestPayerPhone = aOther.mRequestPayerPhone; |
1417 | 0 | mRequestShipping = aOther.mRequestShipping; |
1418 | 0 | mShippingType = aOther.mShippingType; |
1419 | 0 | return *this; |
1420 | 0 | } |
1421 | | |
1422 | | namespace binding_detail { |
1423 | | } // namespace binding_detail |
1424 | | |
1425 | | |
1426 | | |
1427 | | PaymentItem::PaymentItem() |
1428 | | : mAmount(FastDictionaryInitializer()) |
1429 | 0 | { |
1430 | 0 | // Safe to pass a null context if we pass a null value |
1431 | 0 | Init(nullptr, JS::NullHandleValue); |
1432 | 0 | } |
1433 | | |
1434 | | |
1435 | | |
1436 | | bool |
1437 | | PaymentItem::InitIds(JSContext* cx, PaymentItemAtoms* atomsCache) |
1438 | 0 | { |
1439 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1440 | 0 |
|
1441 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1442 | 0 | // uninitialized. |
1443 | 0 | if (!atomsCache->type_id.init(cx, "type") || |
1444 | 0 | !atomsCache->pending_id.init(cx, "pending") || |
1445 | 0 | !atomsCache->label_id.init(cx, "label") || |
1446 | 0 | !atomsCache->amount_id.init(cx, "amount")) { |
1447 | 0 | return false; |
1448 | 0 | } |
1449 | 0 | return true; |
1450 | 0 | } |
1451 | | |
1452 | | bool |
1453 | | PaymentItem::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1454 | 0 | { |
1455 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1456 | 0 | // Since in that case we will not have to do any property gets |
1457 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1458 | 0 | // checkers by static analysis tools |
1459 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1460 | 0 | PaymentItemAtoms* atomsCache = nullptr; |
1461 | 0 | if (cx) { |
1462 | 0 | atomsCache = GetAtomCache<PaymentItemAtoms>(cx); |
1463 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1464 | 0 | return false; |
1465 | 0 | } |
1466 | 0 | } |
1467 | 0 | |
1468 | 0 | if (!IsConvertibleToDictionary(val)) { |
1469 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1470 | 0 | } |
1471 | 0 | |
1472 | 0 | bool isNull = val.isNullOrUndefined(); |
1473 | 0 | // We only need these if !isNull, in which case we have |cx|. |
1474 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
1475 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
1476 | 0 | if (!isNull) { |
1477 | 0 | MOZ_ASSERT(cx); |
1478 | 0 | object.emplace(cx, &val.toObject()); |
1479 | 0 | temp.emplace(cx); |
1480 | 0 | } |
1481 | 0 | if (!isNull) { |
1482 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->amount_id, temp.ptr())) { |
1483 | 0 | return false; |
1484 | 0 | } |
1485 | 0 | } |
1486 | 0 | if (!isNull && !temp->isUndefined()) { |
1487 | 0 | if (!mAmount.Init(cx, temp.ref(), "'amount' member of PaymentItem", passedToJSImpl)) { |
1488 | 0 | return false; |
1489 | 0 | } |
1490 | 0 | mIsAnyMemberPresent = true; |
1491 | 0 | } else if (cx) { |
1492 | 0 | // Don't error out if we have no cx. In that |
1493 | 0 | // situation the caller is default-constructing us and we'll |
1494 | 0 | // just assume they know what they're doing. |
1495 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
1496 | 0 | "'amount' member of PaymentItem"); |
1497 | 0 | } |
1498 | 0 | |
1499 | 0 | if (!isNull) { |
1500 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->label_id, temp.ptr())) { |
1501 | 0 | return false; |
1502 | 0 | } |
1503 | 0 | } |
1504 | 0 | if (!isNull && !temp->isUndefined()) { |
1505 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mLabel)) { |
1506 | 0 | return false; |
1507 | 0 | } |
1508 | 0 | mIsAnyMemberPresent = true; |
1509 | 0 | } else if (cx) { |
1510 | 0 | // Don't error out if we have no cx. In that |
1511 | 0 | // situation the caller is default-constructing us and we'll |
1512 | 0 | // just assume they know what they're doing. |
1513 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
1514 | 0 | "'label' member of PaymentItem"); |
1515 | 0 | } |
1516 | 0 | |
1517 | 0 | if (!isNull) { |
1518 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->pending_id, temp.ptr())) { |
1519 | 0 | return false; |
1520 | 0 | } |
1521 | 0 | } |
1522 | 0 | if (!isNull && !temp->isUndefined()) { |
1523 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mPending)) { |
1524 | 0 | return false; |
1525 | 0 | } |
1526 | 0 | } else { |
1527 | 0 | mPending = false; |
1528 | 0 | } |
1529 | 0 | mIsAnyMemberPresent = true; |
1530 | 0 |
|
1531 | 0 | if (!isNull) { |
1532 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) { |
1533 | 0 | return false; |
1534 | 0 | } |
1535 | 0 | } |
1536 | 0 | if (!isNull && !temp->isUndefined()) { |
1537 | 0 | mType.Construct(); |
1538 | 0 | { |
1539 | 0 | int index; |
1540 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), PaymentItemTypeValues::strings, "PaymentItemType", "'type' member of PaymentItem", &index)) { |
1541 | 0 | return false; |
1542 | 0 | } |
1543 | 0 | MOZ_ASSERT(index >= 0); |
1544 | 0 | (mType.Value()) = static_cast<PaymentItemType>(index); |
1545 | 0 | } |
1546 | 0 | mIsAnyMemberPresent = true; |
1547 | 0 | } |
1548 | 0 | return true; |
1549 | 0 | } |
1550 | | |
1551 | | bool |
1552 | | PaymentItem::Init(const nsAString& aJSON) |
1553 | 0 | { |
1554 | 0 | AutoJSAPI jsapi; |
1555 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
1556 | 0 | if (!cleanGlobal) { |
1557 | 0 | return false; |
1558 | 0 | } |
1559 | 0 | if (!jsapi.Init(cleanGlobal)) { |
1560 | 0 | return false; |
1561 | 0 | } |
1562 | 0 | JSContext* cx = jsapi.cx(); |
1563 | 0 | JS::Rooted<JS::Value> json(cx); |
1564 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
1565 | 0 | NS_ENSURE_TRUE(ok, false); |
1566 | 0 | return Init(cx, json); |
1567 | 0 | } |
1568 | | |
1569 | | bool |
1570 | | PaymentItem::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
1571 | 0 | { |
1572 | 0 | PaymentItemAtoms* atomsCache = GetAtomCache<PaymentItemAtoms>(cx); |
1573 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1574 | 0 | return false; |
1575 | 0 | } |
1576 | 0 | |
1577 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
1578 | 0 | if (!obj) { |
1579 | 0 | return false; |
1580 | 0 | } |
1581 | 0 | rval.set(JS::ObjectValue(*obj)); |
1582 | 0 |
|
1583 | 0 | do { |
1584 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1585 | 0 | JS::Rooted<JS::Value> temp(cx); |
1586 | 0 | PaymentCurrencyAmount const & currentValue = mAmount; |
1587 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
1588 | 0 | return false; |
1589 | 0 | } |
1590 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->amount_id, temp, JSPROP_ENUMERATE)) { |
1591 | 0 | return false; |
1592 | 0 | } |
1593 | 0 | break; |
1594 | 0 | } while(false); |
1595 | 0 |
|
1596 | 0 | do { |
1597 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1598 | 0 | JS::Rooted<JS::Value> temp(cx); |
1599 | 0 | nsString const & currentValue = mLabel; |
1600 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
1601 | 0 | return false; |
1602 | 0 | } |
1603 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->label_id, temp, JSPROP_ENUMERATE)) { |
1604 | 0 | return false; |
1605 | 0 | } |
1606 | 0 | break; |
1607 | 0 | } while(false); |
1608 | 0 |
|
1609 | 0 | do { |
1610 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1611 | 0 | JS::Rooted<JS::Value> temp(cx); |
1612 | 0 | bool const & currentValue = mPending; |
1613 | 0 | temp.setBoolean(currentValue); |
1614 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->pending_id, temp, JSPROP_ENUMERATE)) { |
1615 | 0 | return false; |
1616 | 0 | } |
1617 | 0 | break; |
1618 | 0 | } while(false); |
1619 | 0 |
|
1620 | 0 | if (mType.WasPassed()) { |
1621 | 0 | do { |
1622 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1623 | 0 | JS::Rooted<JS::Value> temp(cx); |
1624 | 0 | PaymentItemType const & currentValue = mType.InternalValue(); |
1625 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
1626 | 0 | return false; |
1627 | 0 | } |
1628 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) { |
1629 | 0 | return false; |
1630 | 0 | } |
1631 | 0 | break; |
1632 | 0 | } while(false); |
1633 | 0 | } |
1634 | 0 |
|
1635 | 0 | return true; |
1636 | 0 | } |
1637 | | |
1638 | | bool |
1639 | | PaymentItem::ToJSON(nsAString& aJSON) const |
1640 | 0 | { |
1641 | 0 | AutoJSAPI jsapi; |
1642 | 0 | jsapi.Init(); |
1643 | 0 | JSContext *cx = jsapi.cx(); |
1644 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
1645 | 0 | // because we'll only be creating objects, in ways that have no |
1646 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
1647 | 0 | // which likewise guarantees no side-effects for the sorts of |
1648 | 0 | // things we will pass it. |
1649 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
1650 | 0 | JS::Rooted<JS::Value> val(cx); |
1651 | 0 | if (!ToObjectInternal(cx, &val)) { |
1652 | 0 | return false; |
1653 | 0 | } |
1654 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
1655 | 0 | return StringifyToJSON(cx, obj, aJSON); |
1656 | 0 | } |
1657 | | |
1658 | | void |
1659 | | PaymentItem::TraceDictionary(JSTracer* trc) |
1660 | 0 | { |
1661 | 0 | } |
1662 | | |
1663 | | PaymentItem& |
1664 | | PaymentItem::operator=(const PaymentItem& aOther) |
1665 | 0 | { |
1666 | 0 | DictionaryBase::operator=(aOther); |
1667 | 0 | mAmount = aOther.mAmount; |
1668 | 0 | mLabel = aOther.mLabel; |
1669 | 0 | mPending = aOther.mPending; |
1670 | 0 | mType.Reset(); |
1671 | 0 | if (aOther.mType.WasPassed()) { |
1672 | 0 | mType.Construct(aOther.mType.Value()); |
1673 | 0 | } |
1674 | 0 | return *this; |
1675 | 0 | } |
1676 | | |
1677 | | namespace binding_detail { |
1678 | | } // namespace binding_detail |
1679 | | |
1680 | | |
1681 | | |
1682 | | PaymentShippingOption::PaymentShippingOption() |
1683 | | : mAmount(FastDictionaryInitializer()) |
1684 | 0 | { |
1685 | 0 | // Safe to pass a null context if we pass a null value |
1686 | 0 | Init(nullptr, JS::NullHandleValue); |
1687 | 0 | } |
1688 | | |
1689 | | |
1690 | | |
1691 | | bool |
1692 | | PaymentShippingOption::InitIds(JSContext* cx, PaymentShippingOptionAtoms* atomsCache) |
1693 | 0 | { |
1694 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1695 | 0 |
|
1696 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1697 | 0 | // uninitialized. |
1698 | 0 | if (!atomsCache->selected_id.init(cx, "selected") || |
1699 | 0 | !atomsCache->label_id.init(cx, "label") || |
1700 | 0 | !atomsCache->id_id.init(cx, "id") || |
1701 | 0 | !atomsCache->amount_id.init(cx, "amount")) { |
1702 | 0 | return false; |
1703 | 0 | } |
1704 | 0 | return true; |
1705 | 0 | } |
1706 | | |
1707 | | bool |
1708 | | PaymentShippingOption::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1709 | 0 | { |
1710 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1711 | 0 | // Since in that case we will not have to do any property gets |
1712 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1713 | 0 | // checkers by static analysis tools |
1714 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1715 | 0 | PaymentShippingOptionAtoms* atomsCache = nullptr; |
1716 | 0 | if (cx) { |
1717 | 0 | atomsCache = GetAtomCache<PaymentShippingOptionAtoms>(cx); |
1718 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1719 | 0 | return false; |
1720 | 0 | } |
1721 | 0 | } |
1722 | 0 | |
1723 | 0 | if (!IsConvertibleToDictionary(val)) { |
1724 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1725 | 0 | } |
1726 | 0 | |
1727 | 0 | bool isNull = val.isNullOrUndefined(); |
1728 | 0 | // We only need these if !isNull, in which case we have |cx|. |
1729 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
1730 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
1731 | 0 | if (!isNull) { |
1732 | 0 | MOZ_ASSERT(cx); |
1733 | 0 | object.emplace(cx, &val.toObject()); |
1734 | 0 | temp.emplace(cx); |
1735 | 0 | } |
1736 | 0 | if (!isNull) { |
1737 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->amount_id, temp.ptr())) { |
1738 | 0 | return false; |
1739 | 0 | } |
1740 | 0 | } |
1741 | 0 | if (!isNull && !temp->isUndefined()) { |
1742 | 0 | if (!mAmount.Init(cx, temp.ref(), "'amount' member of PaymentShippingOption", passedToJSImpl)) { |
1743 | 0 | return false; |
1744 | 0 | } |
1745 | 0 | mIsAnyMemberPresent = true; |
1746 | 0 | } else if (cx) { |
1747 | 0 | // Don't error out if we have no cx. In that |
1748 | 0 | // situation the caller is default-constructing us and we'll |
1749 | 0 | // just assume they know what they're doing. |
1750 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
1751 | 0 | "'amount' member of PaymentShippingOption"); |
1752 | 0 | } |
1753 | 0 | |
1754 | 0 | if (!isNull) { |
1755 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->id_id, temp.ptr())) { |
1756 | 0 | return false; |
1757 | 0 | } |
1758 | 0 | } |
1759 | 0 | if (!isNull && !temp->isUndefined()) { |
1760 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mId)) { |
1761 | 0 | return false; |
1762 | 0 | } |
1763 | 0 | mIsAnyMemberPresent = true; |
1764 | 0 | } else if (cx) { |
1765 | 0 | // Don't error out if we have no cx. In that |
1766 | 0 | // situation the caller is default-constructing us and we'll |
1767 | 0 | // just assume they know what they're doing. |
1768 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
1769 | 0 | "'id' member of PaymentShippingOption"); |
1770 | 0 | } |
1771 | 0 | |
1772 | 0 | if (!isNull) { |
1773 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->label_id, temp.ptr())) { |
1774 | 0 | return false; |
1775 | 0 | } |
1776 | 0 | } |
1777 | 0 | if (!isNull && !temp->isUndefined()) { |
1778 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mLabel)) { |
1779 | 0 | return false; |
1780 | 0 | } |
1781 | 0 | mIsAnyMemberPresent = true; |
1782 | 0 | } else if (cx) { |
1783 | 0 | // Don't error out if we have no cx. In that |
1784 | 0 | // situation the caller is default-constructing us and we'll |
1785 | 0 | // just assume they know what they're doing. |
1786 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
1787 | 0 | "'label' member of PaymentShippingOption"); |
1788 | 0 | } |
1789 | 0 | |
1790 | 0 | if (!isNull) { |
1791 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->selected_id, temp.ptr())) { |
1792 | 0 | return false; |
1793 | 0 | } |
1794 | 0 | } |
1795 | 0 | if (!isNull && !temp->isUndefined()) { |
1796 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mSelected)) { |
1797 | 0 | return false; |
1798 | 0 | } |
1799 | 0 | } else { |
1800 | 0 | mSelected = false; |
1801 | 0 | } |
1802 | 0 | mIsAnyMemberPresent = true; |
1803 | 0 | return true; |
1804 | 0 | } |
1805 | | |
1806 | | bool |
1807 | | PaymentShippingOption::Init(const nsAString& aJSON) |
1808 | 0 | { |
1809 | 0 | AutoJSAPI jsapi; |
1810 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
1811 | 0 | if (!cleanGlobal) { |
1812 | 0 | return false; |
1813 | 0 | } |
1814 | 0 | if (!jsapi.Init(cleanGlobal)) { |
1815 | 0 | return false; |
1816 | 0 | } |
1817 | 0 | JSContext* cx = jsapi.cx(); |
1818 | 0 | JS::Rooted<JS::Value> json(cx); |
1819 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
1820 | 0 | NS_ENSURE_TRUE(ok, false); |
1821 | 0 | return Init(cx, json); |
1822 | 0 | } |
1823 | | |
1824 | | bool |
1825 | | PaymentShippingOption::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
1826 | 0 | { |
1827 | 0 | PaymentShippingOptionAtoms* atomsCache = GetAtomCache<PaymentShippingOptionAtoms>(cx); |
1828 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1829 | 0 | return false; |
1830 | 0 | } |
1831 | 0 | |
1832 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
1833 | 0 | if (!obj) { |
1834 | 0 | return false; |
1835 | 0 | } |
1836 | 0 | rval.set(JS::ObjectValue(*obj)); |
1837 | 0 |
|
1838 | 0 | do { |
1839 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1840 | 0 | JS::Rooted<JS::Value> temp(cx); |
1841 | 0 | PaymentCurrencyAmount const & currentValue = mAmount; |
1842 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
1843 | 0 | return false; |
1844 | 0 | } |
1845 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->amount_id, temp, JSPROP_ENUMERATE)) { |
1846 | 0 | return false; |
1847 | 0 | } |
1848 | 0 | break; |
1849 | 0 | } while(false); |
1850 | 0 |
|
1851 | 0 | do { |
1852 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1853 | 0 | JS::Rooted<JS::Value> temp(cx); |
1854 | 0 | nsString const & currentValue = mId; |
1855 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
1856 | 0 | return false; |
1857 | 0 | } |
1858 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) { |
1859 | 0 | return false; |
1860 | 0 | } |
1861 | 0 | break; |
1862 | 0 | } while(false); |
1863 | 0 |
|
1864 | 0 | do { |
1865 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1866 | 0 | JS::Rooted<JS::Value> temp(cx); |
1867 | 0 | nsString const & currentValue = mLabel; |
1868 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
1869 | 0 | return false; |
1870 | 0 | } |
1871 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->label_id, temp, JSPROP_ENUMERATE)) { |
1872 | 0 | return false; |
1873 | 0 | } |
1874 | 0 | break; |
1875 | 0 | } while(false); |
1876 | 0 |
|
1877 | 0 | do { |
1878 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1879 | 0 | JS::Rooted<JS::Value> temp(cx); |
1880 | 0 | bool const & currentValue = mSelected; |
1881 | 0 | temp.setBoolean(currentValue); |
1882 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->selected_id, temp, JSPROP_ENUMERATE)) { |
1883 | 0 | return false; |
1884 | 0 | } |
1885 | 0 | break; |
1886 | 0 | } while(false); |
1887 | 0 |
|
1888 | 0 | return true; |
1889 | 0 | } |
1890 | | |
1891 | | bool |
1892 | | PaymentShippingOption::ToJSON(nsAString& aJSON) const |
1893 | 0 | { |
1894 | 0 | AutoJSAPI jsapi; |
1895 | 0 | jsapi.Init(); |
1896 | 0 | JSContext *cx = jsapi.cx(); |
1897 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
1898 | 0 | // because we'll only be creating objects, in ways that have no |
1899 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
1900 | 0 | // which likewise guarantees no side-effects for the sorts of |
1901 | 0 | // things we will pass it. |
1902 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
1903 | 0 | JS::Rooted<JS::Value> val(cx); |
1904 | 0 | if (!ToObjectInternal(cx, &val)) { |
1905 | 0 | return false; |
1906 | 0 | } |
1907 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
1908 | 0 | return StringifyToJSON(cx, obj, aJSON); |
1909 | 0 | } |
1910 | | |
1911 | | void |
1912 | | PaymentShippingOption::TraceDictionary(JSTracer* trc) |
1913 | 0 | { |
1914 | 0 | } |
1915 | | |
1916 | | PaymentShippingOption& |
1917 | | PaymentShippingOption::operator=(const PaymentShippingOption& aOther) |
1918 | 0 | { |
1919 | 0 | DictionaryBase::operator=(aOther); |
1920 | 0 | mAmount = aOther.mAmount; |
1921 | 0 | mId = aOther.mId; |
1922 | 0 | mLabel = aOther.mLabel; |
1923 | 0 | mSelected = aOther.mSelected; |
1924 | 0 | return *this; |
1925 | 0 | } |
1926 | | |
1927 | | namespace binding_detail { |
1928 | | } // namespace binding_detail |
1929 | | |
1930 | | |
1931 | | |
1932 | | PaymentValidationErrors::PaymentValidationErrors() |
1933 | | : mPayer(FastDictionaryInitializer()), |
1934 | | mShippingAddress(FastDictionaryInitializer()) |
1935 | 0 | { |
1936 | 0 | // Safe to pass a null context if we pass a null value |
1937 | 0 | Init(nullptr, JS::NullHandleValue); |
1938 | 0 | } |
1939 | | |
1940 | | |
1941 | | bool |
1942 | | PaymentValidationErrors::InitIds(JSContext* cx, PaymentValidationErrorsAtoms* atomsCache) |
1943 | 0 | { |
1944 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1945 | 0 |
|
1946 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1947 | 0 | // uninitialized. |
1948 | 0 | if (!atomsCache->shippingAddress_id.init(cx, "shippingAddress") || |
1949 | 0 | !atomsCache->paymentMethod_id.init(cx, "paymentMethod") || |
1950 | 0 | !atomsCache->payer_id.init(cx, "payer") || |
1951 | 0 | !atomsCache->error_id.init(cx, "error")) { |
1952 | 0 | return false; |
1953 | 0 | } |
1954 | 0 | return true; |
1955 | 0 | } |
1956 | | |
1957 | | bool |
1958 | | PaymentValidationErrors::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1959 | 0 | { |
1960 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1961 | 0 | // Since in that case we will not have to do any property gets |
1962 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1963 | 0 | // checkers by static analysis tools |
1964 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1965 | 0 | PaymentValidationErrorsAtoms* atomsCache = nullptr; |
1966 | 0 | if (cx) { |
1967 | 0 | atomsCache = GetAtomCache<PaymentValidationErrorsAtoms>(cx); |
1968 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1969 | 0 | return false; |
1970 | 0 | } |
1971 | 0 | } |
1972 | 0 | |
1973 | 0 | if (!IsConvertibleToDictionary(val)) { |
1974 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1975 | 0 | } |
1976 | 0 | |
1977 | 0 | bool isNull = val.isNullOrUndefined(); |
1978 | 0 | // We only need these if !isNull, in which case we have |cx|. |
1979 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
1980 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
1981 | 0 | if (!isNull) { |
1982 | 0 | MOZ_ASSERT(cx); |
1983 | 0 | object.emplace(cx, &val.toObject()); |
1984 | 0 | temp.emplace(cx); |
1985 | 0 | } |
1986 | 0 | if (!isNull) { |
1987 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->error_id, temp.ptr())) { |
1988 | 0 | return false; |
1989 | 0 | } |
1990 | 0 | } |
1991 | 0 | if (!isNull && !temp->isUndefined()) { |
1992 | 0 | mError.Construct(); |
1993 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mError.Value()))) { |
1994 | 0 | return false; |
1995 | 0 | } |
1996 | 0 | mIsAnyMemberPresent = true; |
1997 | 0 | } |
1998 | 0 |
|
1999 | 0 | if (!isNull) { |
2000 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->payer_id, temp.ptr())) { |
2001 | 0 | return false; |
2002 | 0 | } |
2003 | 0 | } |
2004 | 0 | if (!mPayer.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'payer' member of PaymentValidationErrors", passedToJSImpl)) { |
2005 | 0 | return false; |
2006 | 0 | } |
2007 | 0 | mIsAnyMemberPresent = true; |
2008 | 0 |
|
2009 | 0 | if (!isNull) { |
2010 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->paymentMethod_id, temp.ptr())) { |
2011 | 0 | return false; |
2012 | 0 | } |
2013 | 0 | } |
2014 | 0 | if (!isNull && !temp->isUndefined()) { |
2015 | 0 | mPaymentMethod.Construct(); |
2016 | 0 | if (temp.ref().isObject()) { |
2017 | 0 | #ifdef __clang__ |
2018 | 0 | #pragma clang diagnostic push |
2019 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
2020 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
2021 | 0 | #endif // __clang__ |
2022 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
2023 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'paymentMethod' member of PaymentValidationErrors"); |
2024 | 0 | return false; |
2025 | 0 | } |
2026 | 0 | #ifdef __clang__ |
2027 | 0 | #pragma clang diagnostic pop |
2028 | 0 | #endif // __clang__ |
2029 | 0 | (mPaymentMethod.Value()) = &temp.ref().toObject(); |
2030 | 0 | } else { |
2031 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'paymentMethod' member of PaymentValidationErrors"); |
2032 | 0 | return false; |
2033 | 0 | } |
2034 | 0 | mIsAnyMemberPresent = true; |
2035 | 0 | } |
2036 | 0 |
|
2037 | 0 | if (!isNull) { |
2038 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->shippingAddress_id, temp.ptr())) { |
2039 | 0 | return false; |
2040 | 0 | } |
2041 | 0 | } |
2042 | 0 | if (!mShippingAddress.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'shippingAddress' member of PaymentValidationErrors", passedToJSImpl)) { |
2043 | 0 | return false; |
2044 | 0 | } |
2045 | 0 | mIsAnyMemberPresent = true; |
2046 | 0 | return true; |
2047 | 0 | } |
2048 | | |
2049 | | bool |
2050 | | PaymentValidationErrors::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
2051 | 0 | { |
2052 | 0 | PaymentValidationErrorsAtoms* atomsCache = GetAtomCache<PaymentValidationErrorsAtoms>(cx); |
2053 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2054 | 0 | return false; |
2055 | 0 | } |
2056 | 0 | |
2057 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
2058 | 0 | if (!obj) { |
2059 | 0 | return false; |
2060 | 0 | } |
2061 | 0 | rval.set(JS::ObjectValue(*obj)); |
2062 | 0 |
|
2063 | 0 | if (mError.WasPassed()) { |
2064 | 0 | do { |
2065 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2066 | 0 | JS::Rooted<JS::Value> temp(cx); |
2067 | 0 | nsString const & currentValue = mError.InternalValue(); |
2068 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
2069 | 0 | return false; |
2070 | 0 | } |
2071 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->error_id, temp, JSPROP_ENUMERATE)) { |
2072 | 0 | return false; |
2073 | 0 | } |
2074 | 0 | break; |
2075 | 0 | } while(false); |
2076 | 0 | } |
2077 | 0 |
|
2078 | 0 | do { |
2079 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2080 | 0 | JS::Rooted<JS::Value> temp(cx); |
2081 | 0 | PayerErrorFields const & currentValue = mPayer; |
2082 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
2083 | 0 | return false; |
2084 | 0 | } |
2085 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->payer_id, temp, JSPROP_ENUMERATE)) { |
2086 | 0 | return false; |
2087 | 0 | } |
2088 | 0 | break; |
2089 | 0 | } while(false); |
2090 | 0 |
|
2091 | 0 | if (mPaymentMethod.WasPassed()) { |
2092 | 0 | do { |
2093 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2094 | 0 | JS::Rooted<JS::Value> temp(cx); |
2095 | 0 | JSObject* const & currentValue = mPaymentMethod.InternalValue(); |
2096 | 0 | JS::ExposeObjectToActiveJS(currentValue); |
2097 | 0 | temp.setObject(*currentValue); |
2098 | 0 | if (!MaybeWrapObjectValue(cx, &temp)) { |
2099 | 0 | return false; |
2100 | 0 | } |
2101 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->paymentMethod_id, temp, JSPROP_ENUMERATE)) { |
2102 | 0 | return false; |
2103 | 0 | } |
2104 | 0 | break; |
2105 | 0 | } while(false); |
2106 | 0 | } |
2107 | 0 |
|
2108 | 0 | do { |
2109 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2110 | 0 | JS::Rooted<JS::Value> temp(cx); |
2111 | 0 | AddressErrors const & currentValue = mShippingAddress; |
2112 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
2113 | 0 | return false; |
2114 | 0 | } |
2115 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->shippingAddress_id, temp, JSPROP_ENUMERATE)) { |
2116 | 0 | return false; |
2117 | 0 | } |
2118 | 0 | break; |
2119 | 0 | } while(false); |
2120 | 0 |
|
2121 | 0 | return true; |
2122 | 0 | } |
2123 | | |
2124 | | void |
2125 | | PaymentValidationErrors::TraceDictionary(JSTracer* trc) |
2126 | 0 | { |
2127 | 0 | if (mPaymentMethod.WasPassed()) { |
2128 | 0 | JS::UnsafeTraceRoot(trc, &mPaymentMethod.Value(), "PaymentValidationErrors.mPaymentMethod"); |
2129 | 0 | } |
2130 | 0 | } |
2131 | | |
2132 | | namespace binding_detail { |
2133 | | } // namespace binding_detail |
2134 | | |
2135 | | |
2136 | | |
2137 | | PaymentDetailsModifier::PaymentDetailsModifier() |
2138 | | : mTotal(FastDictionaryInitializer()) |
2139 | 0 | { |
2140 | 0 | // Safe to pass a null context if we pass a null value |
2141 | 0 | Init(nullptr, JS::NullHandleValue); |
2142 | 0 | } |
2143 | | |
2144 | | |
2145 | | bool |
2146 | | PaymentDetailsModifier::InitIds(JSContext* cx, PaymentDetailsModifierAtoms* atomsCache) |
2147 | 0 | { |
2148 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
2149 | 0 |
|
2150 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
2151 | 0 | // uninitialized. |
2152 | 0 | if (!atomsCache->total_id.init(cx, "total") || |
2153 | 0 | !atomsCache->supportedMethods_id.init(cx, "supportedMethods") || |
2154 | 0 | !atomsCache->data_id.init(cx, "data") || |
2155 | 0 | !atomsCache->additionalDisplayItems_id.init(cx, "additionalDisplayItems")) { |
2156 | 0 | return false; |
2157 | 0 | } |
2158 | 0 | return true; |
2159 | 0 | } |
2160 | | |
2161 | | bool |
2162 | | PaymentDetailsModifier::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
2163 | 0 | { |
2164 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
2165 | 0 | // Since in that case we will not have to do any property gets |
2166 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
2167 | 0 | // checkers by static analysis tools |
2168 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
2169 | 0 | PaymentDetailsModifierAtoms* atomsCache = nullptr; |
2170 | 0 | if (cx) { |
2171 | 0 | atomsCache = GetAtomCache<PaymentDetailsModifierAtoms>(cx); |
2172 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2173 | 0 | return false; |
2174 | 0 | } |
2175 | 0 | } |
2176 | 0 | |
2177 | 0 | if (!IsConvertibleToDictionary(val)) { |
2178 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
2179 | 0 | } |
2180 | 0 | |
2181 | 0 | bool isNull = val.isNullOrUndefined(); |
2182 | 0 | // We only need these if !isNull, in which case we have |cx|. |
2183 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
2184 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
2185 | 0 | if (!isNull) { |
2186 | 0 | MOZ_ASSERT(cx); |
2187 | 0 | object.emplace(cx, &val.toObject()); |
2188 | 0 | temp.emplace(cx); |
2189 | 0 | } |
2190 | 0 | if (!isNull) { |
2191 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->additionalDisplayItems_id, temp.ptr())) { |
2192 | 0 | return false; |
2193 | 0 | } |
2194 | 0 | } |
2195 | 0 | if (!isNull && !temp->isUndefined()) { |
2196 | 0 | mAdditionalDisplayItems.Construct(); |
2197 | 0 | if (temp.ref().isObject()) { |
2198 | 0 | JS::ForOfIterator iter(cx); |
2199 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
2200 | 0 | return false; |
2201 | 0 | } |
2202 | 0 | if (!iter.valueIsIterable()) { |
2203 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'additionalDisplayItems' member of PaymentDetailsModifier"); |
2204 | 0 | return false; |
2205 | 0 | } |
2206 | 0 | Sequence<PaymentItem> &arr = (mAdditionalDisplayItems.Value()); |
2207 | 0 | JS::Rooted<JS::Value> temp(cx); |
2208 | 0 | while (true) { |
2209 | 0 | bool done; |
2210 | 0 | if (!iter.next(&temp, &done)) { |
2211 | 0 | return false; |
2212 | 0 | } |
2213 | 0 | if (done) { |
2214 | 0 | break; |
2215 | 0 | } |
2216 | 0 | PaymentItem* slotPtr = arr.AppendElement(mozilla::fallible); |
2217 | 0 | if (!slotPtr) { |
2218 | 0 | JS_ReportOutOfMemory(cx); |
2219 | 0 | return false; |
2220 | 0 | } |
2221 | 0 | PaymentItem& slot = *slotPtr; |
2222 | 0 | if (!slot.Init(cx, temp, "Element of 'additionalDisplayItems' member of PaymentDetailsModifier", passedToJSImpl)) { |
2223 | 0 | return false; |
2224 | 0 | } |
2225 | 0 | } |
2226 | 0 | } else { |
2227 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'additionalDisplayItems' member of PaymentDetailsModifier"); |
2228 | 0 | return false; |
2229 | 0 | } |
2230 | 0 | mIsAnyMemberPresent = true; |
2231 | 0 | } |
2232 | 0 |
|
2233 | 0 | if (!isNull) { |
2234 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) { |
2235 | 0 | return false; |
2236 | 0 | } |
2237 | 0 | } |
2238 | 0 | if (!isNull && !temp->isUndefined()) { |
2239 | 0 | mData.Construct(); |
2240 | 0 | if (temp.ref().isObject()) { |
2241 | 0 | #ifdef __clang__ |
2242 | 0 | #pragma clang diagnostic push |
2243 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
2244 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
2245 | 0 | #endif // __clang__ |
2246 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
2247 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'data' member of PaymentDetailsModifier"); |
2248 | 0 | return false; |
2249 | 0 | } |
2250 | 0 | #ifdef __clang__ |
2251 | 0 | #pragma clang diagnostic pop |
2252 | 0 | #endif // __clang__ |
2253 | 0 | (mData.Value()) = &temp.ref().toObject(); |
2254 | 0 | } else { |
2255 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'data' member of PaymentDetailsModifier"); |
2256 | 0 | return false; |
2257 | 0 | } |
2258 | 0 | mIsAnyMemberPresent = true; |
2259 | 0 | } |
2260 | 0 |
|
2261 | 0 | if (!isNull) { |
2262 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->supportedMethods_id, temp.ptr())) { |
2263 | 0 | return false; |
2264 | 0 | } |
2265 | 0 | } |
2266 | 0 | if (!isNull && !temp->isUndefined()) { |
2267 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mSupportedMethods)) { |
2268 | 0 | return false; |
2269 | 0 | } |
2270 | 0 | mIsAnyMemberPresent = true; |
2271 | 0 | } else if (cx) { |
2272 | 0 | // Don't error out if we have no cx. In that |
2273 | 0 | // situation the caller is default-constructing us and we'll |
2274 | 0 | // just assume they know what they're doing. |
2275 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
2276 | 0 | "'supportedMethods' member of PaymentDetailsModifier"); |
2277 | 0 | } |
2278 | 0 | |
2279 | 0 | if (!isNull) { |
2280 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->total_id, temp.ptr())) { |
2281 | 0 | return false; |
2282 | 0 | } |
2283 | 0 | } |
2284 | 0 | if (!mTotal.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'total' member of PaymentDetailsModifier", passedToJSImpl)) { |
2285 | 0 | return false; |
2286 | 0 | } |
2287 | 0 | mIsAnyMemberPresent = true; |
2288 | 0 | return true; |
2289 | 0 | } |
2290 | | |
2291 | | bool |
2292 | | PaymentDetailsModifier::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
2293 | 0 | { |
2294 | 0 | PaymentDetailsModifierAtoms* atomsCache = GetAtomCache<PaymentDetailsModifierAtoms>(cx); |
2295 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2296 | 0 | return false; |
2297 | 0 | } |
2298 | 0 | |
2299 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
2300 | 0 | if (!obj) { |
2301 | 0 | return false; |
2302 | 0 | } |
2303 | 0 | rval.set(JS::ObjectValue(*obj)); |
2304 | 0 |
|
2305 | 0 | if (mAdditionalDisplayItems.WasPassed()) { |
2306 | 0 | do { |
2307 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2308 | 0 | JS::Rooted<JS::Value> temp(cx); |
2309 | 0 | Sequence<PaymentItem> const & currentValue = mAdditionalDisplayItems.InternalValue(); |
2310 | 0 |
|
2311 | 0 | uint32_t length = currentValue.Length(); |
2312 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
2313 | 0 | if (!returnArray) { |
2314 | 0 | return false; |
2315 | 0 | } |
2316 | 0 | // Scope for 'tmp' |
2317 | 0 | { |
2318 | 0 | JS::Rooted<JS::Value> tmp(cx); |
2319 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
2320 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
2321 | 0 | // are different ways to succeed at wrapping the object. |
2322 | 0 | do { |
2323 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
2324 | 0 | return false; |
2325 | 0 | } |
2326 | 0 | break; |
2327 | 0 | } while (false); |
2328 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
2329 | 0 | JSPROP_ENUMERATE)) { |
2330 | 0 | return false; |
2331 | 0 | } |
2332 | 0 | } |
2333 | 0 | } |
2334 | 0 | temp.setObject(*returnArray); |
2335 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->additionalDisplayItems_id, temp, JSPROP_ENUMERATE)) { |
2336 | 0 | return false; |
2337 | 0 | } |
2338 | 0 | break; |
2339 | 0 | } while(false); |
2340 | 0 | } |
2341 | 0 |
|
2342 | 0 | if (mData.WasPassed()) { |
2343 | 0 | do { |
2344 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2345 | 0 | JS::Rooted<JS::Value> temp(cx); |
2346 | 0 | JSObject* const & currentValue = mData.InternalValue(); |
2347 | 0 | JS::ExposeObjectToActiveJS(currentValue); |
2348 | 0 | temp.setObject(*currentValue); |
2349 | 0 | if (!MaybeWrapObjectValue(cx, &temp)) { |
2350 | 0 | return false; |
2351 | 0 | } |
2352 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) { |
2353 | 0 | return false; |
2354 | 0 | } |
2355 | 0 | break; |
2356 | 0 | } while(false); |
2357 | 0 | } |
2358 | 0 |
|
2359 | 0 | do { |
2360 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2361 | 0 | JS::Rooted<JS::Value> temp(cx); |
2362 | 0 | nsString const & currentValue = mSupportedMethods; |
2363 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
2364 | 0 | return false; |
2365 | 0 | } |
2366 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->supportedMethods_id, temp, JSPROP_ENUMERATE)) { |
2367 | 0 | return false; |
2368 | 0 | } |
2369 | 0 | break; |
2370 | 0 | } while(false); |
2371 | 0 |
|
2372 | 0 | do { |
2373 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2374 | 0 | JS::Rooted<JS::Value> temp(cx); |
2375 | 0 | PaymentItem const & currentValue = mTotal; |
2376 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
2377 | 0 | return false; |
2378 | 0 | } |
2379 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->total_id, temp, JSPROP_ENUMERATE)) { |
2380 | 0 | return false; |
2381 | 0 | } |
2382 | 0 | break; |
2383 | 0 | } while(false); |
2384 | 0 |
|
2385 | 0 | return true; |
2386 | 0 | } |
2387 | | |
2388 | | void |
2389 | | PaymentDetailsModifier::TraceDictionary(JSTracer* trc) |
2390 | 0 | { |
2391 | 0 | if (mData.WasPassed()) { |
2392 | 0 | JS::UnsafeTraceRoot(trc, &mData.Value(), "PaymentDetailsModifier.mData"); |
2393 | 0 | } |
2394 | 0 | } |
2395 | | |
2396 | | namespace binding_detail { |
2397 | | } // namespace binding_detail |
2398 | | |
2399 | | |
2400 | | |
2401 | | PaymentDetailsBase::PaymentDetailsBase() |
2402 | 0 | { |
2403 | 0 | // Safe to pass a null context if we pass a null value |
2404 | 0 | Init(nullptr, JS::NullHandleValue); |
2405 | 0 | } |
2406 | | |
2407 | | |
2408 | | bool |
2409 | | PaymentDetailsBase::InitIds(JSContext* cx, PaymentDetailsBaseAtoms* atomsCache) |
2410 | 0 | { |
2411 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
2412 | 0 |
|
2413 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
2414 | 0 | // uninitialized. |
2415 | 0 | if (!atomsCache->shippingOptions_id.init(cx, "shippingOptions") || |
2416 | 0 | !atomsCache->modifiers_id.init(cx, "modifiers") || |
2417 | 0 | !atomsCache->displayItems_id.init(cx, "displayItems")) { |
2418 | 0 | return false; |
2419 | 0 | } |
2420 | 0 | return true; |
2421 | 0 | } |
2422 | | |
2423 | | bool |
2424 | | PaymentDetailsBase::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
2425 | 0 | { |
2426 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
2427 | 0 | // Since in that case we will not have to do any property gets |
2428 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
2429 | 0 | // checkers by static analysis tools |
2430 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
2431 | 0 | PaymentDetailsBaseAtoms* atomsCache = nullptr; |
2432 | 0 | if (cx) { |
2433 | 0 | atomsCache = GetAtomCache<PaymentDetailsBaseAtoms>(cx); |
2434 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2435 | 0 | return false; |
2436 | 0 | } |
2437 | 0 | } |
2438 | 0 | |
2439 | 0 | if (!IsConvertibleToDictionary(val)) { |
2440 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
2441 | 0 | } |
2442 | 0 | |
2443 | 0 | bool isNull = val.isNullOrUndefined(); |
2444 | 0 | // We only need these if !isNull, in which case we have |cx|. |
2445 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
2446 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
2447 | 0 | if (!isNull) { |
2448 | 0 | MOZ_ASSERT(cx); |
2449 | 0 | object.emplace(cx, &val.toObject()); |
2450 | 0 | temp.emplace(cx); |
2451 | 0 | } |
2452 | 0 | if (!isNull) { |
2453 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->displayItems_id, temp.ptr())) { |
2454 | 0 | return false; |
2455 | 0 | } |
2456 | 0 | } |
2457 | 0 | if (!isNull && !temp->isUndefined()) { |
2458 | 0 | mDisplayItems.Construct(); |
2459 | 0 | if (temp.ref().isObject()) { |
2460 | 0 | JS::ForOfIterator iter(cx); |
2461 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
2462 | 0 | return false; |
2463 | 0 | } |
2464 | 0 | if (!iter.valueIsIterable()) { |
2465 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'displayItems' member of PaymentDetailsBase"); |
2466 | 0 | return false; |
2467 | 0 | } |
2468 | 0 | Sequence<PaymentItem> &arr = (mDisplayItems.Value()); |
2469 | 0 | JS::Rooted<JS::Value> temp(cx); |
2470 | 0 | while (true) { |
2471 | 0 | bool done; |
2472 | 0 | if (!iter.next(&temp, &done)) { |
2473 | 0 | return false; |
2474 | 0 | } |
2475 | 0 | if (done) { |
2476 | 0 | break; |
2477 | 0 | } |
2478 | 0 | PaymentItem* slotPtr = arr.AppendElement(mozilla::fallible); |
2479 | 0 | if (!slotPtr) { |
2480 | 0 | JS_ReportOutOfMemory(cx); |
2481 | 0 | return false; |
2482 | 0 | } |
2483 | 0 | PaymentItem& slot = *slotPtr; |
2484 | 0 | if (!slot.Init(cx, temp, "Element of 'displayItems' member of PaymentDetailsBase", passedToJSImpl)) { |
2485 | 0 | return false; |
2486 | 0 | } |
2487 | 0 | } |
2488 | 0 | } else { |
2489 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'displayItems' member of PaymentDetailsBase"); |
2490 | 0 | return false; |
2491 | 0 | } |
2492 | 0 | mIsAnyMemberPresent = true; |
2493 | 0 | } |
2494 | 0 |
|
2495 | 0 | if (!isNull) { |
2496 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->modifiers_id, temp.ptr())) { |
2497 | 0 | return false; |
2498 | 0 | } |
2499 | 0 | } |
2500 | 0 | if (!isNull && !temp->isUndefined()) { |
2501 | 0 | mModifiers.Construct(); |
2502 | 0 | if (temp.ref().isObject()) { |
2503 | 0 | JS::ForOfIterator iter(cx); |
2504 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
2505 | 0 | return false; |
2506 | 0 | } |
2507 | 0 | if (!iter.valueIsIterable()) { |
2508 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'modifiers' member of PaymentDetailsBase"); |
2509 | 0 | return false; |
2510 | 0 | } |
2511 | 0 | Sequence<PaymentDetailsModifier> &arr = (mModifiers.Value()); |
2512 | 0 | JS::Rooted<JS::Value> temp(cx); |
2513 | 0 | while (true) { |
2514 | 0 | bool done; |
2515 | 0 | if (!iter.next(&temp, &done)) { |
2516 | 0 | return false; |
2517 | 0 | } |
2518 | 0 | if (done) { |
2519 | 0 | break; |
2520 | 0 | } |
2521 | 0 | PaymentDetailsModifier* slotPtr = arr.AppendElement(mozilla::fallible); |
2522 | 0 | if (!slotPtr) { |
2523 | 0 | JS_ReportOutOfMemory(cx); |
2524 | 0 | return false; |
2525 | 0 | } |
2526 | 0 | PaymentDetailsModifier& slot = *slotPtr; |
2527 | 0 | if (!slot.Init(cx, temp, "Element of 'modifiers' member of PaymentDetailsBase", passedToJSImpl)) { |
2528 | 0 | return false; |
2529 | 0 | } |
2530 | 0 | } |
2531 | 0 | } else { |
2532 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'modifiers' member of PaymentDetailsBase"); |
2533 | 0 | return false; |
2534 | 0 | } |
2535 | 0 | mIsAnyMemberPresent = true; |
2536 | 0 | } |
2537 | 0 |
|
2538 | 0 | if (!isNull) { |
2539 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->shippingOptions_id, temp.ptr())) { |
2540 | 0 | return false; |
2541 | 0 | } |
2542 | 0 | } |
2543 | 0 | if (!isNull && !temp->isUndefined()) { |
2544 | 0 | mShippingOptions.Construct(); |
2545 | 0 | if (temp.ref().isObject()) { |
2546 | 0 | JS::ForOfIterator iter(cx); |
2547 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
2548 | 0 | return false; |
2549 | 0 | } |
2550 | 0 | if (!iter.valueIsIterable()) { |
2551 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'shippingOptions' member of PaymentDetailsBase"); |
2552 | 0 | return false; |
2553 | 0 | } |
2554 | 0 | Sequence<PaymentShippingOption> &arr = (mShippingOptions.Value()); |
2555 | 0 | JS::Rooted<JS::Value> temp(cx); |
2556 | 0 | while (true) { |
2557 | 0 | bool done; |
2558 | 0 | if (!iter.next(&temp, &done)) { |
2559 | 0 | return false; |
2560 | 0 | } |
2561 | 0 | if (done) { |
2562 | 0 | break; |
2563 | 0 | } |
2564 | 0 | PaymentShippingOption* slotPtr = arr.AppendElement(mozilla::fallible); |
2565 | 0 | if (!slotPtr) { |
2566 | 0 | JS_ReportOutOfMemory(cx); |
2567 | 0 | return false; |
2568 | 0 | } |
2569 | 0 | PaymentShippingOption& slot = *slotPtr; |
2570 | 0 | if (!slot.Init(cx, temp, "Element of 'shippingOptions' member of PaymentDetailsBase", passedToJSImpl)) { |
2571 | 0 | return false; |
2572 | 0 | } |
2573 | 0 | } |
2574 | 0 | } else { |
2575 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'shippingOptions' member of PaymentDetailsBase"); |
2576 | 0 | return false; |
2577 | 0 | } |
2578 | 0 | mIsAnyMemberPresent = true; |
2579 | 0 | } |
2580 | 0 | return true; |
2581 | 0 | } |
2582 | | |
2583 | | bool |
2584 | | PaymentDetailsBase::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
2585 | 0 | { |
2586 | 0 | PaymentDetailsBaseAtoms* atomsCache = GetAtomCache<PaymentDetailsBaseAtoms>(cx); |
2587 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2588 | 0 | return false; |
2589 | 0 | } |
2590 | 0 | |
2591 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
2592 | 0 | if (!obj) { |
2593 | 0 | return false; |
2594 | 0 | } |
2595 | 0 | rval.set(JS::ObjectValue(*obj)); |
2596 | 0 |
|
2597 | 0 | if (mDisplayItems.WasPassed()) { |
2598 | 0 | do { |
2599 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2600 | 0 | JS::Rooted<JS::Value> temp(cx); |
2601 | 0 | Sequence<PaymentItem> const & currentValue = mDisplayItems.InternalValue(); |
2602 | 0 |
|
2603 | 0 | uint32_t length = currentValue.Length(); |
2604 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
2605 | 0 | if (!returnArray) { |
2606 | 0 | return false; |
2607 | 0 | } |
2608 | 0 | // Scope for 'tmp' |
2609 | 0 | { |
2610 | 0 | JS::Rooted<JS::Value> tmp(cx); |
2611 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
2612 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
2613 | 0 | // are different ways to succeed at wrapping the object. |
2614 | 0 | do { |
2615 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
2616 | 0 | return false; |
2617 | 0 | } |
2618 | 0 | break; |
2619 | 0 | } while (false); |
2620 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
2621 | 0 | JSPROP_ENUMERATE)) { |
2622 | 0 | return false; |
2623 | 0 | } |
2624 | 0 | } |
2625 | 0 | } |
2626 | 0 | temp.setObject(*returnArray); |
2627 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->displayItems_id, temp, JSPROP_ENUMERATE)) { |
2628 | 0 | return false; |
2629 | 0 | } |
2630 | 0 | break; |
2631 | 0 | } while(false); |
2632 | 0 | } |
2633 | 0 |
|
2634 | 0 | if (mModifiers.WasPassed()) { |
2635 | 0 | do { |
2636 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2637 | 0 | JS::Rooted<JS::Value> temp(cx); |
2638 | 0 | Sequence<PaymentDetailsModifier> const & currentValue = mModifiers.InternalValue(); |
2639 | 0 |
|
2640 | 0 | uint32_t length = currentValue.Length(); |
2641 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
2642 | 0 | if (!returnArray) { |
2643 | 0 | return false; |
2644 | 0 | } |
2645 | 0 | // Scope for 'tmp' |
2646 | 0 | { |
2647 | 0 | JS::Rooted<JS::Value> tmp(cx); |
2648 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
2649 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
2650 | 0 | // are different ways to succeed at wrapping the object. |
2651 | 0 | do { |
2652 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
2653 | 0 | return false; |
2654 | 0 | } |
2655 | 0 | break; |
2656 | 0 | } while (false); |
2657 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
2658 | 0 | JSPROP_ENUMERATE)) { |
2659 | 0 | return false; |
2660 | 0 | } |
2661 | 0 | } |
2662 | 0 | } |
2663 | 0 | temp.setObject(*returnArray); |
2664 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->modifiers_id, temp, JSPROP_ENUMERATE)) { |
2665 | 0 | return false; |
2666 | 0 | } |
2667 | 0 | break; |
2668 | 0 | } while(false); |
2669 | 0 | } |
2670 | 0 |
|
2671 | 0 | if (mShippingOptions.WasPassed()) { |
2672 | 0 | do { |
2673 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2674 | 0 | JS::Rooted<JS::Value> temp(cx); |
2675 | 0 | Sequence<PaymentShippingOption> const & currentValue = mShippingOptions.InternalValue(); |
2676 | 0 |
|
2677 | 0 | uint32_t length = currentValue.Length(); |
2678 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
2679 | 0 | if (!returnArray) { |
2680 | 0 | return false; |
2681 | 0 | } |
2682 | 0 | // Scope for 'tmp' |
2683 | 0 | { |
2684 | 0 | JS::Rooted<JS::Value> tmp(cx); |
2685 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
2686 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
2687 | 0 | // are different ways to succeed at wrapping the object. |
2688 | 0 | do { |
2689 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
2690 | 0 | return false; |
2691 | 0 | } |
2692 | 0 | break; |
2693 | 0 | } while (false); |
2694 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
2695 | 0 | JSPROP_ENUMERATE)) { |
2696 | 0 | return false; |
2697 | 0 | } |
2698 | 0 | } |
2699 | 0 | } |
2700 | 0 | temp.setObject(*returnArray); |
2701 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->shippingOptions_id, temp, JSPROP_ENUMERATE)) { |
2702 | 0 | return false; |
2703 | 0 | } |
2704 | 0 | break; |
2705 | 0 | } while(false); |
2706 | 0 | } |
2707 | 0 |
|
2708 | 0 | return true; |
2709 | 0 | } |
2710 | | |
2711 | | void |
2712 | | PaymentDetailsBase::TraceDictionary(JSTracer* trc) |
2713 | 0 | { |
2714 | 0 | if (mModifiers.WasPassed()) { |
2715 | 0 | DoTraceSequence(trc, mModifiers.Value()); |
2716 | 0 | } |
2717 | 0 | } |
2718 | | |
2719 | | namespace binding_detail { |
2720 | | } // namespace binding_detail |
2721 | | |
2722 | | |
2723 | | |
2724 | | PaymentDetailsInit::PaymentDetailsInit() |
2725 | | : PaymentDetailsBase(FastDictionaryInitializer()), |
2726 | | mTotal(FastDictionaryInitializer()) |
2727 | 0 | { |
2728 | 0 | // Safe to pass a null context if we pass a null value |
2729 | 0 | Init(nullptr, JS::NullHandleValue); |
2730 | 0 | } |
2731 | | |
2732 | | |
2733 | | bool |
2734 | | PaymentDetailsInit::InitIds(JSContext* cx, PaymentDetailsInitAtoms* atomsCache) |
2735 | 0 | { |
2736 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
2737 | 0 |
|
2738 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
2739 | 0 | // uninitialized. |
2740 | 0 | if (!atomsCache->total_id.init(cx, "total") || |
2741 | 0 | !atomsCache->id_id.init(cx, "id")) { |
2742 | 0 | return false; |
2743 | 0 | } |
2744 | 0 | return true; |
2745 | 0 | } |
2746 | | |
2747 | | bool |
2748 | | PaymentDetailsInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
2749 | 0 | { |
2750 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
2751 | 0 | // Since in that case we will not have to do any property gets |
2752 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
2753 | 0 | // checkers by static analysis tools |
2754 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
2755 | 0 | PaymentDetailsInitAtoms* atomsCache = nullptr; |
2756 | 0 | if (cx) { |
2757 | 0 | atomsCache = GetAtomCache<PaymentDetailsInitAtoms>(cx); |
2758 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2759 | 0 | return false; |
2760 | 0 | } |
2761 | 0 | } |
2762 | 0 | |
2763 | 0 | // Per spec, we init the parent's members first |
2764 | 0 | if (!PaymentDetailsBase::Init(cx, val)) { |
2765 | 0 | return false; |
2766 | 0 | } |
2767 | 0 | |
2768 | 0 | bool isNull = val.isNullOrUndefined(); |
2769 | 0 | // We only need these if !isNull, in which case we have |cx|. |
2770 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
2771 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
2772 | 0 | if (!isNull) { |
2773 | 0 | MOZ_ASSERT(cx); |
2774 | 0 | object.emplace(cx, &val.toObject()); |
2775 | 0 | temp.emplace(cx); |
2776 | 0 | } |
2777 | 0 | if (!isNull) { |
2778 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->id_id, temp.ptr())) { |
2779 | 0 | return false; |
2780 | 0 | } |
2781 | 0 | } |
2782 | 0 | if (!isNull && !temp->isUndefined()) { |
2783 | 0 | mId.Construct(); |
2784 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mId.Value()))) { |
2785 | 0 | return false; |
2786 | 0 | } |
2787 | 0 | mIsAnyMemberPresent = true; |
2788 | 0 | } |
2789 | 0 |
|
2790 | 0 | if (!isNull) { |
2791 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->total_id, temp.ptr())) { |
2792 | 0 | return false; |
2793 | 0 | } |
2794 | 0 | } |
2795 | 0 | if (!isNull && !temp->isUndefined()) { |
2796 | 0 | if (!mTotal.Init(cx, temp.ref(), "'total' member of PaymentDetailsInit", passedToJSImpl)) { |
2797 | 0 | return false; |
2798 | 0 | } |
2799 | 0 | mIsAnyMemberPresent = true; |
2800 | 0 | } else if (cx) { |
2801 | 0 | // Don't error out if we have no cx. In that |
2802 | 0 | // situation the caller is default-constructing us and we'll |
2803 | 0 | // just assume they know what they're doing. |
2804 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
2805 | 0 | "'total' member of PaymentDetailsInit"); |
2806 | 0 | } |
2807 | 0 | return true; |
2808 | 0 | } |
2809 | | |
2810 | | bool |
2811 | | PaymentDetailsInit::Init(const nsAString& aJSON) |
2812 | 0 | { |
2813 | 0 | AutoJSAPI jsapi; |
2814 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
2815 | 0 | if (!cleanGlobal) { |
2816 | 0 | return false; |
2817 | 0 | } |
2818 | 0 | if (!jsapi.Init(cleanGlobal)) { |
2819 | 0 | return false; |
2820 | 0 | } |
2821 | 0 | JSContext* cx = jsapi.cx(); |
2822 | 0 | JS::Rooted<JS::Value> json(cx); |
2823 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
2824 | 0 | NS_ENSURE_TRUE(ok, false); |
2825 | 0 | return Init(cx, json); |
2826 | 0 | } |
2827 | | |
2828 | | bool |
2829 | | PaymentDetailsInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
2830 | 0 | { |
2831 | 0 | PaymentDetailsInitAtoms* atomsCache = GetAtomCache<PaymentDetailsInitAtoms>(cx); |
2832 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2833 | 0 | return false; |
2834 | 0 | } |
2835 | 0 | |
2836 | 0 | // Per spec, we define the parent's members first |
2837 | 0 | if (!PaymentDetailsBase::ToObjectInternal(cx, rval)) { |
2838 | 0 | return false; |
2839 | 0 | } |
2840 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
2841 | 0 |
|
2842 | 0 | if (mId.WasPassed()) { |
2843 | 0 | do { |
2844 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2845 | 0 | JS::Rooted<JS::Value> temp(cx); |
2846 | 0 | nsString const & currentValue = mId.InternalValue(); |
2847 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
2848 | 0 | return false; |
2849 | 0 | } |
2850 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) { |
2851 | 0 | return false; |
2852 | 0 | } |
2853 | 0 | break; |
2854 | 0 | } while(false); |
2855 | 0 | } |
2856 | 0 |
|
2857 | 0 | do { |
2858 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2859 | 0 | JS::Rooted<JS::Value> temp(cx); |
2860 | 0 | PaymentItem const & currentValue = mTotal; |
2861 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
2862 | 0 | return false; |
2863 | 0 | } |
2864 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->total_id, temp, JSPROP_ENUMERATE)) { |
2865 | 0 | return false; |
2866 | 0 | } |
2867 | 0 | break; |
2868 | 0 | } while(false); |
2869 | 0 |
|
2870 | 0 | return true; |
2871 | 0 | } |
2872 | | |
2873 | | bool |
2874 | | PaymentDetailsInit::ToJSON(nsAString& aJSON) const |
2875 | 0 | { |
2876 | 0 | AutoJSAPI jsapi; |
2877 | 0 | jsapi.Init(); |
2878 | 0 | JSContext *cx = jsapi.cx(); |
2879 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
2880 | 0 | // because we'll only be creating objects, in ways that have no |
2881 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
2882 | 0 | // which likewise guarantees no side-effects for the sorts of |
2883 | 0 | // things we will pass it. |
2884 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
2885 | 0 | JS::Rooted<JS::Value> val(cx); |
2886 | 0 | if (!ToObjectInternal(cx, &val)) { |
2887 | 0 | return false; |
2888 | 0 | } |
2889 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
2890 | 0 | return StringifyToJSON(cx, obj, aJSON); |
2891 | 0 | } |
2892 | | |
2893 | | void |
2894 | | PaymentDetailsInit::TraceDictionary(JSTracer* trc) |
2895 | 0 | { |
2896 | 0 | PaymentDetailsBase::TraceDictionary(trc); |
2897 | 0 | } |
2898 | | |
2899 | | namespace binding_detail { |
2900 | | } // namespace binding_detail |
2901 | | |
2902 | | |
2903 | | |
2904 | | PaymentDetailsUpdate::PaymentDetailsUpdate() |
2905 | | : PaymentDetailsBase(FastDictionaryInitializer()), |
2906 | | mPayerErrors(FastDictionaryInitializer()), |
2907 | | mShippingAddressErrors(FastDictionaryInitializer()), |
2908 | | mTotal(FastDictionaryInitializer()) |
2909 | 0 | { |
2910 | 0 | // Safe to pass a null context if we pass a null value |
2911 | 0 | Init(nullptr, JS::NullHandleValue); |
2912 | 0 | } |
2913 | | |
2914 | | |
2915 | | bool |
2916 | | PaymentDetailsUpdate::InitIds(JSContext* cx, PaymentDetailsUpdateAtoms* atomsCache) |
2917 | 0 | { |
2918 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
2919 | 0 |
|
2920 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
2921 | 0 | // uninitialized. |
2922 | 0 | if (!atomsCache->total_id.init(cx, "total") || |
2923 | 0 | !atomsCache->shippingAddressErrors_id.init(cx, "shippingAddressErrors") || |
2924 | 0 | !atomsCache->paymentMethodErrors_id.init(cx, "paymentMethodErrors") || |
2925 | 0 | !atomsCache->payerErrors_id.init(cx, "payerErrors") || |
2926 | 0 | !atomsCache->error_id.init(cx, "error")) { |
2927 | 0 | return false; |
2928 | 0 | } |
2929 | 0 | return true; |
2930 | 0 | } |
2931 | | |
2932 | | bool |
2933 | | PaymentDetailsUpdate::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
2934 | 0 | { |
2935 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
2936 | 0 | // Since in that case we will not have to do any property gets |
2937 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
2938 | 0 | // checkers by static analysis tools |
2939 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
2940 | 0 | PaymentDetailsUpdateAtoms* atomsCache = nullptr; |
2941 | 0 | if (cx) { |
2942 | 0 | atomsCache = GetAtomCache<PaymentDetailsUpdateAtoms>(cx); |
2943 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2944 | 0 | return false; |
2945 | 0 | } |
2946 | 0 | } |
2947 | 0 | |
2948 | 0 | // Per spec, we init the parent's members first |
2949 | 0 | if (!PaymentDetailsBase::Init(cx, val)) { |
2950 | 0 | return false; |
2951 | 0 | } |
2952 | 0 | |
2953 | 0 | bool isNull = val.isNullOrUndefined(); |
2954 | 0 | // We only need these if !isNull, in which case we have |cx|. |
2955 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
2956 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
2957 | 0 | if (!isNull) { |
2958 | 0 | MOZ_ASSERT(cx); |
2959 | 0 | object.emplace(cx, &val.toObject()); |
2960 | 0 | temp.emplace(cx); |
2961 | 0 | } |
2962 | 0 | if (!isNull) { |
2963 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->error_id, temp.ptr())) { |
2964 | 0 | return false; |
2965 | 0 | } |
2966 | 0 | } |
2967 | 0 | if (!isNull && !temp->isUndefined()) { |
2968 | 0 | mError.Construct(); |
2969 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mError.Value()))) { |
2970 | 0 | return false; |
2971 | 0 | } |
2972 | 0 | mIsAnyMemberPresent = true; |
2973 | 0 | } |
2974 | 0 |
|
2975 | 0 | if (!isNull) { |
2976 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->payerErrors_id, temp.ptr())) { |
2977 | 0 | return false; |
2978 | 0 | } |
2979 | 0 | } |
2980 | 0 | if (!mPayerErrors.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'payerErrors' member of PaymentDetailsUpdate", passedToJSImpl)) { |
2981 | 0 | return false; |
2982 | 0 | } |
2983 | 0 | mIsAnyMemberPresent = true; |
2984 | 0 |
|
2985 | 0 | if (!isNull) { |
2986 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->paymentMethodErrors_id, temp.ptr())) { |
2987 | 0 | return false; |
2988 | 0 | } |
2989 | 0 | } |
2990 | 0 | if (!isNull && !temp->isUndefined()) { |
2991 | 0 | mPaymentMethodErrors.Construct(); |
2992 | 0 | if (temp.ref().isObject()) { |
2993 | 0 | #ifdef __clang__ |
2994 | 0 | #pragma clang diagnostic push |
2995 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
2996 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
2997 | 0 | #endif // __clang__ |
2998 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
2999 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'paymentMethodErrors' member of PaymentDetailsUpdate"); |
3000 | 0 | return false; |
3001 | 0 | } |
3002 | 0 | #ifdef __clang__ |
3003 | 0 | #pragma clang diagnostic pop |
3004 | 0 | #endif // __clang__ |
3005 | 0 | (mPaymentMethodErrors.Value()) = &temp.ref().toObject(); |
3006 | 0 | } else { |
3007 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'paymentMethodErrors' member of PaymentDetailsUpdate"); |
3008 | 0 | return false; |
3009 | 0 | } |
3010 | 0 | mIsAnyMemberPresent = true; |
3011 | 0 | } |
3012 | 0 |
|
3013 | 0 | if (!isNull) { |
3014 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->shippingAddressErrors_id, temp.ptr())) { |
3015 | 0 | return false; |
3016 | 0 | } |
3017 | 0 | } |
3018 | 0 | if (!mShippingAddressErrors.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'shippingAddressErrors' member of PaymentDetailsUpdate", passedToJSImpl)) { |
3019 | 0 | return false; |
3020 | 0 | } |
3021 | 0 | mIsAnyMemberPresent = true; |
3022 | 0 |
|
3023 | 0 | if (!isNull) { |
3024 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->total_id, temp.ptr())) { |
3025 | 0 | return false; |
3026 | 0 | } |
3027 | 0 | } |
3028 | 0 | if (!mTotal.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'total' member of PaymentDetailsUpdate", passedToJSImpl)) { |
3029 | 0 | return false; |
3030 | 0 | } |
3031 | 0 | mIsAnyMemberPresent = true; |
3032 | 0 | return true; |
3033 | 0 | } |
3034 | | |
3035 | | bool |
3036 | | PaymentDetailsUpdate::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
3037 | 0 | { |
3038 | 0 | PaymentDetailsUpdateAtoms* atomsCache = GetAtomCache<PaymentDetailsUpdateAtoms>(cx); |
3039 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
3040 | 0 | return false; |
3041 | 0 | } |
3042 | 0 | |
3043 | 0 | // Per spec, we define the parent's members first |
3044 | 0 | if (!PaymentDetailsBase::ToObjectInternal(cx, rval)) { |
3045 | 0 | return false; |
3046 | 0 | } |
3047 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
3048 | 0 |
|
3049 | 0 | if (mError.WasPassed()) { |
3050 | 0 | do { |
3051 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3052 | 0 | JS::Rooted<JS::Value> temp(cx); |
3053 | 0 | nsString const & currentValue = mError.InternalValue(); |
3054 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
3055 | 0 | return false; |
3056 | 0 | } |
3057 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->error_id, temp, JSPROP_ENUMERATE)) { |
3058 | 0 | return false; |
3059 | 0 | } |
3060 | 0 | break; |
3061 | 0 | } while(false); |
3062 | 0 | } |
3063 | 0 |
|
3064 | 0 | do { |
3065 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3066 | 0 | JS::Rooted<JS::Value> temp(cx); |
3067 | 0 | PayerErrorFields const & currentValue = mPayerErrors; |
3068 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
3069 | 0 | return false; |
3070 | 0 | } |
3071 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->payerErrors_id, temp, JSPROP_ENUMERATE)) { |
3072 | 0 | return false; |
3073 | 0 | } |
3074 | 0 | break; |
3075 | 0 | } while(false); |
3076 | 0 |
|
3077 | 0 | if (mPaymentMethodErrors.WasPassed()) { |
3078 | 0 | do { |
3079 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3080 | 0 | JS::Rooted<JS::Value> temp(cx); |
3081 | 0 | JSObject* const & currentValue = mPaymentMethodErrors.InternalValue(); |
3082 | 0 | JS::ExposeObjectToActiveJS(currentValue); |
3083 | 0 | temp.setObject(*currentValue); |
3084 | 0 | if (!MaybeWrapObjectValue(cx, &temp)) { |
3085 | 0 | return false; |
3086 | 0 | } |
3087 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->paymentMethodErrors_id, temp, JSPROP_ENUMERATE)) { |
3088 | 0 | return false; |
3089 | 0 | } |
3090 | 0 | break; |
3091 | 0 | } while(false); |
3092 | 0 | } |
3093 | 0 |
|
3094 | 0 | do { |
3095 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3096 | 0 | JS::Rooted<JS::Value> temp(cx); |
3097 | 0 | AddressErrors const & currentValue = mShippingAddressErrors; |
3098 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
3099 | 0 | return false; |
3100 | 0 | } |
3101 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->shippingAddressErrors_id, temp, JSPROP_ENUMERATE)) { |
3102 | 0 | return false; |
3103 | 0 | } |
3104 | 0 | break; |
3105 | 0 | } while(false); |
3106 | 0 |
|
3107 | 0 | do { |
3108 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3109 | 0 | JS::Rooted<JS::Value> temp(cx); |
3110 | 0 | PaymentItem const & currentValue = mTotal; |
3111 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
3112 | 0 | return false; |
3113 | 0 | } |
3114 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->total_id, temp, JSPROP_ENUMERATE)) { |
3115 | 0 | return false; |
3116 | 0 | } |
3117 | 0 | break; |
3118 | 0 | } while(false); |
3119 | 0 |
|
3120 | 0 | return true; |
3121 | 0 | } |
3122 | | |
3123 | | void |
3124 | | PaymentDetailsUpdate::TraceDictionary(JSTracer* trc) |
3125 | 0 | { |
3126 | 0 | PaymentDetailsBase::TraceDictionary(trc); |
3127 | 0 | if (mPaymentMethodErrors.WasPassed()) { |
3128 | 0 | JS::UnsafeTraceRoot(trc, &mPaymentMethodErrors.Value(), "PaymentDetailsUpdate.mPaymentMethodErrors"); |
3129 | 0 | } |
3130 | 0 | } |
3131 | | |
3132 | | namespace binding_detail { |
3133 | | } // namespace binding_detail |
3134 | | |
3135 | | |
3136 | | namespace PaymentRequest_Binding { |
3137 | | |
3138 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
3139 | | "Can't inherit from an interface with a different ownership model."); |
3140 | | |
3141 | | MOZ_CAN_RUN_SCRIPT static bool |
3142 | | show(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, const JSJitMethodCallArgs& args) |
3143 | 0 | { |
3144 | 0 | AUTO_PROFILER_LABEL_FAST("PaymentRequest.show", DOM, cx); |
3145 | 0 |
|
3146 | 0 | Optional<OwningNonNull<Promise>> arg0; |
3147 | 0 | if (args.hasDefined(0)) { |
3148 | 0 | arg0.Construct(); |
3149 | 0 | { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm, |
3150 | 0 | // etc. |
3151 | 0 |
|
3152 | 0 | JS::Rooted<JSObject*> globalObj(cx); |
3153 | 0 | globalObj = JS::CurrentGlobalOrNull(cx); |
3154 | 0 | JSAutoRealm ar(cx, globalObj); |
3155 | 0 | GlobalObject promiseGlobal(cx, globalObj); |
3156 | 0 | if (promiseGlobal.Failed()) { |
3157 | 0 | return false; |
3158 | 0 | } |
3159 | 0 | |
3160 | 0 | JS::Rooted<JS::Value> valueToResolve(cx, args[0]); |
3161 | 0 | if (!JS_WrapValue(cx, &valueToResolve)) { |
3162 | 0 | return false; |
3163 | 0 | } |
3164 | 0 | binding_detail::FastErrorResult promiseRv; |
3165 | 0 | nsCOMPtr<nsIGlobalObject> global = |
3166 | 0 | do_QueryInterface(promiseGlobal.GetAsSupports()); |
3167 | 0 | if (!global) { |
3168 | 0 | promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED); |
3169 | 0 | MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx)); |
3170 | 0 | return false; |
3171 | 0 | } |
3172 | 0 | arg0.Value() = Promise::Resolve(global, cx, valueToResolve, |
3173 | 0 | promiseRv); |
3174 | 0 | if (promiseRv.MaybeSetPendingException(cx)) { |
3175 | 0 | return false; |
3176 | 0 | } |
3177 | 0 | } |
3178 | 0 | } |
3179 | 0 | FastErrorResult rv; |
3180 | 0 | auto result(StrongOrRawPtr<Promise>(self->Show(NonNullHelper(Constify(arg0)), rv))); |
3181 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3182 | 0 | return false; |
3183 | 0 | } |
3184 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3185 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
3186 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
3187 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
3188 | 0 | return false; |
3189 | 0 | } |
3190 | 0 | return true; |
3191 | 0 | } |
3192 | | |
3193 | | MOZ_CAN_RUN_SCRIPT static bool |
3194 | | show_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, const JSJitMethodCallArgs& args) |
3195 | 0 | { |
3196 | 0 | bool ok = show(cx, obj, self, args); |
3197 | 0 | if (ok) { |
3198 | 0 | return true; |
3199 | 0 | } |
3200 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
3201 | 0 | } |
3202 | | |
3203 | | static const JSJitInfo show_methodinfo = { |
3204 | | { (JSJitGetterOp)show_promiseWrapper }, |
3205 | | { prototypes::id::PaymentRequest }, |
3206 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3207 | | JSJitInfo::Method, |
3208 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3209 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
3210 | | false, /* isInfallible. False in setters. */ |
3211 | | false, /* isMovable. Not relevant for setters. */ |
3212 | | false, /* isEliminatable. Not relevant for setters. */ |
3213 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3214 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3215 | | false, /* isTypedMethod. Only relevant for methods. */ |
3216 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3217 | | }; |
3218 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3219 | | static_assert(0 < 1, "There is no slot for us"); |
3220 | | |
3221 | | MOZ_CAN_RUN_SCRIPT static bool |
3222 | | abort(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, const JSJitMethodCallArgs& args) |
3223 | 0 | { |
3224 | 0 | AUTO_PROFILER_LABEL_FAST("PaymentRequest.abort", DOM, cx); |
3225 | 0 |
|
3226 | 0 | FastErrorResult rv; |
3227 | 0 | auto result(StrongOrRawPtr<Promise>(self->Abort(rv))); |
3228 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3229 | 0 | return false; |
3230 | 0 | } |
3231 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3232 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
3233 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
3234 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
3235 | 0 | return false; |
3236 | 0 | } |
3237 | 0 | return true; |
3238 | 0 | } |
3239 | | |
3240 | | MOZ_CAN_RUN_SCRIPT static bool |
3241 | | abort_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, const JSJitMethodCallArgs& args) |
3242 | 0 | { |
3243 | 0 | bool ok = abort(cx, obj, self, args); |
3244 | 0 | if (ok) { |
3245 | 0 | return true; |
3246 | 0 | } |
3247 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
3248 | 0 | } |
3249 | | |
3250 | | static const JSJitInfo abort_methodinfo = { |
3251 | | { (JSJitGetterOp)abort_promiseWrapper }, |
3252 | | { prototypes::id::PaymentRequest }, |
3253 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3254 | | JSJitInfo::Method, |
3255 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3256 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
3257 | | false, /* isInfallible. False in setters. */ |
3258 | | false, /* isMovable. Not relevant for setters. */ |
3259 | | false, /* isEliminatable. Not relevant for setters. */ |
3260 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3261 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3262 | | false, /* isTypedMethod. Only relevant for methods. */ |
3263 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3264 | | }; |
3265 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3266 | | static_assert(0 < 1, "There is no slot for us"); |
3267 | | |
3268 | | MOZ_CAN_RUN_SCRIPT static bool |
3269 | | canMakePayment(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, const JSJitMethodCallArgs& args) |
3270 | 0 | { |
3271 | 0 | AUTO_PROFILER_LABEL_FAST("PaymentRequest.canMakePayment", DOM, cx); |
3272 | 0 |
|
3273 | 0 | FastErrorResult rv; |
3274 | 0 | auto result(StrongOrRawPtr<Promise>(self->CanMakePayment(rv))); |
3275 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3276 | 0 | return false; |
3277 | 0 | } |
3278 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3279 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
3280 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
3281 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
3282 | 0 | return false; |
3283 | 0 | } |
3284 | 0 | return true; |
3285 | 0 | } |
3286 | | |
3287 | | MOZ_CAN_RUN_SCRIPT static bool |
3288 | | canMakePayment_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, const JSJitMethodCallArgs& args) |
3289 | 0 | { |
3290 | 0 | bool ok = canMakePayment(cx, obj, self, args); |
3291 | 0 | if (ok) { |
3292 | 0 | return true; |
3293 | 0 | } |
3294 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
3295 | 0 | } |
3296 | | |
3297 | | static const JSJitInfo canMakePayment_methodinfo = { |
3298 | | { (JSJitGetterOp)canMakePayment_promiseWrapper }, |
3299 | | { prototypes::id::PaymentRequest }, |
3300 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3301 | | JSJitInfo::Method, |
3302 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3303 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
3304 | | false, /* isInfallible. False in setters. */ |
3305 | | false, /* isMovable. Not relevant for setters. */ |
3306 | | false, /* isEliminatable. Not relevant for setters. */ |
3307 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3308 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3309 | | false, /* isTypedMethod. Only relevant for methods. */ |
3310 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3311 | | }; |
3312 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3313 | | static_assert(0 < 1, "There is no slot for us"); |
3314 | | |
3315 | | MOZ_CAN_RUN_SCRIPT static bool |
3316 | | get_id(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitGetterCallArgs args) |
3317 | 0 | { |
3318 | 0 | AUTO_PROFILER_LABEL_FAST("get PaymentRequest.id", DOM, cx); |
3319 | 0 |
|
3320 | 0 | DOMString result; |
3321 | 0 | self->GetId(result); |
3322 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3323 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
3324 | 0 | return false; |
3325 | 0 | } |
3326 | 0 | return true; |
3327 | 0 | } |
3328 | | |
3329 | | static const JSJitInfo id_getterinfo = { |
3330 | | { (JSJitGetterOp)get_id }, |
3331 | | { prototypes::id::PaymentRequest }, |
3332 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3333 | | JSJitInfo::Getter, |
3334 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3335 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
3336 | | false, /* isInfallible. False in setters. */ |
3337 | | false, /* isMovable. Not relevant for setters. */ |
3338 | | false, /* isEliminatable. Not relevant for setters. */ |
3339 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3340 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3341 | | false, /* isTypedMethod. Only relevant for methods. */ |
3342 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3343 | | }; |
3344 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3345 | | static_assert(0 < 1, "There is no slot for us"); |
3346 | | |
3347 | | MOZ_CAN_RUN_SCRIPT static bool |
3348 | | get_shippingAddress(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitGetterCallArgs args) |
3349 | 0 | { |
3350 | 0 | AUTO_PROFILER_LABEL_FAST("get PaymentRequest.shippingAddress", DOM, cx); |
3351 | 0 |
|
3352 | 0 | auto result(StrongOrRawPtr<mozilla::dom::PaymentAddress>(self->GetShippingAddress())); |
3353 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3354 | 0 | if (!result) { |
3355 | 0 | args.rval().setNull(); |
3356 | 0 | return true; |
3357 | 0 | } |
3358 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
3359 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
3360 | 0 | return false; |
3361 | 0 | } |
3362 | 0 | return true; |
3363 | 0 | } |
3364 | | |
3365 | | static const JSJitInfo shippingAddress_getterinfo = { |
3366 | | { (JSJitGetterOp)get_shippingAddress }, |
3367 | | { prototypes::id::PaymentRequest }, |
3368 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3369 | | JSJitInfo::Getter, |
3370 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3371 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
3372 | | false, /* isInfallible. False in setters. */ |
3373 | | false, /* isMovable. Not relevant for setters. */ |
3374 | | false, /* isEliminatable. Not relevant for setters. */ |
3375 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3376 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3377 | | false, /* isTypedMethod. Only relevant for methods. */ |
3378 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3379 | | }; |
3380 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3381 | | static_assert(0 < 1, "There is no slot for us"); |
3382 | | |
3383 | | MOZ_CAN_RUN_SCRIPT static bool |
3384 | | get_shippingOption(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitGetterCallArgs args) |
3385 | 0 | { |
3386 | 0 | AUTO_PROFILER_LABEL_FAST("get PaymentRequest.shippingOption", DOM, cx); |
3387 | 0 |
|
3388 | 0 | DOMString result; |
3389 | 0 | self->GetShippingOption(result); |
3390 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3391 | 0 | if (!xpc::StringToJsval(cx, result, args.rval())) { |
3392 | 0 | return false; |
3393 | 0 | } |
3394 | 0 | return true; |
3395 | 0 | } |
3396 | | |
3397 | | static const JSJitInfo shippingOption_getterinfo = { |
3398 | | { (JSJitGetterOp)get_shippingOption }, |
3399 | | { prototypes::id::PaymentRequest }, |
3400 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3401 | | JSJitInfo::Getter, |
3402 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3403 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
3404 | | false, /* isInfallible. False in setters. */ |
3405 | | false, /* isMovable. Not relevant for setters. */ |
3406 | | false, /* isEliminatable. Not relevant for setters. */ |
3407 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3408 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3409 | | false, /* isTypedMethod. Only relevant for methods. */ |
3410 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3411 | | }; |
3412 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3413 | | static_assert(0 < 1, "There is no slot for us"); |
3414 | | |
3415 | | MOZ_CAN_RUN_SCRIPT static bool |
3416 | | get_shippingType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitGetterCallArgs args) |
3417 | 0 | { |
3418 | 0 | AUTO_PROFILER_LABEL_FAST("get PaymentRequest.shippingType", DOM, cx); |
3419 | 0 |
|
3420 | 0 | Nullable<PaymentShippingType> result(self->GetShippingType()); |
3421 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3422 | 0 | if (result.IsNull()) { |
3423 | 0 | args.rval().setNull(); |
3424 | 0 | return true; |
3425 | 0 | } else { |
3426 | 0 | if (!ToJSValue(cx, result.Value(), args.rval())) { |
3427 | 0 | return false; |
3428 | 0 | } |
3429 | 0 | return true; |
3430 | 0 | } |
3431 | 0 | } |
3432 | | |
3433 | | static const JSJitInfo shippingType_getterinfo = { |
3434 | | { (JSJitGetterOp)get_shippingType }, |
3435 | | { prototypes::id::PaymentRequest }, |
3436 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3437 | | JSJitInfo::Getter, |
3438 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3439 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
3440 | | false, /* isInfallible. False in setters. */ |
3441 | | false, /* isMovable. Not relevant for setters. */ |
3442 | | false, /* isEliminatable. Not relevant for setters. */ |
3443 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3444 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3445 | | false, /* isTypedMethod. Only relevant for methods. */ |
3446 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3447 | | }; |
3448 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3449 | | static_assert(0 < 1, "There is no slot for us"); |
3450 | | |
3451 | | MOZ_CAN_RUN_SCRIPT static bool |
3452 | | get_onmerchantvalidation(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitGetterCallArgs args) |
3453 | 0 | { |
3454 | 0 | AUTO_PROFILER_LABEL_FAST("get PaymentRequest.onmerchantvalidation", DOM, cx); |
3455 | 0 |
|
3456 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnmerchantvalidation()); |
3457 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3458 | 0 | if (result) { |
3459 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
3460 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
3461 | 0 | return false; |
3462 | 0 | } |
3463 | 0 | return true; |
3464 | 0 | } else { |
3465 | 0 | args.rval().setNull(); |
3466 | 0 | return true; |
3467 | 0 | } |
3468 | 0 | } |
3469 | | |
3470 | | MOZ_CAN_RUN_SCRIPT static bool |
3471 | | set_onmerchantvalidation(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitSetterCallArgs args) |
3472 | 0 | { |
3473 | 0 | AUTO_PROFILER_LABEL_FAST("set PaymentRequest.onmerchantvalidation", DOM, cx); |
3474 | 0 |
|
3475 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
3476 | 0 | if (args[0].isObject()) { |
3477 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
3478 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
3479 | 0 | } |
3480 | 0 | } else { |
3481 | 0 | arg0 = nullptr; |
3482 | 0 | } |
3483 | 0 | self->SetOnmerchantvalidation(Constify(arg0)); |
3484 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3485 | 0 |
|
3486 | 0 | return true; |
3487 | 0 | } |
3488 | | |
3489 | | static const JSJitInfo onmerchantvalidation_getterinfo = { |
3490 | | { (JSJitGetterOp)get_onmerchantvalidation }, |
3491 | | { prototypes::id::PaymentRequest }, |
3492 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3493 | | JSJitInfo::Getter, |
3494 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3495 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
3496 | | false, /* isInfallible. False in setters. */ |
3497 | | false, /* isMovable. Not relevant for setters. */ |
3498 | | false, /* isEliminatable. Not relevant for setters. */ |
3499 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3500 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3501 | | false, /* isTypedMethod. Only relevant for methods. */ |
3502 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3503 | | }; |
3504 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3505 | | static_assert(0 < 1, "There is no slot for us"); |
3506 | | static const JSJitInfo onmerchantvalidation_setterinfo = { |
3507 | | { (JSJitGetterOp)set_onmerchantvalidation }, |
3508 | | { prototypes::id::PaymentRequest }, |
3509 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3510 | | JSJitInfo::Setter, |
3511 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3512 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3513 | | false, /* isInfallible. False in setters. */ |
3514 | | false, /* isMovable. Not relevant for setters. */ |
3515 | | false, /* isEliminatable. Not relevant for setters. */ |
3516 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3517 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3518 | | false, /* isTypedMethod. Only relevant for methods. */ |
3519 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3520 | | }; |
3521 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3522 | | static_assert(0 < 1, "There is no slot for us"); |
3523 | | |
3524 | | MOZ_CAN_RUN_SCRIPT static bool |
3525 | | get_onshippingaddresschange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitGetterCallArgs args) |
3526 | 0 | { |
3527 | 0 | AUTO_PROFILER_LABEL_FAST("get PaymentRequest.onshippingaddresschange", DOM, cx); |
3528 | 0 |
|
3529 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnshippingaddresschange()); |
3530 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3531 | 0 | if (result) { |
3532 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
3533 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
3534 | 0 | return false; |
3535 | 0 | } |
3536 | 0 | return true; |
3537 | 0 | } else { |
3538 | 0 | args.rval().setNull(); |
3539 | 0 | return true; |
3540 | 0 | } |
3541 | 0 | } |
3542 | | |
3543 | | MOZ_CAN_RUN_SCRIPT static bool |
3544 | | set_onshippingaddresschange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitSetterCallArgs args) |
3545 | 0 | { |
3546 | 0 | AUTO_PROFILER_LABEL_FAST("set PaymentRequest.onshippingaddresschange", DOM, cx); |
3547 | 0 |
|
3548 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
3549 | 0 | if (args[0].isObject()) { |
3550 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
3551 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
3552 | 0 | } |
3553 | 0 | } else { |
3554 | 0 | arg0 = nullptr; |
3555 | 0 | } |
3556 | 0 | self->SetOnshippingaddresschange(Constify(arg0)); |
3557 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3558 | 0 |
|
3559 | 0 | return true; |
3560 | 0 | } |
3561 | | |
3562 | | static const JSJitInfo onshippingaddresschange_getterinfo = { |
3563 | | { (JSJitGetterOp)get_onshippingaddresschange }, |
3564 | | { prototypes::id::PaymentRequest }, |
3565 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3566 | | JSJitInfo::Getter, |
3567 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3568 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
3569 | | false, /* isInfallible. False in setters. */ |
3570 | | false, /* isMovable. Not relevant for setters. */ |
3571 | | false, /* isEliminatable. Not relevant for setters. */ |
3572 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3573 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3574 | | false, /* isTypedMethod. Only relevant for methods. */ |
3575 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3576 | | }; |
3577 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3578 | | static_assert(0 < 1, "There is no slot for us"); |
3579 | | static const JSJitInfo onshippingaddresschange_setterinfo = { |
3580 | | { (JSJitGetterOp)set_onshippingaddresschange }, |
3581 | | { prototypes::id::PaymentRequest }, |
3582 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3583 | | JSJitInfo::Setter, |
3584 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3585 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3586 | | false, /* isInfallible. False in setters. */ |
3587 | | false, /* isMovable. Not relevant for setters. */ |
3588 | | false, /* isEliminatable. Not relevant for setters. */ |
3589 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3590 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3591 | | false, /* isTypedMethod. Only relevant for methods. */ |
3592 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3593 | | }; |
3594 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3595 | | static_assert(0 < 1, "There is no slot for us"); |
3596 | | |
3597 | | MOZ_CAN_RUN_SCRIPT static bool |
3598 | | get_onshippingoptionchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitGetterCallArgs args) |
3599 | 0 | { |
3600 | 0 | AUTO_PROFILER_LABEL_FAST("get PaymentRequest.onshippingoptionchange", DOM, cx); |
3601 | 0 |
|
3602 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnshippingoptionchange()); |
3603 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3604 | 0 | if (result) { |
3605 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
3606 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
3607 | 0 | return false; |
3608 | 0 | } |
3609 | 0 | return true; |
3610 | 0 | } else { |
3611 | 0 | args.rval().setNull(); |
3612 | 0 | return true; |
3613 | 0 | } |
3614 | 0 | } |
3615 | | |
3616 | | MOZ_CAN_RUN_SCRIPT static bool |
3617 | | set_onshippingoptionchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitSetterCallArgs args) |
3618 | 0 | { |
3619 | 0 | AUTO_PROFILER_LABEL_FAST("set PaymentRequest.onshippingoptionchange", DOM, cx); |
3620 | 0 |
|
3621 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
3622 | 0 | if (args[0].isObject()) { |
3623 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
3624 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
3625 | 0 | } |
3626 | 0 | } else { |
3627 | 0 | arg0 = nullptr; |
3628 | 0 | } |
3629 | 0 | self->SetOnshippingoptionchange(Constify(arg0)); |
3630 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3631 | 0 |
|
3632 | 0 | return true; |
3633 | 0 | } |
3634 | | |
3635 | | static const JSJitInfo onshippingoptionchange_getterinfo = { |
3636 | | { (JSJitGetterOp)get_onshippingoptionchange }, |
3637 | | { prototypes::id::PaymentRequest }, |
3638 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3639 | | JSJitInfo::Getter, |
3640 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3641 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
3642 | | false, /* isInfallible. False in setters. */ |
3643 | | false, /* isMovable. Not relevant for setters. */ |
3644 | | false, /* isEliminatable. Not relevant for setters. */ |
3645 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3646 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3647 | | false, /* isTypedMethod. Only relevant for methods. */ |
3648 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3649 | | }; |
3650 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3651 | | static_assert(0 < 1, "There is no slot for us"); |
3652 | | static const JSJitInfo onshippingoptionchange_setterinfo = { |
3653 | | { (JSJitGetterOp)set_onshippingoptionchange }, |
3654 | | { prototypes::id::PaymentRequest }, |
3655 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3656 | | JSJitInfo::Setter, |
3657 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3658 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3659 | | false, /* isInfallible. False in setters. */ |
3660 | | false, /* isMovable. Not relevant for setters. */ |
3661 | | false, /* isEliminatable. Not relevant for setters. */ |
3662 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3663 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3664 | | false, /* isTypedMethod. Only relevant for methods. */ |
3665 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3666 | | }; |
3667 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3668 | | static_assert(0 < 1, "There is no slot for us"); |
3669 | | |
3670 | | MOZ_CAN_RUN_SCRIPT static bool |
3671 | | get_onpaymentmethodchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitGetterCallArgs args) |
3672 | 0 | { |
3673 | 0 | AUTO_PROFILER_LABEL_FAST("get PaymentRequest.onpaymentmethodchange", DOM, cx); |
3674 | 0 |
|
3675 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnpaymentmethodchange()); |
3676 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3677 | 0 | if (result) { |
3678 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
3679 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
3680 | 0 | return false; |
3681 | 0 | } |
3682 | 0 | return true; |
3683 | 0 | } else { |
3684 | 0 | args.rval().setNull(); |
3685 | 0 | return true; |
3686 | 0 | } |
3687 | 0 | } |
3688 | | |
3689 | | MOZ_CAN_RUN_SCRIPT static bool |
3690 | | set_onpaymentmethodchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequest* self, JSJitSetterCallArgs args) |
3691 | 0 | { |
3692 | 0 | AUTO_PROFILER_LABEL_FAST("set PaymentRequest.onpaymentmethodchange", DOM, cx); |
3693 | 0 |
|
3694 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
3695 | 0 | if (args[0].isObject()) { |
3696 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
3697 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
3698 | 0 | } |
3699 | 0 | } else { |
3700 | 0 | arg0 = nullptr; |
3701 | 0 | } |
3702 | 0 | self->SetOnpaymentmethodchange(Constify(arg0)); |
3703 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3704 | 0 |
|
3705 | 0 | return true; |
3706 | 0 | } |
3707 | | |
3708 | | static const JSJitInfo onpaymentmethodchange_getterinfo = { |
3709 | | { (JSJitGetterOp)get_onpaymentmethodchange }, |
3710 | | { prototypes::id::PaymentRequest }, |
3711 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3712 | | JSJitInfo::Getter, |
3713 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3714 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
3715 | | false, /* isInfallible. False in setters. */ |
3716 | | false, /* isMovable. Not relevant for setters. */ |
3717 | | false, /* isEliminatable. Not relevant for setters. */ |
3718 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3719 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3720 | | false, /* isTypedMethod. Only relevant for methods. */ |
3721 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3722 | | }; |
3723 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3724 | | static_assert(0 < 1, "There is no slot for us"); |
3725 | | static const JSJitInfo onpaymentmethodchange_setterinfo = { |
3726 | | { (JSJitGetterOp)set_onpaymentmethodchange }, |
3727 | | { prototypes::id::PaymentRequest }, |
3728 | | { PrototypeTraits<prototypes::id::PaymentRequest>::Depth }, |
3729 | | JSJitInfo::Setter, |
3730 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3731 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3732 | | false, /* isInfallible. False in setters. */ |
3733 | | false, /* isMovable. Not relevant for setters. */ |
3734 | | false, /* isEliminatable. Not relevant for setters. */ |
3735 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3736 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3737 | | false, /* isTypedMethod. Only relevant for methods. */ |
3738 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3739 | | }; |
3740 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3741 | | static_assert(0 < 1, "There is no slot for us"); |
3742 | | |
3743 | | static bool |
3744 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
3745 | 0 | { |
3746 | 0 | mozilla::dom::PaymentRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PaymentRequest>(obj); |
3747 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
3748 | 0 | // obviously can't preserve if we're not initialized. |
3749 | 0 | if (self && self->GetWrapperPreserveColor()) { |
3750 | 0 | PreserveWrapper(self); |
3751 | 0 | } |
3752 | 0 | return true; |
3753 | 0 | } |
3754 | | |
3755 | | static void |
3756 | | _finalize(js::FreeOp* fop, JSObject* obj) |
3757 | 0 | { |
3758 | 0 | mozilla::dom::PaymentRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PaymentRequest>(obj); |
3759 | 0 | if (self) { |
3760 | 0 | ClearWrapper(self, self, obj); |
3761 | 0 | AddForDeferredFinalization<mozilla::dom::PaymentRequest>(self); |
3762 | 0 | } |
3763 | 0 | } |
3764 | | |
3765 | | static size_t |
3766 | | _objectMoved(JSObject* obj, JSObject* old) |
3767 | 0 | { |
3768 | 0 | mozilla::dom::PaymentRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PaymentRequest>(obj); |
3769 | 0 | if (self) { |
3770 | 0 | UpdateWrapper(self, self, obj, old); |
3771 | 0 | } |
3772 | 0 |
|
3773 | 0 | return 0; |
3774 | 0 | } |
3775 | | |
3776 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
3777 | | #if defined(__clang__) |
3778 | | #pragma clang diagnostic push |
3779 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
3780 | | #endif |
3781 | | static const JSFunctionSpec sMethods_specs[] = { |
3782 | | JS_FNSPEC("show", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&show_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
3783 | | JS_FNSPEC("abort", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&abort_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
3784 | | JS_FNSPEC("canMakePayment", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&canMakePayment_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
3785 | | JS_FS_END |
3786 | | }; |
3787 | | #if defined(__clang__) |
3788 | | #pragma clang diagnostic pop |
3789 | | #endif |
3790 | | |
3791 | | // Can't be const because the pref-enabled boolean needs to be writable |
3792 | | static PrefableDisablers sMethods_disablers0 = { |
3793 | | true, true, 0, nullptr |
3794 | | }; |
3795 | | |
3796 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
3797 | | { &sMethods_disablers0, &sMethods_specs[0] }, |
3798 | | { nullptr, nullptr } |
3799 | | }; |
3800 | | |
3801 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
3802 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
3803 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
3804 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
3805 | | |
3806 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
3807 | | #if defined(__clang__) |
3808 | | #pragma clang diagnostic push |
3809 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
3810 | | #endif |
3811 | | static const JSPropertySpec sAttributes_specs[] = { |
3812 | | { "id", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &id_getterinfo, nullptr, nullptr }, |
3813 | | { "shippingAddress", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &shippingAddress_getterinfo, nullptr, nullptr }, |
3814 | | { "shippingOption", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &shippingOption_getterinfo, nullptr, nullptr }, |
3815 | | { "shippingType", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &shippingType_getterinfo, nullptr, nullptr }, |
3816 | | { "onmerchantvalidation", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onmerchantvalidation_getterinfo, GenericSetter<NormalThisPolicy>, &onmerchantvalidation_setterinfo }, |
3817 | | { "onshippingaddresschange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onshippingaddresschange_getterinfo, GenericSetter<NormalThisPolicy>, &onshippingaddresschange_setterinfo }, |
3818 | | { "onshippingoptionchange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onshippingoptionchange_getterinfo, GenericSetter<NormalThisPolicy>, &onshippingoptionchange_setterinfo }, |
3819 | | { "onpaymentmethodchange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onpaymentmethodchange_getterinfo, GenericSetter<NormalThisPolicy>, &onpaymentmethodchange_setterinfo }, |
3820 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
3821 | | }; |
3822 | | #if defined(__clang__) |
3823 | | #pragma clang diagnostic pop |
3824 | | #endif |
3825 | | |
3826 | | // Can't be const because the pref-enabled boolean needs to be writable |
3827 | | static PrefableDisablers sAttributes_disablers0 = { |
3828 | | true, true, 0, nullptr |
3829 | | }; |
3830 | | |
3831 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
3832 | | { &sAttributes_disablers0, &sAttributes_specs[0] }, |
3833 | | { nullptr, nullptr } |
3834 | | }; |
3835 | | |
3836 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
3837 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
3838 | | static_assert(8 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
3839 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
3840 | | |
3841 | | |
3842 | | static uint16_t sNativeProperties_sortedPropertyIndices[11]; |
3843 | | static PropertyInfo sNativeProperties_propertyInfos[11]; |
3844 | | |
3845 | | static const NativePropertiesN<2> sNativeProperties = { |
3846 | | false, 0, |
3847 | | false, 0, |
3848 | | true, 0 /* sMethods */, |
3849 | | true, 1 /* sAttributes */, |
3850 | | false, 0, |
3851 | | false, 0, |
3852 | | false, 0, |
3853 | | -1, |
3854 | | 11, |
3855 | | sNativeProperties_sortedPropertyIndices, |
3856 | | { |
3857 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
3858 | | { sAttributes, &sNativeProperties_propertyInfos[3] } |
3859 | | } |
3860 | | }; |
3861 | | static_assert(11 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
3862 | | "We have a property info count that is oversized"); |
3863 | | |
3864 | | static bool |
3865 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
3866 | 0 | { |
3867 | 0 | AUTO_PROFILER_LABEL_FAST("PaymentRequest constructor", DOM, cx); |
3868 | 0 |
|
3869 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
3870 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
3871 | 0 | if (!args.isConstructing()) { |
3872 | 0 | // XXXbz wish I could get the name from the callee instead of |
3873 | 0 | // Adding more relocations |
3874 | 0 | return ThrowConstructorWithoutNew(cx, "PaymentRequest"); |
3875 | 0 | } |
3876 | 0 | |
3877 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
3878 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
3879 | 0 | return false; |
3880 | 0 | } |
3881 | 0 | |
3882 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
3883 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PaymentRequest"); |
3884 | 0 | } |
3885 | 0 | GlobalObject global(cx, obj); |
3886 | 0 | if (global.Failed()) { |
3887 | 0 | return false; |
3888 | 0 | } |
3889 | 0 | |
3890 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
3891 | 0 | binding_detail::AutoSequence<PaymentMethodData> arg0; |
3892 | 0 | SequenceRooter<PaymentMethodData> arg0_holder(cx, &arg0); |
3893 | 0 | if (args[0].isObject()) { |
3894 | 0 | JS::ForOfIterator iter(cx); |
3895 | 0 | if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) { |
3896 | 0 | return false; |
3897 | 0 | } |
3898 | 0 | if (!iter.valueIsIterable()) { |
3899 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of PaymentRequest.constructor"); |
3900 | 0 | return false; |
3901 | 0 | } |
3902 | 0 | binding_detail::AutoSequence<PaymentMethodData> &arr = arg0; |
3903 | 0 | JS::Rooted<JS::Value> temp(cx); |
3904 | 0 | while (true) { |
3905 | 0 | bool done; |
3906 | 0 | if (!iter.next(&temp, &done)) { |
3907 | 0 | return false; |
3908 | 0 | } |
3909 | 0 | if (done) { |
3910 | 0 | break; |
3911 | 0 | } |
3912 | 0 | PaymentMethodData* slotPtr = arr.AppendElement(mozilla::fallible); |
3913 | 0 | if (!slotPtr) { |
3914 | 0 | JS_ReportOutOfMemory(cx); |
3915 | 0 | return false; |
3916 | 0 | } |
3917 | 0 | PaymentMethodData& slot = *slotPtr; |
3918 | 0 | if (!slot.Init(cx, temp, "Element of argument 1 of PaymentRequest.constructor", false)) { |
3919 | 0 | return false; |
3920 | 0 | } |
3921 | 0 | } |
3922 | 0 | } else { |
3923 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of PaymentRequest.constructor"); |
3924 | 0 | return false; |
3925 | 0 | } |
3926 | 0 | RootedDictionary<binding_detail::FastPaymentDetailsInit> arg1(cx); |
3927 | 0 | if (!arg1.Init(cx, args[1], "Argument 2 of PaymentRequest.constructor", false)) { |
3928 | 0 | return false; |
3929 | 0 | } |
3930 | 0 | binding_detail::FastPaymentOptions arg2; |
3931 | 0 | if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue, "Argument 3 of PaymentRequest.constructor", false)) { |
3932 | 0 | return false; |
3933 | 0 | } |
3934 | 0 | Maybe<JSAutoRealm> ar; |
3935 | 0 | if (objIsXray) { |
3936 | 0 | obj = js::CheckedUnwrap(obj); |
3937 | 0 | if (!obj) { |
3938 | 0 | return false; |
3939 | 0 | } |
3940 | 0 | ar.emplace(cx, obj); |
3941 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
3942 | 0 | return false; |
3943 | 0 | } |
3944 | 0 | for (uint32_t indexName0 = 0; indexName0 < arg0.Length(); ++indexName0) { |
3945 | 0 | if (arg0[indexName0].mData.WasPassed()) { |
3946 | 0 | if (!JS_WrapObject(cx, JS::MutableHandle<JSObject*>::fromMarkedLocation(&arg0[indexName0].mData.Value()))) { |
3947 | 0 | return false; |
3948 | 0 | } |
3949 | 0 | } |
3950 | 0 | } |
3951 | 0 | if (arg1.mModifiers.WasPassed()) { |
3952 | 0 | for (uint32_t indexName0 = 0; indexName0 < arg1.mModifiers.Value().Length(); ++indexName0) { |
3953 | 0 | if (arg1.mModifiers.Value()[indexName0].mData.WasPassed()) { |
3954 | 0 | if (!JS_WrapObject(cx, JS::MutableHandle<JSObject*>::fromMarkedLocation(&arg1.mModifiers.Value()[indexName0].mData.Value()))) { |
3955 | 0 | return false; |
3956 | 0 | } |
3957 | 0 | } |
3958 | 0 | } |
3959 | 0 | } |
3960 | 0 | } |
3961 | 0 | FastErrorResult rv; |
3962 | 0 | auto result(StrongOrRawPtr<mozilla::dom::PaymentRequest>(mozilla::dom::PaymentRequest::Constructor(global, Constify(arg0), Constify(arg1), Constify(arg2), rv))); |
3963 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3964 | 0 | return false; |
3965 | 0 | } |
3966 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3967 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
3968 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
3969 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
3970 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
3971 | 0 | return false; |
3972 | 0 | } |
3973 | 0 | return true; |
3974 | 0 | } |
3975 | | |
3976 | | static const js::ClassOps sInterfaceObjectClassOps = { |
3977 | | nullptr, /* addProperty */ |
3978 | | nullptr, /* delProperty */ |
3979 | | nullptr, /* enumerate */ |
3980 | | nullptr, /* newEnumerate */ |
3981 | | nullptr, /* resolve */ |
3982 | | nullptr, /* mayResolve */ |
3983 | | nullptr, /* finalize */ |
3984 | | _constructor, /* call */ |
3985 | | nullptr, /* hasInstance */ |
3986 | | _constructor, /* construct */ |
3987 | | nullptr, /* trace */ |
3988 | | }; |
3989 | | |
3990 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
3991 | | { |
3992 | | "Function", |
3993 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
3994 | | &sInterfaceObjectClassOps, |
3995 | | JS_NULL_CLASS_SPEC, |
3996 | | JS_NULL_CLASS_EXT, |
3997 | | &sInterfaceObjectClassObjectOps |
3998 | | }, |
3999 | | eInterface, |
4000 | | true, |
4001 | | prototypes::id::PaymentRequest, |
4002 | | PrototypeTraits<prototypes::id::PaymentRequest>::Depth, |
4003 | | sNativePropertyHooks, |
4004 | | "function PaymentRequest() {\n [native code]\n}", |
4005 | | EventTarget_Binding::GetConstructorObject |
4006 | | }; |
4007 | | |
4008 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
4009 | | { |
4010 | | "PaymentRequestPrototype", |
4011 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
4012 | | JS_NULL_CLASS_OPS, |
4013 | | JS_NULL_CLASS_SPEC, |
4014 | | JS_NULL_CLASS_EXT, |
4015 | | JS_NULL_OBJECT_OPS |
4016 | | }, |
4017 | | eInterfacePrototype, |
4018 | | false, |
4019 | | prototypes::id::PaymentRequest, |
4020 | | PrototypeTraits<prototypes::id::PaymentRequest>::Depth, |
4021 | | sNativePropertyHooks, |
4022 | | "[object PaymentRequestPrototype]", |
4023 | | EventTarget_Binding::GetProtoObject |
4024 | | }; |
4025 | | |
4026 | | bool |
4027 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
4028 | 0 | { |
4029 | 0 | return mozilla::dom::PaymentRequest::PrefEnabled(aCx, aObj) && |
4030 | 0 | mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj); |
4031 | 0 | } |
4032 | | |
4033 | | static const js::ClassOps sClassOps = { |
4034 | | _addProperty, /* addProperty */ |
4035 | | nullptr, /* delProperty */ |
4036 | | nullptr, /* enumerate */ |
4037 | | nullptr, /* newEnumerate */ |
4038 | | nullptr, /* resolve */ |
4039 | | nullptr, /* mayResolve */ |
4040 | | _finalize, /* finalize */ |
4041 | | nullptr, /* call */ |
4042 | | nullptr, /* hasInstance */ |
4043 | | nullptr, /* construct */ |
4044 | | nullptr, /* trace */ |
4045 | | }; |
4046 | | |
4047 | | static const js::ClassExtension sClassExtension = { |
4048 | | nullptr, /* weakmapKeyDelegateOp */ |
4049 | | _objectMoved /* objectMovedOp */ |
4050 | | }; |
4051 | | |
4052 | | static const DOMJSClass sClass = { |
4053 | | { "PaymentRequest", |
4054 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
4055 | | &sClassOps, |
4056 | | JS_NULL_CLASS_SPEC, |
4057 | | &sClassExtension, |
4058 | | JS_NULL_OBJECT_OPS |
4059 | | }, |
4060 | | { prototypes::id::EventTarget, prototypes::id::PaymentRequest, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
4061 | | IsBaseOf<nsISupports, mozilla::dom::PaymentRequest >::value, |
4062 | | sNativePropertyHooks, |
4063 | | FindAssociatedGlobalForNative<mozilla::dom::PaymentRequest>::Get, |
4064 | | GetProtoObjectHandle, |
4065 | | GetCCParticipant<mozilla::dom::PaymentRequest>::Get() |
4066 | | }; |
4067 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
4068 | | "Must have the right minimal number of reserved slots."); |
4069 | | static_assert(1 >= 1, |
4070 | | "Must have enough reserved slots."); |
4071 | | |
4072 | | const JSClass* |
4073 | | GetJSClass() |
4074 | 0 | { |
4075 | 0 | return sClass.ToJSClass(); |
4076 | 0 | } |
4077 | | |
4078 | | bool |
4079 | | Wrap(JSContext* aCx, mozilla::dom::PaymentRequest* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
4080 | 0 | { |
4081 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::PaymentRequest>::value, |
4082 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
4083 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::PaymentRequest*>(aObject) == |
4084 | 0 | reinterpret_cast<mozilla::dom::PaymentRequest*>(aObject), |
4085 | 0 | "Multiple inheritance for mozilla::dom::PaymentRequest is broken."); |
4086 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
4087 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
4088 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
4089 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
4090 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
4091 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
4092 | 0 | "You should probably not be using Wrap() directly; use " |
4093 | 0 | "GetOrCreateDOMReflector instead"); |
4094 | 0 |
|
4095 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
4096 | 0 | "nsISupports must be on our primary inheritance chain"); |
4097 | 0 |
|
4098 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
4099 | 0 | if (!global) { |
4100 | 0 | return false; |
4101 | 0 | } |
4102 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
4103 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
4104 | 0 |
|
4105 | 0 | // That might have ended up wrapping us already, due to the wonders |
4106 | 0 | // of XBL. Check for that, and bail out as needed. |
4107 | 0 | aReflector.set(aCache->GetWrapper()); |
4108 | 0 | if (aReflector) { |
4109 | | #ifdef DEBUG |
4110 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
4111 | | #endif // DEBUG |
4112 | | return true; |
4113 | 0 | } |
4114 | 0 |
|
4115 | 0 | JSAutoRealm ar(aCx, global); |
4116 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
4117 | 0 | if (!canonicalProto) { |
4118 | 0 | return false; |
4119 | 0 | } |
4120 | 0 | JS::Rooted<JSObject*> proto(aCx); |
4121 | 0 | if (aGivenProto) { |
4122 | 0 | proto = aGivenProto; |
4123 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
4124 | 0 | // coming in, we changed compartments to that of "parent" so may need |
4125 | 0 | // to wrap the proto here. |
4126 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
4127 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
4128 | 0 | return false; |
4129 | 0 | } |
4130 | 0 | } |
4131 | 0 | } else { |
4132 | 0 | proto = canonicalProto; |
4133 | 0 | } |
4134 | 0 |
|
4135 | 0 | BindingJSObjectCreator<mozilla::dom::PaymentRequest> creator(aCx); |
4136 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
4137 | 0 | if (!aReflector) { |
4138 | 0 | return false; |
4139 | 0 | } |
4140 | 0 | |
4141 | 0 | aCache->SetWrapper(aReflector); |
4142 | 0 | creator.InitializationSucceeded(); |
4143 | 0 |
|
4144 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
4145 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
4146 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
4147 | 0 | // otherwise we won't be able to properly recreate it later, since |
4148 | 0 | // we won't know what proto to use. Note that we don't check |
4149 | 0 | // aGivenProto here, since it's entirely possible (and even |
4150 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
4151 | 0 | // same as canonicalProto. |
4152 | 0 | if (proto != canonicalProto) { |
4153 | 0 | PreserveWrapper(aObject); |
4154 | 0 | } |
4155 | 0 |
|
4156 | 0 | return true; |
4157 | 0 | } |
4158 | | |
4159 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
4160 | | nullptr, |
4161 | | nullptr, |
4162 | | nullptr, |
4163 | | { sNativeProperties.Upcast(), nullptr }, |
4164 | | prototypes::id::PaymentRequest, |
4165 | | constructors::id::PaymentRequest, |
4166 | | EventTarget_Binding::sNativePropertyHooks, |
4167 | | &DefaultXrayExpandoObjectClass |
4168 | | } }; |
4169 | | |
4170 | | void |
4171 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
4172 | 0 | { |
4173 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
4174 | 0 | if (!parentProto) { |
4175 | 0 | return; |
4176 | 0 | } |
4177 | 0 | |
4178 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
4179 | 0 | if (!constructorProto) { |
4180 | 0 | return; |
4181 | 0 | } |
4182 | 0 | |
4183 | 0 | static bool sIdsInited = false; |
4184 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
4185 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
4186 | 0 | return; |
4187 | 0 | } |
4188 | 0 | sIdsInited = true; |
4189 | 0 | } |
4190 | 0 |
|
4191 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PaymentRequest); |
4192 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PaymentRequest); |
4193 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
4194 | 0 | &sPrototypeClass.mBase, protoCache, |
4195 | 0 | nullptr, |
4196 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr, |
4197 | 0 | interfaceCache, |
4198 | 0 | sNativeProperties.Upcast(), |
4199 | 0 | nullptr, |
4200 | 0 | "PaymentRequest", aDefineOnGlobal, |
4201 | 0 | nullptr, |
4202 | 0 | false); |
4203 | 0 | } |
4204 | | |
4205 | | JSObject* |
4206 | | GetConstructorObject(JSContext* aCx) |
4207 | 0 | { |
4208 | 0 | return GetConstructorObjectHandle(aCx); |
4209 | 0 | } |
4210 | | |
4211 | | } // namespace PaymentRequest_Binding |
4212 | | |
4213 | | |
4214 | | |
4215 | | } // namespace dom |
4216 | | } // namespace mozilla |