Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM PaymentRequestUpdateEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "EventBinding.h"
5 : #include "PaymentRequestUpdateEventBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/NonRefcountedDOMObject.h"
11 : #include "mozilla/dom/PaymentRequest.h"
12 : #include "mozilla/dom/PaymentRequestUpdateEvent.h"
13 : #include "mozilla/dom/PrimitiveConversions.h"
14 : #include "mozilla/dom/Promise.h"
15 : #include "mozilla/dom/ScriptSettings.h"
16 : #include "mozilla/dom/SimpleGlobalObject.h"
17 : #include "mozilla/dom/ToJSValue.h"
18 : #include "mozilla/dom/XrayExpandoClass.h"
19 :
20 : namespace mozilla {
21 : namespace dom {
22 :
23 :
24 0 : PaymentDetailsUpdate::PaymentDetailsUpdate()
25 0 : : PaymentDetailsBase(FastDictionaryInitializer()),
26 0 : mTotal(FastDictionaryInitializer())
27 : {
28 : // Safe to pass a null context if we pass a null value
29 0 : Init(nullptr, JS::NullHandleValue);
30 0 : }
31 :
32 :
33 : bool
34 0 : PaymentDetailsUpdate::InitIds(JSContext* cx, PaymentDetailsUpdateAtoms* atomsCache)
35 : {
36 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
37 :
38 : // Initialize these in reverse order so that any failure leaves the first one
39 : // uninitialized.
40 0 : if (!atomsCache->total_id.init(cx, "total") ||
41 0 : !atomsCache->error_id.init(cx, "error")) {
42 0 : return false;
43 : }
44 0 : return true;
45 : }
46 :
47 : bool
48 0 : PaymentDetailsUpdate::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
49 : {
50 : // Passing a null JSContext is OK only if we're initing from null,
51 : // Since in that case we will not have to do any property gets
52 : // Also evaluate isNullOrUndefined in order to avoid false-positive
53 : // checkers by static analysis tools
54 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
55 0 : PaymentDetailsUpdateAtoms* atomsCache = nullptr;
56 0 : if (cx) {
57 0 : atomsCache = GetAtomCache<PaymentDetailsUpdateAtoms>(cx);
58 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
59 0 : return false;
60 : }
61 : }
62 :
63 : // Per spec, we init the parent's members first
64 0 : if (!PaymentDetailsBase::Init(cx, val)) {
65 0 : return false;
66 : }
67 :
68 0 : bool isNull = val.isNullOrUndefined();
69 : // We only need these if !isNull, in which case we have |cx|.
70 0 : Maybe<JS::Rooted<JSObject *> > object;
71 0 : Maybe<JS::Rooted<JS::Value> > temp;
72 0 : if (!isNull) {
73 0 : MOZ_ASSERT(cx);
74 0 : object.emplace(cx, &val.toObject());
75 0 : temp.emplace(cx);
76 : }
77 0 : if (!isNull) {
78 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->error_id, temp.ptr())) {
79 0 : return false;
80 : }
81 : }
82 0 : if (!isNull && !temp->isUndefined()) {
83 0 : mError.Construct();
84 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mError.Value()))) {
85 0 : return false;
86 : }
87 0 : mIsAnyMemberPresent = true;
88 : }
89 :
90 0 : if (!isNull) {
91 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->total_id, temp.ptr())) {
92 0 : return false;
93 : }
94 : }
95 0 : if (!mTotal.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'total' member of PaymentDetailsUpdate", passedToJSImpl)) {
96 0 : return false;
97 : }
98 0 : mIsAnyMemberPresent = true;
99 0 : return true;
100 : }
101 :
102 : bool
103 0 : PaymentDetailsUpdate::Init(const nsAString& aJSON)
104 : {
105 0 : AutoJSAPI jsapi;
106 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
107 0 : if (!cleanGlobal) {
108 0 : return false;
109 : }
110 0 : if (!jsapi.Init(cleanGlobal)) {
111 0 : return false;
112 : }
113 0 : JSContext* cx = jsapi.cx();
114 0 : JS::Rooted<JS::Value> json(cx);
115 0 : bool ok = ParseJSON(cx, aJSON, &json);
116 0 : NS_ENSURE_TRUE(ok, false);
117 0 : return Init(cx, json);
118 : }
119 :
120 : bool
121 0 : PaymentDetailsUpdate::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
122 : {
123 0 : PaymentDetailsUpdateAtoms* atomsCache = GetAtomCache<PaymentDetailsUpdateAtoms>(cx);
124 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
125 0 : return false;
126 : }
127 :
128 : // Per spec, we define the parent's members first
129 0 : if (!PaymentDetailsBase::ToObjectInternal(cx, rval)) {
130 0 : return false;
131 : }
132 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
133 :
134 0 : if (mError.WasPassed()) {
135 : do {
136 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
137 0 : JS::Rooted<JS::Value> temp(cx);
138 0 : nsString const & currentValue = mError.InternalValue();
139 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
140 0 : return false;
141 : }
142 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->error_id, temp, JSPROP_ENUMERATE)) {
143 0 : return false;
144 : }
145 0 : break;
146 : } while(0);
147 : }
148 :
149 : do {
150 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
151 0 : JS::Rooted<JS::Value> temp(cx);
152 0 : PaymentItem const & currentValue = mTotal;
153 0 : if (!currentValue.ToObjectInternal(cx, &temp)) {
154 0 : return false;
155 : }
156 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->total_id, temp, JSPROP_ENUMERATE)) {
157 0 : return false;
158 : }
159 0 : break;
160 : } while(0);
161 :
162 0 : return true;
163 : }
164 :
165 : bool
166 0 : PaymentDetailsUpdate::ToJSON(nsAString& aJSON) const
167 : {
168 0 : AutoJSAPI jsapi;
169 0 : jsapi.Init();
170 0 : JSContext *cx = jsapi.cx();
171 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
172 : // because we'll only be creating objects, in ways that have no
173 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
174 : // which likewise guarantees no side-effects for the sorts of
175 : // things we will pass it.
176 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
177 0 : JS::Rooted<JS::Value> val(cx);
178 0 : if (!ToObjectInternal(cx, &val)) {
179 0 : return false;
180 : }
181 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
182 0 : return StringifyToJSON(cx, obj, aJSON);
183 : }
184 :
185 : void
186 0 : PaymentDetailsUpdate::TraceDictionary(JSTracer* trc)
187 : {
188 0 : PaymentDetailsBase::TraceDictionary(trc);
189 0 : }
190 :
191 : namespace binding_detail {
192 : } // namespace binding_detail
193 :
194 :
195 :
196 0 : PaymentRequestUpdateEventInit::PaymentRequestUpdateEventInit()
197 0 : : EventInit(FastDictionaryInitializer())
198 : {
199 : // Safe to pass a null context if we pass a null value
200 0 : Init(nullptr, JS::NullHandleValue);
201 0 : }
202 :
203 :
204 :
205 : bool
206 0 : PaymentRequestUpdateEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
207 : {
208 : // Passing a null JSContext is OK only if we're initing from null,
209 : // Since in that case we will not have to do any property gets
210 : // Also evaluate isNullOrUndefined in order to avoid false-positive
211 : // checkers by static analysis tools
212 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
213 : // Per spec, we init the parent's members first
214 0 : if (!EventInit::Init(cx, val)) {
215 0 : return false;
216 : }
217 :
218 0 : return true;
219 : }
220 :
221 : bool
222 0 : PaymentRequestUpdateEventInit::Init(const nsAString& aJSON)
223 : {
224 0 : AutoJSAPI jsapi;
225 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
226 0 : if (!cleanGlobal) {
227 0 : return false;
228 : }
229 0 : if (!jsapi.Init(cleanGlobal)) {
230 0 : return false;
231 : }
232 0 : JSContext* cx = jsapi.cx();
233 0 : JS::Rooted<JS::Value> json(cx);
234 0 : bool ok = ParseJSON(cx, aJSON, &json);
235 0 : NS_ENSURE_TRUE(ok, false);
236 0 : return Init(cx, json);
237 : }
238 :
239 : bool
240 0 : PaymentRequestUpdateEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
241 : {
242 : // Per spec, we define the parent's members first
243 0 : if (!EventInit::ToObjectInternal(cx, rval)) {
244 0 : return false;
245 : }
246 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
247 :
248 :
249 0 : return true;
250 : }
251 :
252 : bool
253 0 : PaymentRequestUpdateEventInit::ToJSON(nsAString& aJSON) const
254 : {
255 0 : AutoJSAPI jsapi;
256 0 : jsapi.Init();
257 0 : JSContext *cx = jsapi.cx();
258 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
259 : // because we'll only be creating objects, in ways that have no
260 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
261 : // which likewise guarantees no side-effects for the sorts of
262 : // things we will pass it.
263 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
264 0 : JS::Rooted<JS::Value> val(cx);
265 0 : if (!ToObjectInternal(cx, &val)) {
266 0 : return false;
267 : }
268 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
269 0 : return StringifyToJSON(cx, obj, aJSON);
270 : }
271 :
272 : void
273 0 : PaymentRequestUpdateEventInit::TraceDictionary(JSTracer* trc)
274 : {
275 0 : EventInit::TraceDictionary(trc);
276 0 : }
277 :
278 : PaymentRequestUpdateEventInit&
279 0 : PaymentRequestUpdateEventInit::operator=(const PaymentRequestUpdateEventInit& aOther)
280 : {
281 0 : EventInit::operator=(aOther);
282 0 : return *this;
283 : }
284 :
285 : namespace binding_detail {
286 : } // namespace binding_detail
287 :
288 :
289 : namespace PaymentRequestUpdateEventBinding {
290 :
291 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
292 : "Can't inherit from an interface with a different ownership model.");
293 :
294 : static bool
295 0 : updateWith(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequestUpdateEvent* self, const JSJitMethodCallArgs& args)
296 : {
297 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
298 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PaymentRequestUpdateEvent.updateWith");
299 : }
300 0 : OwningNonNull<Promise> arg0;
301 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
302 : // etc.
303 :
304 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
305 0 : JSAutoCompartment ac(cx, globalObj);
306 0 : GlobalObject promiseGlobal(cx, globalObj);
307 0 : if (promiseGlobal.Failed()) {
308 0 : return false;
309 : }
310 :
311 0 : JS::Rooted<JS::Value> valueToResolve(cx, args[0]);
312 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
313 0 : return false;
314 : }
315 0 : binding_detail::FastErrorResult promiseRv;
316 : nsCOMPtr<nsIGlobalObject> global =
317 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
318 0 : if (!global) {
319 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
320 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
321 0 : return false;
322 : }
323 0 : arg0 = Promise::Resolve(global, cx, valueToResolve,
324 0 : promiseRv);
325 0 : if (promiseRv.MaybeSetPendingException(cx)) {
326 0 : return false;
327 : }
328 : }
329 0 : binding_detail::FastErrorResult rv;
330 0 : self->UpdateWith(NonNullHelper(arg0), rv);
331 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
332 0 : return false;
333 : }
334 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
335 0 : args.rval().setUndefined();
336 0 : return true;
337 : }
338 :
339 : static const JSJitInfo updateWith_methodinfo = {
340 : { (JSJitGetterOp)updateWith },
341 : { prototypes::id::PaymentRequestUpdateEvent },
342 : { PrototypeTraits<prototypes::id::PaymentRequestUpdateEvent>::Depth },
343 : JSJitInfo::Method,
344 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
345 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
346 : false, /* isInfallible. False in setters. */
347 : false, /* isMovable. Not relevant for setters. */
348 : false, /* isEliminatable. Not relevant for setters. */
349 : false, /* isAlwaysInSlot. Only relevant for getters. */
350 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
351 : false, /* isTypedMethod. Only relevant for methods. */
352 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
353 : };
354 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
355 : static_assert(0 < 1, "There is no slot for us");
356 :
357 : static bool
358 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentRequestUpdateEvent* self, JSJitGetterCallArgs args)
359 : {
360 0 : bool result(self->IsTrusted());
361 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
362 0 : args.rval().setBoolean(result);
363 0 : return true;
364 : }
365 :
366 : static const JSJitInfo isTrusted_getterinfo = {
367 : { (JSJitGetterOp)get_isTrusted },
368 : { prototypes::id::PaymentRequestUpdateEvent },
369 : { PrototypeTraits<prototypes::id::PaymentRequestUpdateEvent>::Depth },
370 : JSJitInfo::Getter,
371 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
372 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
373 : true, /* isInfallible. False in setters. */
374 : true, /* isMovable. Not relevant for setters. */
375 : true, /* isEliminatable. Not relevant for setters. */
376 : false, /* isAlwaysInSlot. Only relevant for getters. */
377 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
378 : false, /* isTypedMethod. Only relevant for methods. */
379 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
380 : };
381 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
382 : static_assert(0 < 1, "There is no slot for us");
383 :
384 : static bool
385 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
386 : {
387 0 : mozilla::dom::PaymentRequestUpdateEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PaymentRequestUpdateEvent>(obj);
388 : // We don't want to preserve if we don't have a wrapper, and we
389 : // obviously can't preserve if we're not initialized.
390 0 : if (self && self->GetWrapperPreserveColor()) {
391 0 : PreserveWrapper(self);
392 : }
393 0 : return true;
394 : }
395 :
396 : static void
397 0 : _finalize(js::FreeOp* fop, JSObject* obj)
398 : {
399 0 : mozilla::dom::PaymentRequestUpdateEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PaymentRequestUpdateEvent>(obj);
400 0 : if (self) {
401 0 : ClearWrapper(self, self, obj);
402 0 : AddForDeferredFinalization<mozilla::dom::PaymentRequestUpdateEvent>(self);
403 : }
404 0 : }
405 :
406 : static void
407 0 : _objectMoved(JSObject* obj, const JSObject* old)
408 : {
409 0 : mozilla::dom::PaymentRequestUpdateEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PaymentRequestUpdateEvent>(obj);
410 0 : if (self) {
411 0 : UpdateWrapper(self, self, obj, old);
412 : }
413 0 : }
414 :
415 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
416 : #if defined(__clang__)
417 : #pragma clang diagnostic push
418 : #pragma clang diagnostic ignored "-Wmissing-braces"
419 : #endif
420 : static const JSFunctionSpec sMethods_specs[] = {
421 : JS_FNSPEC("updateWith", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&updateWith_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
422 : JS_FS_END
423 : };
424 : #if defined(__clang__)
425 : #pragma clang diagnostic pop
426 : #endif
427 :
428 : static PrefableDisablers sMethods_disablers0 = {
429 : true, true, 0, nullptr
430 : };
431 :
432 : // Can't be const because the pref-enabled boolean needs to be writable
433 : static Prefable<const JSFunctionSpec> sMethods[] = {
434 : { &sMethods_disablers0, &sMethods_specs[0] },
435 : { nullptr, nullptr }
436 : };
437 :
438 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
439 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
440 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
441 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
442 :
443 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
444 : #if defined(__clang__)
445 : #pragma clang diagnostic push
446 : #pragma clang diagnostic ignored "-Wmissing-braces"
447 : #endif
448 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
449 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
450 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
451 : };
452 : #if defined(__clang__)
453 : #pragma clang diagnostic pop
454 : #endif
455 :
456 :
457 : // Can't be const because the pref-enabled boolean needs to be writable
458 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
459 : { nullptr, &sUnforgeableAttributes_specs[0] },
460 : { nullptr, nullptr }
461 : };
462 :
463 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
464 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
465 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
466 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
467 :
468 :
469 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
470 : static PropertyInfo sNativeProperties_propertyInfos[2];
471 :
472 : static const NativePropertiesN<2> sNativeProperties = {
473 : false, 0,
474 : false, 0,
475 : true, 0 /* sMethods */,
476 : false, 0,
477 : false, 0,
478 : true, 1 /* sUnforgeableAttributes */,
479 : false, 0,
480 : -1,
481 : 2,
482 : sNativeProperties_sortedPropertyIndices,
483 : {
484 : { sMethods, &sNativeProperties_propertyInfos[0] },
485 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[1] }
486 : }
487 : };
488 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
489 : "We have a property info count that is oversized");
490 :
491 : static bool
492 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
493 : {
494 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
495 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
496 0 : if (!args.isConstructing()) {
497 : // XXXbz wish I could get the name from the callee instead of
498 : // Adding more relocations
499 0 : return ThrowConstructorWithoutNew(cx, "PaymentRequestUpdateEvent");
500 : }
501 :
502 0 : GlobalObject global(cx, obj);
503 0 : if (global.Failed()) {
504 0 : return false;
505 : }
506 :
507 0 : JS::Rooted<JSObject*> desiredProto(cx);
508 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
509 0 : return false;
510 : }
511 :
512 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
513 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PaymentRequestUpdateEvent");
514 : }
515 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
516 0 : binding_detail::FakeString arg0;
517 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
518 0 : return false;
519 : }
520 0 : binding_detail::FastPaymentRequestUpdateEventInit arg1;
521 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of PaymentRequestUpdateEvent.constructor", false)) {
522 0 : return false;
523 : }
524 0 : Maybe<JSAutoCompartment> ac;
525 0 : if (objIsXray) {
526 0 : obj = js::CheckedUnwrap(obj);
527 0 : if (!obj) {
528 0 : return false;
529 : }
530 0 : ac.emplace(cx, obj);
531 0 : if (!JS_WrapObject(cx, &desiredProto)) {
532 0 : return false;
533 : }
534 : }
535 0 : binding_detail::FastErrorResult rv;
536 0 : auto result(StrongOrRawPtr<mozilla::dom::PaymentRequestUpdateEvent>(mozilla::dom::PaymentRequestUpdateEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
537 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
538 0 : return false;
539 : }
540 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
541 : static_assert(!IsPointer<decltype(result)>::value,
542 : "NewObject implies that we need to keep the object alive with a strong reference.");
543 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
544 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
545 0 : return false;
546 : }
547 0 : return true;
548 : }
549 :
550 : static const js::ClassOps sInterfaceObjectClassOps = {
551 : nullptr, /* addProperty */
552 : nullptr, /* delProperty */
553 : nullptr, /* getProperty */
554 : nullptr, /* setProperty */
555 : nullptr, /* enumerate */
556 : nullptr, /* newEnumerate */
557 : nullptr, /* resolve */
558 : nullptr, /* mayResolve */
559 : nullptr, /* finalize */
560 : _constructor, /* call */
561 : nullptr, /* hasInstance */
562 : _constructor, /* construct */
563 : nullptr, /* trace */
564 : };
565 :
566 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
567 : {
568 : "Function",
569 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
570 : &sInterfaceObjectClassOps,
571 : JS_NULL_CLASS_SPEC,
572 : JS_NULL_CLASS_EXT,
573 : &sInterfaceObjectClassObjectOps
574 : },
575 : eInterface,
576 : true,
577 : prototypes::id::PaymentRequestUpdateEvent,
578 : PrototypeTraits<prototypes::id::PaymentRequestUpdateEvent>::Depth,
579 : sNativePropertyHooks,
580 : "function PaymentRequestUpdateEvent() {\n [native code]\n}",
581 : EventBinding::GetConstructorObject
582 : };
583 :
584 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
585 : {
586 : "PaymentRequestUpdateEventPrototype",
587 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
588 : JS_NULL_CLASS_OPS,
589 : JS_NULL_CLASS_SPEC,
590 : JS_NULL_CLASS_EXT,
591 : JS_NULL_OBJECT_OPS
592 : },
593 : eInterfacePrototype,
594 : false,
595 : prototypes::id::PaymentRequestUpdateEvent,
596 : PrototypeTraits<prototypes::id::PaymentRequestUpdateEvent>::Depth,
597 : sNativePropertyHooks,
598 : "[object PaymentRequestUpdateEventPrototype]",
599 : EventBinding::GetProtoObject
600 : };
601 :
602 : bool
603 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
604 : {
605 0 : return mozilla::dom::PaymentRequest::PrefEnabled(aCx, aObj) &&
606 0 : mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
607 : }
608 :
609 : JSObject*
610 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
611 : {
612 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
613 : }
614 :
615 : static const js::ClassOps sClassOps = {
616 : _addProperty, /* addProperty */
617 : nullptr, /* delProperty */
618 : nullptr, /* getProperty */
619 : nullptr, /* setProperty */
620 : nullptr, /* enumerate */
621 : nullptr, /* newEnumerate */
622 : nullptr, /* resolve */
623 : nullptr, /* mayResolve */
624 : _finalize, /* finalize */
625 : nullptr, /* call */
626 : nullptr, /* hasInstance */
627 : nullptr, /* construct */
628 : nullptr, /* trace */
629 : };
630 :
631 : static const js::ClassExtension sClassExtension = {
632 : nullptr, /* weakmapKeyDelegateOp */
633 : _objectMoved /* objectMovedOp */
634 : };
635 :
636 : static const DOMJSClass sClass = {
637 : { "PaymentRequestUpdateEvent",
638 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
639 : &sClassOps,
640 : JS_NULL_CLASS_SPEC,
641 : &sClassExtension,
642 : JS_NULL_OBJECT_OPS
643 : },
644 : { prototypes::id::Event, prototypes::id::PaymentRequestUpdateEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
645 : IsBaseOf<nsISupports, mozilla::dom::PaymentRequestUpdateEvent >::value,
646 : sNativePropertyHooks,
647 : FindAssociatedGlobalForNative<mozilla::dom::PaymentRequestUpdateEvent>::Get,
648 : GetProtoObjectHandle,
649 : GetCCParticipant<mozilla::dom::PaymentRequestUpdateEvent>::Get()
650 : };
651 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
652 : "Must have the right minimal number of reserved slots.");
653 : static_assert(1 >= 1,
654 : "Must have enough reserved slots.");
655 :
656 : const JSClass*
657 0 : GetJSClass()
658 : {
659 0 : return sClass.ToJSClass();
660 : }
661 :
662 : bool
663 0 : Wrap(JSContext* aCx, mozilla::dom::PaymentRequestUpdateEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
664 : {
665 : MOZ_ASSERT(static_cast<mozilla::dom::PaymentRequestUpdateEvent*>(aObject) ==
666 : reinterpret_cast<mozilla::dom::PaymentRequestUpdateEvent*>(aObject),
667 : "Multiple inheritance for mozilla::dom::PaymentRequestUpdateEvent is broken.");
668 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
669 : reinterpret_cast<mozilla::dom::Event*>(aObject),
670 : "Multiple inheritance for mozilla::dom::Event is broken.");
671 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
672 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
673 0 : MOZ_ASSERT(!aCache->GetWrapper(),
674 : "You should probably not be using Wrap() directly; use "
675 : "GetOrCreateDOMReflector instead");
676 :
677 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
678 : "nsISupports must be on our primary inheritance chain");
679 :
680 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
681 0 : if (!global) {
682 0 : return false;
683 : }
684 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
685 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
686 :
687 : // That might have ended up wrapping us already, due to the wonders
688 : // of XBL. Check for that, and bail out as needed.
689 0 : aReflector.set(aCache->GetWrapper());
690 0 : if (aReflector) {
691 : #ifdef DEBUG
692 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
693 : #endif // DEBUG
694 0 : return true;
695 : }
696 :
697 0 : JSAutoCompartment ac(aCx, global);
698 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
699 0 : if (!canonicalProto) {
700 0 : return false;
701 : }
702 0 : JS::Rooted<JSObject*> proto(aCx);
703 0 : if (aGivenProto) {
704 0 : proto = aGivenProto;
705 : // Unfortunately, while aGivenProto was in the compartment of aCx
706 : // coming in, we changed compartments to that of "parent" so may need
707 : // to wrap the proto here.
708 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
709 0 : if (!JS_WrapObject(aCx, &proto)) {
710 0 : return false;
711 : }
712 : }
713 : } else {
714 0 : proto = canonicalProto;
715 : }
716 :
717 0 : BindingJSObjectCreator<mozilla::dom::PaymentRequestUpdateEvent> creator(aCx);
718 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
719 0 : if (!aReflector) {
720 0 : return false;
721 : }
722 :
723 0 : aCache->SetWrapper(aReflector);
724 :
725 : // Important: do unforgeable property setup after we have handed
726 : // over ownership of the C++ object to obj as needed, so that if
727 : // we fail and it ends up GCed it won't have problems in the
728 : // finalizer trying to drop its ownership of the C++ object.
729 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
730 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
731 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
732 0 : aCache->ReleaseWrapper(aObject);
733 0 : aCache->ClearWrapper();
734 0 : return false;
735 : }
736 0 : creator.InitializationSucceeded();
737 :
738 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
739 : aCache->GetWrapperPreserveColor() == aReflector);
740 : // If proto != canonicalProto, we have to preserve our wrapper;
741 : // otherwise we won't be able to properly recreate it later, since
742 : // we won't know what proto to use. Note that we don't check
743 : // aGivenProto here, since it's entirely possible (and even
744 : // somewhat common) to have a non-null aGivenProto which is the
745 : // same as canonicalProto.
746 0 : if (proto != canonicalProto) {
747 0 : PreserveWrapper(aObject);
748 : }
749 :
750 0 : return true;
751 : }
752 :
753 : const NativePropertyHooks sNativePropertyHooks[] = { {
754 : nullptr,
755 : nullptr,
756 : nullptr,
757 : { sNativeProperties.Upcast(), nullptr },
758 : prototypes::id::PaymentRequestUpdateEvent,
759 : constructors::id::PaymentRequestUpdateEvent,
760 : EventBinding::sNativePropertyHooks,
761 : &DefaultXrayExpandoObjectClass
762 : } };
763 :
764 : void
765 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
766 : {
767 0 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
768 0 : if (!parentProto) {
769 0 : return;
770 : }
771 :
772 0 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
773 0 : if (!constructorProto) {
774 0 : return;
775 : }
776 :
777 : static bool sIdsInited = false;
778 0 : if (!sIdsInited && NS_IsMainThread()) {
779 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
780 0 : return;
781 : }
782 0 : sIdsInited = true;
783 : }
784 :
785 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PaymentRequestUpdateEvent);
786 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PaymentRequestUpdateEvent);
787 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
788 : &sPrototypeClass.mBase, protoCache,
789 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
790 : interfaceCache,
791 : sNativeProperties.Upcast(),
792 : nullptr,
793 : "PaymentRequestUpdateEvent", aDefineOnGlobal,
794 : nullptr,
795 0 : false);
796 :
797 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
798 : {
799 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
800 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
801 0 : if (!unforgeableHolder) {
802 0 : *protoCache = nullptr;
803 0 : if (interfaceCache) {
804 0 : *interfaceCache = nullptr;
805 : }
806 0 : return;
807 : }
808 : }
809 :
810 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
811 0 : *protoCache = nullptr;
812 0 : if (interfaceCache) {
813 0 : *interfaceCache = nullptr;
814 : }
815 0 : return;
816 : }
817 :
818 0 : if (*protoCache) {
819 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
820 0 : JS::ObjectValue(*unforgeableHolder));
821 : }
822 : }
823 :
824 : JS::Handle<JSObject*>
825 0 : GetProtoObjectHandle(JSContext* aCx)
826 : {
827 : /* Get the interface prototype object for this class. This will create the
828 : object as needed. */
829 0 : bool aDefineOnGlobal = true;
830 :
831 : /* Make sure our global is sane. Hopefully we can remove this sometime */
832 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
833 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
834 0 : return nullptr;
835 : }
836 :
837 : /* Check to see whether the interface objects are already installed */
838 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
839 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::PaymentRequestUpdateEvent)) {
840 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
841 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
842 : }
843 :
844 : /*
845 : * The object might _still_ be null, but that's OK.
846 : *
847 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
848 : * traced by TraceProtoAndIfaceCache() and its contents are never
849 : * changed after they have been set.
850 : *
851 : * Calling address() avoids the read read barrier that does gray
852 : * unmarking, but it's not possible for the object to be gray here.
853 : */
854 :
855 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::PaymentRequestUpdateEvent);
856 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
857 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
858 : }
859 :
860 : JS::Handle<JSObject*>
861 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
862 : {
863 : /* Get the interface object for this class. This will create the object as
864 : needed. */
865 :
866 : /* Make sure our global is sane. Hopefully we can remove this sometime */
867 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
868 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
869 0 : return nullptr;
870 : }
871 :
872 : /* Check to see whether the interface objects are already installed */
873 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
874 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::PaymentRequestUpdateEvent)) {
875 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
876 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
877 : }
878 :
879 : /*
880 : * The object might _still_ be null, but that's OK.
881 : *
882 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
883 : * traced by TraceProtoAndIfaceCache() and its contents are never
884 : * changed after they have been set.
885 : *
886 : * Calling address() avoids the read read barrier that does gray
887 : * unmarking, but it's not possible for the object to be gray here.
888 : */
889 :
890 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::PaymentRequestUpdateEvent);
891 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
892 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
893 : }
894 :
895 : JSObject*
896 0 : GetConstructorObject(JSContext* aCx)
897 : {
898 0 : return GetConstructorObjectHandle(aCx);
899 : }
900 :
901 : } // namespace PaymentRequestUpdateEventBinding
902 :
903 :
904 :
905 : } // namespace dom
906 : } // namespace mozilla
|