/work/obj-fuzz/dom/bindings/PlacesObserversBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM PlacesObservers.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "PlacesObserversBinding.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/PlacesEvent.h" |
10 | | #include "mozilla/dom/PlacesObservers.h" |
11 | | #include "mozilla/dom/PlacesWeakCallbackWrapper.h" |
12 | | #include "mozilla/dom/XrayExpandoClass.h" |
13 | | #include "nsContentUtils.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 | | void |
23 | | PlacesEventCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const Sequence<OwningNonNull<PlacesEvent>>& events, ErrorResult& aRv) |
24 | 0 | { |
25 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
26 | 0 | JS::AutoValueVector argv(cx); |
27 | 0 | if (!argv.resize(1)) { |
28 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
29 | 0 | return; |
30 | 0 | } |
31 | 0 | unsigned argc = 1; |
32 | 0 |
|
33 | 0 | do { |
34 | 0 |
|
35 | 0 | uint32_t length = events.Length(); |
36 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
37 | 0 | if (!returnArray) { |
38 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
39 | 0 | return; |
40 | 0 | } |
41 | 0 | // Scope for 'tmp' |
42 | 0 | { |
43 | 0 | JS::Rooted<JS::Value> tmp(cx); |
44 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
45 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
46 | 0 | // are different ways to succeed at wrapping the object. |
47 | 0 | do { |
48 | 0 | if (!GetOrCreateDOMReflector(cx, events[sequenceIdx0], &tmp)) { |
49 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
50 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
51 | 0 | return; |
52 | 0 | } |
53 | 0 | break; |
54 | 0 | } while (false); |
55 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
56 | 0 | JSPROP_ENUMERATE)) { |
57 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
58 | 0 | return; |
59 | 0 | } |
60 | 0 | } |
61 | 0 | } |
62 | 0 | argv[0].setObject(*returnArray); |
63 | 0 | break; |
64 | 0 | } while (false); |
65 | 0 |
|
66 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
67 | 0 | if (!JS::Call(cx, aThisVal, callable, |
68 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
69 | 0 | aRv.NoteJSContextException(cx); |
70 | 0 | return; |
71 | 0 | } |
72 | 0 | } |
73 | | |
74 | | |
75 | | |
76 | | namespace binding_detail { |
77 | | } // namespace binding_detail |
78 | | |
79 | | |
80 | | namespace PlacesObservers_Binding { |
81 | | |
82 | | static bool |
83 | | addListener(JSContext* cx, unsigned argc, JS::Value* vp) |
84 | 0 | { |
85 | 0 | AUTO_PROFILER_LABEL_FAST("PlacesObservers.addListener", DOM, cx); |
86 | 0 |
|
87 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
88 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
89 | 0 |
|
90 | 0 | unsigned argcount = std::min(args.length(), 2u); |
91 | 0 | switch (argcount) { |
92 | 0 | case 2: { |
93 | 0 | binding_detail::AutoSequence<PlacesEventType> arg0; |
94 | 0 | if (args[0].isObject()) { |
95 | 0 | JS::ForOfIterator iter(cx); |
96 | 0 | if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) { |
97 | 0 | return false; |
98 | 0 | } |
99 | 0 | if (!iter.valueIsIterable()) { |
100 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of PlacesObservers.addListener"); |
101 | 0 | return false; |
102 | 0 | } |
103 | 0 | binding_detail::AutoSequence<PlacesEventType> &arr = arg0; |
104 | 0 | JS::Rooted<JS::Value> temp(cx); |
105 | 0 | while (true) { |
106 | 0 | bool done; |
107 | 0 | if (!iter.next(&temp, &done)) { |
108 | 0 | return false; |
109 | 0 | } |
110 | 0 | if (done) { |
111 | 0 | break; |
112 | 0 | } |
113 | 0 | PlacesEventType* slotPtr = arr.AppendElement(mozilla::fallible); |
114 | 0 | if (!slotPtr) { |
115 | 0 | JS_ReportOutOfMemory(cx); |
116 | 0 | return false; |
117 | 0 | } |
118 | 0 | PlacesEventType& slot = *slotPtr; |
119 | 0 | { |
120 | 0 | int index; |
121 | 0 | if (!FindEnumStringIndex<true>(cx, temp, PlacesEventTypeValues::strings, "PlacesEventType", "Element of argument 1 of PlacesObservers.addListener", &index)) { |
122 | 0 | return false; |
123 | 0 | } |
124 | 0 | MOZ_ASSERT(index >= 0); |
125 | 0 | slot = static_cast<PlacesEventType>(index); |
126 | 0 | } |
127 | 0 | } |
128 | 0 | } else { |
129 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of PlacesObservers.addListener"); |
130 | 0 | return false; |
131 | 0 | } |
132 | 0 | if (args[1].isObject()) { |
133 | 0 | do { |
134 | 0 | NonNull<mozilla::dom::PlacesWeakCallbackWrapper> arg1; |
135 | 0 | { |
136 | 0 | nsresult rv = UnwrapObject<prototypes::id::PlacesWeakCallbackWrapper, mozilla::dom::PlacesWeakCallbackWrapper>(args[1], arg1); |
137 | 0 | if (NS_FAILED(rv)) { |
138 | 0 | break; |
139 | 0 | } |
140 | 0 | } |
141 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
142 | 0 | if (global.Failed()) { |
143 | 0 | return false; |
144 | 0 | } |
145 | 0 | |
146 | 0 | FastErrorResult rv; |
147 | 0 | mozilla::dom::PlacesObservers::AddListener(global, Constify(arg0), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
148 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
149 | 0 | return false; |
150 | 0 | } |
151 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
152 | 0 | args.rval().setUndefined(); |
153 | 0 | return true; |
154 | 0 | } while (false); |
155 | 0 | do { |
156 | 0 | RootedCallback<OwningNonNull<binding_detail::FastPlacesEventCallback>> arg1(cx); |
157 | 0 | if (JS::IsCallable(&args[1].toObject())) { |
158 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
159 | 0 | arg1 = new binding_detail::FastPlacesEventCallback(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
160 | 0 | } |
161 | 0 | } else { |
162 | 0 | break; |
163 | 0 | } |
164 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
165 | 0 | if (global.Failed()) { |
166 | 0 | return false; |
167 | 0 | } |
168 | 0 | |
169 | 0 | FastErrorResult rv; |
170 | 0 | mozilla::dom::PlacesObservers::AddListener(global, Constify(arg0), NonNullHelper(arg1), rv); |
171 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
172 | 0 | return false; |
173 | 0 | } |
174 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
175 | 0 | args.rval().setUndefined(); |
176 | 0 | return true; |
177 | 0 | } while (false); |
178 | 0 | } |
179 | 0 | return ThrowErrorMessage(cx, MSG_OVERLOAD_RESOLUTION_FAILED, "2", "2", "PlacesObservers.addListener"); |
180 | 0 | break; |
181 | 0 | } |
182 | 0 | default: { |
183 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PlacesObservers.addListener"); |
184 | 0 | break; |
185 | 0 | } |
186 | 0 | } |
187 | 0 | MOZ_CRASH("We have an always-returning default case"); |
188 | 0 | return false; |
189 | 0 | } |
190 | | |
191 | | static bool |
192 | | removeListener(JSContext* cx, unsigned argc, JS::Value* vp) |
193 | 0 | { |
194 | 0 | AUTO_PROFILER_LABEL_FAST("PlacesObservers.removeListener", DOM, cx); |
195 | 0 |
|
196 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
197 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
198 | 0 |
|
199 | 0 | unsigned argcount = std::min(args.length(), 2u); |
200 | 0 | switch (argcount) { |
201 | 0 | case 2: { |
202 | 0 | binding_detail::AutoSequence<PlacesEventType> arg0; |
203 | 0 | if (args[0].isObject()) { |
204 | 0 | JS::ForOfIterator iter(cx); |
205 | 0 | if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) { |
206 | 0 | return false; |
207 | 0 | } |
208 | 0 | if (!iter.valueIsIterable()) { |
209 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of PlacesObservers.removeListener"); |
210 | 0 | return false; |
211 | 0 | } |
212 | 0 | binding_detail::AutoSequence<PlacesEventType> &arr = arg0; |
213 | 0 | JS::Rooted<JS::Value> temp(cx); |
214 | 0 | while (true) { |
215 | 0 | bool done; |
216 | 0 | if (!iter.next(&temp, &done)) { |
217 | 0 | return false; |
218 | 0 | } |
219 | 0 | if (done) { |
220 | 0 | break; |
221 | 0 | } |
222 | 0 | PlacesEventType* slotPtr = arr.AppendElement(mozilla::fallible); |
223 | 0 | if (!slotPtr) { |
224 | 0 | JS_ReportOutOfMemory(cx); |
225 | 0 | return false; |
226 | 0 | } |
227 | 0 | PlacesEventType& slot = *slotPtr; |
228 | 0 | { |
229 | 0 | int index; |
230 | 0 | if (!FindEnumStringIndex<true>(cx, temp, PlacesEventTypeValues::strings, "PlacesEventType", "Element of argument 1 of PlacesObservers.removeListener", &index)) { |
231 | 0 | return false; |
232 | 0 | } |
233 | 0 | MOZ_ASSERT(index >= 0); |
234 | 0 | slot = static_cast<PlacesEventType>(index); |
235 | 0 | } |
236 | 0 | } |
237 | 0 | } else { |
238 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of PlacesObservers.removeListener"); |
239 | 0 | return false; |
240 | 0 | } |
241 | 0 | if (args[1].isObject()) { |
242 | 0 | do { |
243 | 0 | NonNull<mozilla::dom::PlacesWeakCallbackWrapper> arg1; |
244 | 0 | { |
245 | 0 | nsresult rv = UnwrapObject<prototypes::id::PlacesWeakCallbackWrapper, mozilla::dom::PlacesWeakCallbackWrapper>(args[1], arg1); |
246 | 0 | if (NS_FAILED(rv)) { |
247 | 0 | break; |
248 | 0 | } |
249 | 0 | } |
250 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
251 | 0 | if (global.Failed()) { |
252 | 0 | return false; |
253 | 0 | } |
254 | 0 | |
255 | 0 | FastErrorResult rv; |
256 | 0 | mozilla::dom::PlacesObservers::RemoveListener(global, Constify(arg0), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
257 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
258 | 0 | return false; |
259 | 0 | } |
260 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
261 | 0 | args.rval().setUndefined(); |
262 | 0 | return true; |
263 | 0 | } while (false); |
264 | 0 | do { |
265 | 0 | RootedCallback<OwningNonNull<binding_detail::FastPlacesEventCallback>> arg1(cx); |
266 | 0 | if (JS::IsCallable(&args[1].toObject())) { |
267 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
268 | 0 | arg1 = new binding_detail::FastPlacesEventCallback(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
269 | 0 | } |
270 | 0 | } else { |
271 | 0 | break; |
272 | 0 | } |
273 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
274 | 0 | if (global.Failed()) { |
275 | 0 | return false; |
276 | 0 | } |
277 | 0 | |
278 | 0 | FastErrorResult rv; |
279 | 0 | mozilla::dom::PlacesObservers::RemoveListener(global, Constify(arg0), NonNullHelper(arg1), rv); |
280 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
281 | 0 | return false; |
282 | 0 | } |
283 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
284 | 0 | args.rval().setUndefined(); |
285 | 0 | return true; |
286 | 0 | } while (false); |
287 | 0 | } |
288 | 0 | return ThrowErrorMessage(cx, MSG_OVERLOAD_RESOLUTION_FAILED, "2", "2", "PlacesObservers.removeListener"); |
289 | 0 | break; |
290 | 0 | } |
291 | 0 | default: { |
292 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PlacesObservers.removeListener"); |
293 | 0 | break; |
294 | 0 | } |
295 | 0 | } |
296 | 0 | MOZ_CRASH("We have an always-returning default case"); |
297 | 0 | return false; |
298 | 0 | } |
299 | | |
300 | | static bool |
301 | | notifyListeners(JSContext* cx, unsigned argc, JS::Value* vp) |
302 | 0 | { |
303 | 0 | AUTO_PROFILER_LABEL_FAST("PlacesObservers.notifyListeners", DOM, cx); |
304 | 0 |
|
305 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
306 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
307 | 0 |
|
308 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
309 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PlacesObservers.notifyListeners"); |
310 | 0 | } |
311 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
312 | 0 | if (global.Failed()) { |
313 | 0 | return false; |
314 | 0 | } |
315 | 0 | |
316 | 0 | binding_detail::AutoSequence<OwningNonNull<mozilla::dom::PlacesEvent>> arg0; |
317 | 0 | if (args[0].isObject()) { |
318 | 0 | JS::ForOfIterator iter(cx); |
319 | 0 | if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) { |
320 | 0 | return false; |
321 | 0 | } |
322 | 0 | if (!iter.valueIsIterable()) { |
323 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of PlacesObservers.notifyListeners"); |
324 | 0 | return false; |
325 | 0 | } |
326 | 0 | binding_detail::AutoSequence<OwningNonNull<mozilla::dom::PlacesEvent>> &arr = arg0; |
327 | 0 | JS::Rooted<JS::Value> temp(cx); |
328 | 0 | while (true) { |
329 | 0 | bool done; |
330 | 0 | if (!iter.next(&temp, &done)) { |
331 | 0 | return false; |
332 | 0 | } |
333 | 0 | if (done) { |
334 | 0 | break; |
335 | 0 | } |
336 | 0 | OwningNonNull<mozilla::dom::PlacesEvent>* slotPtr = arr.AppendElement(mozilla::fallible); |
337 | 0 | if (!slotPtr) { |
338 | 0 | JS_ReportOutOfMemory(cx); |
339 | 0 | return false; |
340 | 0 | } |
341 | 0 | OwningNonNull<mozilla::dom::PlacesEvent>& slot = *slotPtr; |
342 | 0 | if (temp.isObject()) { |
343 | 0 | static_assert(IsRefcounted<mozilla::dom::PlacesEvent>::value, "We can only store refcounted classes.");{ |
344 | 0 | nsresult rv = UnwrapObject<prototypes::id::PlacesEvent, mozilla::dom::PlacesEvent>(&temp, slot); |
345 | 0 | if (NS_FAILED(rv)) { |
346 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of argument 1 of PlacesObservers.notifyListeners", "PlacesEvent"); |
347 | 0 | return false; |
348 | 0 | } |
349 | 0 | } |
350 | 0 | } else { |
351 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of argument 1 of PlacesObservers.notifyListeners"); |
352 | 0 | return false; |
353 | 0 | } |
354 | 0 | } |
355 | 0 | } else { |
356 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of PlacesObservers.notifyListeners"); |
357 | 0 | return false; |
358 | 0 | } |
359 | 0 | FastErrorResult rv; |
360 | 0 | mozilla::dom::PlacesObservers::NotifyListeners(global, Constify(arg0), rv); |
361 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
362 | 0 | return false; |
363 | 0 | } |
364 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
365 | 0 | args.rval().setUndefined(); |
366 | 0 | return true; |
367 | 0 | } |
368 | | |
369 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
370 | | #if defined(__clang__) |
371 | | #pragma clang diagnostic push |
372 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
373 | | #endif |
374 | | static const JSFunctionSpec sStaticMethods_specs[] = { |
375 | | JS_FNSPEC("addListener", addListener, nullptr, 2, JSPROP_ENUMERATE, nullptr), |
376 | | JS_FNSPEC("removeListener", removeListener, nullptr, 2, JSPROP_ENUMERATE, nullptr), |
377 | | JS_FNSPEC("notifyListeners", notifyListeners, nullptr, 1, JSPROP_ENUMERATE, nullptr), |
378 | | JS_FS_END |
379 | | }; |
380 | | #if defined(__clang__) |
381 | | #pragma clang diagnostic pop |
382 | | #endif |
383 | | |
384 | | |
385 | | static const Prefable<const JSFunctionSpec> sStaticMethods[] = { |
386 | | { nullptr, &sStaticMethods_specs[0] }, |
387 | | { nullptr, nullptr } |
388 | | }; |
389 | | |
390 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
391 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
392 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
393 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
394 | | |
395 | | |
396 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
397 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
398 | | |
399 | | static const NativePropertiesN<1> sNativeProperties = { |
400 | | true, 0 /* sStaticMethods */, |
401 | | false, 0, |
402 | | false, 0, |
403 | | false, 0, |
404 | | false, 0, |
405 | | false, 0, |
406 | | false, 0, |
407 | | -1, |
408 | | 3, |
409 | | sNativeProperties_sortedPropertyIndices, |
410 | | { |
411 | | { sStaticMethods, &sNativeProperties_propertyInfos[0] } |
412 | | } |
413 | | }; |
414 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
415 | | "We have a property info count that is oversized"); |
416 | | |
417 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
418 | | { |
419 | | "Object", |
420 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
421 | | JS_NULL_CLASS_OPS, |
422 | | JS_NULL_CLASS_SPEC, |
423 | | JS_NULL_CLASS_EXT, |
424 | | JS_NULL_OBJECT_OPS |
425 | | }, |
426 | | eInterface, |
427 | | false, |
428 | | prototypes::id::_ID_Count, |
429 | | 0, |
430 | | sNativePropertyHooks, |
431 | | "[object Object]", |
432 | | JS::GetRealmObjectPrototype |
433 | | }; |
434 | | |
435 | | bool |
436 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
437 | 0 | { |
438 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
439 | 0 | } |
440 | | |
441 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
442 | | nullptr, |
443 | | nullptr, |
444 | | nullptr, |
445 | | { sNativeProperties.Upcast(), nullptr }, |
446 | | prototypes::id::_ID_Count, |
447 | | constructors::id::PlacesObservers, |
448 | | nullptr, |
449 | | &DefaultXrayExpandoObjectClass |
450 | | } }; |
451 | | |
452 | | void |
453 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
454 | 0 | { |
455 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
456 | 0 | if (!constructorProto) { |
457 | 0 | return; |
458 | 0 | } |
459 | 0 | |
460 | 0 | static bool sIdsInited = false; |
461 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
462 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
463 | 0 | return; |
464 | 0 | } |
465 | 0 | sIdsInited = true; |
466 | 0 | } |
467 | 0 |
|
468 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
469 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PlacesObservers); |
470 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
471 | 0 | nullptr, protoCache, |
472 | 0 | nullptr, |
473 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
474 | 0 | interfaceCache, |
475 | 0 | sNativeProperties.Upcast(), |
476 | 0 | nullptr, |
477 | 0 | "PlacesObservers", aDefineOnGlobal, |
478 | 0 | nullptr, |
479 | 0 | false); |
480 | 0 | } |
481 | | |
482 | | JSObject* |
483 | | GetConstructorObject(JSContext* aCx) |
484 | 0 | { |
485 | 0 | return GetConstructorObjectHandle(aCx); |
486 | 0 | } |
487 | | |
488 | | } // namespace PlacesObservers_Binding |
489 | | |
490 | | |
491 | | |
492 | | namespace PlacesWeakCallbackWrapper_Binding { |
493 | | |
494 | | static bool |
495 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
496 | 0 | { |
497 | 0 | mozilla::dom::PlacesWeakCallbackWrapper* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PlacesWeakCallbackWrapper>(obj); |
498 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
499 | 0 | // obviously can't preserve if we're not initialized. |
500 | 0 | if (self && self->GetWrapperPreserveColor()) { |
501 | 0 | PreserveWrapper(self); |
502 | 0 | } |
503 | 0 | return true; |
504 | 0 | } |
505 | | |
506 | | static void |
507 | | _finalize(js::FreeOp* fop, JSObject* obj) |
508 | 0 | { |
509 | 0 | mozilla::dom::PlacesWeakCallbackWrapper* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PlacesWeakCallbackWrapper>(obj); |
510 | 0 | if (self) { |
511 | 0 | ClearWrapper(self, self, obj); |
512 | 0 | AddForDeferredFinalization<mozilla::dom::PlacesWeakCallbackWrapper>(self); |
513 | 0 | } |
514 | 0 | } |
515 | | |
516 | | static size_t |
517 | | _objectMoved(JSObject* obj, JSObject* old) |
518 | 0 | { |
519 | 0 | mozilla::dom::PlacesWeakCallbackWrapper* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PlacesWeakCallbackWrapper>(obj); |
520 | 0 | if (self) { |
521 | 0 | UpdateWrapper(self, self, obj, old); |
522 | 0 | } |
523 | 0 |
|
524 | 0 | return 0; |
525 | 0 | } |
526 | | |
527 | | static bool |
528 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
529 | 0 | { |
530 | 0 | AUTO_PROFILER_LABEL_FAST("PlacesWeakCallbackWrapper constructor", DOM, cx); |
531 | 0 |
|
532 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
533 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
534 | 0 | if (!args.isConstructing()) { |
535 | 0 | // XXXbz wish I could get the name from the callee instead of |
536 | 0 | // Adding more relocations |
537 | 0 | return ThrowConstructorWithoutNew(cx, "PlacesWeakCallbackWrapper"); |
538 | 0 | } |
539 | 0 | |
540 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
541 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
542 | 0 | return false; |
543 | 0 | } |
544 | 0 | |
545 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
546 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PlacesWeakCallbackWrapper"); |
547 | 0 | } |
548 | 0 | GlobalObject global(cx, obj); |
549 | 0 | if (global.Failed()) { |
550 | 0 | return false; |
551 | 0 | } |
552 | 0 | |
553 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
554 | 0 | RootedCallback<OwningNonNull<binding_detail::FastPlacesEventCallback>> arg0(cx); |
555 | 0 | if (args[0].isObject()) { |
556 | 0 | if (JS::IsCallable(&args[0].toObject())) { |
557 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
558 | 0 | arg0 = new binding_detail::FastPlacesEventCallback(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
559 | 0 | } |
560 | 0 | } else { |
561 | 0 | ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of PlacesWeakCallbackWrapper.constructor"); |
562 | 0 | return false; |
563 | 0 | } |
564 | 0 | } else { |
565 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of PlacesWeakCallbackWrapper.constructor"); |
566 | 0 | return false; |
567 | 0 | } |
568 | 0 | Maybe<JSAutoRealm> ar; |
569 | 0 | if (objIsXray) { |
570 | 0 | obj = js::CheckedUnwrap(obj); |
571 | 0 | if (!obj) { |
572 | 0 | return false; |
573 | 0 | } |
574 | 0 | ar.emplace(cx, obj); |
575 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
576 | 0 | return false; |
577 | 0 | } |
578 | 0 | } |
579 | 0 | FastErrorResult rv; |
580 | 0 | auto result(StrongOrRawPtr<mozilla::dom::PlacesWeakCallbackWrapper>(mozilla::dom::PlacesWeakCallbackWrapper::Constructor(global, NonNullHelper(arg0), rv))); |
581 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
582 | 0 | return false; |
583 | 0 | } |
584 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
585 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
586 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
587 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
588 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
589 | 0 | return false; |
590 | 0 | } |
591 | 0 | return true; |
592 | 0 | } |
593 | | |
594 | | static const js::ClassOps sInterfaceObjectClassOps = { |
595 | | nullptr, /* addProperty */ |
596 | | nullptr, /* delProperty */ |
597 | | nullptr, /* enumerate */ |
598 | | nullptr, /* newEnumerate */ |
599 | | nullptr, /* resolve */ |
600 | | nullptr, /* mayResolve */ |
601 | | nullptr, /* finalize */ |
602 | | _constructor, /* call */ |
603 | | nullptr, /* hasInstance */ |
604 | | _constructor, /* construct */ |
605 | | nullptr, /* trace */ |
606 | | }; |
607 | | |
608 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
609 | | { |
610 | | "Function", |
611 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
612 | | &sInterfaceObjectClassOps, |
613 | | JS_NULL_CLASS_SPEC, |
614 | | JS_NULL_CLASS_EXT, |
615 | | &sInterfaceObjectClassObjectOps |
616 | | }, |
617 | | eInterface, |
618 | | true, |
619 | | prototypes::id::PlacesWeakCallbackWrapper, |
620 | | PrototypeTraits<prototypes::id::PlacesWeakCallbackWrapper>::Depth, |
621 | | sNativePropertyHooks, |
622 | | "function PlacesWeakCallbackWrapper() {\n [native code]\n}", |
623 | | JS::GetRealmFunctionPrototype |
624 | | }; |
625 | | |
626 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
627 | | { |
628 | | "PlacesWeakCallbackWrapperPrototype", |
629 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
630 | | JS_NULL_CLASS_OPS, |
631 | | JS_NULL_CLASS_SPEC, |
632 | | JS_NULL_CLASS_EXT, |
633 | | JS_NULL_OBJECT_OPS |
634 | | }, |
635 | | eInterfacePrototype, |
636 | | false, |
637 | | prototypes::id::PlacesWeakCallbackWrapper, |
638 | | PrototypeTraits<prototypes::id::PlacesWeakCallbackWrapper>::Depth, |
639 | | sNativePropertyHooks, |
640 | | "[object PlacesWeakCallbackWrapperPrototype]", |
641 | | JS::GetRealmObjectPrototype |
642 | | }; |
643 | | |
644 | | bool |
645 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
646 | 0 | { |
647 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
648 | 0 | } |
649 | | |
650 | | static const js::ClassOps sClassOps = { |
651 | | _addProperty, /* addProperty */ |
652 | | nullptr, /* delProperty */ |
653 | | nullptr, /* enumerate */ |
654 | | nullptr, /* newEnumerate */ |
655 | | nullptr, /* resolve */ |
656 | | nullptr, /* mayResolve */ |
657 | | _finalize, /* finalize */ |
658 | | nullptr, /* call */ |
659 | | nullptr, /* hasInstance */ |
660 | | nullptr, /* construct */ |
661 | | nullptr, /* trace */ |
662 | | }; |
663 | | |
664 | | static const js::ClassExtension sClassExtension = { |
665 | | nullptr, /* weakmapKeyDelegateOp */ |
666 | | _objectMoved /* objectMovedOp */ |
667 | | }; |
668 | | |
669 | | static const DOMJSClass sClass = { |
670 | | { "PlacesWeakCallbackWrapper", |
671 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
672 | | &sClassOps, |
673 | | JS_NULL_CLASS_SPEC, |
674 | | &sClassExtension, |
675 | | JS_NULL_OBJECT_OPS |
676 | | }, |
677 | | { prototypes::id::PlacesWeakCallbackWrapper, 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 }, |
678 | | IsBaseOf<nsISupports, mozilla::dom::PlacesWeakCallbackWrapper >::value, |
679 | | sNativePropertyHooks, |
680 | | FindAssociatedGlobalForNative<mozilla::dom::PlacesWeakCallbackWrapper>::Get, |
681 | | GetProtoObjectHandle, |
682 | | GetCCParticipant<mozilla::dom::PlacesWeakCallbackWrapper>::Get() |
683 | | }; |
684 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
685 | | "Must have the right minimal number of reserved slots."); |
686 | | static_assert(1 >= 1, |
687 | | "Must have enough reserved slots."); |
688 | | |
689 | | const JSClass* |
690 | | GetJSClass() |
691 | 0 | { |
692 | 0 | return sClass.ToJSClass(); |
693 | 0 | } |
694 | | |
695 | | bool |
696 | | Wrap(JSContext* aCx, mozilla::dom::PlacesWeakCallbackWrapper* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
697 | 0 | { |
698 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::PlacesWeakCallbackWrapper>::value, |
699 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
700 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::PlacesWeakCallbackWrapper*>(aObject) == |
701 | 0 | reinterpret_cast<mozilla::dom::PlacesWeakCallbackWrapper*>(aObject), |
702 | 0 | "Multiple inheritance for mozilla::dom::PlacesWeakCallbackWrapper is broken."); |
703 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
704 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
705 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
706 | 0 | "You should probably not be using Wrap() directly; use " |
707 | 0 | "GetOrCreateDOMReflector instead"); |
708 | 0 |
|
709 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
710 | 0 | "nsISupports must be on our primary inheritance chain"); |
711 | 0 |
|
712 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
713 | 0 | if (!global) { |
714 | 0 | return false; |
715 | 0 | } |
716 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
717 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
718 | 0 |
|
719 | 0 | // That might have ended up wrapping us already, due to the wonders |
720 | 0 | // of XBL. Check for that, and bail out as needed. |
721 | 0 | aReflector.set(aCache->GetWrapper()); |
722 | 0 | if (aReflector) { |
723 | | #ifdef DEBUG |
724 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
725 | | #endif // DEBUG |
726 | | return true; |
727 | 0 | } |
728 | 0 |
|
729 | 0 | JSAutoRealm ar(aCx, global); |
730 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
731 | 0 | if (!canonicalProto) { |
732 | 0 | return false; |
733 | 0 | } |
734 | 0 | JS::Rooted<JSObject*> proto(aCx); |
735 | 0 | if (aGivenProto) { |
736 | 0 | proto = aGivenProto; |
737 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
738 | 0 | // coming in, we changed compartments to that of "parent" so may need |
739 | 0 | // to wrap the proto here. |
740 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
741 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
742 | 0 | return false; |
743 | 0 | } |
744 | 0 | } |
745 | 0 | } else { |
746 | 0 | proto = canonicalProto; |
747 | 0 | } |
748 | 0 |
|
749 | 0 | BindingJSObjectCreator<mozilla::dom::PlacesWeakCallbackWrapper> creator(aCx); |
750 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
751 | 0 | if (!aReflector) { |
752 | 0 | return false; |
753 | 0 | } |
754 | 0 | |
755 | 0 | aCache->SetWrapper(aReflector); |
756 | 0 | creator.InitializationSucceeded(); |
757 | 0 |
|
758 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
759 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
760 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
761 | 0 | // otherwise we won't be able to properly recreate it later, since |
762 | 0 | // we won't know what proto to use. Note that we don't check |
763 | 0 | // aGivenProto here, since it's entirely possible (and even |
764 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
765 | 0 | // same as canonicalProto. |
766 | 0 | if (proto != canonicalProto) { |
767 | 0 | PreserveWrapper(aObject); |
768 | 0 | } |
769 | 0 |
|
770 | 0 | return true; |
771 | 0 | } |
772 | | |
773 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
774 | | nullptr, |
775 | | nullptr, |
776 | | nullptr, |
777 | | { nullptr, nullptr }, |
778 | | prototypes::id::PlacesWeakCallbackWrapper, |
779 | | constructors::id::PlacesWeakCallbackWrapper, |
780 | | nullptr, |
781 | | &DefaultXrayExpandoObjectClass |
782 | | } }; |
783 | | |
784 | | void |
785 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
786 | 0 | { |
787 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
788 | 0 | if (!parentProto) { |
789 | 0 | return; |
790 | 0 | } |
791 | 0 | |
792 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
793 | 0 | if (!constructorProto) { |
794 | 0 | return; |
795 | 0 | } |
796 | 0 | |
797 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PlacesWeakCallbackWrapper); |
798 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PlacesWeakCallbackWrapper); |
799 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
800 | 0 | &sPrototypeClass.mBase, protoCache, |
801 | 0 | nullptr, |
802 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr, |
803 | 0 | interfaceCache, |
804 | 0 | nullptr, |
805 | 0 | nullptr, |
806 | 0 | "PlacesWeakCallbackWrapper", aDefineOnGlobal, |
807 | 0 | nullptr, |
808 | 0 | false); |
809 | 0 | } |
810 | | |
811 | | JSObject* |
812 | | GetConstructorObject(JSContext* aCx) |
813 | 0 | { |
814 | 0 | return GetConstructorObjectHandle(aCx); |
815 | 0 | } |
816 | | |
817 | | } // namespace PlacesWeakCallbackWrapper_Binding |
818 | | |
819 | | |
820 | | |
821 | | } // namespace dom |
822 | | } // namespace mozilla |