Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM Promise.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "PromiseBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "mozilla/OwningNonNull.h"
6 : #include "mozilla/dom/BindingUtils.h"
7 : #include "mozilla/dom/DOMJSClass.h"
8 : #include "mozilla/dom/NonRefcountedDOMObject.h"
9 : #include "mozilla/dom/PromiseNativeHandler.h"
10 : #include "mozilla/dom/XrayExpandoClass.h"
11 :
12 : namespace mozilla {
13 : namespace dom {
14 :
15 : void
16 235 : PromiseJobCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, ErrorResult& aRv)
17 : {
18 470 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
19 :
20 470 : JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
21 705 : if (!JS::Call(cx, aThisVal, callable,
22 470 : JS::HandleValueArray::empty(), &rval)) {
23 0 : aRv.NoteJSContextException(cx);
24 0 : return;
25 : }
26 : }
27 :
28 :
29 :
30 : void
31 0 : AnyCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, JS::Handle<JS::Value> value, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv)
32 : {
33 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
34 0 : JS::AutoValueVector argv(cx);
35 0 : if (!argv.resize(1)) {
36 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
37 0 : return;
38 : }
39 0 : unsigned argc = 1;
40 :
41 : do {
42 0 : JS::ExposeValueToActiveJS(value);
43 0 : argv[0].set(value);
44 0 : if (!MaybeWrapValue(cx, argv[0])) {
45 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
46 0 : return;
47 : }
48 0 : break;
49 : } while (0);
50 :
51 0 : JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
52 0 : if (!JS::Call(cx, aThisVal, callable,
53 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
54 0 : aRv.NoteJSContextException(cx);
55 0 : return;
56 : }
57 0 : JS::Rooted<JS::Value> rvalDecl(cx);
58 : #ifdef __clang__
59 : #pragma clang diagnostic push
60 : #pragma clang diagnostic ignored "-Wunreachable-code"
61 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
62 : #endif // __clang__
63 0 : if ((false) && !CallerSubsumes(rval)) {
64 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "return value of AnyCallback");
65 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
66 0 : return;
67 : }
68 : #ifdef __clang__
69 : #pragma clang diagnostic pop
70 : #endif // __clang__
71 0 : rvalDecl = rval;
72 0 : aRetVal.set(rvalDecl);
73 : }
74 :
75 :
76 :
77 : namespace binding_detail {
78 : } // namespace binding_detail
79 :
80 :
81 : namespace binding_detail {
82 : } // namespace binding_detail
83 :
84 :
85 : namespace PromiseNativeHandlerBinding {
86 :
87 : static void
88 0 : _finalize(js::FreeOp* fop, JSObject* obj)
89 : {
90 0 : mozilla::dom::PromiseNativeHandler* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PromiseNativeHandler>(obj);
91 0 : if (self) {
92 0 : AddForDeferredFinalization<mozilla::dom::PromiseNativeHandler>(self);
93 : }
94 0 : }
95 :
96 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
97 : {
98 : "PromiseNativeHandlerPrototype",
99 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
100 : JS_NULL_CLASS_OPS,
101 : JS_NULL_CLASS_SPEC,
102 : JS_NULL_CLASS_EXT,
103 : JS_NULL_OBJECT_OPS
104 : },
105 : eInterfacePrototype,
106 : false,
107 : prototypes::id::PromiseNativeHandler,
108 : PrototypeTraits<prototypes::id::PromiseNativeHandler>::Depth,
109 : sNativePropertyHooks,
110 : "[object PromiseNativeHandlerPrototype]",
111 : JS::GetRealmObjectPrototype
112 : };
113 :
114 : static const js::ClassOps sClassOps = {
115 : nullptr, /* addProperty */
116 : nullptr, /* delProperty */
117 : nullptr, /* getProperty */
118 : nullptr, /* setProperty */
119 : nullptr, /* enumerate */
120 : nullptr, /* newEnumerate */
121 : nullptr, /* resolve */
122 : nullptr, /* mayResolve */
123 : _finalize, /* finalize */
124 : nullptr, /* call */
125 : nullptr, /* hasInstance */
126 : nullptr, /* construct */
127 : nullptr, /* trace */
128 : };
129 :
130 : static const js::ClassExtension sClassExtension = {
131 : nullptr, /* weakmapKeyDelegateOp */
132 : nullptr /* objectMovedOp */
133 : };
134 :
135 : static const DOMJSClass sClass = {
136 : { "PromiseNativeHandler",
137 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
138 : &sClassOps,
139 : JS_NULL_CLASS_SPEC,
140 : &sClassExtension,
141 : JS_NULL_OBJECT_OPS
142 : },
143 : { prototypes::id::PromiseNativeHandler, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
144 : IsBaseOf<nsISupports, mozilla::dom::PromiseNativeHandler >::value,
145 : sNativePropertyHooks,
146 : FindAssociatedGlobalForNative<mozilla::dom::PromiseNativeHandler>::Get,
147 : GetProtoObjectHandle,
148 : GetCCParticipant<mozilla::dom::PromiseNativeHandler>::Get()
149 : };
150 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
151 : "Must have the right minimal number of reserved slots.");
152 : static_assert(1 >= 1,
153 : "Must have enough reserved slots.");
154 :
155 : const JSClass*
156 0 : GetJSClass()
157 : {
158 0 : return sClass.ToJSClass();
159 : }
160 :
161 : bool
162 0 : Wrap(JSContext* aCx, mozilla::dom::PromiseNativeHandler* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
163 : {
164 : MOZ_ASSERT(static_cast<mozilla::dom::PromiseNativeHandler*>(aObject) ==
165 : reinterpret_cast<mozilla::dom::PromiseNativeHandler*>(aObject),
166 : "Multiple inheritance for mozilla::dom::PromiseNativeHandler is broken.");
167 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
168 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
169 :
170 0 : JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
171 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
172 0 : if (!canonicalProto) {
173 0 : return false;
174 : }
175 0 : JS::Rooted<JSObject*> proto(aCx);
176 0 : if (aGivenProto) {
177 0 : proto = aGivenProto;
178 : // Unfortunately, while aGivenProto was in the compartment of aCx
179 : // coming in, we changed compartments to that of "parent" so may need
180 : // to wrap the proto here.
181 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
182 0 : if (!JS_WrapObject(aCx, &proto)) {
183 0 : return false;
184 : }
185 : }
186 : } else {
187 0 : proto = canonicalProto;
188 : }
189 :
190 0 : BindingJSObjectCreator<mozilla::dom::PromiseNativeHandler> creator(aCx);
191 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
192 0 : if (!aReflector) {
193 0 : return false;
194 : }
195 :
196 :
197 :
198 0 : creator.InitializationSucceeded();
199 0 : return true;
200 : }
201 :
202 : const NativePropertyHooks sNativePropertyHooks[] = { {
203 : nullptr,
204 : nullptr,
205 : nullptr,
206 : { nullptr, nullptr },
207 : prototypes::id::PromiseNativeHandler,
208 : constructors::id::_ID_Count,
209 : nullptr,
210 : &DefaultXrayExpandoObjectClass
211 : } };
212 :
213 : void
214 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
215 : {
216 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
217 0 : if (!parentProto) {
218 0 : return;
219 : }
220 :
221 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PromiseNativeHandler);
222 0 : JS::Heap<JSObject*>* interfaceCache = nullptr;
223 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
224 : &sPrototypeClass.mBase, protoCache,
225 : nullptr, nullptr, 0, nullptr,
226 : interfaceCache,
227 : nullptr,
228 : nullptr,
229 : nullptr, aDefineOnGlobal,
230 : nullptr,
231 0 : false);
232 : }
233 :
234 : JS::Handle<JSObject*>
235 0 : GetProtoObjectHandle(JSContext* aCx)
236 : {
237 : /* Get the interface prototype object for this class. This will create the
238 : object as needed. */
239 0 : bool aDefineOnGlobal = true;
240 :
241 : /* Make sure our global is sane. Hopefully we can remove this sometime */
242 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
243 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
244 0 : return nullptr;
245 : }
246 :
247 : /* Check to see whether the interface objects are already installed */
248 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
249 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::PromiseNativeHandler)) {
250 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
251 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
252 : }
253 :
254 : /*
255 : * The object might _still_ be null, but that's OK.
256 : *
257 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
258 : * traced by TraceProtoAndIfaceCache() and its contents are never
259 : * changed after they have been set.
260 : *
261 : * Calling address() avoids the read read barrier that does gray
262 : * unmarking, but it's not possible for the object to be gray here.
263 : */
264 :
265 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::PromiseNativeHandler);
266 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
267 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
268 : }
269 :
270 : } // namespace PromiseNativeHandlerBinding
271 :
272 :
273 :
274 : } // namespace dom
275 : } // namespace mozilla
|