Source code

Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM TestJSImplInheritanceGen.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "AtomList.h"
#include "EventTargetBinding.h"
#include "MainThreadUtils.h"
#include "TestJSImplGenBinding.h"
#include "TestJSImplInheritanceGenBinding.h"
#include "WrapperFactory.h"
#include "js/CallAndConstruct.h"
#include "js/Exception.h"
#include "js/MapAndSet.h"
#include "js/Object.h"
#include "js/PropertyAndElement.h"
#include "js/PropertyDescriptor.h"
#include "js/experimental/JitInfo.h"
#include "mozilla/Atomics.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/BindingCallContext.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/XrayExpandoClass.h"
#include "nsContentUtils.h"
#include "nsIGlobalObject.h"
namespace mozilla::dom {
namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;
namespace TestJSImplInterface2_Binding {
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<TestCImplementedInterface_Binding::NativeType>::value,
"Can't inherit from an interface with a different ownership model.");
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::TestJSImplInterface2* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface2>(obj);
// We don't want to preserve if we don't have a wrapper, and we
// obviously can't preserve if we're not initialized.
if (self && self->GetWrapperPreserveColor()) {
PreserveWrapper(self);
}
return true;
}
static void
_finalize(JS::GCContext* gcx, JSObject* obj)
{
mozilla::dom::TestJSImplInterface2* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface2>(obj);
if (self) {
JS::SetReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue());
ClearWrapper(self, self, obj);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(obj, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<mozilla::dom::TestJSImplInterface2>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::TestJSImplInterface2* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface2>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::TestJSImplInterface2* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface2>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
JS_FNSPEC("_create", TestJSImplInterface2::_Create, nullptr, 2, 0, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
{ nullptr, &sChromeStaticMethods_specs[0] },
{ nullptr, nullptr }
};
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
true, 0 /* sChromeStaticMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
1,
sChromeOnlyNativeProperties_sortedPropertyIndices,
{
{ sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
}
};
static_assert(1 < 1ull << (CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ nullptr, sChromeOnlyNativeProperties.Upcast(), &sNativePropertiesInited },
prototypes::id::TestJSImplInterface2,
constructors::id::TestJSImplInterface2,
&DefaultXrayExpandoObjectClass
};
static bool
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestJSImplInterface2", "constructor", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.isConstructing()) {
return ThrowConstructorWithoutNew(cx, "TestJSImplInterface2");
}
JS::Rooted<JSObject*> desiredProto(cx);
if (!GetDesiredProto(cx, args,
prototypes::id::TestJSImplInterface2,
CreateInterfaceObjects,
&desiredProto)) {
return false;
}
GlobalObject global(cx, obj);
if (global.Failed()) {
return false;
}
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
Maybe<JSAutoRealm> ar;
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
obj = js::CheckedUnwrapStatic(obj);
if (!obj) {
return false;
}
ar.emplace(cx, obj);
if (!JS_WrapObject(cx, &desiredProto)) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<mozilla::dom::TestJSImplInterface2>(mozilla::dom::TestJSImplInterface2::Constructor(global, cx, rv, desiredProto)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestJSImplInterface2 constructor"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
static_assert(!std::is_pointer_v<decltype(result)>,
"NewObject implies that we need to keep the object alive with a strong reference.");
if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ _constructor, &sNativePropertyHooks },
TestCImplementedInterface_Binding::GetConstructorObject,
prototypes::id::TestJSImplInterface2,
PrototypeTraits<prototypes::id::TestJSImplInterface2>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"TestJSImplInterface2Prototype",
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
JS_NULL_CLASS_OPS,
JS_NULL_CLASS_SPEC,
JS_NULL_CLASS_EXT,
JS_NULL_OBJECT_OPS
},
eInterfacePrototype,
prototypes::id::TestJSImplInterface2,
PrototypeTraits<prototypes::id::TestJSImplInterface2>::Depth,
&sNativePropertyHooks,
TestCImplementedInterface_Binding::GetProtoObject
};
static const JSClassOps sClassOps = {
_addProperty, /* addProperty */
nullptr, /* delProperty */
nullptr, /* enumerate */
nullptr, /* newEnumerate */
nullptr, /* resolve */
nullptr, /* mayResolve */
_finalize, /* finalize */
nullptr, /* call */
nullptr, /* construct */
nullptr, /* trace */
};
static const js::ClassExtension sClassExtension = {
_objectMoved /* objectMovedOp */
};
static const DOMJSClass sClass = {
{ "TestJSImplInterface2",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::TestJSImplInterface, prototypes::id::TestCImplementedInterface, prototypes::id::TestJSImplInterface2, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
std::is_base_of_v<nsISupports, mozilla::dom::TestJSImplInterface2>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::TestJSImplInterface2>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::TestJSImplInterface2>::Get(),
nullptr,
_getWrapperCache
};
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
"Must have the right minimal number of reserved slots.");
static_assert(1 >= 1,
"Must have enough reserved slots.");
bool
Wrap(JSContext* aCx, mozilla::dom::TestJSImplInterface2* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::TestJSImplInterface2>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::TestJSImplInterface2*>);
MOZ_ASSERT(static_cast<mozilla::dom::TestCImplementedInterface*>(aObject) ==
reinterpret_cast<mozilla::dom::TestCImplementedInterface*>(aObject),
"Multiple inheritance for mozilla::dom::TestCImplementedInterface is broken.");
MOZ_ASSERT(static_cast<mozilla::dom::TestJSImplInterface*>(aObject) ==
reinterpret_cast<mozilla::dom::TestJSImplInterface*>(aObject),
"Multiple inheritance for mozilla::dom::TestJSImplInterface is broken.");
MOZ_ASSERT(ToSupportsIsCorrect(aObject));
MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
MOZ_ASSERT(!aCache->GetWrapper(),
"You should probably not be using Wrap() directly; use "
"GetOrCreateDOMReflector instead");
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
"nsISupports must be on our primary inheritance chain");
// If the wrapper cache contains a dead reflector then finalize that
// now, ensuring that the finalizer for the old reflector always
// runs before the new reflector is created and attached. This
// avoids the awkward situation where there are multiple reflector
// objects that contain pointers to the same native.
if (JSObject* oldReflector = aCache->GetWrapperMaybeDead()) {
_finalize(nullptr /* unused */, oldReflector);
MOZ_ASSERT(!aCache->GetWrapperMaybeDead());
}
JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
if (!global) {
return false;
}
MOZ_ASSERT(JS_IsGlobalObject(global));
JS::AssertObjectIsNotGray(global);
// That might have ended up wrapping us already, due to the wonders
// of XBL. Check for that, and bail out as needed.
aReflector.set(aCache->GetWrapper());
if (aReflector) {
#ifdef DEBUG
AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
#endif // DEBUG
return true;
}
JSAutoRealm ar(aCx, global);
JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
if (!canonicalProto) {
return false;
}
JS::Rooted<JSObject*> proto(aCx);
if (aGivenProto) {
proto = aGivenProto;
// Unfortunately, while aGivenProto was in the compartment of aCx
// coming in, we changed compartments to that of "parent" so may need
// to wrap the proto here.
if (js::GetContextCompartment(aCx) != JS::GetCompartment(proto)) {
if (!JS_WrapObject(aCx, &proto)) {
return false;
}
}
} else {
proto = canonicalProto;
}
BindingJSObjectCreator<mozilla::dom::TestJSImplInterface2> creator(aCx);
creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
if (!aReflector) {
return false;
}
aCache->SetWrapper(aReflector);
creator.InitializationSucceeded();
MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
aCache->GetWrapperPreserveColor() == aReflector);
// If proto != canonicalProto, we have to preserve our wrapper;
// otherwise we won't be able to properly recreate it later, since
// we won't know what proto to use. Note that we don't check
// aGivenProto here, since it's entirely possible (and even
// somewhat common) to have a non-null aGivenProto which is the
// same as canonicalProto.
if (proto != canonicalProto) {
PreserveWrapper(aObject);
}
return true;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TestJSImplInterface2);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TestJSImplInterface2);
JS::Handle<JSObject*> parentProto(TestCImplementedInterface_Binding::GetProtoObjectHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(TestCImplementedInterface_Binding::GetConstructorObjectHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
nullptr,
sChromeOnlyNativeProperties.Upcast(),
"TestJSImplInterface2", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace TestJSImplInterface2_Binding
namespace TestJSImplInterface3_Binding {
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<TestCImplementedInterface2_Binding::NativeType>::value,
"Can't inherit from an interface with a different ownership model.");
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::TestJSImplInterface3* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface3>(obj);
// We don't want to preserve if we don't have a wrapper, and we
// obviously can't preserve if we're not initialized.
if (self && self->GetWrapperPreserveColor()) {
PreserveWrapper(self);
}
return true;
}
static void
_finalize(JS::GCContext* gcx, JSObject* obj)
{
mozilla::dom::TestJSImplInterface3* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface3>(obj);
if (self) {
JS::SetReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue());
ClearWrapper(self, self, obj);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(obj, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<mozilla::dom::TestJSImplInterface3>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::TestJSImplInterface3* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface3>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::TestJSImplInterface3* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface3>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
JS_FNSPEC("_create", TestJSImplInterface3::_Create, nullptr, 2, 0, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
{ nullptr, &sChromeStaticMethods_specs[0] },
{ nullptr, nullptr }
};
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
true, 0 /* sChromeStaticMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
1,
sChromeOnlyNativeProperties_sortedPropertyIndices,
{
{ sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
}
};
static_assert(1 < 1ull << (CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ nullptr, sChromeOnlyNativeProperties.Upcast(), &sNativePropertiesInited },
prototypes::id::TestJSImplInterface3,
constructors::id::TestJSImplInterface3,
&DefaultXrayExpandoObjectClass
};
static bool
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestJSImplInterface3", "constructor", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.isConstructing()) {
return ThrowConstructorWithoutNew(cx, "TestJSImplInterface3");
}
JS::Rooted<JSObject*> desiredProto(cx);
if (!GetDesiredProto(cx, args,
prototypes::id::TestJSImplInterface3,
CreateInterfaceObjects,
&desiredProto)) {
return false;
}
GlobalObject global(cx, obj);
if (global.Failed()) {
return false;
}
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
Maybe<JSAutoRealm> ar;
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
obj = js::CheckedUnwrapStatic(obj);
if (!obj) {
return false;
}
ar.emplace(cx, obj);
if (!JS_WrapObject(cx, &desiredProto)) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<mozilla::dom::TestJSImplInterface3>(mozilla::dom::TestJSImplInterface3::Constructor(global, cx, rv, desiredProto)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestJSImplInterface3 constructor"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
static_assert(!std::is_pointer_v<decltype(result)>,
"NewObject implies that we need to keep the object alive with a strong reference.");
if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ _constructor, &sNativePropertyHooks },
TestCImplementedInterface2_Binding::GetConstructorObject,
prototypes::id::TestJSImplInterface3,
PrototypeTraits<prototypes::id::TestJSImplInterface3>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"TestJSImplInterface3Prototype",
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
JS_NULL_CLASS_OPS,
JS_NULL_CLASS_SPEC,
JS_NULL_CLASS_EXT,
JS_NULL_OBJECT_OPS
},
eInterfacePrototype,
prototypes::id::TestJSImplInterface3,
PrototypeTraits<prototypes::id::TestJSImplInterface3>::Depth,
&sNativePropertyHooks,
TestCImplementedInterface2_Binding::GetProtoObject
};
static const JSClassOps sClassOps = {
_addProperty, /* addProperty */
nullptr, /* delProperty */
nullptr, /* enumerate */
nullptr, /* newEnumerate */
nullptr, /* resolve */
nullptr, /* mayResolve */
_finalize, /* finalize */
nullptr, /* call */
nullptr, /* construct */
nullptr, /* trace */
};
static const js::ClassExtension sClassExtension = {
_objectMoved /* objectMovedOp */
};
static const DOMJSClass sClass = {
{ "TestJSImplInterface3",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::TestCImplementedInterface2, prototypes::id::TestJSImplInterface3, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
std::is_base_of_v<nsISupports, mozilla::dom::TestJSImplInterface3>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::TestJSImplInterface3>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::TestJSImplInterface3>::Get(),
nullptr,
_getWrapperCache
};
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
"Must have the right minimal number of reserved slots.");
static_assert(1 >= 1,
"Must have enough reserved slots.");
bool
Wrap(JSContext* aCx, mozilla::dom::TestJSImplInterface3* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::TestJSImplInterface3>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::TestJSImplInterface3*>);
MOZ_ASSERT(static_cast<mozilla::dom::TestCImplementedInterface2*>(aObject) ==
reinterpret_cast<mozilla::dom::TestCImplementedInterface2*>(aObject),
"Multiple inheritance for mozilla::dom::TestCImplementedInterface2 is broken.");
MOZ_ASSERT(ToSupportsIsCorrect(aObject));
MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
MOZ_ASSERT(!aCache->GetWrapper(),
"You should probably not be using Wrap() directly; use "
"GetOrCreateDOMReflector instead");
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
"nsISupports must be on our primary inheritance chain");
// If the wrapper cache contains a dead reflector then finalize that
// now, ensuring that the finalizer for the old reflector always
// runs before the new reflector is created and attached. This
// avoids the awkward situation where there are multiple reflector
// objects that contain pointers to the same native.
if (JSObject* oldReflector = aCache->GetWrapperMaybeDead()) {
_finalize(nullptr /* unused */, oldReflector);
MOZ_ASSERT(!aCache->GetWrapperMaybeDead());
}
JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
if (!global) {
return false;
}
MOZ_ASSERT(JS_IsGlobalObject(global));
JS::AssertObjectIsNotGray(global);
// That might have ended up wrapping us already, due to the wonders
// of XBL. Check for that, and bail out as needed.
aReflector.set(aCache->GetWrapper());
if (aReflector) {
#ifdef DEBUG
AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
#endif // DEBUG
return true;
}
JSAutoRealm ar(aCx, global);
JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
if (!canonicalProto) {
return false;
}
JS::Rooted<JSObject*> proto(aCx);
if (aGivenProto) {
proto = aGivenProto;
// Unfortunately, while aGivenProto was in the compartment of aCx
// coming in, we changed compartments to that of "parent" so may need
// to wrap the proto here.
if (js::GetContextCompartment(aCx) != JS::GetCompartment(proto)) {
if (!JS_WrapObject(aCx, &proto)) {
return false;
}
}
} else {
proto = canonicalProto;
}
BindingJSObjectCreator<mozilla::dom::TestJSImplInterface3> creator(aCx);
creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
if (!aReflector) {
return false;
}
aCache->SetWrapper(aReflector);
creator.InitializationSucceeded();
MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
aCache->GetWrapperPreserveColor() == aReflector);
// If proto != canonicalProto, we have to preserve our wrapper;
// otherwise we won't be able to properly recreate it later, since
// we won't know what proto to use. Note that we don't check
// aGivenProto here, since it's entirely possible (and even
// somewhat common) to have a non-null aGivenProto which is the
// same as canonicalProto.
if (proto != canonicalProto) {
PreserveWrapper(aObject);
}
return true;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TestJSImplInterface3);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TestJSImplInterface3);
JS::Handle<JSObject*> parentProto(TestCImplementedInterface2_Binding::GetProtoObjectHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(TestCImplementedInterface2_Binding::GetConstructorObjectHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
nullptr,
sChromeOnlyNativeProperties.Upcast(),
"TestJSImplInterface3", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetProtoObject(JSContext* aCx)
{
return GetProtoObjectHandle(aCx);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace TestJSImplInterface3_Binding
namespace TestJSImplInterface4_Binding {
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
"Can't inherit from an interface with a different ownership model.");
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::TestJSImplInterface4* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface4>(obj);
// We don't want to preserve if we don't have a wrapper, and we
// obviously can't preserve if we're not initialized.
if (self && self->GetWrapperPreserveColor()) {
PreserveWrapper(self);
}
return true;
}
static void
_finalize(JS::GCContext* gcx, JSObject* obj)
{
mozilla::dom::TestJSImplInterface4* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface4>(obj);
if (self) {
JS::SetReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue());
ClearWrapper(self, self, obj);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(obj, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<mozilla::dom::TestJSImplInterface4>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::TestJSImplInterface4* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface4>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::TestJSImplInterface4* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface4>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
JS_FNSPEC("_create", TestJSImplInterface4::_Create, nullptr, 2, 0, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
{ nullptr, &sChromeStaticMethods_specs[0] },
{ nullptr, nullptr }
};
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
true, 0 /* sChromeStaticMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
1,
sChromeOnlyNativeProperties_sortedPropertyIndices,
{
{ sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
}
};
static_assert(1 < 1ull << (CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ nullptr, sChromeOnlyNativeProperties.Upcast(), &sNativePropertiesInited },
prototypes::id::TestJSImplInterface4,
constructors::id::TestJSImplInterface4,
&DefaultXrayExpandoObjectClass
};
static bool
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestJSImplInterface4", "constructor", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.isConstructing()) {
return ThrowConstructorWithoutNew(cx, "TestJSImplInterface4");
}
JS::Rooted<JSObject*> desiredProto(cx);
if (!GetDesiredProto(cx, args,
prototypes::id::TestJSImplInterface4,
CreateInterfaceObjects,
&desiredProto)) {
return false;
}
GlobalObject global(cx, obj);
if (global.Failed()) {
return false;
}
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
Maybe<JSAutoRealm> ar;
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
obj = js::CheckedUnwrapStatic(obj);
if (!obj) {
return false;
}
ar.emplace(cx, obj);
if (!JS_WrapObject(cx, &desiredProto)) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<mozilla::dom::TestJSImplInterface4>(mozilla::dom::TestJSImplInterface4::Constructor(global, cx, rv, desiredProto)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestJSImplInterface4 constructor"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
static_assert(!std::is_pointer_v<decltype(result)>,
"NewObject implies that we need to keep the object alive with a strong reference.");
if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ _constructor, &sNativePropertyHooks },
EventTarget_Binding::GetConstructorObject,
prototypes::id::TestJSImplInterface4,
PrototypeTraits<prototypes::id::TestJSImplInterface4>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"TestJSImplInterface4Prototype",
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
JS_NULL_CLASS_OPS,
JS_NULL_CLASS_SPEC,
JS_NULL_CLASS_EXT,
JS_NULL_OBJECT_OPS
},
eInterfacePrototype,
prototypes::id::TestJSImplInterface4,
PrototypeTraits<prototypes::id::TestJSImplInterface4>::Depth,
&sNativePropertyHooks,
EventTarget_Binding::GetProtoObject
};
static const JSClassOps sClassOps = {
_addProperty, /* addProperty */
nullptr, /* delProperty */
nullptr, /* enumerate */
nullptr, /* newEnumerate */
nullptr, /* resolve */
nullptr, /* mayResolve */
_finalize, /* finalize */
nullptr, /* call */
nullptr, /* construct */
nullptr, /* trace */
};
static const js::ClassExtension sClassExtension = {
_objectMoved /* objectMovedOp */
};
static const DOMJSClass sClass = {
{ "TestJSImplInterface4",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::EventTarget, prototypes::id::TestJSImplInterface4, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
std::is_base_of_v<nsISupports, mozilla::dom::TestJSImplInterface4>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::TestJSImplInterface4>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::TestJSImplInterface4>::Get(),
nullptr,
_getWrapperCache
};
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
"Must have the right minimal number of reserved slots.");
static_assert(1 >= 1,
"Must have enough reserved slots.");
bool
Wrap(JSContext* aCx, mozilla::dom::TestJSImplInterface4* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::TestJSImplInterface4>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::TestJSImplInterface4*>);
MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
"Multiple inheritance for mozilla::dom::EventTarget is broken.");
MOZ_ASSERT(ToSupportsIsCorrect(aObject));
MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
MOZ_ASSERT(!aCache->GetWrapper(),
"You should probably not be using Wrap() directly; use "
"GetOrCreateDOMReflector instead");
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
"nsISupports must be on our primary inheritance chain");
// If the wrapper cache contains a dead reflector then finalize that
// now, ensuring that the finalizer for the old reflector always
// runs before the new reflector is created and attached. This
// avoids the awkward situation where there are multiple reflector
// objects that contain pointers to the same native.
if (JSObject* oldReflector = aCache->GetWrapperMaybeDead()) {
_finalize(nullptr /* unused */, oldReflector);
MOZ_ASSERT(!aCache->GetWrapperMaybeDead());
}
JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
if (!global) {
return false;
}
MOZ_ASSERT(JS_IsGlobalObject(global));
JS::AssertObjectIsNotGray(global);
// That might have ended up wrapping us already, due to the wonders
// of XBL. Check for that, and bail out as needed.
aReflector.set(aCache->GetWrapper());
if (aReflector) {
#ifdef DEBUG
AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
#endif // DEBUG
return true;
}
JSAutoRealm ar(aCx, global);
JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
if (!canonicalProto) {
return false;
}
JS::Rooted<JSObject*> proto(aCx);
if (aGivenProto) {
proto = aGivenProto;
// Unfortunately, while aGivenProto was in the compartment of aCx
// coming in, we changed compartments to that of "parent" so may need
// to wrap the proto here.
if (js::GetContextCompartment(aCx) != JS::GetCompartment(proto)) {
if (!JS_WrapObject(aCx, &proto)) {
return false;
}
}
} else {
proto = canonicalProto;
}
BindingJSObjectCreator<mozilla::dom::TestJSImplInterface4> creator(aCx);
creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
if (!aReflector) {
return false;
}
aCache->SetWrapper(aReflector);
creator.InitializationSucceeded();
MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
aCache->GetWrapperPreserveColor() == aReflector);
// If proto != canonicalProto, we have to preserve our wrapper;
// otherwise we won't be able to properly recreate it later, since
// we won't know what proto to use. Note that we don't check
// aGivenProto here, since it's entirely possible (and even
// somewhat common) to have a non-null aGivenProto which is the
// same as canonicalProto.
if (proto != canonicalProto) {
PreserveWrapper(aObject);
}
return true;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TestJSImplInterface4);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TestJSImplInterface4);
JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
nullptr,
sChromeOnlyNativeProperties.Upcast(),
"TestJSImplInterface4", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace TestJSImplInterface4_Binding
namespace TestJSImplInterface5_Binding {
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<TestJSImplInterface6_Binding::NativeType>::value,
"Can't inherit from an interface with a different ownership model.");
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::TestJSImplInterface5* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface5>(obj);
// We don't want to preserve if we don't have a wrapper, and we
// obviously can't preserve if we're not initialized.
if (self && self->GetWrapperPreserveColor()) {
PreserveWrapper(self);
}
return true;
}
static void
_finalize(JS::GCContext* gcx, JSObject* obj)
{
mozilla::dom::TestJSImplInterface5* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface5>(obj);
if (self) {
JS::SetReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue());
ClearWrapper(self, self, obj);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(obj, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<mozilla::dom::TestJSImplInterface5>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::TestJSImplInterface5* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface5>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::TestJSImplInterface5* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface5>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
JS_FNSPEC("_create", TestJSImplInterface5::_Create, nullptr, 2, 0, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
{ nullptr, &sChromeStaticMethods_specs[0] },
{ nullptr, nullptr }
};
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
true, 0 /* sChromeStaticMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
1,
sChromeOnlyNativeProperties_sortedPropertyIndices,
{
{ sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
}
};
static_assert(1 < 1ull << (CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ nullptr, sChromeOnlyNativeProperties.Upcast(), &sNativePropertiesInited },
prototypes::id::TestJSImplInterface5,
constructors::id::TestJSImplInterface5,
&DefaultXrayExpandoObjectClass
};
static bool
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestJSImplInterface5", "constructor", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.isConstructing()) {
return ThrowConstructorWithoutNew(cx, "TestJSImplInterface5");
}
JS::Rooted<JSObject*> desiredProto(cx);
if (!GetDesiredProto(cx, args,
prototypes::id::TestJSImplInterface5,
CreateInterfaceObjects,
&desiredProto)) {
return false;
}
GlobalObject global(cx, obj);
if (global.Failed()) {
return false;
}
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
Maybe<JSAutoRealm> ar;
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
obj = js::CheckedUnwrapStatic(obj);
if (!obj) {
return false;
}
ar.emplace(cx, obj);
if (!JS_WrapObject(cx, &desiredProto)) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<mozilla::dom::TestJSImplInterface5>(mozilla::dom::TestJSImplInterface5::Constructor(global, cx, rv, desiredProto)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestJSImplInterface5 constructor"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
static_assert(!std::is_pointer_v<decltype(result)>,
"NewObject implies that we need to keep the object alive with a strong reference.");
if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ _constructor, &sNativePropertyHooks },
TestJSImplInterface6_Binding::GetConstructorObject,
prototypes::id::TestJSImplInterface5,
PrototypeTraits<prototypes::id::TestJSImplInterface5>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"TestJSImplInterface5Prototype",
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
JS_NULL_CLASS_OPS,
JS_NULL_CLASS_SPEC,
JS_NULL_CLASS_EXT,
JS_NULL_OBJECT_OPS
},
eInterfacePrototype,
prototypes::id::TestJSImplInterface5,
PrototypeTraits<prototypes::id::TestJSImplInterface5>::Depth,
&sNativePropertyHooks,
TestJSImplInterface6_Binding::GetProtoObject
};
static const JSClassOps sClassOps = {
_addProperty, /* addProperty */
nullptr, /* delProperty */
nullptr, /* enumerate */
nullptr, /* newEnumerate */
nullptr, /* resolve */
nullptr, /* mayResolve */
_finalize, /* finalize */
nullptr, /* call */
nullptr, /* construct */
nullptr, /* trace */
};
static const js::ClassExtension sClassExtension = {
_objectMoved /* objectMovedOp */
};
static const DOMJSClass sClass = {
{ "TestJSImplInterface5",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::TestCImplementedInterface2, prototypes::id::TestJSImplInterface3, prototypes::id::TestJSImplInterface6, prototypes::id::TestJSImplInterface5, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
std::is_base_of_v<nsISupports, mozilla::dom::TestJSImplInterface5>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::TestJSImplInterface5>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::TestJSImplInterface5>::Get(),
nullptr,
_getWrapperCache
};
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
"Must have the right minimal number of reserved slots.");
static_assert(1 >= 1,
"Must have enough reserved slots.");
bool
Wrap(JSContext* aCx, mozilla::dom::TestJSImplInterface5* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::TestJSImplInterface5>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::TestJSImplInterface5*>);
MOZ_ASSERT(static_cast<mozilla::dom::TestJSImplInterface6*>(aObject) ==
reinterpret_cast<mozilla::dom::TestJSImplInterface6*>(aObject),
"Multiple inheritance for mozilla::dom::TestJSImplInterface6 is broken.");
MOZ_ASSERT(static_cast<mozilla::dom::TestJSImplInterface3*>(aObject) ==
reinterpret_cast<mozilla::dom::TestJSImplInterface3*>(aObject),
"Multiple inheritance for mozilla::dom::TestJSImplInterface3 is broken.");
MOZ_ASSERT(static_cast<mozilla::dom::TestCImplementedInterface2*>(aObject) ==
reinterpret_cast<mozilla::dom::TestCImplementedInterface2*>(aObject),
"Multiple inheritance for mozilla::dom::TestCImplementedInterface2 is broken.");
MOZ_ASSERT(ToSupportsIsCorrect(aObject));
MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
MOZ_ASSERT(!aCache->GetWrapper(),
"You should probably not be using Wrap() directly; use "
"GetOrCreateDOMReflector instead");
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
"nsISupports must be on our primary inheritance chain");
// If the wrapper cache contains a dead reflector then finalize that
// now, ensuring that the finalizer for the old reflector always
// runs before the new reflector is created and attached. This
// avoids the awkward situation where there are multiple reflector
// objects that contain pointers to the same native.
if (JSObject* oldReflector = aCache->GetWrapperMaybeDead()) {
_finalize(nullptr /* unused */, oldReflector);
MOZ_ASSERT(!aCache->GetWrapperMaybeDead());
}
JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
if (!global) {
return false;
}
MOZ_ASSERT(JS_IsGlobalObject(global));
JS::AssertObjectIsNotGray(global);
// That might have ended up wrapping us already, due to the wonders
// of XBL. Check for that, and bail out as needed.
aReflector.set(aCache->GetWrapper());
if (aReflector) {
#ifdef DEBUG
AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
#endif // DEBUG
return true;
}
JSAutoRealm ar(aCx, global);
JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
if (!canonicalProto) {
return false;
}
JS::Rooted<JSObject*> proto(aCx);
if (aGivenProto) {
proto = aGivenProto;
// Unfortunately, while aGivenProto was in the compartment of aCx
// coming in, we changed compartments to that of "parent" so may need
// to wrap the proto here.
if (js::GetContextCompartment(aCx) != JS::GetCompartment(proto)) {
if (!JS_WrapObject(aCx, &proto)) {
return false;
}
}
} else {
proto = canonicalProto;
}
BindingJSObjectCreator<mozilla::dom::TestJSImplInterface5> creator(aCx);
creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
if (!aReflector) {
return false;
}
aCache->SetWrapper(aReflector);
creator.InitializationSucceeded();
MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
aCache->GetWrapperPreserveColor() == aReflector);
// If proto != canonicalProto, we have to preserve our wrapper;
// otherwise we won't be able to properly recreate it later, since
// we won't know what proto to use. Note that we don't check
// aGivenProto here, since it's entirely possible (and even
// somewhat common) to have a non-null aGivenProto which is the
// same as canonicalProto.
if (proto != canonicalProto) {
PreserveWrapper(aObject);
}
return true;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TestJSImplInterface5);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TestJSImplInterface5);
JS::Handle<JSObject*> parentProto(TestJSImplInterface6_Binding::GetProtoObjectHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(TestJSImplInterface6_Binding::GetConstructorObjectHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
nullptr,
sChromeOnlyNativeProperties.Upcast(),
"TestJSImplInterface5", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace TestJSImplInterface5_Binding
namespace TestJSImplInterface6_Binding {
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<TestJSImplInterface3_Binding::NativeType>::value,
"Can't inherit from an interface with a different ownership model.");
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::TestJSImplInterface6* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface6>(obj);
// We don't want to preserve if we don't have a wrapper, and we
// obviously can't preserve if we're not initialized.
if (self && self->GetWrapperPreserveColor()) {
PreserveWrapper(self);
}
return true;
}
static void
_finalize(JS::GCContext* gcx, JSObject* obj)
{
mozilla::dom::TestJSImplInterface6* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface6>(obj);
if (self) {
JS::SetReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue());
ClearWrapper(self, self, obj);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(obj, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<mozilla::dom::TestJSImplInterface6>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::TestJSImplInterface6* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface6>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::TestJSImplInterface6* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestJSImplInterface6>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
JS_FNSPEC("_create", TestJSImplInterface6::_Create, nullptr, 2, 0, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
{ nullptr, &sChromeStaticMethods_specs[0] },
{ nullptr, nullptr }
};
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
"We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
true, 0 /* sChromeStaticMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
1,
sChromeOnlyNativeProperties_sortedPropertyIndices,
{
{ sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
}
};
static_assert(1 < 1ull << (CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ nullptr, sChromeOnlyNativeProperties.Upcast(), &sNativePropertiesInited },
prototypes::id::TestJSImplInterface6,
constructors::id::TestJSImplInterface6,
&DefaultXrayExpandoObjectClass
};
static bool
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TestJSImplInterface6", "constructor", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::Rooted<JSObject*> obj(cx, &args.callee());
if (!args.isConstructing()) {
return ThrowConstructorWithoutNew(cx, "TestJSImplInterface6");
}
JS::Rooted<JSObject*> desiredProto(cx);
if (!GetDesiredProto(cx, args,
prototypes::id::TestJSImplInterface6,
CreateInterfaceObjects,
&desiredProto)) {
return false;
}
GlobalObject global(cx, obj);
if (global.Failed()) {
return false;
}
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
Maybe<JSAutoRealm> ar;
if (objIsXray) {
// Since our object is an Xray, we can just CheckedUnwrapStatic:
// we know Xrays have no dynamic unwrap behavior.
obj = js::CheckedUnwrapStatic(obj);
if (!obj) {
return false;
}
ar.emplace(cx, obj);
if (!JS_WrapObject(cx, &desiredProto)) {
return false;
}
}
FastErrorResult rv;
auto result(StrongOrRawPtr<mozilla::dom::TestJSImplInterface6>(mozilla::dom::TestJSImplInterface6::Constructor(global, cx, rv, desiredProto)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "TestJSImplInterface6 constructor"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
static_assert(!std::is_pointer_v<decltype(result)>,
"NewObject implies that we need to keep the object alive with a strong reference.");
if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ _constructor, &sNativePropertyHooks },
TestJSImplInterface3_Binding::GetConstructorObject,
prototypes::id::TestJSImplInterface6,
PrototypeTraits<prototypes::id::TestJSImplInterface6>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"TestJSImplInterface6Prototype",
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
JS_NULL_CLASS_OPS,
JS_NULL_CLASS_SPEC,
JS_NULL_CLASS_EXT,
JS_NULL_OBJECT_OPS
},
eInterfacePrototype,
prototypes::id::TestJSImplInterface6,
PrototypeTraits<prototypes::id::TestJSImplInterface6>::Depth,
&sNativePropertyHooks,
TestJSImplInterface3_Binding::GetProtoObject
};
static const JSClassOps sClassOps = {
_addProperty, /* addProperty */
nullptr, /* delProperty */
nullptr, /* enumerate */
nullptr, /* newEnumerate */
nullptr, /* resolve */
nullptr, /* mayResolve */
_finalize, /* finalize */
nullptr, /* call */
nullptr, /* construct */
nullptr, /* trace */
};
static const js::ClassExtension sClassExtension = {
_objectMoved /* objectMovedOp */
};
static const DOMJSClass sClass = {
{ "TestJSImplInterface6",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::TestCImplementedInterface2, prototypes::id::TestJSImplInterface3, prototypes::id::TestJSImplInterface6, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
std::is_base_of_v<nsISupports, mozilla::dom::TestJSImplInterface6>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::TestJSImplInterface6>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::TestJSImplInterface6>::Get(),
nullptr,
_getWrapperCache
};
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
"Must have the right minimal number of reserved slots.");
static_assert(1 >= 1,
"Must have enough reserved slots.");
bool
Wrap(JSContext* aCx, mozilla::dom::TestJSImplInterface6* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::TestJSImplInterface6>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::TestJSImplInterface6*>);
MOZ_ASSERT(static_cast<mozilla::dom::TestJSImplInterface3*>(aObject) ==
reinterpret_cast<mozilla::dom::TestJSImplInterface3*>(aObject),
"Multiple inheritance for mozilla::dom::TestJSImplInterface3 is broken.");
MOZ_ASSERT(static_cast<mozilla::dom::TestCImplementedInterface2*>(aObject) ==
reinterpret_cast<mozilla::dom::TestCImplementedInterface2*>(aObject),
"Multiple inheritance for mozilla::dom::TestCImplementedInterface2 is broken.");
MOZ_ASSERT(ToSupportsIsCorrect(aObject));
MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
MOZ_ASSERT(!aCache->GetWrapper(),
"You should probably not be using Wrap() directly; use "
"GetOrCreateDOMReflector instead");
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
"nsISupports must be on our primary inheritance chain");
// If the wrapper cache contains a dead reflector then finalize that
// now, ensuring that the finalizer for the old reflector always
// runs before the new reflector is created and attached. This
// avoids the awkward situation where there are multiple reflector
// objects that contain pointers to the same native.
if (JSObject* oldReflector = aCache->GetWrapperMaybeDead()) {
_finalize(nullptr /* unused */, oldReflector);
MOZ_ASSERT(!aCache->GetWrapperMaybeDead());
}
JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
if (!global) {
return false;
}
MOZ_ASSERT(JS_IsGlobalObject(global));
JS::AssertObjectIsNotGray(global);
// That might have ended up wrapping us already, due to the wonders
// of XBL. Check for that, and bail out as needed.
aReflector.set(aCache->GetWrapper());
if (aReflector) {
#ifdef DEBUG
AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
#endif // DEBUG
return true;
}
JSAutoRealm ar(aCx, global);
JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
if (!canonicalProto) {
return false;
}
JS::Rooted<JSObject*> proto(aCx);
if (aGivenProto) {
proto = aGivenProto;
// Unfortunately, while aGivenProto was in the compartment of aCx
// coming in, we changed compartments to that of "parent" so may need
// to wrap the proto here.
if (js::GetContextCompartment(aCx) != JS::GetCompartment(proto)) {
if (!JS_WrapObject(aCx, &proto)) {
return false;
}
}
} else {
proto = canonicalProto;
}
BindingJSObjectCreator<mozilla::dom::TestJSImplInterface6> creator(aCx);
creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
if (!aReflector) {
return false;
}
aCache->SetWrapper(aReflector);
creator.InitializationSucceeded();
MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
aCache->GetWrapperPreserveColor() == aReflector);
// If proto != canonicalProto, we have to preserve our wrapper;
// otherwise we won't be able to properly recreate it later, since
// we won't know what proto to use. Note that we don't check
// aGivenProto here, since it's entirely possible (and even
// somewhat common) to have a non-null aGivenProto which is the
// same as canonicalProto.
if (proto != canonicalProto) {
PreserveWrapper(aObject);
}
return true;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TestJSImplInterface6);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TestJSImplInterface6);
JS::Handle<JSObject*> parentProto(TestJSImplInterface3_Binding::GetProtoObjectHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(TestJSImplInterface3_Binding::GetConstructorObjectHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
nullptr,
sChromeOnlyNativeProperties.Upcast(),
"TestJSImplInterface6", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetProtoObject(JSContext* aCx)
{
return GetProtoObjectHandle(aCx);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace TestJSImplInterface6_Binding
void
TestJSImplInterface2JSImpl::__Init(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestJSImplInterface2Atoms* atomsCache = GetAtomCache<TestJSImplInterface2Atoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
bool
TestJSImplInterface2JSImpl::InitIds(JSContext* cx, TestJSImplInterface2Atoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->__init_id.init(cx, "__init")) {
return false;
}
return true;
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(TestJSImplInterface2, mozilla::dom::TestCImplementedInterface, mImpl, mParent)
NS_IMPL_ADDREF_INHERITED(TestJSImplInterface2, mozilla::dom::TestCImplementedInterface)
NS_IMPL_RELEASE_INHERITED(TestJSImplInterface2, mozilla::dom::TestCImplementedInterface)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestJSImplInterface2)
NS_INTERFACE_MAP_END_INHERITING(mozilla::dom::TestCImplementedInterface)
TestJSImplInterface2::TestJSImplInterface2(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
: mozilla::dom::TestCImplementedInterface(aJSImplObject, aJSImplGlobal, aParent),
mImpl(new TestJSImplInterface2JSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
mParent(aParent)
{
}
TestJSImplInterface2::~TestJSImplInterface2()
{
}
nsISupports*
TestJSImplInterface2::GetParentObject() const
{
return mParent;
}
JSObject*
TestJSImplInterface2::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
JS::Rooted<JSObject*> obj(aCx, TestJSImplInterface2_Binding::Wrap(aCx, this, aGivenProto));
if (!obj) {
return nullptr;
}
// Now define it on our chrome object
JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
if (!JS_WrapObject(aCx, &obj)) {
return nullptr;
}
JS::Rooted<JSObject*> callback(aCx, mImpl->CallbackOrNull());
if (!JS_DefineProperty(aCx, callback, "__DOM_IMPL__", obj, 0)) {
return nullptr;
}
return obj;
}
already_AddRefed<TestJSImplInterface2>
TestJSImplInterface2::Constructor(const GlobalObject& global, JSContext* cx, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto)
{
RefPtr<TestJSImplInterface2> impl =
ConstructJSImplementation<TestJSImplInterface2>("@mozilla.org/test-js-impl-interface2;1", global, aRv);
if (aRv.Failed()) {
return nullptr;
}
return impl.forget();
}
bool
TestJSImplInterface2::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (!args.requireAtLeast(cx, "TestJSImplInterface2._create", 2)) {
return false;
}
BindingCallContext callCx(cx, "TestJSImplInterface2._create");
if (!args[0].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
}
if (!args[1].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
}
// GlobalObject will go through wrappers as needed for us, and
// is simpler than the right UnwrapArg incantation.
GlobalObject global(cx, &args[0].toObject());
if (global.Failed()) {
return false;
}
nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
MOZ_ASSERT(globalHolder);
JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
RefPtr<TestJSImplInterface2> impl = new TestJSImplInterface2(arg, argGlobal, globalHolder);
MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
return GetOrCreateDOMReflector(cx, impl, args.rval());
}
void
TestJSImplInterface3JSImpl::__Init(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestJSImplInterface3Atoms* atomsCache = GetAtomCache<TestJSImplInterface3Atoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
bool
TestJSImplInterface3JSImpl::InitIds(JSContext* cx, TestJSImplInterface3Atoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->__init_id.init(cx, "__init")) {
return false;
}
return true;
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(TestJSImplInterface3, mozilla::dom::TestCImplementedInterface2, mImpl, mParent)
NS_IMPL_ADDREF_INHERITED(TestJSImplInterface3, mozilla::dom::TestCImplementedInterface2)
NS_IMPL_RELEASE_INHERITED(TestJSImplInterface3, mozilla::dom::TestCImplementedInterface2)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestJSImplInterface3)
NS_INTERFACE_MAP_END_INHERITING(mozilla::dom::TestCImplementedInterface2)
TestJSImplInterface3::TestJSImplInterface3(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
: mozilla::dom::TestCImplementedInterface2(aParent),
mImpl(new TestJSImplInterface3JSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
mParent(aParent)
{
}
TestJSImplInterface3::~TestJSImplInterface3()
{
}
nsISupports*
TestJSImplInterface3::GetParentObject() const
{
return mParent;
}
JSObject*
TestJSImplInterface3::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
JS::Rooted<JSObject*> obj(aCx, TestJSImplInterface3_Binding::Wrap(aCx, this, aGivenProto));
if (!obj) {
return nullptr;
}
// Now define it on our chrome object
JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
if (!JS_WrapObject(aCx, &obj)) {
return nullptr;
}
JS::Rooted<JSObject*> callback(aCx, mImpl->CallbackOrNull());
if (!JS_DefineProperty(aCx, callback, "__DOM_IMPL__", obj, 0)) {
return nullptr;
}
return obj;
}
already_AddRefed<TestJSImplInterface3>
TestJSImplInterface3::Constructor(const GlobalObject& global, JSContext* cx, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto)
{
RefPtr<TestJSImplInterface3> impl =
ConstructJSImplementation<TestJSImplInterface3>("@mozilla.org/test-js-impl-interface3;1", global, aRv);
if (aRv.Failed()) {
return nullptr;
}
return impl.forget();
}
bool
TestJSImplInterface3::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (!args.requireAtLeast(cx, "TestJSImplInterface3._create", 2)) {
return false;
}
BindingCallContext callCx(cx, "TestJSImplInterface3._create");
if (!args[0].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
}
if (!args[1].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
}
// GlobalObject will go through wrappers as needed for us, and
// is simpler than the right UnwrapArg incantation.
GlobalObject global(cx, &args[0].toObject());
if (global.Failed()) {
return false;
}
nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
MOZ_ASSERT(globalHolder);
JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
RefPtr<TestJSImplInterface3> impl = new TestJSImplInterface3(arg, argGlobal, globalHolder);
MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
return GetOrCreateDOMReflector(cx, impl, args.rval());
}
void
TestJSImplInterface4JSImpl::__Init(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestJSImplInterface4Atoms* atomsCache = GetAtomCache<TestJSImplInterface4Atoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
bool
TestJSImplInterface4JSImpl::InitIds(JSContext* cx, TestJSImplInterface4Atoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->__init_id.init(cx, "__init")) {
return false;
}
return true;
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(TestJSImplInterface4, mozilla::DOMEventTargetHelper, mImpl, mParent)
NS_IMPL_ADDREF_INHERITED(TestJSImplInterface4, mozilla::DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(TestJSImplInterface4, mozilla::DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestJSImplInterface4)
NS_INTERFACE_MAP_END_INHERITING(mozilla::DOMEventTargetHelper)
TestJSImplInterface4::TestJSImplInterface4(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
: mozilla::DOMEventTargetHelper(aParent),
mImpl(new TestJSImplInterface4JSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
mParent(aParent)
{
}
TestJSImplInterface4::~TestJSImplInterface4()
{
}
nsISupports*
TestJSImplInterface4::GetParentObject() const
{
return mParent;
}
JSObject*
TestJSImplInterface4::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
JS::Rooted<JSObject*> obj(aCx, TestJSImplInterface4_Binding::Wrap(aCx, this, aGivenProto));
if (!obj) {
return nullptr;
}
// Now define it on our chrome object
JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
if (!JS_WrapObject(aCx, &obj)) {
return nullptr;
}
JS::Rooted<JSObject*> callback(aCx, mImpl->CallbackOrNull());
if (!JS_DefineProperty(aCx, callback, "__DOM_IMPL__", obj, 0)) {
return nullptr;
}
return obj;
}
already_AddRefed<TestJSImplInterface4>
TestJSImplInterface4::Constructor(const GlobalObject& global, JSContext* cx, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto)
{
RefPtr<TestJSImplInterface4> impl =
ConstructJSImplementation<TestJSImplInterface4>("@mozilla.org/test-js-impl-interface4;1", global, aRv);
if (aRv.Failed()) {
return nullptr;
}
return impl.forget();
}
bool
TestJSImplInterface4::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (!args.requireAtLeast(cx, "TestJSImplInterface4._create", 2)) {
return false;
}
BindingCallContext callCx(cx, "TestJSImplInterface4._create");
if (!args[0].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
}
if (!args[1].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
}
// GlobalObject will go through wrappers as needed for us, and
// is simpler than the right UnwrapArg incantation.
GlobalObject global(cx, &args[0].toObject());
if (global.Failed()) {
return false;
}
nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
MOZ_ASSERT(globalHolder);
JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
RefPtr<TestJSImplInterface4> impl = new TestJSImplInterface4(arg, argGlobal, globalHolder);
MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
return GetOrCreateDOMReflector(cx, impl, args.rval());
}
void
TestJSImplInterface6JSImpl::__Init(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestJSImplInterface6Atoms* atomsCache = GetAtomCache<TestJSImplInterface6Atoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
bool
TestJSImplInterface6JSImpl::InitIds(JSContext* cx, TestJSImplInterface6Atoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->__init_id.init(cx, "__init")) {
return false;
}
return true;
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(TestJSImplInterface6, mozilla::dom::TestJSImplInterface3, mImpl, mParent)
NS_IMPL_ADDREF_INHERITED(TestJSImplInterface6, mozilla::dom::TestJSImplInterface3)
NS_IMPL_RELEASE_INHERITED(TestJSImplInterface6, mozilla::dom::TestJSImplInterface3)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestJSImplInterface6)
NS_INTERFACE_MAP_END_INHERITING(mozilla::dom::TestJSImplInterface3)
TestJSImplInterface6::TestJSImplInterface6(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
: mozilla::dom::TestJSImplInterface3(aJSImplObject, aJSImplGlobal, aParent),
mImpl(new TestJSImplInterface6JSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
mParent(aParent)
{
}
TestJSImplInterface6::~TestJSImplInterface6()
{
}
nsISupports*
TestJSImplInterface6::GetParentObject() const
{
return mParent;
}
JSObject*
TestJSImplInterface6::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
JS::Rooted<JSObject*> obj(aCx, TestJSImplInterface6_Binding::Wrap(aCx, this, aGivenProto));
if (!obj) {
return nullptr;
}
// Now define it on our chrome object
JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
if (!JS_WrapObject(aCx, &obj)) {
return nullptr;
}
JS::Rooted<JSObject*> callback(aCx, mImpl->CallbackOrNull());
if (!JS_DefineProperty(aCx, callback, "__DOM_IMPL__", obj, 0)) {
return nullptr;
}
return obj;
}
already_AddRefed<TestJSImplInterface6>
TestJSImplInterface6::Constructor(const GlobalObject& global, JSContext* cx, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto)
{
RefPtr<TestJSImplInterface6> impl =
ConstructJSImplementation<TestJSImplInterface6>("@mozilla.org/test-js-impl-interface6;1", global, aRv);
if (aRv.Failed()) {
return nullptr;
}
return impl.forget();
}
bool
TestJSImplInterface6::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (!args.requireAtLeast(cx, "TestJSImplInterface6._create", 2)) {
return false;
}
BindingCallContext callCx(cx, "TestJSImplInterface6._create");
if (!args[0].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
}
if (!args[1].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
}
// GlobalObject will go through wrappers as needed for us, and
// is simpler than the right UnwrapArg incantation.
GlobalObject global(cx, &args[0].toObject());
if (global.Failed()) {
return false;
}
nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
MOZ_ASSERT(globalHolder);
JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
RefPtr<TestJSImplInterface6> impl = new TestJSImplInterface6(arg, argGlobal, globalHolder);
MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
return GetOrCreateDOMReflector(cx, impl, args.rval());
}
void
TestJSImplInterface5JSImpl::__Init(ErrorResult& aRv, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::Rooted<JS::Value> callable(cx);
TestJSImplInterface5Atoms* atomsCache = GetAtomCache<TestJSImplInterface5Atoms>(cx);
if ((reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) ||
!GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
if (!JS::Call(cx, thisValue, callable,
JS::HandleValueArray::empty(), &rval)) {
aRv.NoteJSContextException(cx);
return;
}
}
bool
TestJSImplInterface5JSImpl::InitIds(JSContext* cx, TestJSImplInterface5Atoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->__init_id.init(cx, "__init")) {
return false;
}
return true;
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(TestJSImplInterface5, mozilla::dom::TestJSImplInterface6, mImpl, mParent)
NS_IMPL_ADDREF_INHERITED(TestJSImplInterface5, mozilla::dom::TestJSImplInterface6)
NS_IMPL_RELEASE_INHERITED(TestJSImplInterface5, mozilla::dom::TestJSImplInterface6)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestJSImplInterface5)
NS_INTERFACE_MAP_END_INHERITING(mozilla::dom::TestJSImplInterface6)
TestJSImplInterface5::TestJSImplInterface5(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
: mozilla::dom::TestJSImplInterface6(aJSImplObject, aJSImplGlobal, aParent),
mImpl(new TestJSImplInterface5JSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
mParent(aParent)
{
}
TestJSImplInterface5::~TestJSImplInterface5()
{
}
nsISupports*
TestJSImplInterface5::GetParentObject() const
{
return mParent;
}
JSObject*
TestJSImplInterface5::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
JS::Rooted<JSObject*> obj(aCx, TestJSImplInterface5_Binding::Wrap(aCx, this, aGivenProto));
if (!obj) {
return nullptr;
}
// Now define it on our chrome object
JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
if (!JS_WrapObject(aCx, &obj)) {
return nullptr;
}
JS::Rooted<JSObject*> callback(aCx, mImpl->CallbackOrNull());
if (!JS_DefineProperty(aCx, callback, "__DOM_IMPL__", obj, 0)) {
return nullptr;
}
return obj;
}
already_AddRefed<TestJSImplInterface5>
TestJSImplInterface5::Constructor(const GlobalObject& global, JSContext* cx, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto)
{
RefPtr<TestJSImplInterface5> impl =
ConstructJSImplementation<TestJSImplInterface5>("@mozilla.org/test-js-impl-interface5;1", global, aRv);
if (aRv.Failed()) {
return nullptr;
}
return impl.forget();
}
bool
TestJSImplInterface5::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (!args.requireAtLeast(cx, "TestJSImplInterface5._create", 2)) {
return false;
}
BindingCallContext callCx(cx, "TestJSImplInterface5._create");
if (!args[0].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
}
if (!args[1].isObject()) {
return callCx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
}
// GlobalObject will go through wrappers as needed for us, and
// is simpler than the right UnwrapArg incantation.
GlobalObject global(cx, &args[0].toObject());
if (global.Failed()) {
return false;
}
nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
MOZ_ASSERT(globalHolder);
JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
RefPtr<TestJSImplInterface5> impl = new TestJSImplInterface5(arg, argGlobal, globalHolder);
MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
return GetOrCreateDOMReflector(cx, impl, args.rval());
}
} // namespace mozilla::dom