Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM Event.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "EventBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/FloatingPoint.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/Event.h"
11 : #include "mozilla/dom/EventTarget.h"
12 : #include "mozilla/dom/NonRefcountedDOMObject.h"
13 : #include "mozilla/dom/Nullable.h"
14 : #include "mozilla/dom/PrimitiveConversions.h"
15 : #include "mozilla/dom/ScriptSettings.h"
16 : #include "mozilla/dom/SimpleGlobalObject.h"
17 : #include "mozilla/dom/XrayExpandoClass.h"
18 : #include "nsContentUtils.h"
19 : #include "nsISupports.h"
20 : #include "xpcjsid.h"
21 :
22 : namespace mozilla {
23 : namespace dom {
24 :
25 :
26 0 : EventInit::EventInit()
27 : {
28 : // Safe to pass a null context if we pass a null value
29 0 : Init(nullptr, JS::NullHandleValue);
30 0 : }
31 :
32 :
33 :
34 : bool
35 2 : EventInit::InitIds(JSContext* cx, EventInitAtoms* atomsCache)
36 : {
37 2 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
38 :
39 : // Initialize these in reverse order so that any failure leaves the first one
40 : // uninitialized.
41 6 : if (!atomsCache->composed_id.init(cx, "composed") ||
42 4 : !atomsCache->cancelable_id.init(cx, "cancelable") ||
43 2 : !atomsCache->bubbles_id.init(cx, "bubbles")) {
44 0 : return false;
45 : }
46 2 : return true;
47 : }
48 :
49 : bool
50 36 : EventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
51 : {
52 : // Passing a null JSContext is OK only if we're initing from null,
53 : // Since in that case we will not have to do any property gets
54 : // Also evaluate isNullOrUndefined in order to avoid false-positive
55 : // checkers by static analysis tools
56 36 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
57 36 : EventInitAtoms* atomsCache = nullptr;
58 36 : if (cx) {
59 9 : atomsCache = GetAtomCache<EventInitAtoms>(cx);
60 9 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
61 0 : return false;
62 : }
63 : }
64 :
65 36 : if (!IsConvertibleToDictionary(val)) {
66 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
67 : }
68 :
69 36 : bool isNull = val.isNullOrUndefined();
70 : // We only need these if !isNull, in which case we have |cx|.
71 72 : Maybe<JS::Rooted<JSObject *> > object;
72 72 : Maybe<JS::Rooted<JS::Value> > temp;
73 36 : if (!isNull) {
74 7 : MOZ_ASSERT(cx);
75 7 : object.emplace(cx, &val.toObject());
76 7 : temp.emplace(cx);
77 : }
78 36 : if (!isNull) {
79 7 : if (!JS_GetPropertyById(cx, *object, atomsCache->bubbles_id, temp.ptr())) {
80 0 : return false;
81 : }
82 : }
83 36 : if (!isNull && !temp->isUndefined()) {
84 7 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mBubbles)) {
85 0 : return false;
86 : }
87 : } else {
88 29 : mBubbles = false;
89 : }
90 36 : mIsAnyMemberPresent = true;
91 :
92 36 : if (!isNull) {
93 7 : if (!JS_GetPropertyById(cx, *object, atomsCache->cancelable_id, temp.ptr())) {
94 0 : return false;
95 : }
96 : }
97 36 : if (!isNull && !temp->isUndefined()) {
98 4 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mCancelable)) {
99 0 : return false;
100 : }
101 : } else {
102 32 : mCancelable = false;
103 : }
104 36 : mIsAnyMemberPresent = true;
105 :
106 36 : if (!isNull) {
107 7 : if (!JS_GetPropertyById(cx, *object, atomsCache->composed_id, temp.ptr())) {
108 0 : return false;
109 : }
110 : }
111 36 : if (!isNull && !temp->isUndefined()) {
112 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mComposed)) {
113 0 : return false;
114 : }
115 : } else {
116 36 : mComposed = false;
117 : }
118 36 : mIsAnyMemberPresent = true;
119 36 : return true;
120 : }
121 :
122 : bool
123 0 : EventInit::Init(const nsAString& aJSON)
124 : {
125 0 : AutoJSAPI jsapi;
126 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
127 0 : if (!cleanGlobal) {
128 0 : return false;
129 : }
130 0 : if (!jsapi.Init(cleanGlobal)) {
131 0 : return false;
132 : }
133 0 : JSContext* cx = jsapi.cx();
134 0 : JS::Rooted<JS::Value> json(cx);
135 0 : bool ok = ParseJSON(cx, aJSON, &json);
136 0 : NS_ENSURE_TRUE(ok, false);
137 0 : return Init(cx, json);
138 : }
139 :
140 : bool
141 0 : EventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
142 : {
143 0 : EventInitAtoms* atomsCache = GetAtomCache<EventInitAtoms>(cx);
144 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
145 0 : return false;
146 : }
147 :
148 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
149 0 : if (!obj) {
150 0 : return false;
151 : }
152 0 : rval.set(JS::ObjectValue(*obj));
153 :
154 : do {
155 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
156 0 : JS::Rooted<JS::Value> temp(cx);
157 0 : bool const & currentValue = mBubbles;
158 0 : temp.setBoolean(currentValue);
159 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->bubbles_id, temp, JSPROP_ENUMERATE)) {
160 0 : return false;
161 : }
162 0 : break;
163 : } while(0);
164 :
165 : do {
166 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
167 0 : JS::Rooted<JS::Value> temp(cx);
168 0 : bool const & currentValue = mCancelable;
169 0 : temp.setBoolean(currentValue);
170 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->cancelable_id, temp, JSPROP_ENUMERATE)) {
171 0 : return false;
172 : }
173 0 : break;
174 : } while(0);
175 :
176 : do {
177 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
178 0 : JS::Rooted<JS::Value> temp(cx);
179 0 : bool const & currentValue = mComposed;
180 0 : temp.setBoolean(currentValue);
181 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->composed_id, temp, JSPROP_ENUMERATE)) {
182 0 : return false;
183 : }
184 0 : break;
185 : } while(0);
186 :
187 0 : return true;
188 : }
189 :
190 : bool
191 0 : EventInit::ToJSON(nsAString& aJSON) const
192 : {
193 0 : AutoJSAPI jsapi;
194 0 : jsapi.Init();
195 0 : JSContext *cx = jsapi.cx();
196 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
197 : // because we'll only be creating objects, in ways that have no
198 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
199 : // which likewise guarantees no side-effects for the sorts of
200 : // things we will pass it.
201 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
202 0 : JS::Rooted<JS::Value> val(cx);
203 0 : if (!ToObjectInternal(cx, &val)) {
204 0 : return false;
205 : }
206 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
207 0 : return StringifyToJSON(cx, obj, aJSON);
208 : }
209 :
210 : void
211 0 : EventInit::TraceDictionary(JSTracer* trc)
212 : {
213 0 : }
214 :
215 : EventInit&
216 0 : EventInit::operator=(const EventInit& aOther)
217 : {
218 0 : mBubbles = aOther.mBubbles;
219 0 : mCancelable = aOther.mCancelable;
220 0 : mComposed = aOther.mComposed;
221 0 : return *this;
222 : }
223 :
224 : namespace binding_detail {
225 : } // namespace binding_detail
226 :
227 :
228 : namespace EventBinding {
229 :
230 : static bool
231 39 : get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
232 : {
233 78 : DOMString result;
234 39 : self->GetType(result);
235 39 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
236 39 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
237 0 : return false;
238 : }
239 39 : return true;
240 : }
241 :
242 : static const JSJitInfo type_getterinfo = {
243 : { (JSJitGetterOp)get_type },
244 : { prototypes::id::Event },
245 : { PrototypeTraits<prototypes::id::Event>::Depth },
246 : JSJitInfo::Getter,
247 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
248 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
249 : false, /* isInfallible. False in setters. */
250 : true, /* isMovable. Not relevant for setters. */
251 : true, /* isEliminatable. Not relevant for setters. */
252 : false, /* isAlwaysInSlot. Only relevant for getters. */
253 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
254 : false, /* isTypedMethod. Only relevant for methods. */
255 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
256 : };
257 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
258 : static_assert(0 < 1, "There is no slot for us");
259 :
260 : static bool
261 18 : get_target(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
262 : {
263 18 : auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetTarget()));
264 18 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
265 18 : if (!result) {
266 0 : args.rval().setNull();
267 0 : return true;
268 : }
269 18 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
270 0 : if (!HandleNewBindingWrappingFailure(cx, obj, result, args.rval())) {
271 0 : return false;
272 : }
273 0 : return true;
274 : }
275 18 : return true;
276 : }
277 :
278 : static const JSJitInfo target_getterinfo = {
279 : { (JSJitGetterOp)get_target },
280 : { prototypes::id::Event },
281 : { PrototypeTraits<prototypes::id::Event>::Depth },
282 : JSJitInfo::Getter,
283 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
284 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
285 : false, /* isInfallible. False in setters. */
286 : true, /* isMovable. Not relevant for setters. */
287 : true, /* isEliminatable. Not relevant for setters. */
288 : false, /* isAlwaysInSlot. Only relevant for getters. */
289 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
290 : false, /* isTypedMethod. Only relevant for methods. */
291 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
292 : };
293 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
294 : static_assert(0 < 1, "There is no slot for us");
295 :
296 : static bool
297 0 : get_currentTarget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
298 : {
299 0 : auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetCurrentTarget()));
300 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
301 0 : if (!result) {
302 0 : args.rval().setNull();
303 0 : return true;
304 : }
305 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
306 0 : if (!HandleNewBindingWrappingFailure(cx, obj, result, args.rval())) {
307 0 : return false;
308 : }
309 0 : return true;
310 : }
311 0 : return true;
312 : }
313 :
314 : static const JSJitInfo currentTarget_getterinfo = {
315 : { (JSJitGetterOp)get_currentTarget },
316 : { prototypes::id::Event },
317 : { PrototypeTraits<prototypes::id::Event>::Depth },
318 : JSJitInfo::Getter,
319 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
320 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
321 : false, /* isInfallible. False in setters. */
322 : true, /* isMovable. Not relevant for setters. */
323 : true, /* isEliminatable. Not relevant for setters. */
324 : false, /* isAlwaysInSlot. Only relevant for getters. */
325 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
326 : false, /* isTypedMethod. Only relevant for methods. */
327 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
328 : };
329 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
330 : static_assert(0 < 1, "There is no slot for us");
331 :
332 : static bool
333 0 : get_eventPhase(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
334 : {
335 0 : uint16_t result(self->EventPhase());
336 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
337 0 : args.rval().setInt32(int32_t(result));
338 0 : return true;
339 : }
340 :
341 : static const JSJitInfo eventPhase_getterinfo = {
342 : { (JSJitGetterOp)get_eventPhase },
343 : { prototypes::id::Event },
344 : { PrototypeTraits<prototypes::id::Event>::Depth },
345 : JSJitInfo::Getter,
346 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
347 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
348 : true, /* isInfallible. False in setters. */
349 : true, /* isMovable. Not relevant for setters. */
350 : true, /* isEliminatable. Not relevant for setters. */
351 : false, /* isAlwaysInSlot. Only relevant for getters. */
352 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
353 : false, /* isTypedMethod. Only relevant for methods. */
354 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
355 : };
356 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
357 : static_assert(0 < 1, "There is no slot for us");
358 :
359 : static bool
360 0 : stopPropagation(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, const JSJitMethodCallArgs& args)
361 : {
362 0 : self->StopPropagation();
363 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
364 0 : args.rval().setUndefined();
365 0 : return true;
366 : }
367 :
368 : static const JSJitInfo stopPropagation_methodinfo = {
369 : { (JSJitGetterOp)stopPropagation },
370 : { prototypes::id::Event },
371 : { PrototypeTraits<prototypes::id::Event>::Depth },
372 : JSJitInfo::Method,
373 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
374 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
375 : true, /* isInfallible. False in setters. */
376 : false, /* isMovable. Not relevant for setters. */
377 : false, /* isEliminatable. Not relevant for setters. */
378 : false, /* isAlwaysInSlot. Only relevant for getters. */
379 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
380 : false, /* isTypedMethod. Only relevant for methods. */
381 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
382 : };
383 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
384 : static_assert(0 < 1, "There is no slot for us");
385 :
386 : static bool
387 0 : stopImmediatePropagation(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, const JSJitMethodCallArgs& args)
388 : {
389 0 : self->StopImmediatePropagation();
390 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
391 0 : args.rval().setUndefined();
392 0 : return true;
393 : }
394 :
395 : static const JSJitInfo stopImmediatePropagation_methodinfo = {
396 : { (JSJitGetterOp)stopImmediatePropagation },
397 : { prototypes::id::Event },
398 : { PrototypeTraits<prototypes::id::Event>::Depth },
399 : JSJitInfo::Method,
400 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
401 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
402 : true, /* isInfallible. False in setters. */
403 : false, /* isMovable. Not relevant for setters. */
404 : false, /* isEliminatable. Not relevant for setters. */
405 : false, /* isAlwaysInSlot. Only relevant for getters. */
406 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
407 : false, /* isTypedMethod. Only relevant for methods. */
408 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
409 : };
410 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
411 : static_assert(0 < 1, "There is no slot for us");
412 :
413 : static bool
414 0 : get_bubbles(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
415 : {
416 0 : bool result(self->Bubbles());
417 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
418 0 : args.rval().setBoolean(result);
419 0 : return true;
420 : }
421 :
422 : static const JSJitInfo bubbles_getterinfo = {
423 : { (JSJitGetterOp)get_bubbles },
424 : { prototypes::id::Event },
425 : { PrototypeTraits<prototypes::id::Event>::Depth },
426 : JSJitInfo::Getter,
427 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
428 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
429 : true, /* isInfallible. False in setters. */
430 : true, /* isMovable. Not relevant for setters. */
431 : true, /* isEliminatable. Not relevant for setters. */
432 : false, /* isAlwaysInSlot. Only relevant for getters. */
433 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
434 : false, /* isTypedMethod. Only relevant for methods. */
435 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
436 : };
437 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
438 : static_assert(0 < 1, "There is no slot for us");
439 :
440 : static bool
441 0 : get_cancelable(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
442 : {
443 0 : bool result(self->Cancelable());
444 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
445 0 : args.rval().setBoolean(result);
446 0 : return true;
447 : }
448 :
449 : static const JSJitInfo cancelable_getterinfo = {
450 : { (JSJitGetterOp)get_cancelable },
451 : { prototypes::id::Event },
452 : { PrototypeTraits<prototypes::id::Event>::Depth },
453 : JSJitInfo::Getter,
454 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
455 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
456 : true, /* isInfallible. False in setters. */
457 : true, /* isMovable. Not relevant for setters. */
458 : true, /* isEliminatable. Not relevant for setters. */
459 : false, /* isAlwaysInSlot. Only relevant for getters. */
460 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
461 : false, /* isTypedMethod. Only relevant for methods. */
462 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
463 : };
464 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
465 : static_assert(0 < 1, "There is no slot for us");
466 :
467 : static bool
468 0 : preventDefault(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, const JSJitMethodCallArgs& args)
469 : {
470 0 : self->PreventDefault(cx, nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem);
471 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
472 0 : args.rval().setUndefined();
473 0 : return true;
474 : }
475 :
476 : static const JSJitInfo preventDefault_methodinfo = {
477 : { (JSJitGetterOp)preventDefault },
478 : { prototypes::id::Event },
479 : { PrototypeTraits<prototypes::id::Event>::Depth },
480 : JSJitInfo::Method,
481 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
482 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
483 : true, /* isInfallible. False in setters. */
484 : false, /* isMovable. Not relevant for setters. */
485 : false, /* isEliminatable. Not relevant for setters. */
486 : false, /* isAlwaysInSlot. Only relevant for getters. */
487 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
488 : false, /* isTypedMethod. Only relevant for methods. */
489 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
490 : };
491 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
492 : static_assert(0 < 1, "There is no slot for us");
493 :
494 : static bool
495 0 : get_defaultPrevented(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
496 : {
497 0 : bool result(self->DefaultPrevented(nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem));
498 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
499 0 : args.rval().setBoolean(result);
500 0 : return true;
501 : }
502 :
503 : static const JSJitInfo defaultPrevented_getterinfo = {
504 : { (JSJitGetterOp)get_defaultPrevented },
505 : { prototypes::id::Event },
506 : { PrototypeTraits<prototypes::id::Event>::Depth },
507 : JSJitInfo::Getter,
508 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
509 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
510 : true, /* isInfallible. False in setters. */
511 : true, /* isMovable. Not relevant for setters. */
512 : true, /* isEliminatable. Not relevant for setters. */
513 : false, /* isAlwaysInSlot. Only relevant for getters. */
514 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
515 : false, /* isTypedMethod. Only relevant for methods. */
516 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
517 : };
518 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
519 : static_assert(0 < 1, "There is no slot for us");
520 :
521 : static bool
522 0 : get_defaultPreventedByChrome(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
523 : {
524 0 : bool result(self->DefaultPreventedByChrome());
525 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
526 0 : args.rval().setBoolean(result);
527 0 : return true;
528 : }
529 :
530 : static const JSJitInfo defaultPreventedByChrome_getterinfo = {
531 : { (JSJitGetterOp)get_defaultPreventedByChrome },
532 : { prototypes::id::Event },
533 : { PrototypeTraits<prototypes::id::Event>::Depth },
534 : JSJitInfo::Getter,
535 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
536 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
537 : true, /* isInfallible. False in setters. */
538 : true, /* isMovable. Not relevant for setters. */
539 : true, /* isEliminatable. Not relevant for setters. */
540 : false, /* isAlwaysInSlot. Only relevant for getters. */
541 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
542 : false, /* isTypedMethod. Only relevant for methods. */
543 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
544 : };
545 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
546 : static_assert(0 < 1, "There is no slot for us");
547 :
548 : static bool
549 0 : get_defaultPreventedByContent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
550 : {
551 0 : bool result(self->DefaultPreventedByContent());
552 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
553 0 : args.rval().setBoolean(result);
554 0 : return true;
555 : }
556 :
557 : static const JSJitInfo defaultPreventedByContent_getterinfo = {
558 : { (JSJitGetterOp)get_defaultPreventedByContent },
559 : { prototypes::id::Event },
560 : { PrototypeTraits<prototypes::id::Event>::Depth },
561 : JSJitInfo::Getter,
562 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
563 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
564 : true, /* isInfallible. False in setters. */
565 : true, /* isMovable. Not relevant for setters. */
566 : true, /* isEliminatable. Not relevant for setters. */
567 : false, /* isAlwaysInSlot. Only relevant for getters. */
568 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
569 : false, /* isTypedMethod. Only relevant for methods. */
570 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
571 : };
572 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
573 : static_assert(0 < 1, "There is no slot for us");
574 :
575 : static bool
576 0 : get_composed(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
577 : {
578 0 : bool result(self->Composed());
579 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
580 0 : args.rval().setBoolean(result);
581 0 : return true;
582 : }
583 :
584 : static const JSJitInfo composed_getterinfo = {
585 : { (JSJitGetterOp)get_composed },
586 : { prototypes::id::Event },
587 : { PrototypeTraits<prototypes::id::Event>::Depth },
588 : JSJitInfo::Getter,
589 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
590 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
591 : true, /* isInfallible. False in setters. */
592 : true, /* isMovable. Not relevant for setters. */
593 : true, /* isEliminatable. Not relevant for setters. */
594 : false, /* isAlwaysInSlot. Only relevant for getters. */
595 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
596 : false, /* isTypedMethod. Only relevant for methods. */
597 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
598 : };
599 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
600 : static_assert(0 < 1, "There is no slot for us");
601 :
602 : static bool
603 1 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
604 : {
605 1 : bool result(self->IsTrusted());
606 1 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
607 1 : args.rval().setBoolean(result);
608 1 : return true;
609 : }
610 :
611 : static const JSJitInfo isTrusted_getterinfo = {
612 : { (JSJitGetterOp)get_isTrusted },
613 : { prototypes::id::Event },
614 : { PrototypeTraits<prototypes::id::Event>::Depth },
615 : JSJitInfo::Getter,
616 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
617 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
618 : true, /* isInfallible. False in setters. */
619 : true, /* isMovable. Not relevant for setters. */
620 : true, /* isEliminatable. Not relevant for setters. */
621 : false, /* isAlwaysInSlot. Only relevant for getters. */
622 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
623 : false, /* isTypedMethod. Only relevant for methods. */
624 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
625 : };
626 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
627 : static_assert(0 < 1, "There is no slot for us");
628 :
629 : static bool
630 0 : get_timeStamp(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
631 : {
632 0 : double result(self->TimeStamp());
633 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
634 0 : args.rval().set(JS_NumberValue(double(result)));
635 0 : return true;
636 : }
637 :
638 : static const JSJitInfo timeStamp_getterinfo = {
639 : { (JSJitGetterOp)get_timeStamp },
640 : { prototypes::id::Event },
641 : { PrototypeTraits<prototypes::id::Event>::Depth },
642 : JSJitInfo::Getter,
643 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
644 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
645 : true, /* isInfallible. False in setters. */
646 : true, /* isMovable. Not relevant for setters. */
647 : true, /* isEliminatable. Not relevant for setters. */
648 : false, /* isAlwaysInSlot. Only relevant for getters. */
649 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
650 : false, /* isTypedMethod. Only relevant for methods. */
651 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
652 : };
653 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
654 : static_assert(0 < 1, "There is no slot for us");
655 :
656 : static bool
657 3 : initEvent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, const JSJitMethodCallArgs& args)
658 : {
659 3 : if (MOZ_UNLIKELY(args.length() < 1)) {
660 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Event.initEvent");
661 : }
662 6 : binding_detail::FakeString arg0;
663 3 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
664 0 : return false;
665 : }
666 : bool arg1;
667 3 : if (args.hasDefined(1)) {
668 3 : if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) {
669 0 : return false;
670 : }
671 : } else {
672 0 : arg1 = false;
673 : }
674 : bool arg2;
675 3 : if (args.hasDefined(2)) {
676 3 : if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) {
677 0 : return false;
678 : }
679 : } else {
680 0 : arg2 = false;
681 : }
682 3 : self->InitEvent(NonNullHelper(Constify(arg0)), arg1, arg2);
683 3 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
684 3 : args.rval().setUndefined();
685 3 : return true;
686 : }
687 :
688 : static const JSJitInfo initEvent_methodinfo = {
689 : { (JSJitGetterOp)initEvent },
690 : { prototypes::id::Event },
691 : { PrototypeTraits<prototypes::id::Event>::Depth },
692 : JSJitInfo::Method,
693 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
694 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
695 : false, /* isInfallible. False in setters. */
696 : false, /* isMovable. Not relevant for setters. */
697 : false, /* isEliminatable. Not relevant for setters. */
698 : false, /* isAlwaysInSlot. Only relevant for getters. */
699 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
700 : false, /* isTypedMethod. Only relevant for methods. */
701 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
702 : };
703 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
704 : static_assert(0 < 1, "There is no slot for us");
705 :
706 : static bool
707 0 : get_cancelBubble(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
708 : {
709 0 : bool result(self->CancelBubble());
710 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
711 0 : args.rval().setBoolean(result);
712 0 : return true;
713 : }
714 :
715 : static bool
716 0 : set_cancelBubble(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitSetterCallArgs args)
717 : {
718 : bool arg0;
719 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
720 0 : return false;
721 : }
722 0 : self->SetCancelBubble(arg0);
723 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
724 :
725 0 : return true;
726 : }
727 :
728 : static const JSJitInfo cancelBubble_getterinfo = {
729 : { (JSJitGetterOp)get_cancelBubble },
730 : { prototypes::id::Event },
731 : { PrototypeTraits<prototypes::id::Event>::Depth },
732 : JSJitInfo::Getter,
733 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
734 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
735 : true, /* isInfallible. False in setters. */
736 : false, /* isMovable. Not relevant for setters. */
737 : false, /* isEliminatable. Not relevant for setters. */
738 : false, /* isAlwaysInSlot. Only relevant for getters. */
739 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
740 : false, /* isTypedMethod. Only relevant for methods. */
741 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
742 : };
743 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
744 : static_assert(0 < 1, "There is no slot for us");
745 : static const JSJitInfo cancelBubble_setterinfo = {
746 : { (JSJitGetterOp)set_cancelBubble },
747 : { prototypes::id::Event },
748 : { PrototypeTraits<prototypes::id::Event>::Depth },
749 : JSJitInfo::Setter,
750 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
751 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
752 : false, /* isInfallible. False in setters. */
753 : false, /* isMovable. Not relevant for setters. */
754 : false, /* isEliminatable. Not relevant for setters. */
755 : false, /* isAlwaysInSlot. Only relevant for getters. */
756 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
757 : false, /* isTypedMethod. Only relevant for methods. */
758 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
759 : };
760 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
761 : static_assert(0 < 1, "There is no slot for us");
762 :
763 : static bool
764 7 : get_originalTarget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
765 : {
766 7 : auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetOriginalTarget()));
767 7 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
768 7 : if (!result) {
769 0 : args.rval().setNull();
770 0 : return true;
771 : }
772 7 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
773 0 : if (!HandleNewBindingWrappingFailure(cx, obj, result, args.rval())) {
774 0 : return false;
775 : }
776 0 : return true;
777 : }
778 7 : return true;
779 : }
780 :
781 : static const JSJitInfo originalTarget_getterinfo = {
782 : { (JSJitGetterOp)get_originalTarget },
783 : { prototypes::id::Event },
784 : { PrototypeTraits<prototypes::id::Event>::Depth },
785 : JSJitInfo::Getter,
786 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
787 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
788 : false, /* isInfallible. False in setters. */
789 : false, /* isMovable. Not relevant for setters. */
790 : false, /* isEliminatable. Not relevant for setters. */
791 : false, /* isAlwaysInSlot. Only relevant for getters. */
792 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
793 : false, /* isTypedMethod. Only relevant for methods. */
794 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
795 : };
796 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
797 : static_assert(0 < 1, "There is no slot for us");
798 :
799 : static bool
800 0 : get_explicitOriginalTarget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
801 : {
802 0 : auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetExplicitOriginalTarget()));
803 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
804 0 : if (!result) {
805 0 : args.rval().setNull();
806 0 : return true;
807 : }
808 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
809 0 : if (!HandleNewBindingWrappingFailure(cx, obj, result, args.rval())) {
810 0 : return false;
811 : }
812 0 : return true;
813 : }
814 0 : return true;
815 : }
816 :
817 : static const JSJitInfo explicitOriginalTarget_getterinfo = {
818 : { (JSJitGetterOp)get_explicitOriginalTarget },
819 : { prototypes::id::Event },
820 : { PrototypeTraits<prototypes::id::Event>::Depth },
821 : JSJitInfo::Getter,
822 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
823 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
824 : false, /* isInfallible. False in setters. */
825 : false, /* isMovable. Not relevant for setters. */
826 : false, /* isEliminatable. Not relevant for setters. */
827 : false, /* isAlwaysInSlot. Only relevant for getters. */
828 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
829 : false, /* isTypedMethod. Only relevant for methods. */
830 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
831 : };
832 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
833 : static_assert(0 < 1, "There is no slot for us");
834 :
835 : static bool
836 0 : get_composedTarget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
837 : {
838 0 : auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetComposedTarget()));
839 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
840 0 : if (!result) {
841 0 : args.rval().setNull();
842 0 : return true;
843 : }
844 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
845 0 : if (!HandleNewBindingWrappingFailure(cx, obj, result, args.rval())) {
846 0 : return false;
847 : }
848 0 : return true;
849 : }
850 0 : return true;
851 : }
852 :
853 : static const JSJitInfo composedTarget_getterinfo = {
854 : { (JSJitGetterOp)get_composedTarget },
855 : { prototypes::id::Event },
856 : { PrototypeTraits<prototypes::id::Event>::Depth },
857 : JSJitInfo::Getter,
858 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
859 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
860 : false, /* isInfallible. False in setters. */
861 : false, /* isMovable. Not relevant for setters. */
862 : false, /* isEliminatable. Not relevant for setters. */
863 : false, /* isAlwaysInSlot. Only relevant for getters. */
864 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
865 : false, /* isTypedMethod. Only relevant for methods. */
866 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
867 : };
868 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
869 : static_assert(0 < 1, "There is no slot for us");
870 :
871 : static bool
872 0 : get_multipleActionsPrevented(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
873 : {
874 0 : bool result(self->MultipleActionsPrevented());
875 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
876 0 : args.rval().setBoolean(result);
877 0 : return true;
878 : }
879 :
880 : static const JSJitInfo multipleActionsPrevented_getterinfo = {
881 : { (JSJitGetterOp)get_multipleActionsPrevented },
882 : { prototypes::id::Event },
883 : { PrototypeTraits<prototypes::id::Event>::Depth },
884 : JSJitInfo::Getter,
885 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
886 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
887 : true, /* isInfallible. False in setters. */
888 : false, /* isMovable. Not relevant for setters. */
889 : false, /* isEliminatable. Not relevant for setters. */
890 : false, /* isAlwaysInSlot. Only relevant for getters. */
891 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
892 : false, /* isTypedMethod. Only relevant for methods. */
893 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
894 : };
895 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
896 : static_assert(0 < 1, "There is no slot for us");
897 :
898 : static bool
899 0 : get_isSynthesized(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
900 : {
901 0 : bool result(self->IsSynthesized());
902 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
903 0 : args.rval().setBoolean(result);
904 0 : return true;
905 : }
906 :
907 : static const JSJitInfo isSynthesized_getterinfo = {
908 : { (JSJitGetterOp)get_isSynthesized },
909 : { prototypes::id::Event },
910 : { PrototypeTraits<prototypes::id::Event>::Depth },
911 : JSJitInfo::Getter,
912 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
913 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
914 : true, /* isInfallible. False in setters. */
915 : false, /* isMovable. Not relevant for setters. */
916 : false, /* isEliminatable. Not relevant for setters. */
917 : false, /* isAlwaysInSlot. Only relevant for getters. */
918 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
919 : false, /* isTypedMethod. Only relevant for methods. */
920 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
921 : };
922 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
923 : static_assert(0 < 1, "There is no slot for us");
924 :
925 : static bool
926 0 : getPreventDefault(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, const JSJitMethodCallArgs& args)
927 : {
928 0 : bool result(self->GetPreventDefault());
929 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
930 0 : args.rval().setBoolean(result);
931 0 : return true;
932 : }
933 :
934 : static const JSJitInfo getPreventDefault_methodinfo = {
935 : { (JSJitGetterOp)getPreventDefault },
936 : { prototypes::id::Event },
937 : { PrototypeTraits<prototypes::id::Event>::Depth },
938 : JSJitInfo::Method,
939 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
940 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
941 : true, /* isInfallible. False in setters. */
942 : false, /* isMovable. Not relevant for setters. */
943 : false, /* isEliminatable. Not relevant for setters. */
944 : false, /* isAlwaysInSlot. Only relevant for getters. */
945 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
946 : false, /* isTypedMethod. Only relevant for methods. */
947 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
948 : };
949 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
950 : static_assert(0 < 1, "There is no slot for us");
951 :
952 : static bool
953 20 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
954 : {
955 20 : mozilla::dom::Event* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Event>(obj);
956 : // We don't want to preserve if we don't have a wrapper, and we
957 : // obviously can't preserve if we're not initialized.
958 20 : if (self && self->GetWrapperPreserveColor()) {
959 0 : PreserveWrapper(self);
960 : }
961 20 : return true;
962 : }
963 :
964 : static void
965 20 : _finalize(js::FreeOp* fop, JSObject* obj)
966 : {
967 20 : mozilla::dom::Event* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Event>(obj);
968 20 : if (self) {
969 20 : ClearWrapper(self, self, obj);
970 20 : AddForDeferredFinalization<mozilla::dom::Event>(self);
971 : }
972 20 : }
973 :
974 : static void
975 17 : _objectMoved(JSObject* obj, const JSObject* old)
976 : {
977 17 : mozilla::dom::Event* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Event>(obj);
978 17 : if (self) {
979 0 : UpdateWrapper(self, self, obj, old);
980 : }
981 17 : }
982 :
983 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
984 : #if defined(__clang__)
985 : #pragma clang diagnostic push
986 : #pragma clang diagnostic ignored "-Wmissing-braces"
987 : #endif
988 : static const JSFunctionSpec sMethods_specs[] = {
989 : JS_FNSPEC("stopPropagation", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&stopPropagation_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
990 : JS_FNSPEC("stopImmediatePropagation", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&stopImmediatePropagation_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
991 : JS_FNSPEC("preventDefault", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&preventDefault_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
992 : JS_FNSPEC("initEvent", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&initEvent_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
993 : JS_FNSPEC("getPreventDefault", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getPreventDefault_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
994 : JS_FS_END,
995 : JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
996 : JS_FS_END
997 : };
998 : #if defined(__clang__)
999 : #pragma clang diagnostic pop
1000 : #endif
1001 :
1002 : static PrefableDisablers sMethods_disablers6 = {
1003 : true, false, 0, &WantsQueryInterface<mozilla::dom::Event>::Enabled
1004 : };
1005 :
1006 : // Can't be const because the pref-enabled boolean needs to be writable
1007 : static Prefable<const JSFunctionSpec> sMethods[] = {
1008 : { nullptr, &sMethods_specs[0] },
1009 : { &sMethods_disablers6, &sMethods_specs[6] },
1010 : { nullptr, nullptr }
1011 : };
1012 :
1013 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1014 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1015 : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1016 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1017 :
1018 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
1019 : #if defined(__clang__)
1020 : #pragma clang diagnostic push
1021 : #pragma clang diagnostic ignored "-Wmissing-braces"
1022 : #endif
1023 : static const JSPropertySpec sAttributes_specs[] = {
1024 : { "type", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &type_getterinfo, nullptr, nullptr },
1025 : { "target", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &target_getterinfo, nullptr, nullptr },
1026 : { "currentTarget", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, ¤tTarget_getterinfo, nullptr, nullptr },
1027 : { "eventPhase", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &eventPhase_getterinfo, nullptr, nullptr },
1028 : { "bubbles", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &bubbles_getterinfo, nullptr, nullptr },
1029 : { "cancelable", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &cancelable_getterinfo, nullptr, nullptr },
1030 : { "defaultPrevented", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &defaultPrevented_getterinfo, nullptr, nullptr },
1031 : { "composed", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &composed_getterinfo, nullptr, nullptr },
1032 : { "timeStamp", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &timeStamp_getterinfo, nullptr, nullptr },
1033 : { "cancelBubble", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &cancelBubble_getterinfo, GenericBindingSetter, &cancelBubble_setterinfo },
1034 : { "originalTarget", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &originalTarget_getterinfo, nullptr, nullptr },
1035 : { "explicitOriginalTarget", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &explicitOriginalTarget_getterinfo, nullptr, nullptr },
1036 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1037 : };
1038 : #if defined(__clang__)
1039 : #pragma clang diagnostic pop
1040 : #endif
1041 :
1042 :
1043 : // Can't be const because the pref-enabled boolean needs to be writable
1044 : static Prefable<const JSPropertySpec> sAttributes[] = {
1045 : { nullptr, &sAttributes_specs[0] },
1046 : { nullptr, nullptr }
1047 : };
1048 :
1049 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1050 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1051 : static_assert(12 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1052 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1053 :
1054 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
1055 : #if defined(__clang__)
1056 : #pragma clang diagnostic push
1057 : #pragma clang diagnostic ignored "-Wmissing-braces"
1058 : #endif
1059 : static const JSPropertySpec sChromeAttributes_specs[] = {
1060 : { "defaultPreventedByChrome", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &defaultPreventedByChrome_getterinfo, nullptr, nullptr },
1061 : { "defaultPreventedByContent", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &defaultPreventedByContent_getterinfo, nullptr, nullptr },
1062 : { "composedTarget", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &composedTarget_getterinfo, nullptr, nullptr },
1063 : { "multipleActionsPrevented", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &multipleActionsPrevented_getterinfo, nullptr, nullptr },
1064 : { "isSynthesized", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &isSynthesized_getterinfo, nullptr, nullptr },
1065 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1066 : };
1067 : #if defined(__clang__)
1068 : #pragma clang diagnostic pop
1069 : #endif
1070 :
1071 :
1072 : // Can't be const because the pref-enabled boolean needs to be writable
1073 : static Prefable<const JSPropertySpec> sChromeAttributes[] = {
1074 : { nullptr, &sChromeAttributes_specs[0] },
1075 : { nullptr, nullptr }
1076 : };
1077 :
1078 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1079 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1080 : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1081 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1082 :
1083 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
1084 : #if defined(__clang__)
1085 : #pragma clang diagnostic push
1086 : #pragma clang diagnostic ignored "-Wmissing-braces"
1087 : #endif
1088 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
1089 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
1090 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1091 : };
1092 : #if defined(__clang__)
1093 : #pragma clang diagnostic pop
1094 : #endif
1095 :
1096 :
1097 : // Can't be const because the pref-enabled boolean needs to be writable
1098 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
1099 : { nullptr, &sUnforgeableAttributes_specs[0] },
1100 : { nullptr, nullptr }
1101 : };
1102 :
1103 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1104 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1105 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1106 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1107 :
1108 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
1109 : #if defined(__clang__)
1110 : #pragma clang diagnostic push
1111 : #pragma clang diagnostic ignored "-Wmissing-braces"
1112 : #endif
1113 : static const ConstantSpec sConstants_specs[] = {
1114 : { "NONE", JS::Int32Value(0) },
1115 : { "CAPTURING_PHASE", JS::Int32Value(1) },
1116 : { "AT_TARGET", JS::Int32Value(2) },
1117 : { "BUBBLING_PHASE", JS::Int32Value(3) },
1118 : { "ALT_MASK", JS::Int32Value(1) },
1119 : { "CONTROL_MASK", JS::Int32Value(2) },
1120 : { "SHIFT_MASK", JS::Int32Value(4) },
1121 : { "META_MASK", JS::Int32Value(8) },
1122 : { 0, JS::UndefinedValue() }
1123 : };
1124 : #if defined(__clang__)
1125 : #pragma clang diagnostic pop
1126 : #endif
1127 :
1128 :
1129 : // Can't be const because the pref-enabled boolean needs to be writable
1130 : static Prefable<const ConstantSpec> sConstants[] = {
1131 : { nullptr, &sConstants_specs[0] },
1132 : { nullptr, nullptr }
1133 : };
1134 :
1135 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1136 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1137 : static_assert(8 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1138 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1139 :
1140 :
1141 : static uint16_t sNativeProperties_sortedPropertyIndices[27];
1142 : static PropertyInfo sNativeProperties_propertyInfos[27];
1143 :
1144 : static const NativePropertiesN<4> sNativeProperties = {
1145 : false, 0,
1146 : false, 0,
1147 : true, 0 /* sMethods */,
1148 : true, 1 /* sAttributes */,
1149 : false, 0,
1150 : true, 2 /* sUnforgeableAttributes */,
1151 : true, 3 /* sConstants */,
1152 : -1,
1153 : 27,
1154 : sNativeProperties_sortedPropertyIndices,
1155 : {
1156 : { sMethods, &sNativeProperties_propertyInfos[0] },
1157 : { sAttributes, &sNativeProperties_propertyInfos[6] },
1158 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[18] },
1159 : { sConstants, &sNativeProperties_propertyInfos[19] }
1160 : }
1161 : };
1162 : static_assert(27 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1163 : "We have a property info count that is oversized");
1164 :
1165 : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[5];
1166 : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[5];
1167 :
1168 : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
1169 : false, 0,
1170 : false, 0,
1171 : false, 0,
1172 : true, 0 /* sChromeAttributes */,
1173 : false, 0,
1174 : false, 0,
1175 : false, 0,
1176 : -1,
1177 : 5,
1178 : sChromeOnlyNativeProperties_sortedPropertyIndices,
1179 : {
1180 : { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[0] }
1181 : }
1182 : };
1183 : static_assert(5 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
1184 : "We have a property info count that is oversized");
1185 :
1186 : static bool
1187 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
1188 : {
1189 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1190 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
1191 0 : if (!args.isConstructing()) {
1192 : // XXXbz wish I could get the name from the callee instead of
1193 : // Adding more relocations
1194 0 : return ThrowConstructorWithoutNew(cx, "Event");
1195 : }
1196 :
1197 0 : GlobalObject global(cx, obj);
1198 0 : if (global.Failed()) {
1199 0 : return false;
1200 : }
1201 :
1202 0 : JS::Rooted<JSObject*> desiredProto(cx);
1203 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
1204 0 : return false;
1205 : }
1206 :
1207 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
1208 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Event");
1209 : }
1210 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1211 0 : binding_detail::FakeString arg0;
1212 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1213 0 : return false;
1214 : }
1215 0 : binding_detail::FastEventInit arg1;
1216 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of Event.constructor", false)) {
1217 0 : return false;
1218 : }
1219 0 : Maybe<JSAutoCompartment> ac;
1220 0 : if (objIsXray) {
1221 0 : obj = js::CheckedUnwrap(obj);
1222 0 : if (!obj) {
1223 0 : return false;
1224 : }
1225 0 : ac.emplace(cx, obj);
1226 0 : if (!JS_WrapObject(cx, &desiredProto)) {
1227 0 : return false;
1228 : }
1229 : }
1230 0 : binding_detail::FastErrorResult rv;
1231 0 : auto result(StrongOrRawPtr<mozilla::dom::Event>(mozilla::dom::Event::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
1232 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1233 0 : return false;
1234 : }
1235 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1236 : static_assert(!IsPointer<decltype(result)>::value,
1237 : "NewObject implies that we need to keep the object alive with a strong reference.");
1238 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
1239 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
1240 0 : return false;
1241 : }
1242 0 : return true;
1243 : }
1244 :
1245 : static const js::ClassOps sInterfaceObjectClassOps = {
1246 : nullptr, /* addProperty */
1247 : nullptr, /* delProperty */
1248 : nullptr, /* getProperty */
1249 : nullptr, /* setProperty */
1250 : nullptr, /* enumerate */
1251 : nullptr, /* newEnumerate */
1252 : nullptr, /* resolve */
1253 : nullptr, /* mayResolve */
1254 : nullptr, /* finalize */
1255 : _constructor, /* call */
1256 : nullptr, /* hasInstance */
1257 : _constructor, /* construct */
1258 : nullptr, /* trace */
1259 : };
1260 :
1261 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1262 : {
1263 : "Function",
1264 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1265 : &sInterfaceObjectClassOps,
1266 : JS_NULL_CLASS_SPEC,
1267 : JS_NULL_CLASS_EXT,
1268 : &sInterfaceObjectClassObjectOps
1269 : },
1270 : eInterface,
1271 : true,
1272 : prototypes::id::Event,
1273 : PrototypeTraits<prototypes::id::Event>::Depth,
1274 : sNativePropertyHooks,
1275 : "function Event() {\n [native code]\n}",
1276 : JS::GetRealmFunctionPrototype
1277 : };
1278 :
1279 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1280 : {
1281 : "EventPrototype",
1282 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
1283 : JS_NULL_CLASS_OPS,
1284 : JS_NULL_CLASS_SPEC,
1285 : JS_NULL_CLASS_EXT,
1286 : JS_NULL_OBJECT_OPS
1287 : },
1288 : eInterfacePrototype,
1289 : false,
1290 : prototypes::id::Event,
1291 : PrototypeTraits<prototypes::id::Event>::Depth,
1292 : sNativePropertyHooks,
1293 : "[object EventPrototype]",
1294 : JS::GetRealmObjectPrototype
1295 : };
1296 :
1297 : JSObject*
1298 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
1299 : {
1300 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
1301 : }
1302 :
1303 : static const js::ClassOps sClassOps = {
1304 : _addProperty, /* addProperty */
1305 : nullptr, /* delProperty */
1306 : nullptr, /* getProperty */
1307 : nullptr, /* setProperty */
1308 : nullptr, /* enumerate */
1309 : nullptr, /* newEnumerate */
1310 : nullptr, /* resolve */
1311 : nullptr, /* mayResolve */
1312 : _finalize, /* finalize */
1313 : nullptr, /* call */
1314 : nullptr, /* hasInstance */
1315 : nullptr, /* construct */
1316 : nullptr, /* trace */
1317 : };
1318 :
1319 : static const js::ClassExtension sClassExtension = {
1320 : nullptr, /* weakmapKeyDelegateOp */
1321 : _objectMoved /* objectMovedOp */
1322 : };
1323 :
1324 : static const DOMJSClass sClass = {
1325 : { "Event",
1326 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
1327 : &sClassOps,
1328 : JS_NULL_CLASS_SPEC,
1329 : &sClassExtension,
1330 : JS_NULL_OBJECT_OPS
1331 : },
1332 : { prototypes::id::Event, 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 },
1333 : IsBaseOf<nsISupports, mozilla::dom::Event >::value,
1334 : sNativePropertyHooks,
1335 : FindAssociatedGlobalForNative<mozilla::dom::Event>::Get,
1336 : GetProtoObjectHandle,
1337 : GetCCParticipant<mozilla::dom::Event>::Get()
1338 : };
1339 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1340 : "Must have the right minimal number of reserved slots.");
1341 : static_assert(1 >= 1,
1342 : "Must have enough reserved slots.");
1343 :
1344 : const JSClass*
1345 0 : GetJSClass()
1346 : {
1347 0 : return sClass.ToJSClass();
1348 : }
1349 :
1350 : bool
1351 27 : Wrap(JSContext* aCx, mozilla::dom::Event* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1352 : {
1353 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
1354 : reinterpret_cast<mozilla::dom::Event*>(aObject),
1355 : "Multiple inheritance for mozilla::dom::Event is broken.");
1356 27 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1357 27 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1358 27 : MOZ_ASSERT(!aCache->GetWrapper(),
1359 : "You should probably not be using Wrap() directly; use "
1360 : "GetOrCreateDOMReflector instead");
1361 :
1362 27 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1363 : "nsISupports must be on our primary inheritance chain");
1364 :
1365 54 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1366 27 : if (!global) {
1367 0 : return false;
1368 : }
1369 27 : MOZ_ASSERT(JS_IsGlobalObject(global));
1370 27 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
1371 :
1372 : // That might have ended up wrapping us already, due to the wonders
1373 : // of XBL. Check for that, and bail out as needed.
1374 27 : aReflector.set(aCache->GetWrapper());
1375 27 : if (aReflector) {
1376 : #ifdef DEBUG
1377 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1378 : #endif // DEBUG
1379 0 : return true;
1380 : }
1381 :
1382 54 : JSAutoCompartment ac(aCx, global);
1383 27 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1384 27 : if (!canonicalProto) {
1385 0 : return false;
1386 : }
1387 54 : JS::Rooted<JSObject*> proto(aCx);
1388 27 : if (aGivenProto) {
1389 0 : proto = aGivenProto;
1390 : // Unfortunately, while aGivenProto was in the compartment of aCx
1391 : // coming in, we changed compartments to that of "parent" so may need
1392 : // to wrap the proto here.
1393 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1394 0 : if (!JS_WrapObject(aCx, &proto)) {
1395 0 : return false;
1396 : }
1397 : }
1398 : } else {
1399 27 : proto = canonicalProto;
1400 : }
1401 :
1402 54 : BindingJSObjectCreator<mozilla::dom::Event> creator(aCx);
1403 27 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1404 27 : if (!aReflector) {
1405 0 : return false;
1406 : }
1407 :
1408 27 : aCache->SetWrapper(aReflector);
1409 :
1410 : // Important: do unforgeable property setup after we have handed
1411 : // over ownership of the C++ object to obj as needed, so that if
1412 : // we fail and it ends up GCed it won't have problems in the
1413 : // finalizer trying to drop its ownership of the C++ object.
1414 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
1415 54 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
1416 27 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
1417 0 : aCache->ReleaseWrapper(aObject);
1418 0 : aCache->ClearWrapper();
1419 0 : return false;
1420 : }
1421 27 : creator.InitializationSucceeded();
1422 :
1423 27 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1424 : aCache->GetWrapperPreserveColor() == aReflector);
1425 : // If proto != canonicalProto, we have to preserve our wrapper;
1426 : // otherwise we won't be able to properly recreate it later, since
1427 : // we won't know what proto to use. Note that we don't check
1428 : // aGivenProto here, since it's entirely possible (and even
1429 : // somewhat common) to have a non-null aGivenProto which is the
1430 : // same as canonicalProto.
1431 27 : if (proto != canonicalProto) {
1432 0 : PreserveWrapper(aObject);
1433 : }
1434 :
1435 27 : return true;
1436 : }
1437 :
1438 : const NativePropertyHooks sNativePropertyHooks[] = { {
1439 : nullptr,
1440 : nullptr,
1441 : nullptr,
1442 : { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
1443 : prototypes::id::Event,
1444 : constructors::id::Event,
1445 : nullptr,
1446 : &DefaultXrayExpandoObjectClass
1447 : } };
1448 :
1449 : void
1450 20 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1451 : {
1452 40 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1453 20 : if (!parentProto) {
1454 0 : return;
1455 : }
1456 :
1457 40 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1458 20 : if (!constructorProto) {
1459 0 : return;
1460 : }
1461 :
1462 : static bool sIdsInited = false;
1463 20 : if (!sIdsInited && NS_IsMainThread()) {
1464 2 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1465 0 : return;
1466 : }
1467 2 : if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
1468 0 : return;
1469 : }
1470 2 : sIdsInited = true;
1471 : }
1472 :
1473 20 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Event);
1474 20 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Event);
1475 60 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1476 : &sPrototypeClass.mBase, protoCache,
1477 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
1478 : interfaceCache,
1479 : sNativeProperties.Upcast(),
1480 20 : nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
1481 : "Event", aDefineOnGlobal,
1482 : nullptr,
1483 20 : false);
1484 :
1485 40 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
1486 : {
1487 40 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
1488 20 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
1489 20 : if (!unforgeableHolder) {
1490 0 : *protoCache = nullptr;
1491 0 : if (interfaceCache) {
1492 0 : *interfaceCache = nullptr;
1493 : }
1494 0 : return;
1495 : }
1496 : }
1497 :
1498 20 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
1499 0 : *protoCache = nullptr;
1500 0 : if (interfaceCache) {
1501 0 : *interfaceCache = nullptr;
1502 : }
1503 0 : return;
1504 : }
1505 :
1506 20 : if (*protoCache) {
1507 20 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
1508 40 : JS::ObjectValue(*unforgeableHolder));
1509 : }
1510 : }
1511 :
1512 : JS::Handle<JSObject*>
1513 66 : GetProtoObjectHandle(JSContext* aCx)
1514 : {
1515 : /* Get the interface prototype object for this class. This will create the
1516 : object as needed. */
1517 66 : bool aDefineOnGlobal = true;
1518 :
1519 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1520 66 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1521 66 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1522 0 : return nullptr;
1523 : }
1524 :
1525 : /* Check to see whether the interface objects are already installed */
1526 66 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1527 66 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::Event)) {
1528 40 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1529 20 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1530 : }
1531 :
1532 : /*
1533 : * The object might _still_ be null, but that's OK.
1534 : *
1535 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1536 : * traced by TraceProtoAndIfaceCache() and its contents are never
1537 : * changed after they have been set.
1538 : *
1539 : * Calling address() avoids the read read barrier that does gray
1540 : * unmarking, but it's not possible for the object to be gray here.
1541 : */
1542 :
1543 66 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::Event);
1544 66 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1545 66 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1546 : }
1547 :
1548 : JSObject*
1549 7 : GetProtoObject(JSContext* aCx)
1550 : {
1551 7 : return GetProtoObjectHandle(aCx);
1552 : }
1553 :
1554 : JS::Handle<JSObject*>
1555 30 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1556 : {
1557 : /* Get the interface object for this class. This will create the object as
1558 : needed. */
1559 :
1560 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1561 30 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1562 30 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1563 0 : return nullptr;
1564 : }
1565 :
1566 : /* Check to see whether the interface objects are already installed */
1567 30 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1568 30 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::Event)) {
1569 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1570 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1571 : }
1572 :
1573 : /*
1574 : * The object might _still_ be null, but that's OK.
1575 : *
1576 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1577 : * traced by TraceProtoAndIfaceCache() and its contents are never
1578 : * changed after they have been set.
1579 : *
1580 : * Calling address() avoids the read read barrier that does gray
1581 : * unmarking, but it's not possible for the object to be gray here.
1582 : */
1583 :
1584 30 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::Event);
1585 30 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1586 30 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1587 : }
1588 :
1589 : JSObject*
1590 1 : GetConstructorObject(JSContext* aCx)
1591 : {
1592 1 : return GetConstructorObjectHandle(aCx);
1593 : }
1594 :
1595 : } // namespace EventBinding
1596 :
1597 :
1598 :
1599 : } // namespace dom
1600 : } // namespace mozilla
|