/work/obj-fuzz/dom/bindings/BrowserFeedWriterBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM BrowserFeedWriter.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "BrowserFeedWriterBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "mozilla/FeedWriterEnabled.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/XrayExpandoClass.h" |
12 | | #include "nsContentUtils.h" |
13 | | #include "nsIGlobalObject.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
19 | | using namespace mozilla::dom::binding_detail; |
20 | | |
21 | | |
22 | | namespace BrowserFeedWriter_Binding { |
23 | | |
24 | | MOZ_CAN_RUN_SCRIPT static bool |
25 | | writeContent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BrowserFeedWriter* self, const JSJitMethodCallArgs& args) |
26 | 0 | { |
27 | 0 | AUTO_PROFILER_LABEL_FAST("BrowserFeedWriter.writeContent", DOM, cx); |
28 | 0 |
|
29 | 0 | Maybe<JS::Rooted<JSObject*> > unwrappedObj; |
30 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
31 | 0 | if (objIsXray) { |
32 | 0 | unwrappedObj.emplace(cx, obj); |
33 | 0 | } |
34 | 0 | if (objIsXray) { |
35 | 0 | unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref()); |
36 | 0 | if (!unwrappedObj.ref()) { |
37 | 0 | return false; |
38 | 0 | } |
39 | 0 | } |
40 | 0 | FastErrorResult rv; |
41 | 0 | self->WriteContent(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))); |
42 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
43 | 0 | return false; |
44 | 0 | } |
45 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
46 | 0 | args.rval().setUndefined(); |
47 | 0 | return true; |
48 | 0 | } |
49 | | |
50 | | static const JSJitInfo writeContent_methodinfo = { |
51 | | { (JSJitGetterOp)writeContent }, |
52 | | { prototypes::id::BrowserFeedWriter }, |
53 | | { PrototypeTraits<prototypes::id::BrowserFeedWriter>::Depth }, |
54 | | JSJitInfo::Method, |
55 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
56 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
57 | | false, /* isInfallible. False in setters. */ |
58 | | false, /* isMovable. Not relevant for setters. */ |
59 | | false, /* isEliminatable. Not relevant for setters. */ |
60 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
61 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
62 | | false, /* isTypedMethod. Only relevant for methods. */ |
63 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
64 | | }; |
65 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
66 | | static_assert(0 < 1, "There is no slot for us"); |
67 | | |
68 | | MOZ_CAN_RUN_SCRIPT static bool |
69 | | close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BrowserFeedWriter* self, const JSJitMethodCallArgs& args) |
70 | 0 | { |
71 | 0 | AUTO_PROFILER_LABEL_FAST("BrowserFeedWriter.close", DOM, cx); |
72 | 0 |
|
73 | 0 | Maybe<JS::Rooted<JSObject*> > unwrappedObj; |
74 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
75 | 0 | if (objIsXray) { |
76 | 0 | unwrappedObj.emplace(cx, obj); |
77 | 0 | } |
78 | 0 | if (objIsXray) { |
79 | 0 | unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref()); |
80 | 0 | if (!unwrappedObj.ref()) { |
81 | 0 | return false; |
82 | 0 | } |
83 | 0 | } |
84 | 0 | FastErrorResult rv; |
85 | 0 | self->Close(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))); |
86 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
87 | 0 | return false; |
88 | 0 | } |
89 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
90 | 0 | args.rval().setUndefined(); |
91 | 0 | return true; |
92 | 0 | } |
93 | | |
94 | | static const JSJitInfo close_methodinfo = { |
95 | | { (JSJitGetterOp)close }, |
96 | | { prototypes::id::BrowserFeedWriter }, |
97 | | { PrototypeTraits<prototypes::id::BrowserFeedWriter>::Depth }, |
98 | | JSJitInfo::Method, |
99 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
100 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
101 | | false, /* isInfallible. False in setters. */ |
102 | | false, /* isMovable. Not relevant for setters. */ |
103 | | false, /* isEliminatable. Not relevant for setters. */ |
104 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
105 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
106 | | false, /* isTypedMethod. Only relevant for methods. */ |
107 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
108 | | }; |
109 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
110 | | static_assert(0 < 1, "There is no slot for us"); |
111 | | |
112 | | static bool |
113 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
114 | 0 | { |
115 | 0 | mozilla::dom::BrowserFeedWriter* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::BrowserFeedWriter>(obj); |
116 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
117 | 0 | // obviously can't preserve if we're not initialized. |
118 | 0 | if (self && self->GetWrapperPreserveColor()) { |
119 | 0 | PreserveWrapper(self); |
120 | 0 | } |
121 | 0 | return true; |
122 | 0 | } |
123 | | |
124 | | static void |
125 | | _finalize(js::FreeOp* fop, JSObject* obj) |
126 | 0 | { |
127 | 0 | mozilla::dom::BrowserFeedWriter* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::BrowserFeedWriter>(obj); |
128 | 0 | if (self) { |
129 | 0 | ClearWrapper(self, self, obj); |
130 | 0 | AddForDeferredFinalization<mozilla::dom::BrowserFeedWriter>(self); |
131 | 0 | } |
132 | 0 | } |
133 | | |
134 | | static size_t |
135 | | _objectMoved(JSObject* obj, JSObject* old) |
136 | 0 | { |
137 | 0 | mozilla::dom::BrowserFeedWriter* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::BrowserFeedWriter>(obj); |
138 | 0 | if (self) { |
139 | 0 | UpdateWrapper(self, self, obj, old); |
140 | 0 | } |
141 | 0 |
|
142 | 0 | return 0; |
143 | 0 | } |
144 | | |
145 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
146 | | #if defined(__clang__) |
147 | | #pragma clang diagnostic push |
148 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
149 | | #endif |
150 | | static const JSFunctionSpec sChromeStaticMethods_specs[] = { |
151 | | JS_FNSPEC("_create", BrowserFeedWriter::_Create, nullptr, 2, 0, nullptr), |
152 | | JS_FS_END |
153 | | }; |
154 | | #if defined(__clang__) |
155 | | #pragma clang diagnostic pop |
156 | | #endif |
157 | | |
158 | | |
159 | | static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = { |
160 | | { nullptr, &sChromeStaticMethods_specs[0] }, |
161 | | { nullptr, nullptr } |
162 | | }; |
163 | | |
164 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
165 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
166 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
167 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
168 | | |
169 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
170 | | #if defined(__clang__) |
171 | | #pragma clang diagnostic push |
172 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
173 | | #endif |
174 | | static const JSFunctionSpec sMethods_specs[] = { |
175 | | JS_FNSPEC("writeContent", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&writeContent_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
176 | | JS_FNSPEC("close", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
177 | | JS_FS_END |
178 | | }; |
179 | | #if defined(__clang__) |
180 | | #pragma clang diagnostic pop |
181 | | #endif |
182 | | |
183 | | |
184 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
185 | | { nullptr, &sMethods_specs[0] }, |
186 | | { nullptr, nullptr } |
187 | | }; |
188 | | |
189 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
190 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
191 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
192 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
193 | | |
194 | | |
195 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
196 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
197 | | |
198 | | static const NativePropertiesN<1> sNativeProperties = { |
199 | | false, 0, |
200 | | false, 0, |
201 | | true, 0 /* sMethods */, |
202 | | false, 0, |
203 | | false, 0, |
204 | | false, 0, |
205 | | false, 0, |
206 | | -1, |
207 | | 2, |
208 | | sNativeProperties_sortedPropertyIndices, |
209 | | { |
210 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
211 | | } |
212 | | }; |
213 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
214 | | "We have a property info count that is oversized"); |
215 | | |
216 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1]; |
217 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1]; |
218 | | |
219 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
220 | | true, 0 /* sChromeStaticMethods */, |
221 | | false, 0, |
222 | | false, 0, |
223 | | false, 0, |
224 | | false, 0, |
225 | | false, 0, |
226 | | false, 0, |
227 | | -1, |
228 | | 1, |
229 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
230 | | { |
231 | | { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] } |
232 | | } |
233 | | }; |
234 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
235 | | "We have a property info count that is oversized"); |
236 | | |
237 | | static bool |
238 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
239 | 0 | { |
240 | 0 | AUTO_PROFILER_LABEL_FAST("BrowserFeedWriter constructor", DOM, cx); |
241 | 0 |
|
242 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
243 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
244 | 0 | if (!args.isConstructing()) { |
245 | 0 | // XXXbz wish I could get the name from the callee instead of |
246 | 0 | // Adding more relocations |
247 | 0 | return ThrowConstructorWithoutNew(cx, "BrowserFeedWriter"); |
248 | 0 | } |
249 | 0 | |
250 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
251 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
252 | 0 | return false; |
253 | 0 | } |
254 | 0 | |
255 | 0 | GlobalObject global(cx, obj); |
256 | 0 | if (global.Failed()) { |
257 | 0 | return false; |
258 | 0 | } |
259 | 0 | |
260 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
261 | 0 | Maybe<JSAutoRealm> ar; |
262 | 0 | if (objIsXray) { |
263 | 0 | obj = js::CheckedUnwrap(obj); |
264 | 0 | if (!obj) { |
265 | 0 | return false; |
266 | 0 | } |
267 | 0 | ar.emplace(cx, obj); |
268 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
269 | 0 | return false; |
270 | 0 | } |
271 | 0 | } |
272 | 0 | FastErrorResult rv; |
273 | 0 | auto result(StrongOrRawPtr<mozilla::dom::BrowserFeedWriter>(mozilla::dom::BrowserFeedWriter::Constructor(global, cx, rv, desiredProto))); |
274 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
275 | 0 | return false; |
276 | 0 | } |
277 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
278 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
279 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
280 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
281 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
282 | 0 | return false; |
283 | 0 | } |
284 | 0 | return true; |
285 | 0 | } |
286 | | |
287 | | static const js::ClassOps sInterfaceObjectClassOps = { |
288 | | nullptr, /* addProperty */ |
289 | | nullptr, /* delProperty */ |
290 | | nullptr, /* enumerate */ |
291 | | nullptr, /* newEnumerate */ |
292 | | nullptr, /* resolve */ |
293 | | nullptr, /* mayResolve */ |
294 | | nullptr, /* finalize */ |
295 | | _constructor, /* call */ |
296 | | nullptr, /* hasInstance */ |
297 | | _constructor, /* construct */ |
298 | | nullptr, /* trace */ |
299 | | }; |
300 | | |
301 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
302 | | { |
303 | | "Function", |
304 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
305 | | &sInterfaceObjectClassOps, |
306 | | JS_NULL_CLASS_SPEC, |
307 | | JS_NULL_CLASS_EXT, |
308 | | &sInterfaceObjectClassObjectOps |
309 | | }, |
310 | | eInterface, |
311 | | true, |
312 | | prototypes::id::BrowserFeedWriter, |
313 | | PrototypeTraits<prototypes::id::BrowserFeedWriter>::Depth, |
314 | | sNativePropertyHooks, |
315 | | "function BrowserFeedWriter() {\n [native code]\n}", |
316 | | JS::GetRealmFunctionPrototype |
317 | | }; |
318 | | |
319 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
320 | | { |
321 | | "BrowserFeedWriterPrototype", |
322 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
323 | | JS_NULL_CLASS_OPS, |
324 | | JS_NULL_CLASS_SPEC, |
325 | | JS_NULL_CLASS_EXT, |
326 | | JS_NULL_OBJECT_OPS |
327 | | }, |
328 | | eInterfacePrototype, |
329 | | false, |
330 | | prototypes::id::BrowserFeedWriter, |
331 | | PrototypeTraits<prototypes::id::BrowserFeedWriter>::Depth, |
332 | | sNativePropertyHooks, |
333 | | "[object BrowserFeedWriterPrototype]", |
334 | | JS::GetRealmObjectPrototype |
335 | | }; |
336 | | |
337 | | bool |
338 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
339 | 0 | { |
340 | 0 | return mozilla::FeedWriterEnabled::IsEnabled(aCx, aObj); |
341 | 0 | } |
342 | | |
343 | | static const js::ClassOps sClassOps = { |
344 | | _addProperty, /* addProperty */ |
345 | | nullptr, /* delProperty */ |
346 | | nullptr, /* enumerate */ |
347 | | nullptr, /* newEnumerate */ |
348 | | nullptr, /* resolve */ |
349 | | nullptr, /* mayResolve */ |
350 | | _finalize, /* finalize */ |
351 | | nullptr, /* call */ |
352 | | nullptr, /* hasInstance */ |
353 | | nullptr, /* construct */ |
354 | | nullptr, /* trace */ |
355 | | }; |
356 | | |
357 | | static const js::ClassExtension sClassExtension = { |
358 | | nullptr, /* weakmapKeyDelegateOp */ |
359 | | _objectMoved /* objectMovedOp */ |
360 | | }; |
361 | | |
362 | | static const DOMJSClass sClass = { |
363 | | { "BrowserFeedWriter", |
364 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
365 | | &sClassOps, |
366 | | JS_NULL_CLASS_SPEC, |
367 | | &sClassExtension, |
368 | | JS_NULL_OBJECT_OPS |
369 | | }, |
370 | | { prototypes::id::BrowserFeedWriter, 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 }, |
371 | | IsBaseOf<nsISupports, mozilla::dom::BrowserFeedWriter >::value, |
372 | | sNativePropertyHooks, |
373 | | FindAssociatedGlobalForNative<mozilla::dom::BrowserFeedWriter>::Get, |
374 | | GetProtoObjectHandle, |
375 | | GetCCParticipant<mozilla::dom::BrowserFeedWriter>::Get() |
376 | | }; |
377 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
378 | | "Must have the right minimal number of reserved slots."); |
379 | | static_assert(1 >= 1, |
380 | | "Must have enough reserved slots."); |
381 | | |
382 | | const JSClass* |
383 | | GetJSClass() |
384 | 0 | { |
385 | 0 | return sClass.ToJSClass(); |
386 | 0 | } |
387 | | |
388 | | bool |
389 | | Wrap(JSContext* aCx, mozilla::dom::BrowserFeedWriter* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
390 | 0 | { |
391 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::BrowserFeedWriter>::value, |
392 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
393 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::BrowserFeedWriter*>(aObject) == |
394 | 0 | reinterpret_cast<mozilla::dom::BrowserFeedWriter*>(aObject), |
395 | 0 | "Multiple inheritance for mozilla::dom::BrowserFeedWriter is broken."); |
396 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
397 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
398 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
399 | 0 | "You should probably not be using Wrap() directly; use " |
400 | 0 | "GetOrCreateDOMReflector instead"); |
401 | 0 |
|
402 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
403 | 0 | "nsISupports must be on our primary inheritance chain"); |
404 | 0 |
|
405 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
406 | 0 | if (!global) { |
407 | 0 | return false; |
408 | 0 | } |
409 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
410 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
411 | 0 |
|
412 | 0 | // That might have ended up wrapping us already, due to the wonders |
413 | 0 | // of XBL. Check for that, and bail out as needed. |
414 | 0 | aReflector.set(aCache->GetWrapper()); |
415 | 0 | if (aReflector) { |
416 | | #ifdef DEBUG |
417 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
418 | | #endif // DEBUG |
419 | | return true; |
420 | 0 | } |
421 | 0 |
|
422 | 0 | JSAutoRealm ar(aCx, global); |
423 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
424 | 0 | if (!canonicalProto) { |
425 | 0 | return false; |
426 | 0 | } |
427 | 0 | JS::Rooted<JSObject*> proto(aCx); |
428 | 0 | if (aGivenProto) { |
429 | 0 | proto = aGivenProto; |
430 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
431 | 0 | // coming in, we changed compartments to that of "parent" so may need |
432 | 0 | // to wrap the proto here. |
433 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
434 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
435 | 0 | return false; |
436 | 0 | } |
437 | 0 | } |
438 | 0 | } else { |
439 | 0 | proto = canonicalProto; |
440 | 0 | } |
441 | 0 |
|
442 | 0 | BindingJSObjectCreator<mozilla::dom::BrowserFeedWriter> creator(aCx); |
443 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
444 | 0 | if (!aReflector) { |
445 | 0 | return false; |
446 | 0 | } |
447 | 0 | |
448 | 0 | aCache->SetWrapper(aReflector); |
449 | 0 | creator.InitializationSucceeded(); |
450 | 0 |
|
451 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
452 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
453 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
454 | 0 | // otherwise we won't be able to properly recreate it later, since |
455 | 0 | // we won't know what proto to use. Note that we don't check |
456 | 0 | // aGivenProto here, since it's entirely possible (and even |
457 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
458 | 0 | // same as canonicalProto. |
459 | 0 | if (proto != canonicalProto) { |
460 | 0 | PreserveWrapper(aObject); |
461 | 0 | } |
462 | 0 |
|
463 | 0 | return true; |
464 | 0 | } |
465 | | |
466 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
467 | | nullptr, |
468 | | nullptr, |
469 | | nullptr, |
470 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
471 | | prototypes::id::BrowserFeedWriter, |
472 | | constructors::id::BrowserFeedWriter, |
473 | | nullptr, |
474 | | &DefaultXrayExpandoObjectClass |
475 | | } }; |
476 | | |
477 | | void |
478 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
479 | 0 | { |
480 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
481 | 0 | if (!parentProto) { |
482 | 0 | return; |
483 | 0 | } |
484 | 0 | |
485 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
486 | 0 | if (!constructorProto) { |
487 | 0 | return; |
488 | 0 | } |
489 | 0 | |
490 | 0 | static bool sIdsInited = false; |
491 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
492 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
493 | 0 | return; |
494 | 0 | } |
495 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
496 | 0 | return; |
497 | 0 | } |
498 | 0 | sIdsInited = true; |
499 | 0 | } |
500 | 0 |
|
501 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::BrowserFeedWriter); |
502 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::BrowserFeedWriter); |
503 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
504 | 0 | &sPrototypeClass.mBase, protoCache, |
505 | 0 | nullptr, |
506 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
507 | 0 | interfaceCache, |
508 | 0 | sNativeProperties.Upcast(), |
509 | 0 | sChromeOnlyNativeProperties.Upcast(), |
510 | 0 | "BrowserFeedWriter", aDefineOnGlobal, |
511 | 0 | nullptr, |
512 | 0 | false); |
513 | 0 | } |
514 | | |
515 | | JSObject* |
516 | | GetConstructorObject(JSContext* aCx) |
517 | 0 | { |
518 | 0 | return GetConstructorObjectHandle(aCx); |
519 | 0 | } |
520 | | |
521 | | } // namespace BrowserFeedWriter_Binding |
522 | | |
523 | | |
524 | | |
525 | | void |
526 | | BrowserFeedWriterJSImpl::WriteContent(ErrorResult& aRv, JS::Realm* aRealm) |
527 | 0 | { |
528 | 0 | CallSetup s(this, aRv, "BrowserFeedWriter.writeContent", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true); |
529 | 0 | JSContext* cx = s.GetContext(); |
530 | 0 | if (!cx) { |
531 | 0 | MOZ_ASSERT(aRv.Failed()); |
532 | 0 | return; |
533 | 0 | } |
534 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
535 | 0 |
|
536 | 0 | JS::Rooted<JS::Value> callable(cx); |
537 | 0 | BrowserFeedWriterAtoms* atomsCache = GetAtomCache<BrowserFeedWriterAtoms>(cx); |
538 | 0 | if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) || |
539 | 0 | !GetCallableProperty(cx, atomsCache->writeContent_id, &callable)) { |
540 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
541 | 0 | return; |
542 | 0 | } |
543 | 0 | JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback)); |
544 | 0 | if (!JS::Call(cx, thisValue, callable, |
545 | 0 | JS::HandleValueArray::empty(), &rval)) { |
546 | 0 | aRv.NoteJSContextException(cx); |
547 | 0 | return; |
548 | 0 | } |
549 | 0 | } |
550 | | |
551 | | void |
552 | | BrowserFeedWriterJSImpl::Close(ErrorResult& aRv, JS::Realm* aRealm) |
553 | 0 | { |
554 | 0 | CallSetup s(this, aRv, "BrowserFeedWriter.close", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true); |
555 | 0 | JSContext* cx = s.GetContext(); |
556 | 0 | if (!cx) { |
557 | 0 | MOZ_ASSERT(aRv.Failed()); |
558 | 0 | return; |
559 | 0 | } |
560 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
561 | 0 |
|
562 | 0 | JS::Rooted<JS::Value> callable(cx); |
563 | 0 | BrowserFeedWriterAtoms* atomsCache = GetAtomCache<BrowserFeedWriterAtoms>(cx); |
564 | 0 | if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) || |
565 | 0 | !GetCallableProperty(cx, atomsCache->close_id, &callable)) { |
566 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
567 | 0 | return; |
568 | 0 | } |
569 | 0 | JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback)); |
570 | 0 | if (!JS::Call(cx, thisValue, callable, |
571 | 0 | JS::HandleValueArray::empty(), &rval)) { |
572 | 0 | aRv.NoteJSContextException(cx); |
573 | 0 | return; |
574 | 0 | } |
575 | 0 | } |
576 | | |
577 | | void |
578 | | BrowserFeedWriterJSImpl::__Init(ErrorResult& aRv, JS::Realm* aRealm) |
579 | 0 | { |
580 | 0 | CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true); |
581 | 0 | JSContext* cx = s.GetContext(); |
582 | 0 | if (!cx) { |
583 | 0 | MOZ_ASSERT(aRv.Failed()); |
584 | 0 | return; |
585 | 0 | } |
586 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
587 | 0 |
|
588 | 0 | JS::Rooted<JS::Value> callable(cx); |
589 | 0 | BrowserFeedWriterAtoms* atomsCache = GetAtomCache<BrowserFeedWriterAtoms>(cx); |
590 | 0 | if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) || |
591 | 0 | !GetCallableProperty(cx, atomsCache->__init_id, &callable)) { |
592 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
593 | 0 | return; |
594 | 0 | } |
595 | 0 | JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback)); |
596 | 0 | if (!JS::Call(cx, thisValue, callable, |
597 | 0 | JS::HandleValueArray::empty(), &rval)) { |
598 | 0 | aRv.NoteJSContextException(cx); |
599 | 0 | return; |
600 | 0 | } |
601 | 0 | } |
602 | | |
603 | | bool |
604 | | BrowserFeedWriterJSImpl::InitIds(JSContext* cx, BrowserFeedWriterAtoms* atomsCache) |
605 | 0 | { |
606 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
607 | 0 |
|
608 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
609 | 0 | // uninitialized. |
610 | 0 | if (!atomsCache->__init_id.init(cx, "__init") || |
611 | 0 | !atomsCache->close_id.init(cx, "close") || |
612 | 0 | !atomsCache->writeContent_id.init(cx, "writeContent")) { |
613 | 0 | return false; |
614 | 0 | } |
615 | 0 | return true; |
616 | 0 | } |
617 | | |
618 | | |
619 | | |
620 | | NS_IMPL_CYCLE_COLLECTION_CLASS(BrowserFeedWriter) |
621 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(BrowserFeedWriter) |
622 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mImpl) |
623 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent) |
624 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER |
625 | 0 | tmp->ClearWeakReferences(); |
626 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
627 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(BrowserFeedWriter) |
628 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImpl) |
629 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent) |
630 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
631 | | NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(BrowserFeedWriter) |
632 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(BrowserFeedWriter) |
633 | | NS_IMPL_CYCLE_COLLECTING_RELEASE(BrowserFeedWriter) |
634 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BrowserFeedWriter) |
635 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
636 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
637 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) |
638 | 0 | NS_INTERFACE_MAP_END |
639 | | |
640 | | BrowserFeedWriter::BrowserFeedWriter(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent) |
641 | | : mImpl(new BrowserFeedWriterJSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)), |
642 | | mParent(aParent) |
643 | 0 | { |
644 | 0 | } |
645 | | |
646 | | |
647 | | BrowserFeedWriter::~BrowserFeedWriter() |
648 | 0 | { |
649 | 0 | } |
650 | | |
651 | | nsISupports* |
652 | | BrowserFeedWriter::GetParentObject() const |
653 | 0 | { |
654 | 0 | return mParent; |
655 | 0 | } |
656 | | |
657 | | JSObject* |
658 | | BrowserFeedWriter::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
659 | 0 | { |
660 | 0 | JS::Rooted<JSObject*> obj(aCx, BrowserFeedWriter_Binding::Wrap(aCx, this, aGivenProto)); |
661 | 0 | if (!obj) { |
662 | 0 | return nullptr; |
663 | 0 | } |
664 | 0 | |
665 | 0 | // Now define it on our chrome object |
666 | 0 | JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull()); |
667 | 0 | if (!JS_WrapObject(aCx, &obj)) { |
668 | 0 | return nullptr; |
669 | 0 | } |
670 | 0 | if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) { |
671 | 0 | return nullptr; |
672 | 0 | } |
673 | 0 | return obj; |
674 | 0 | } |
675 | | |
676 | | already_AddRefed<BrowserFeedWriter> |
677 | | BrowserFeedWriter::Constructor(const GlobalObject& global, JSContext* cx, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto) |
678 | 0 | { |
679 | 0 | JS::Rooted<JSObject*> jsImplObj(cx); |
680 | 0 | nsCOMPtr<nsIGlobalObject> globalHolder = |
681 | 0 | ConstructJSImplementation("@mozilla.org/browser/feeds/result-writer;1", global, &jsImplObj, aRv); |
682 | 0 | if (aRv.Failed()) { |
683 | 0 | return nullptr; |
684 | 0 | } |
685 | 0 | // We should be getting the implementation object for the relevant |
686 | 0 | // contract here, which should never be a cross-compartment wrapper. |
687 | 0 | JS::Rooted<JSObject*> jsImplGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplObj)); |
688 | 0 | // Build the C++ implementation. |
689 | 0 | RefPtr<BrowserFeedWriter> impl = new BrowserFeedWriter(jsImplObj, jsImplGlobal, globalHolder); |
690 | 0 | return impl.forget(); |
691 | 0 | } |
692 | | |
693 | | void |
694 | | BrowserFeedWriter::WriteContent(ErrorResult& aRv, JS::Realm* aRealm) |
695 | 0 | { |
696 | 0 | return mImpl->WriteContent(aRv, aRealm); |
697 | 0 | } |
698 | | |
699 | | void |
700 | | BrowserFeedWriter::Close(ErrorResult& aRv, JS::Realm* aRealm) |
701 | 0 | { |
702 | 0 | return mImpl->Close(aRv, aRealm); |
703 | 0 | } |
704 | | |
705 | | bool |
706 | | BrowserFeedWriter::_Create(JSContext* cx, unsigned argc, JS::Value* vp) |
707 | 0 | { |
708 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
709 | 0 | if (args.length() < 2) { |
710 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "BrowserFeedWriter._create"); |
711 | 0 | } |
712 | 0 | if (!args[0].isObject()) { |
713 | 0 | return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of BrowserFeedWriter._create"); |
714 | 0 | } |
715 | 0 | if (!args[1].isObject()) { |
716 | 0 | return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of BrowserFeedWriter._create"); |
717 | 0 | } |
718 | 0 | |
719 | 0 | // GlobalObject will go through wrappers as needed for us, and |
720 | 0 | // is simpler than the right UnwrapArg incantation. |
721 | 0 | GlobalObject global(cx, &args[0].toObject()); |
722 | 0 | if (global.Failed()) { |
723 | 0 | return false; |
724 | 0 | } |
725 | 0 | nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports()); |
726 | 0 | MOZ_ASSERT(globalHolder); |
727 | 0 | JS::Rooted<JSObject*> arg(cx, &args[1].toObject()); |
728 | 0 | JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx)); |
729 | 0 | RefPtr<BrowserFeedWriter> impl = new BrowserFeedWriter(arg, argGlobal, globalHolder); |
730 | 0 | MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx)); |
731 | 0 | return GetOrCreateDOMReflector(cx, impl, args.rval()); |
732 | 0 | } |
733 | | |
734 | | |
735 | | } // namespace dom |
736 | | } // namespace mozilla |