Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM TreeColumns.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "MainThreadUtils.h"
#include "TreeColumnsBinding.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/DOMJSProxyHandler.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PrimitiveConversions.h"
#include "mozilla/dom/ProxyHandlerUtils.h"
#include "mozilla/dom/XULTreeElement.h"
#include "mozilla/dom/XrayExpandoClass.h"
#include "nsContentUtils.h"
#include "nsTreeColumns.h"
namespace mozilla::dom {
namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;
namespace TreeColumns_Binding {
MOZ_CAN_RUN_SCRIPT static bool
get_tree(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "tree", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
auto result(StrongOrRawPtr<mozilla::dom::XULTreeElement>(MOZ_KnownLive(self)->GetTree()));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result) {
args.rval().setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo tree_getterinfo = {
{ get_tree },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
get_count(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "count", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
uint32_t result(MOZ_KnownLive(self)->Count());
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setNumber(result);
return true;
}
static const JSJitInfo count_getterinfo = {
{ get_count },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
true, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
get_length(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "length", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
uint32_t result(MOZ_KnownLive(self)->Length());
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setNumber(result);
return true;
}
static const JSJitInfo length_getterinfo = {
{ get_length },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
true, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getFirstColumn(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "getFirstColumn", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->GetFirstColumn()));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result) {
args.rval().setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo getFirstColumn_methodinfo = {
{ (JSJitGetterOp)getFirstColumn },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getLastColumn(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "getLastColumn", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->GetLastColumn()));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result) {
args.rval().setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo getLastColumn_methodinfo = {
{ (JSJitGetterOp)getLastColumn },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getPrimaryColumn(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "getPrimaryColumn", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->GetPrimaryColumn()));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result) {
args.rval().setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo getPrimaryColumn_methodinfo = {
{ (JSJitGetterOp)getPrimaryColumn },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getSortedColumn(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "getSortedColumn", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->GetSortedColumn()));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result) {
args.rval().setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo getSortedColumn_methodinfo = {
{ (JSJitGetterOp)getSortedColumn },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getKeyColumn(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "getKeyColumn", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->GetKeyColumn()));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result) {
args.rval().setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo getKeyColumn_methodinfo = {
{ (JSJitGetterOp)getKeyColumn },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getColumnFor(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "TreeColumns.getColumnFor");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "getColumnFor", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
if (!args.requireAtLeast(cx, "TreeColumns.getColumnFor", 1)) {
return false;
}
mozilla::dom::Element* arg0;
if (args[0].isObject()) {
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::Element, mozilla::dom::Element>(args[0], arg0, cx);
if (NS_FAILED(rv)) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Argument 1", "Element");
return false;
}
}
} else if (args[0].isNullOrUndefined()) {
arg0 = nullptr;
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 1");
return false;
}
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->GetColumnFor(MOZ_KnownLive(Constify(arg0)))));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result) {
args.rval().setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo getColumnFor_methodinfo = {
{ (JSJitGetterOp)getColumnFor },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getNamedColumn(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "getNamedColumn", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
if (!args.requireAtLeast(cx, "TreeColumns.getNamedColumn", 1)) {
return false;
}
binding_detail::FakeString<char16_t> arg0;
if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
return false;
}
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->GetNamedColumn(NonNullHelper(Constify(arg0)))));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result) {
args.rval().setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo getNamedColumn_methodinfo = {
{ (JSJitGetterOp)getNamedColumn },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
getColumnAt(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "getColumnAt", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
if (!args.requireAtLeast(cx, "TreeColumns.getColumnAt", 1)) {
return false;
}
uint32_t arg0;
if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], "Argument 1", &arg0)) {
return false;
}
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->GetColumnAt(arg0)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (!result) {
args.rval().setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo getColumnAt_methodinfo = {
{ (JSJitGetterOp)getColumnAt },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
invalidateColumns(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"TreeColumns", "invalidateColumns", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<nsTreeColumns*>(void_self);
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->InvalidateColumns())>, "Should be returning void here");
MOZ_KnownLive(self)->InvalidateColumns();
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo invalidateColumns_methodinfo = {
{ (JSJitGetterOp)invalidateColumns },
{ prototypes::id::TreeColumns },
{ PrototypeTraits<prototypes::id::TreeColumns>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
true, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
static const JSFunctionSpec sMethods_specs[] = {
JS_FNSPEC("getFirstColumn", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getFirstColumn_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getLastColumn", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getLastColumn_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getPrimaryColumn", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getPrimaryColumn_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getSortedColumn", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getSortedColumn_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getKeyColumn", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getKeyColumn_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getColumnFor", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getColumnFor_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getNamedColumn", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getNamedColumn_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("getColumnAt", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getColumnAt_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FNSPEC("invalidateColumns", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&invalidateColumns_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "$ArrayValues"),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sMethods[] = {
{ nullptr, &sMethods_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(10 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static const JSPropertySpec sAttributes_specs[] = {
JSPropertySpec::nativeAccessors("tree", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &tree_getterinfo, nullptr, nullptr),
JSPropertySpec::nativeAccessors("count", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &count_getterinfo, nullptr, nullptr),
JSPropertySpec::nativeAccessors("length", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &length_getterinfo, nullptr, nullptr),
JS_PS_END
};
static const Prefable<const JSPropertySpec> sAttributes[] = {
{ nullptr, &sAttributes_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(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
"We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
static uint16_t sNativeProperties_sortedPropertyIndices[13];
static PropertyInfo sNativeProperties_propertyInfos[13];
static const NativePropertiesN<2> sNativeProperties = {
false, 0,
false, 0,
true, 0 /* sMethods */,
true, 1 /* sAttributes */,
false, 0,
false, 0,
false, 0,
-1,
13,
sNativeProperties_sortedPropertyIndices,
{
{ sMethods, &sNativeProperties_propertyInfos[0] },
{ sAttributes, &sNativeProperties_propertyInfos[10] }
}
};
static_assert(13 < 1ull << (CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
static_assert(std::is_base_of_v<nsISupports, nsTreeColumns>,
"We don't support non-nsISupports native classes for "
"proxy-based bindings yet");
class DOMProxyHandler : public mozilla::dom::DOMProxyHandler
{
public:
explicit constexpr DOMProxyHandler()
{
}
bool
getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<Maybe<JS::PropertyDescriptor>> desc) const override;
bool
defineProperty(JSContext* cx_, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* done) const override;
using mozilla::dom::DOMProxyHandler::defineProperty;
bool
ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::MutableHandleVector<jsid> props) const override;
bool
hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override;
bool
get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override;
const char*
className(JSContext* cx, JS::Handle<JSObject*> proxy) const override;
bool
finalizeInBackground(const JS::Value& priv) const override;
void
finalize(JS::GCContext* gcx, JSObject* proxy) const override;
static const DOMProxyHandler*
getInstance();
bool
delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override;
bool
getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override;
size_t
objectMoved(JSObject* obj, JSObject* old) const override;
};
MOZ_ALWAYS_INLINE bool
IsProxy(JSObject* obj)
{
return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance();
}
MOZ_ALWAYS_INLINE nsTreeColumns*
UnwrapProxy(JSObject* obj)
{
MOZ_ASSERT(js::IsProxy(obj));
if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) {
MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj));
obj = js::UncheckedUnwrap(obj);
}
MOZ_ASSERT(IsProxy(obj));
return static_cast<nsTreeColumns*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate());
}
const NativeNamedOrIndexedPropertyHooks sNativeNamedOrIndexedPropertyHooks = {
binding_detail::ResolveOwnProperty,
binding_detail::EnumerateOwnProperties,
nullptr
};
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
&sNativeNamedOrIndexedPropertyHooks,
{ sNativeProperties.Upcast(), nullptr, &sNativePropertiesInited },
prototypes::id::TreeColumns,
constructors::id::TreeColumns,
&DefaultXrayExpandoObjectClass
};
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ ThrowingConstructor, &sNativePropertyHooks },
JS::GetRealmFunctionPrototype,
prototypes::id::TreeColumns,
PrototypeTraits<prototypes::id::TreeColumns>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"TreeColumnsPrototype",
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::TreeColumns,
PrototypeTraits<prototypes::id::TreeColumns>::Depth,
&sNativePropertyHooks,
JS::GetRealmObjectPrototype
};
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
}
bool
DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<Maybe<JS::PropertyDescriptor>> desc) const
{
bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
uint32_t index = GetArrayIndexFromId(id);
if (IsArrayIndex(index)) {
JS::Rooted<JS::Value> value(cx);
nsTreeColumns* self = UnwrapProxy(proxy);
bool found = false;
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->IndexedGetter(index, found)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (found) {
if (!result) {
value.setNull();
desc.set(mozilla::Some(JS::PropertyDescriptor::Data(value, { JS::PropertyAttribute::Configurable, JS::PropertyAttribute::Enumerable })));
return true;
}
if (!GetOrCreateDOMReflector(cx, result, &value)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
desc.set(mozilla::Some(JS::PropertyDescriptor::Data(value, { JS::PropertyAttribute::Configurable, JS::PropertyAttribute::Enumerable })));
return true;
}
}
JS::Rooted<JSObject*> expando(cx);
if (!isXray &&(expando = GetExpandoObject(proxy))) {
if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) {
return false;
}
if (desc.isSome()) {
return true;
}
}
bool callNamedGetter = false;
if (!IsArrayIndex(index) && !ignoreNamedProps) {
bool hasOnProto;
if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) {
return false;
}
callNamedGetter = !hasOnProto;
}
if (callNamedGetter) {
JS::Rooted<JS::Value> value(cx);
FakeString<char16_t> name;
bool isSymbol;
if (!ConvertIdToString(cx, id, name, isSymbol)) {
return false;
}
if (!isSymbol) {
nsTreeColumns* self = UnwrapProxy(proxy);
bool found = false;
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->NamedGetter(NonNullHelper(Constify(name)), found)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (found) {
if (!result) {
value.setNull();
desc.set(mozilla::Some(JS::PropertyDescriptor::Data(value, { JS::PropertyAttribute::Configurable, JS::PropertyAttribute::Enumerable })));
return true;
}
if (!GetOrCreateDOMReflector(cx, result, &value)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
desc.set(mozilla::Some(JS::PropertyDescriptor::Data(value, { JS::PropertyAttribute::Configurable, JS::PropertyAttribute::Enumerable })));
return true;
}
}
}
desc.reset();
return true;
}
bool
DOMProxyHandler::defineProperty(JSContext* cx_, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* done) const
{
if (IsArrayIndex(GetArrayIndexFromId(id))) {
*done = true;
return opresult.failNoIndexedSetter();
}
JSContext* cx = cx_;
bool found = false;
FakeString<char16_t> name;
bool isSymbol;
if (!ConvertIdToString(cx, id, name, isSymbol)) {
return false;
}
if (!isSymbol) {
nsTreeColumns* self = UnwrapProxy(proxy);
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->NamedGetter(NonNullHelper(Constify(name)), found)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
(void)result;
}
if (found) {
*done = true;
return opresult.failNoNamedSetter();
}
return mozilla::dom::DOMProxyHandler::defineProperty(cx_, proxy, id, desc, opresult, done);
}
bool
DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::MutableHandleVector<jsid> props) const
{
bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
uint32_t length = UnwrapProxy(proxy)->Length();
MOZ_ASSERT(int32_t(length) >= 0);
for (int32_t i = 0; i < int32_t(length); ++i) {
if (!props.append(JS::PropertyKey::Int(i))) {
return false;
}
}
nsTArray<nsString> names;
UnwrapProxy(proxy)->GetSupportedNames(names);
if (!AppendNamedPropertyIds(cx, proxy, names, false, props)) {
return false;
}
JS::Rooted<JSObject*> expando(cx);
if (!isXray &&(expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
!js::GetPropertyKeys(cx, expando, flags, props)) {
return false;
}
return true;
}
bool
DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const
{
MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
"Should not have a XrayWrapper here");
uint32_t index = GetArrayIndexFromId(id);
if (IsArrayIndex(index)) {
bool found = false;
nsTreeColumns* self = UnwrapProxy(proxy);
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->IndexedGetter(index, found)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
(void)result;
*bp = found;
return true;
}
JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
if (expando) {
bool b = true;
bool ok = JS_HasPropertyById(cx, expando, id, &b);
*bp = !!b;
if (!ok || *bp) {
return ok;
}
}
bool hasOnProto;
if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) {
return false;
}
if (!hasOnProto) {
bool found = false;
FakeString<char16_t> name;
bool isSymbol;
if (!ConvertIdToString(cx, id, name, isSymbol)) {
return false;
}
if (!isSymbol) {
nsTreeColumns* self = UnwrapProxy(proxy);
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->NamedGetter(NonNullHelper(Constify(name)), found)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
(void)result;
}
*bp = found;
return true;
}
*bp = false;
return true;
}
bool
DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const
{
MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
"Should not have a XrayWrapper here");
uint32_t index = GetArrayIndexFromId(id);
if (IsArrayIndex(index)) {
nsTreeColumns* self = UnwrapProxy(proxy);
bool found = false;
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->IndexedGetter(index, found)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (found) {
if (!result) {
vp.setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, vp)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
// Even if we don't have this index, we don't forward the
// get on to our expando object.
} else {
bool expandoHasProp = false;
{ // Scope for expando
JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
if (expando) {
if (!JS_HasPropertyById(cx, expando, id, &expandoHasProp)) {
return false;
}
if (expandoHasProp) {
// Forward the get to the expando object, but our receiver is whatever our
// receiver is.
if (!JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp)) {
return false;
}
}
}
}
if (expandoHasProp) {
return true;
}
}
bool foundOnPrototype;
if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) {
return false;
}
if (foundOnPrototype) {
return true;
}
MOZ_ASSERT(vp.isUndefined());
if (!IsArrayIndex(index)) {
FakeString<char16_t> name;
bool isSymbol;
if (!ConvertIdToString(cx, id, name, isSymbol)) {
return false;
}
if (!isSymbol) {
nsTreeColumns* self = UnwrapProxy(proxy);
bool found = false;
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->NamedGetter(NonNullHelper(Constify(name)), found)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
if (found) {
if (!result) {
vp.setNull();
return true;
}
if (!GetOrCreateDOMReflector(cx, result, vp)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
}
}
return true;
}
const char*
DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const
{
return "TreeColumns";
}
bool
DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const
{
return false;
}
void
DOMProxyHandler::finalize(JS::GCContext* gcx, JSObject* proxy) const
{
nsTreeColumns* self = UnwrapPossiblyNotInitializedDOMObject<nsTreeColumns>(proxy);
if (self) {
JS::SetReservedSlot(proxy, DOM_OBJECT_SLOT, JS::UndefinedValue());
ClearWrapper(self, self, proxy);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(proxy, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<nsTreeColumns>(self);
}
}
const DOMProxyHandler*
DOMProxyHandler::getInstance()
{
static const DOMProxyHandler instance;
return &instance;
}
bool
DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const
{
MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
"Should not have a XrayWrapper here");
uint32_t index = GetArrayIndexFromId(id);
if (IsArrayIndex(index)) {
bool deleteSucceeded;
bool found = false;
nsTreeColumns* self = UnwrapProxy(proxy);
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->IndexedGetter(index, found)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
(void)result;
deleteSucceeded = !found;
return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
}
// Try named delete only if the named property visibility
// algorithm says the property is visible.
bool tryNamedDelete = true;
{ // Scope for expando
JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
if (expando) {
bool hasProp;
if (!JS_HasPropertyById(cx, expando, id, &hasProp)) {
return false;
}
tryNamedDelete = !hasProp;
}
}
if (tryNamedDelete) {
bool hasOnProto;
if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) {
return false;
}
tryNamedDelete = !hasOnProto;
}
if (tryNamedDelete) {
bool found = false;
bool deleteSucceeded;
FakeString<char16_t> name;
bool isSymbol;
if (!ConvertIdToString(cx, id, name, isSymbol)) {
return false;
}
if (!isSymbol) {
nsTreeColumns* self = UnwrapProxy(proxy);
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->NamedGetter(NonNullHelper(Constify(name)), found)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
(void)result;
}
deleteSucceeded = !found;
if (found) {
return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
}
}
return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult);
}
bool
DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const
{
JS::Rooted<JS::Value> temp(cx);
MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
"Should not have a XrayWrapper here");
nsTreeColumns* self = UnwrapProxy(proxy);
uint32_t length = self->Length();
// Compute the end of the indices we'll get ourselves
uint32_t ourEnd = std::max(begin, std::min(end, length));
for (uint32_t index = begin; index < ourEnd; ++index) {
bool found = false;
auto result(StrongOrRawPtr<nsTreeColumn>(MOZ_KnownLive(self)->IndexedGetter(index, found)));
MOZ_ASSERT(!JS_IsExceptionPending(cx));
MOZ_ASSERT(found);
if (!result) {
temp.setNull();
if (!adder->append(cx, temp)) return false;
continue;
}
if (!GetOrCreateDOMReflector(cx, result, &temp)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
if (!adder->append(cx, temp)) return false;
continue;
}
if (end > ourEnd) {
JS::Rooted<JSObject*> proto(cx);
if (!js::GetObjectProto(cx, proxy, &proto)) {
return false;
}
return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder);
}
return true;
}
size_t
DOMProxyHandler::objectMoved(JSObject* obj, JSObject* old) const
{
nsTreeColumns* self = UnwrapPossiblyNotInitializedDOMObject<nsTreeColumns>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const DOMJSClass sClass = {
PROXY_CLASS_DEF("TreeColumns",
JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1)),
{ prototypes::id::TreeColumns, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
std::is_base_of_v<nsISupports, nsTreeColumns>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<nsTreeColumns>::Get,
GetProtoObjectHandle,
GetCCParticipant<nsTreeColumns>::Get(),
nullptr,
nullptr
};
bool
Wrap(JSContext* aCx, nsTreeColumns* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, nsTreeColumns>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), nsTreeColumns*>);
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()) {
DOMProxyHandler::getInstance()->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<nsTreeColumns> creator(aCx);
creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(),
proto, /* aLazyProto = */ false,
aObject, JS::UndefinedHandleValue, 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::TreeColumns);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TreeColumns);
JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
if (!parentProto) {
return;
}
JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
sNativeProperties.Upcast(),
nullptr,
"TreeColumns", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace TreeColumns_Binding
} // namespace mozilla::dom