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