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