Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM CommandEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "CommandEventBinding.h"
4 : #include "EventBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/OwningNonNull.h"
7 : #include "mozilla/dom/BindingUtils.h"
8 : #include "mozilla/dom/CommandEvent.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/NonRefcountedDOMObject.h"
11 : #include "mozilla/dom/Nullable.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/XrayExpandoClass.h"
14 :
15 : namespace mozilla {
16 : namespace dom {
17 :
18 : namespace CommandEventBinding {
19 :
20 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
21 : "Can't inherit from an interface with a different ownership model.");
22 :
23 : static bool
24 0 : get_command(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CommandEvent* self, JSJitGetterCallArgs args)
25 : {
26 0 : DOMString result;
27 0 : self->GetCommand(result);
28 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
29 0 : if (!xpc::StringToJsval(cx, result, args.rval())) {
30 0 : return false;
31 : }
32 0 : return true;
33 : }
34 :
35 : static const JSJitInfo command_getterinfo = {
36 : { (JSJitGetterOp)get_command },
37 : { prototypes::id::CommandEvent },
38 : { PrototypeTraits<prototypes::id::CommandEvent>::Depth },
39 : JSJitInfo::Getter,
40 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
41 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
42 : false, /* isInfallible. False in setters. */
43 : false, /* isMovable. Not relevant for setters. */
44 : false, /* isEliminatable. Not relevant for setters. */
45 : false, /* isAlwaysInSlot. Only relevant for getters. */
46 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
47 : false, /* isTypedMethod. Only relevant for methods. */
48 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
49 : };
50 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
51 : static_assert(0 < 1, "There is no slot for us");
52 :
53 : static bool
54 0 : initCommandEvent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CommandEvent* self, const JSJitMethodCallArgs& args)
55 : {
56 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
57 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CommandEvent.initCommandEvent");
58 : }
59 0 : binding_detail::FakeString arg0;
60 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
61 0 : return false;
62 : }
63 : bool arg1;
64 0 : if (args.hasDefined(1)) {
65 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) {
66 0 : return false;
67 : }
68 : } else {
69 0 : arg1 = false;
70 : }
71 : bool arg2;
72 0 : if (args.hasDefined(2)) {
73 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) {
74 0 : return false;
75 : }
76 : } else {
77 0 : arg2 = false;
78 : }
79 0 : binding_detail::FakeString arg3;
80 0 : if (args.hasDefined(3)) {
81 0 : if (!ConvertJSValueToString(cx, args[3], eNull, eNull, arg3)) {
82 0 : return false;
83 : }
84 : } else {
85 0 : arg3.SetIsVoid(true);
86 : }
87 0 : self->InitCommandEvent(NonNullHelper(Constify(arg0)), arg1, arg2, NonNullHelper(Constify(arg3)));
88 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
89 0 : args.rval().setUndefined();
90 0 : return true;
91 : }
92 :
93 : static const JSJitInfo initCommandEvent_methodinfo = {
94 : { (JSJitGetterOp)initCommandEvent },
95 : { prototypes::id::CommandEvent },
96 : { PrototypeTraits<prototypes::id::CommandEvent>::Depth },
97 : JSJitInfo::Method,
98 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
99 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
100 : false, /* isInfallible. False in setters. */
101 : false, /* isMovable. Not relevant for setters. */
102 : false, /* isEliminatable. Not relevant for setters. */
103 : false, /* isAlwaysInSlot. Only relevant for getters. */
104 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
105 : false, /* isTypedMethod. Only relevant for methods. */
106 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
107 : };
108 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
109 : static_assert(0 < 1, "There is no slot for us");
110 :
111 : static bool
112 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CommandEvent* self, JSJitGetterCallArgs args)
113 : {
114 0 : bool result(self->IsTrusted());
115 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
116 0 : args.rval().setBoolean(result);
117 0 : return true;
118 : }
119 :
120 : static const JSJitInfo isTrusted_getterinfo = {
121 : { (JSJitGetterOp)get_isTrusted },
122 : { prototypes::id::CommandEvent },
123 : { PrototypeTraits<prototypes::id::CommandEvent>::Depth },
124 : JSJitInfo::Getter,
125 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
126 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
127 : true, /* isInfallible. False in setters. */
128 : true, /* isMovable. Not relevant for setters. */
129 : true, /* isEliminatable. Not relevant for setters. */
130 : false, /* isAlwaysInSlot. Only relevant for getters. */
131 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
132 : false, /* isTypedMethod. Only relevant for methods. */
133 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
134 : };
135 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
136 : static_assert(0 < 1, "There is no slot for us");
137 :
138 : static bool
139 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
140 : {
141 0 : mozilla::dom::CommandEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CommandEvent>(obj);
142 : // We don't want to preserve if we don't have a wrapper, and we
143 : // obviously can't preserve if we're not initialized.
144 0 : if (self && self->GetWrapperPreserveColor()) {
145 0 : PreserveWrapper(self);
146 : }
147 0 : return true;
148 : }
149 :
150 : static void
151 0 : _finalize(js::FreeOp* fop, JSObject* obj)
152 : {
153 0 : mozilla::dom::CommandEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CommandEvent>(obj);
154 0 : if (self) {
155 0 : ClearWrapper(self, self, obj);
156 0 : AddForDeferredFinalization<mozilla::dom::CommandEvent>(self);
157 : }
158 0 : }
159 :
160 : static void
161 0 : _objectMoved(JSObject* obj, const JSObject* old)
162 : {
163 0 : mozilla::dom::CommandEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CommandEvent>(obj);
164 0 : if (self) {
165 0 : UpdateWrapper(self, self, obj, old);
166 : }
167 0 : }
168 :
169 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
170 : #if defined(__clang__)
171 : #pragma clang diagnostic push
172 : #pragma clang diagnostic ignored "-Wmissing-braces"
173 : #endif
174 : static const JSFunctionSpec sMethods_specs[] = {
175 : JS_FNSPEC("initCommandEvent", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&initCommandEvent_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
176 : JS_FS_END
177 : };
178 : #if defined(__clang__)
179 : #pragma clang diagnostic pop
180 : #endif
181 :
182 :
183 : // Can't be const because the pref-enabled boolean needs to be writable
184 : static Prefable<const JSFunctionSpec> sMethods[] = {
185 : { nullptr, &sMethods_specs[0] },
186 : { nullptr, nullptr }
187 : };
188 :
189 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
190 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
191 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
192 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
193 :
194 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
195 : #if defined(__clang__)
196 : #pragma clang diagnostic push
197 : #pragma clang diagnostic ignored "-Wmissing-braces"
198 : #endif
199 : static const JSPropertySpec sAttributes_specs[] = {
200 : { "command", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &command_getterinfo, nullptr, nullptr },
201 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
202 : };
203 : #if defined(__clang__)
204 : #pragma clang diagnostic pop
205 : #endif
206 :
207 :
208 : // Can't be const because the pref-enabled boolean needs to be writable
209 : static Prefable<const JSPropertySpec> sAttributes[] = {
210 : { nullptr, &sAttributes_specs[0] },
211 : { nullptr, nullptr }
212 : };
213 :
214 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
215 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
216 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
217 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
218 :
219 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
220 : #if defined(__clang__)
221 : #pragma clang diagnostic push
222 : #pragma clang diagnostic ignored "-Wmissing-braces"
223 : #endif
224 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
225 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
226 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
227 : };
228 : #if defined(__clang__)
229 : #pragma clang diagnostic pop
230 : #endif
231 :
232 :
233 : // Can't be const because the pref-enabled boolean needs to be writable
234 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
235 : { nullptr, &sUnforgeableAttributes_specs[0] },
236 : { nullptr, nullptr }
237 : };
238 :
239 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
240 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
241 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
242 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
243 :
244 :
245 : static uint16_t sNativeProperties_sortedPropertyIndices[3];
246 : static PropertyInfo sNativeProperties_propertyInfos[3];
247 :
248 : static const NativePropertiesN<3> sNativeProperties = {
249 : false, 0,
250 : false, 0,
251 : true, 0 /* sMethods */,
252 : true, 1 /* sAttributes */,
253 : false, 0,
254 : true, 2 /* sUnforgeableAttributes */,
255 : false, 0,
256 : -1,
257 : 3,
258 : sNativeProperties_sortedPropertyIndices,
259 : {
260 : { sMethods, &sNativeProperties_propertyInfos[0] },
261 : { sAttributes, &sNativeProperties_propertyInfos[1] },
262 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[2] }
263 : }
264 : };
265 : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
266 : "We have a property info count that is oversized");
267 :
268 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
269 : {
270 : "Function",
271 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
272 : &sBoringInterfaceObjectClassClassOps,
273 : JS_NULL_CLASS_SPEC,
274 : JS_NULL_CLASS_EXT,
275 : &sInterfaceObjectClassObjectOps
276 : },
277 : eInterface,
278 : true,
279 : prototypes::id::CommandEvent,
280 : PrototypeTraits<prototypes::id::CommandEvent>::Depth,
281 : sNativePropertyHooks,
282 : "function CommandEvent() {\n [native code]\n}",
283 : EventBinding::GetConstructorObject
284 : };
285 :
286 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
287 : {
288 : "CommandEventPrototype",
289 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
290 : JS_NULL_CLASS_OPS,
291 : JS_NULL_CLASS_SPEC,
292 : JS_NULL_CLASS_EXT,
293 : JS_NULL_OBJECT_OPS
294 : },
295 : eInterfacePrototype,
296 : false,
297 : prototypes::id::CommandEvent,
298 : PrototypeTraits<prototypes::id::CommandEvent>::Depth,
299 : sNativePropertyHooks,
300 : "[object CommandEventPrototype]",
301 : EventBinding::GetProtoObject
302 : };
303 :
304 : bool
305 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
306 : {
307 0 : return IsChromeOrXBL(aCx, aObj);
308 : }
309 :
310 : JSObject*
311 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
312 : {
313 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
314 : }
315 :
316 : static const js::ClassOps sClassOps = {
317 : _addProperty, /* addProperty */
318 : nullptr, /* delProperty */
319 : nullptr, /* getProperty */
320 : nullptr, /* setProperty */
321 : nullptr, /* enumerate */
322 : nullptr, /* newEnumerate */
323 : nullptr, /* resolve */
324 : nullptr, /* mayResolve */
325 : _finalize, /* finalize */
326 : nullptr, /* call */
327 : nullptr, /* hasInstance */
328 : nullptr, /* construct */
329 : nullptr, /* trace */
330 : };
331 :
332 : static const js::ClassExtension sClassExtension = {
333 : nullptr, /* weakmapKeyDelegateOp */
334 : _objectMoved /* objectMovedOp */
335 : };
336 :
337 : static const DOMJSClass sClass = {
338 : { "CommandEvent",
339 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
340 : &sClassOps,
341 : JS_NULL_CLASS_SPEC,
342 : &sClassExtension,
343 : JS_NULL_OBJECT_OPS
344 : },
345 : { prototypes::id::Event, prototypes::id::CommandEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
346 : IsBaseOf<nsISupports, mozilla::dom::CommandEvent >::value,
347 : sNativePropertyHooks,
348 : FindAssociatedGlobalForNative<mozilla::dom::CommandEvent>::Get,
349 : GetProtoObjectHandle,
350 : GetCCParticipant<mozilla::dom::CommandEvent>::Get()
351 : };
352 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
353 : "Must have the right minimal number of reserved slots.");
354 : static_assert(1 >= 1,
355 : "Must have enough reserved slots.");
356 :
357 : const JSClass*
358 0 : GetJSClass()
359 : {
360 0 : return sClass.ToJSClass();
361 : }
362 :
363 : bool
364 0 : Wrap(JSContext* aCx, mozilla::dom::CommandEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
365 : {
366 : MOZ_ASSERT(static_cast<mozilla::dom::CommandEvent*>(aObject) ==
367 : reinterpret_cast<mozilla::dom::CommandEvent*>(aObject),
368 : "Multiple inheritance for mozilla::dom::CommandEvent is broken.");
369 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
370 : reinterpret_cast<mozilla::dom::Event*>(aObject),
371 : "Multiple inheritance for mozilla::dom::Event is broken.");
372 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
373 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
374 0 : MOZ_ASSERT(!aCache->GetWrapper(),
375 : "You should probably not be using Wrap() directly; use "
376 : "GetOrCreateDOMReflector instead");
377 :
378 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
379 : "nsISupports must be on our primary inheritance chain");
380 :
381 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
382 0 : if (!global) {
383 0 : return false;
384 : }
385 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
386 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
387 :
388 : // That might have ended up wrapping us already, due to the wonders
389 : // of XBL. Check for that, and bail out as needed.
390 0 : aReflector.set(aCache->GetWrapper());
391 0 : if (aReflector) {
392 : #ifdef DEBUG
393 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
394 : #endif // DEBUG
395 0 : return true;
396 : }
397 :
398 0 : JSAutoCompartment ac(aCx, global);
399 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
400 0 : if (!canonicalProto) {
401 0 : return false;
402 : }
403 0 : JS::Rooted<JSObject*> proto(aCx);
404 0 : if (aGivenProto) {
405 0 : proto = aGivenProto;
406 : // Unfortunately, while aGivenProto was in the compartment of aCx
407 : // coming in, we changed compartments to that of "parent" so may need
408 : // to wrap the proto here.
409 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
410 0 : if (!JS_WrapObject(aCx, &proto)) {
411 0 : return false;
412 : }
413 : }
414 : } else {
415 0 : proto = canonicalProto;
416 : }
417 :
418 0 : BindingJSObjectCreator<mozilla::dom::CommandEvent> creator(aCx);
419 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
420 0 : if (!aReflector) {
421 0 : return false;
422 : }
423 :
424 0 : aCache->SetWrapper(aReflector);
425 :
426 : // Important: do unforgeable property setup after we have handed
427 : // over ownership of the C++ object to obj as needed, so that if
428 : // we fail and it ends up GCed it won't have problems in the
429 : // finalizer trying to drop its ownership of the C++ object.
430 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
431 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
432 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
433 0 : aCache->ReleaseWrapper(aObject);
434 0 : aCache->ClearWrapper();
435 0 : return false;
436 : }
437 0 : creator.InitializationSucceeded();
438 :
439 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
440 : aCache->GetWrapperPreserveColor() == aReflector);
441 : // If proto != canonicalProto, we have to preserve our wrapper;
442 : // otherwise we won't be able to properly recreate it later, since
443 : // we won't know what proto to use. Note that we don't check
444 : // aGivenProto here, since it's entirely possible (and even
445 : // somewhat common) to have a non-null aGivenProto which is the
446 : // same as canonicalProto.
447 0 : if (proto != canonicalProto) {
448 0 : PreserveWrapper(aObject);
449 : }
450 :
451 0 : return true;
452 : }
453 :
454 : const NativePropertyHooks sNativePropertyHooks[] = { {
455 : nullptr,
456 : nullptr,
457 : nullptr,
458 : { sNativeProperties.Upcast(), nullptr },
459 : prototypes::id::CommandEvent,
460 : constructors::id::CommandEvent,
461 : EventBinding::sNativePropertyHooks,
462 : &DefaultXrayExpandoObjectClass
463 : } };
464 :
465 : void
466 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
467 : {
468 0 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
469 0 : if (!parentProto) {
470 0 : return;
471 : }
472 :
473 0 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
474 0 : if (!constructorProto) {
475 0 : return;
476 : }
477 :
478 : static bool sIdsInited = false;
479 0 : if (!sIdsInited && NS_IsMainThread()) {
480 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
481 0 : return;
482 : }
483 0 : sIdsInited = true;
484 : }
485 :
486 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CommandEvent);
487 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CommandEvent);
488 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
489 : &sPrototypeClass.mBase, protoCache,
490 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
491 : interfaceCache,
492 : sNativeProperties.Upcast(),
493 : nullptr,
494 : "CommandEvent", aDefineOnGlobal,
495 : nullptr,
496 0 : false);
497 :
498 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
499 : {
500 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
501 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
502 0 : if (!unforgeableHolder) {
503 0 : *protoCache = nullptr;
504 0 : if (interfaceCache) {
505 0 : *interfaceCache = nullptr;
506 : }
507 0 : return;
508 : }
509 : }
510 :
511 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
512 0 : *protoCache = nullptr;
513 0 : if (interfaceCache) {
514 0 : *interfaceCache = nullptr;
515 : }
516 0 : return;
517 : }
518 :
519 0 : if (*protoCache) {
520 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
521 0 : JS::ObjectValue(*unforgeableHolder));
522 : }
523 : }
524 :
525 : JS::Handle<JSObject*>
526 0 : GetProtoObjectHandle(JSContext* aCx)
527 : {
528 : /* Get the interface prototype object for this class. This will create the
529 : object as needed. */
530 0 : bool aDefineOnGlobal = true;
531 :
532 : /* Make sure our global is sane. Hopefully we can remove this sometime */
533 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
534 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
535 0 : return nullptr;
536 : }
537 :
538 : /* Check to see whether the interface objects are already installed */
539 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
540 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::CommandEvent)) {
541 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
542 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
543 : }
544 :
545 : /*
546 : * The object might _still_ be null, but that's OK.
547 : *
548 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
549 : * traced by TraceProtoAndIfaceCache() and its contents are never
550 : * changed after they have been set.
551 : *
552 : * Calling address() avoids the read read barrier that does gray
553 : * unmarking, but it's not possible for the object to be gray here.
554 : */
555 :
556 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::CommandEvent);
557 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
558 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
559 : }
560 :
561 : JS::Handle<JSObject*>
562 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
563 : {
564 : /* Get the interface object for this class. This will create the object as
565 : needed. */
566 :
567 : /* Make sure our global is sane. Hopefully we can remove this sometime */
568 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
569 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
570 0 : return nullptr;
571 : }
572 :
573 : /* Check to see whether the interface objects are already installed */
574 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
575 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::CommandEvent)) {
576 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
577 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
578 : }
579 :
580 : /*
581 : * The object might _still_ be null, but that's OK.
582 : *
583 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
584 : * traced by TraceProtoAndIfaceCache() and its contents are never
585 : * changed after they have been set.
586 : *
587 : * Calling address() avoids the read read barrier that does gray
588 : * unmarking, but it's not possible for the object to be gray here.
589 : */
590 :
591 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::CommandEvent);
592 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
593 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
594 : }
595 :
596 : JSObject*
597 0 : GetConstructorObject(JSContext* aCx)
598 : {
599 0 : return GetConstructorObjectHandle(aCx);
600 : }
601 :
602 : } // namespace CommandEventBinding
603 :
604 :
605 :
606 : } // namespace dom
607 : } // namespace mozilla
|