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