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