namespace std {
struct ostream {};
template <bool B>
struct enable_if {
using type = bool;
};
template <typename T, typename U>
struct is_convertible {
const bool value = true;
};
template<class T>
struct remove_cv {
using type = T;
};
template<class T>
struct remove_reference {
using type = T;
};
}
struct AutoIncumbentScript {};
struct JSString {};
struct JSObject {};
struct JSAutoCompartment {};
namespace JS {
template <class T>
struct Rooted {
T t;
};
struct AutoSetAsyncStackForNewCalls {};
struct RootedObject {};
struct HandleObject {};
struct HandleId {};
struct WarningReporter {};
}
namespace js {
using namespace JS;
}
struct nsresult {};
struct nsStringBuffer {};
struct nsAutoString {};
struct nsIAtom {};
struct nsAString {};
struct nsString {};
using uint8_t = unsigned char;
using uint32_t = unsigned int;
using size_t = unsigned long long;
namespace mozilla {
struct FalseType {};
template<class T, size_t N = 0>
struct Vector {};
namespace dom {
struct Element {};
} // namespace dom
struct CSSPseudoClassType {};
struct CSSEnabledState {};
template<class T>
using RemoveCv = std::remove_cv<T>;
template<class T>
using RemoveReference = std::remove_reference<T>;
template<class T>
struct Forward {};
enum NotNullTag {
KnownNotNull,
};
struct Nothing { };
template<class T>
class Maybe
{
alignas(T) unsigned char mStorage[sizeof(T)];
char mIsSome;
void* data() { return mStorage; }
const void* data() const { return mStorage; }
public:
using ValueType = T;
Maybe() : mIsSome(false) { }
~Maybe() { reset(); }
Maybe(Nothing) : mIsSome(false) { }
Maybe(const Maybe& aOther)
: mIsSome(false)
{
if (aOther.mIsSome) {
emplace(*aOther);
}
}
template<typename U,
typename =
typename std::enable_if<std::is_convertible<U, T>::value>::type>
Maybe(const Maybe<U>& aOther)
: mIsSome(false)
{
if (aOther.isSome()) {
emplace(*aOther);
}
}
Maybe(Maybe&& aOther)
: mIsSome(false)
{
if (aOther.mIsSome) {
emplace(Move(*aOther));
aOther.reset();
}
}
template<typename U,
typename =
typename std::enable_if<std::is_convertible<U, T>::value>::type>
Maybe(Maybe<U>&& aOther)
: mIsSome(false)
{
if (aOther.isSome()) {
emplace(Move(*aOther));
aOther.reset();
}
}
Maybe& operator=(const Maybe& aOther)
{
if (&aOther != this) {
if (aOther.mIsSome) {
if (mIsSome) {
ref() = aOther.ref();
} else {
emplace(*aOther);
}
} else {
reset();
}
}
return *this;
}
template<typename U,
typename =
typename std::enable_if<std::is_convertible<U, T>::value>::type>
Maybe& operator=(const Maybe<U>& aOther)
{
if (aOther.isSome()) {
if (mIsSome) {
ref() = aOther.ref();
} else {
emplace(*aOther);
}
} else {
reset();
}
return *this;
}
Maybe& operator=(Maybe&& aOther)
{
do { } while (0);
if (aOther.mIsSome) {
if (mIsSome) {
ref() = Move(aOther.ref());
} else {
emplace(Move(*aOther));
}
aOther.reset();
} else {
reset();
}
return *this;
}
template<typename U,
typename =
typename std::enable_if<std::is_convertible<U, T>::value>::type>
Maybe& operator=(Maybe<U>&& aOther)
{
if (aOther.isSome()) {
if (mIsSome) {
ref() = Move(aOther.ref());
} else {
emplace(Move(*aOther));
}
aOther.reset();
} else {
reset();
}
return *this;
}
explicit operator bool() const { return isSome(); }
bool isSome() const { return mIsSome; }
bool isNothing() const { return !mIsSome; }
T value() const
{
do { } while (0);
return ref();
}
template<typename V>
T valueOr(V&& aDefault) const
{
if (isSome()) {
return ref();
}
return Forward<V>(aDefault);
}
template<typename F>
T valueOrFrom(F&& aFunc) const
{
if (isSome()) {
return ref();
}
return aFunc();
}
T* ptr()
{
do { } while (0);
return &ref();
}
const T* ptr() const
{
do { } while (0);
return &ref();
}
T* ptrOr(T* aDefault)
{
if (isSome()) {
return ptr();
}
return aDefault;
}
const T* ptrOr(const T* aDefault) const
{
if (isSome()) {
return ptr();
}
return aDefault;
}
template<typename F>
T* ptrOrFrom(F&& aFunc)
{
if (isSome()) {
return ptr();
}
return aFunc();
}
template<typename F>
const T* ptrOrFrom(F&& aFunc) const
{
if (isSome()) {
return ptr();
}
return aFunc();
}
T* operator->()
{
do { } while (0);
return ptr();
}
const T* operator->() const
{
do { } while (0);
return ptr();
}
T& ref()
{
do { } while (0);
return *static_cast<T*>(data());
}
const T& ref() const
{
do { } while (0);
return *static_cast<const T*>(data());
}
T& refOr(T& aDefault)
{
if (isSome()) {
return ref();
}
return aDefault;
}
const T& refOr(const T& aDefault) const
{
if (isSome()) {
return ref();
}
return aDefault;
}
template<typename F>
T& refOrFrom(F&& aFunc)
{
if (isSome()) {
return ref();
}
return aFunc();
}
template<typename F>
const T& refOrFrom(F&& aFunc) const
{
if (isSome()) {
return ref();
}
return aFunc();
}
T& operator*()
{
do { } while (0);
return ref();
}
const T& operator*() const
{
do { } while (0);
return ref();
}
template<typename Func>
Maybe& apply(Func aFunc)
{
if (isSome()) {
aFunc(ref());
}
return *this;
}
template<typename Func>
const Maybe& apply(Func aFunc) const
{
if (isSome()) {
aFunc(ref());
}
return *this;
}
// template<typename Func>
// auto map(Func aFunc) -> Maybe<decltype(aFunc(DeclVal<Maybe<T>>().ref()))>
// {
// using ReturnType = decltype(aFunc(ref()));
// if (isSome()) {
// Maybe<ReturnType> val;
// val.emplace(aFunc(ref()));
// return val;
// }
// return Maybe<ReturnType>();
// }
// template<typename Func>
// auto map(Func aFunc) const -> Maybe<decltype(aFunc(DeclVal<Maybe<T>>().ref()))>
// {
// using ReturnType = decltype(aFunc(ref()));
// if (isSome()) {
// Maybe<ReturnType> val;
// val.emplace(aFunc(ref()));
// return val;
// }
// return Maybe<ReturnType>();
// }
void reset()
{
if (isSome()) {
ref().T::~T();
mIsSome = false;
}
}
template<typename... Args>
void emplace(Args&&... aArgs)
{
do { } while (0);
::new (KnownNotNull, data()) T(Forward<Args>(aArgs)...);
mIsSome = true;
}
// friend std::ostream&
// operator<<(std::ostream& aStream, const Maybe<T>& aMaybe)
// {
// if (aMaybe) {
// aStream << aMaybe.ref();
// } else {
// aStream << "<Nothing>";
// }
// return aStream;
// }
};
template<typename T,
typename U = typename std::remove_cv<
typename std::remove_reference<T>::type>::type>
Maybe<U>
Some(T&& aValue)
{
Maybe<U> value;
value.emplace(Forward<T>(aValue));
return value;
}
// template<typename T>
// Maybe<typename RemoveCV<typename RemoveReference<T>::Type>::Type>
// ToMaybe(T* aPtr)
// {
// if (aPtr) {
// return Some(*aPtr);
// }
// return Nothing();
// }
template<typename T> bool
operator==(const Maybe<T>& aLHS, const Maybe<T>& aRHS)
{
if (aLHS.isNothing() != aRHS.isNothing()) {
return false;
}
return aLHS.isNothing() || *aLHS == *aRHS;
}
template<typename T> bool
operator!=(const Maybe<T>& aLHS, const Maybe<T>& aRHS)
{
return !(aLHS == aRHS);
}
template<typename T> bool
operator==(const Maybe<T>& aLHS, const Nothing& aRHS)
{
return aLHS.isNothing();
}
template<typename T> bool
operator!=(const Maybe<T>& aLHS, const Nothing& aRHS)
{
return !(aLHS == aRHS);
}
template<typename T> bool
operator==(const Nothing& aLHS, const Maybe<T>& aRHS)
{
return aRHS.isNothing();
}
template<typename T> bool
operator!=(const Nothing& aLHS, const Maybe<T>& aRHS)
{
return !(aLHS == aRHS);
}
template<typename T> bool
operator<(const Maybe<T>& aLHS, const Maybe<T>& aRHS)
{
if (aLHS.isNothing()) {
return aRHS.isSome();
}
if (aRHS.isNothing()) {
return false;
}
return *aLHS < *aRHS;
}
template<typename T> bool
operator>(const Maybe<T>& aLHS, const Maybe<T>& aRHS)
{
return !(aLHS < aRHS || aLHS == aRHS);
}
template<typename T> bool
operator<=(const Maybe<T>& aLHS, const Maybe<T>& aRHS)
{
return aLHS < aRHS || aLHS == aRHS;
}
template<typename T> bool
operator>=(const Maybe<T>& aLHS, const Maybe<T>& aRHS)
{
return !(aLHS < aRHS);
}
} // namespace mozilla
class nsCSSPseudoClasses
{
typedef mozilla::CSSPseudoClassType Type;
typedef mozilla::CSSEnabledState EnabledState;
public:
static void AddRefAtoms();
static Type GetPseudoType(nsIAtom* aAtom, EnabledState aEnabledState);
static bool HasStringArg(Type aType);
static bool HasNthPairArg(Type aType);
static bool HasSelectorListArg(Type aType) {
// return aType == Type::any;
return true;
}
static bool IsUserActionPseudoClass(Type aType);
static void PseudoTypeToString(Type aType, nsAString& aString);
// static bool IsEnabled(Type aType, EnabledState aEnabledState)
// {
// auto index = static_cast<size_t>(aType);
// do { } while (0);
// if (sPseudoClassEnabled[index] ||
// aEnabledState == EnabledState::eIgnoreEnabledState) {
// return true;
// }
// auto flags = kPseudoClassFlags[index];
// if (((aEnabledState & EnabledState::eInChrome) &&
// (flags & (1<<1))) ||
// ((aEnabledState & EnabledState::eInUASheets) &&
// (flags & (1<<0)))) {
// return true;
// }
// return false;
// }
static mozilla::Maybe<bool>
MatchesElement(Type aType, const mozilla::dom::Element* aElement);
private:
// static const uint32_t kPseudoClassFlags[size_t(Type::Count)];
// static bool sPseudoClassEnabled[size_t(Type::Count)];
};
namespace mozilla {
namespace dom {
class DOMString {
public:
DOMString()
: mStringBuffer(nullptr)
, mLength(0)
, mIsNull(false)
, mStringBufferOwned(false)
{}
~DOMString()
{
// do { } while (0);
// if (mStringBufferOwned) {
// do { } while (0);
// mStringBuffer->Release();
// }
}
// operator nsString&()
// {
// return AsAString();
// }
operator const nsString&() = delete;
operator const nsAString&() = delete;
// nsString& AsAString()
// {
// do { } while (0);
// do { } while (0);
// if (!mString) {
// mString.emplace();
// }
// return *mString;
// }
bool HasStringBuffer() const
{
do { } while (0);
do { } while (0);
return !mString;
}
nsStringBuffer* StringBuffer() const
{
do { } while (0);
do { } while (0);
do { } while (0);
do { } while (0);
return mStringBuffer;
}
uint32_t StringBufferLength() const
{
do { } while (0);
return mLength;
}
void RelinquishBufferOwnership()
{
// do { } while (0);
// if (mStringBufferOwned) {
// mStringBufferOwned = false;
// } else {
// mStringBuffer->AddRef();
// }
}
void SetStringBuffer(nsStringBuffer* aStringBuffer, uint32_t aLength)
{
do { } while (0);
do { } while (0);
do { } while (0);
do { } while (0);
mStringBuffer = aStringBuffer;
mLength = aLength;
}
void SetEphemeralStringBuffer(nsStringBuffer* aStringBuffer, uint32_t aLength)
{
// SetStringBuffer(aStringBuffer, aLength);
// aStringBuffer->AddRef();
// mStringBufferOwned = true;
}
// void SetOwnedString(const nsAString& aString)
// {
// do { } while (0);
// do { } while (0);
// do { } while (0);
// nsStringBuffer* buf = nsStringBuffer::FromString(aString);
// if (buf) {
// SetStringBuffer(buf, aString.Length());
// } else if (aString.IsVoid()) {
// SetNull();
// } else if (!aString.IsEmpty()) {
// AsAString() = aString;
// }
// }
enum NullHandling
{
eTreatNullAsNull,
eTreatNullAsEmpty,
eNullNotExpected
};
// void SetOwnedAtom(nsIAtom* aAtom, NullHandling aNullHandling)
// {
// do { } while (0);
// do { } while (0);
// do { } while (0);
// do { } while (0);
// if (aNullHandling == eNullNotExpected || aAtom) {
// SetStringBuffer(aAtom->GetStringBuffer(), aAtom->GetLength());
// } else if (aNullHandling == eTreatNullAsNull) {
// SetNull();
// }
// }
void SetNull()
{
do { } while (0);
do { } while (0);
mIsNull = true;
}
bool IsNull() const
{
// do { } while (0);
// return mIsNull || (mString && mString->IsVoid());
return false;
}
void ToString(nsAString& aString)
{
// if (IsNull()) {
// SetDOMStringToNull(aString);
// } else if (HasStringBuffer()) {
// if (StringBufferLength() == 0) {
// aString.Truncate();
// } else {
// nsStringBuffer* buf = StringBuffer();
// uint32_t len = StringBufferLength();
// auto chars = static_cast<char16_t*>(buf->Data());
// if (chars[len] == '\0') {
// buf->ToString(len, aString);
// } else {
// aString.Assign(chars, len);
// }
// }
// } else {
// aString = AsAString();
// }
}
private:
Maybe<nsAutoString> mString;
nsStringBuffer* mStringBuffer;
uint32_t mLength;
bool mIsNull;
bool mStringBufferOwned;
};
} // namespace dom
} // namespace mozilla
class nsIPrincipal;
class nsWrapperCache;
class JSContext;
namespace mozilla {
namespace dom {
struct DictionaryBase
{
protected:
// bool ParseJSON(JSContext* aCx, const nsAString& aJSON,
// JS::MutableHandle<JS::Value> aVal);
// bool StringifyToJSON(JSContext* aCx,
// JS::Handle<JSObject*> aObj,
// nsAString& aJSON) const;
struct FastDictionaryInitializer {
};
bool mIsAnyMemberPresent = false;
private:
static bool AppendJSONToString(const char16_t* aJSONData,
uint32_t aDataLength, void* aString);
public:
bool IsAnyMemberPresent() const
{
return mIsAnyMemberPresent;
}
};
struct AllTypedArraysBase {
};
struct AllOwningUnionBase {
};
struct EnumEntry {
const char* value;
size_t length;
};
enum class CallerType : uint32_t;
class GlobalObject
{
public:
// GlobalObject(JSContext* aCx, JSObject* aObject);
// JSObject* Get() const
// {
// return mGlobalJSObject;
// }
// nsISupports* GetAsSupports() const;
JSContext* Context() const
{
return mCx;
}
bool Failed() const
{
// return !Get();
return false;
}
nsIPrincipal* GetSubjectPrincipal() const;
dom::CallerType CallerType() const;
protected:
// JS::Rooted<JSObject*> mGlobalJSObject;
JSContext* mCx;
// mutable nsISupports* mGlobalObject;
};
template<typename T, typename InternalType>
class Optional_base
{
public:
Optional_base()
{}
explicit Optional_base(const T& aValue)
{
mImpl.emplace(aValue);
}
bool operator==(const Optional_base<T, InternalType>& aOther) const
{
return mImpl == aOther.mImpl;
}
template<typename T1, typename T2>
explicit Optional_base(const T1& aValue1, const T2& aValue2)
{
mImpl.emplace(aValue1, aValue2);
}
bool WasPassed() const
{
return mImpl.isSome();
}
template<typename... Args>
InternalType& Construct(Args&&... aArgs)
{
mImpl.emplace(Forward<Args>(aArgs)...);
return *mImpl;
}
void Reset()
{
mImpl.reset();
}
const T& Value() const
{
return *mImpl;
}
InternalType& Value()
{
return *mImpl;
}
const InternalType& InternalValue() const
{
return *mImpl;
}
private:
Optional_base(const Optional_base& other) = delete;
const Optional_base &operator=(const Optional_base &other) = delete;
protected:
Maybe<InternalType> mImpl;
};
} // namespace dom
} // namespace mozilla
namespace mozilla {
namespace dom {
template <typename T>
struct Nullable
{
private:
Maybe<T> mValue;
public:
Nullable()
: mValue()
{}
Nullable(const decltype(nullptr)&)
: mValue()
{}
explicit Nullable(const T& aValue)
: mValue()
{
mValue.emplace(aValue);
}
Nullable(T&& aValue)
: mValue()
{
// mValue.emplace(mozilla::Move(aValue));
}
Nullable(Nullable<T>&& aOther)
// : mValue(mozilla::Move(aOther.mValue))
{}
Nullable(const Nullable<T>& aOther)
: mValue(aOther.mValue)
{}
void operator=(const Nullable<T>& aOther)
{
mValue = aOther.mValue;
}
void SetValue(const T& aArgs)
{
mValue.reset();
mValue.emplace(aArgs);
}
void SetValue(T&& aArgs)
{
mValue.reset();
// mValue.emplace(mozilla::Move(aArgs));
}
T& SetValue() {
if (mValue.isNothing()) {
mValue.emplace();
}
return mValue.ref();
}
void SetNull() {
mValue.reset();
}
const T& Value() const {
return mValue.ref();
}
T& Value() {
return mValue.ref();
}
bool IsNull() const {
return mValue.isNothing();
}
bool Equals(const Nullable<T>& aOtherNullable) const
{
return mValue == aOtherNullable.mValue;
}
bool operator==(const Nullable<T>& aOtherNullable) const
{
return Equals(aOtherNullable);
}
bool operator!=(const Nullable<T>& aOtherNullable) const
{
return !Equals(aOtherNullable);
}
friend std::ostream& operator<<(std::ostream& aStream,
const Nullable& aNullable) {
return aStream << aNullable.mValue;
}
};
}
}
namespace js {
// extern const JSErrorFormatString*
// GetErrorMessage(void* userRef, const unsigned errorNumber);
class AutoStableStringChars
{
static const size_t InlineCapacity = 24;
// JS::RootedString s_;
// union {
// const char16_t* twoByteChars_;
// const JS::Latin1Char* latin1Chars_;
// };
mozilla::Maybe<mozilla::Vector<uint8_t, InlineCapacity>> ownChars_;
enum State { Uninitialized, Latin1, TwoByte };
State state_;
public:
// explicit AutoStableStringChars(JSContext* cx)
// : s_(cx), state_(Uninitialized)
// {}
// __attribute__ ((warn_unused_result))
// bool init(JSContext* cx, JSString* s);
__attribute__ ((warn_unused_result))
bool initTwoByte(JSContext* cx, JSString* s);
bool isLatin1() const { return state_ == Latin1; }
bool isTwoByte() const { return state_ == TwoByte; }
const char16_t* twoByteChars() const {
// do { } while (0);
// return twoByteChars_;
return nullptr;
}
// mozilla::Range<const JS::Latin1Char> latin1Range() const {
// do { } while (0);
// return mozilla::Range<const JS::Latin1Char>(latin1Chars_,
// GetStringLength(s_));
// }
// mozilla::Range<const char16_t> twoByteRange() const {
// do { } while (0);
// return mozilla::Range<const char16_t>(twoByteChars_,
// GetStringLength(s_));
// }
bool maybeGiveOwnershipToCaller() {
// do { } while (0);
// if (!ownChars_.isSome() || !ownChars_->extractRawBuffer())
// return false;
// state_ = Uninitialized;
// ownChars_.reset();
return true;
}
private:
AutoStableStringChars(const AutoStableStringChars& other) = delete;
void operator=(const AutoStableStringChars& other) = delete;
// bool baseIsInline(JS::Handle<JSLinearString*> linearString);
template <typename T> T* allocOwnChars(JSContext* cx, size_t count);
// bool copyLatin1Chars(JSContext* cx, JS::Handle<JSLinearString*> linearString);
// bool copyTwoByteChars(JSContext* cx, JS::Handle<JSLinearString*> linearString);
// bool copyAndInflateLatin1Chars(JSContext*, JS::Handle<JSLinearString*> linearString);
};
class AutoEnterPolicy
{
public:
// typedef BaseProxyHandler::Action Action;
// AutoEnterPolicy(JSContext* cx, const BaseProxyHandler* handler,
// HandleObject wrapper, HandleId id, Action act, bool mayThrow)
// : context(nullptr)
// {
// allow = handler->hasSecurityPolicy() ? handler->enter(cx, wrapper, id, act, mayThrow, &rv)
// : true;
// recordEnter(cx, wrapper, id, act);
// if (!allow && !rv && mayThrow)
// reportErrorIfExceptionIsNotPending(cx, id);
// }
// virtual ~AutoEnterPolicy() { recordLeave(); }
// inline bool allowed() { return allow; }
// inline bool returnValue() { do { } while (0); return rv; }
// protected:
// AutoEnterPolicy()
// : context(nullptr)
// , enteredAction(BaseProxyHandler::NONE)
// {}
// void reportErrorIfExceptionIsNotPending(JSContext* cx, jsid id);
// bool allow;
// bool rv;
// JSContext* context;
mozilla::Maybe<HandleObject> enteredProxy;
mozilla::Maybe<HandleId> enteredId;
// Action enteredAction;
// AutoEnterPolicy* prev;
// void recordEnter(JSContext* cx, HandleObject proxy, HandleId id, Action act);
// void recordLeave();
// friend void assertEnteredPolicy(JSContext* cx, JSObject* proxy, jsid id, Action act);
// private:
// AutoEnterPolicy(const AutoEnterPolicy&) = delete;
// AutoEnterPolicy& operator=(const AutoEnterPolicy&) = delete;
};
}
namespace js {
struct ProxyOptions {};
class WrapperOptions : public ProxyOptions {
// public:
// WrapperOptions() : ProxyOptions(false),
// proto_()
// {}
// explicit WrapperOptions(JSContext* cx) : ProxyOptions(false),
// proto_()
// {
// proto_.emplace(cx);
// }
// inline JSObject* proto() const;
// WrapperOptions& setProto(JSObject* protoArg) {
// do { } while (0);
// *proto_ = protoArg;
// return *this;
// }
// private:
mozilla::Maybe<JS::RootedObject> proto_;
};
struct ScriptSettingsStackEntry {};
struct JSAutoRequest {};
struct JSAutoNullableCompartment {};
class AutoJSAPI : protected ScriptSettingsStackEntry {
public:
AutoJSAPI();
~AutoJSAPI();
void Init();
// __attribute__ ((warn_unused_result)) bool Init(nsIGlobalObject* aGlobalObject);
// __attribute__ ((warn_unused_result)) bool Init(JSObject* aObject);
// __attribute__ ((warn_unused_result)) bool Init(nsIGlobalObject* aGlobalObject, JSContext* aCx);
// __attribute__ ((warn_unused_result)) bool Init(nsPIDOMWindowInner* aWindow);
// __attribute__ ((warn_unused_result)) bool Init(nsPIDOMWindowInner* aWindow, JSContext* aCx);
// __attribute__ ((warn_unused_result)) bool Init(nsGlobalWindow* aWindow);
// __attribute__ ((warn_unused_result)) bool Init(nsGlobalWindow* aWindow, JSContext* aCx);
// JSContext* cx() const {
// do { } while (0);
// do { } while (0);
// return mCx;
// }
// void ReportException();
// bool HasException() const {
// do { } while (0);
// return JS_IsExceptionPending(cx());
// };
// __attribute__ ((warn_unused_result)) bool StealException(JS::MutableHandle<JS::Value> aVal);
// __attribute__ ((warn_unused_result)) bool PeekException(JS::MutableHandle<JS::Value> aVal);
// void ClearException() {
// do { } while (0);
// JS_ClearPendingException(cx());
// }
// protected:
// AutoJSAPI(nsIGlobalObject* aGlobalObject, bool aIsMainThread, Type aType);
// private:
mozilla::Maybe<JSAutoRequest> mAutoRequest;
mozilla::Maybe<JSAutoNullableCompartment> mAutoNullableCompartment;
// JSContext *mCx;
// bool mIsMainThread;
mozilla::Maybe<JS::WarningReporter> mOldWarningReporter;
// void InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal,
// JSContext* aCx, bool aIsMainThread);
// AutoJSAPI(const AutoJSAPI&) = delete;
// AutoJSAPI& operator= (const AutoJSAPI&) = delete;
};
struct DocshellEntryMonitor {};
class AutoEntryScript : public AutoJSAPI {
// public:
// AutoEntryScript(nsIGlobalObject* aGlobalObject,
// const char *aReason,
// bool aIsMainThread = NS_IsMainThread());
// AutoEntryScript(JSObject* aObject,
// const char *aReason,
// bool aIsMainThread = NS_IsMainThread());
// ~AutoEntryScript();
// void SetWebIDLCallerPrincipal(nsIPrincipal *aPrincipal) {
// mWebIDLCallerPrincipal = aPrincipal;
// }
// private:
// class DocshellEntryMonitor final : public JS::dbg::AutoEntryMonitor
// {
// public:
// DocshellEntryMonitor(JSContext* aCx, const char* aReason);
// void Entry(JSContext* aCx, JSFunction* aFunction,
// JS::Handle<JS::Value> aAsyncStack,
// const char* aAsyncCause) override
// {
// Entry(aCx, aFunction, nullptr, aAsyncStack, aAsyncCause);
// }
// void Entry(JSContext* aCx, JSScript* aScript,
// JS::Handle<JS::Value> aAsyncStack,
// const char* aAsyncCause) override
// {
// Entry(aCx, nullptr, aScript, aAsyncStack, aAsyncCause);
// }
// void Exit(JSContext* aCx) override;
// private:
// void Entry(JSContext* aCx, JSFunction* aFunction, JSScript* aScript,
// JS::Handle<JS::Value> aAsyncStack,
// const char* aAsyncCause);
// const char* mReason;
// };
// nsIPrincipal* mWebIDLCallerPrincipal;
// friend nsIPrincipal* GetWebIDLCallerPrincipal();
mozilla::Maybe<DocshellEntryMonitor> mDocShellEntryMonitor;
// JS::AutoHideScriptedCaller mCallerOverride;
};
}
namespace mozilla {
template <class> class Maybe;
struct CycleCollectorResults;
}
namespace mozilla {
namespace dom {
struct nsIID {};
struct nsISupports {};
class CallbackObject : public nsISupports
{
// public:
// template<typename T, typename U> struct COMTypeInfo;
// public: virtual nsresult QueryInterface(const nsIID& aIID, void** aInstancePtr) override; virtual MozExternalRefCountType AddRef(void) override; virtual MozExternalRefCountType Release(void) override; virtual void DeleteCycleCollectable(void); typedef mozilla::FalseType HasThreadSafeRefCnt; protected: nsCycleCollectingAutoRefCnt mRefCnt; public:
// class cycleCollection : public nsXPCOMCycleCollectionParticipant { public: constexpr explicit cycleCollection (bool aSkip = true) : nsXPCOMCycleCollectionParticipant(true) {} private: public: virtual nsresult TraverseNative(void *p, nsCycleCollectionTraversalCallback &cb) override; virtual const char* ClassName() override { return "CallbackObject"; }; virtual void DeleteCycleCollectable(void *p) override { DowncastCCParticipant<CallbackObject>(p)->DeleteCycleCollectable(); } static CallbackObject* Downcast(nsISupports* s) { return static_cast<CallbackObject*>(static_cast<CallbackObject*>(s)); } static nsISupports* Upcast(CallbackObject *p) { return static_cast<nsISupports*>(static_cast<CallbackObject*>(p)); } template<typename T> friend nsISupports* ToSupports(T* p, cycleCollection* dummy); virtual void Unlink(void *p) override; virtual void Trace(void *p, const TraceCallbacks &cb, void *closure) override; virtual bool CanSkipReal(void *p, bool aRemovingAllowed) override; virtual bool CanSkipInCCReal(void *p) override; virtual bool CanSkipThisReal(void *p) override; static constexpr nsXPCOMCycleCollectionParticipant* GetParticipant() { return &CallbackObject::_cycleCollectorGlobal; } }; static cycleCollection _cycleCollectorGlobal;
// explicit CallbackObject(JSContext* aCx, JS::Handle<JSObject*> aCallback,
// nsIGlobalObject* aIncumbentGlobal)
// {
// if (aCx && JS::ContextOptionsRef(aCx).asyncStack()) {
// JS::RootedObject stack(aCx);
// if (!JS::CaptureCurrentStack(aCx, &stack)) {
// JS_ClearPendingException(aCx);
// }
// Init(aCallback, stack, aIncumbentGlobal);
// } else {
// Init(aCallback, nullptr, aIncumbentGlobal);
// }
// }
// explicit CallbackObject(JS::Handle<JSObject*> aCallback,
// JS::Handle<JSObject*> aAsyncStack,
// nsIGlobalObject* aIncumbentGlobal)
// {
// Init(aCallback, aAsyncStack, aIncumbentGlobal);
// }
// JS::Handle<JSObject*> CallbackOrNull() const
// {
// mCallback.exposeToActiveJS();
// return CallbackPreserveColor();
// }
// JSObject* GetCreationStack() const
// {
// return mCreationStack;
// }
// void MarkForCC()
// {
// mCallback.exposeToActiveJS();
// mCreationStack.exposeToActiveJS();
// }
// JS::Handle<JSObject*> CallbackPreserveColor() const
// {
// return JS::Handle<JSObject*>::fromMarkedLocation(mCallback.address());
// }
// JS::Handle<JSObject*> CallbackKnownNotGray() const
// {
// do { } while (0);
// return CallbackPreserveColor();
// }
// nsIGlobalObject* IncumbentGlobalOrNull() const
// {
// return mIncumbentGlobal;
// }
// enum ExceptionHandling {
// eReportExceptions,
// eRethrowContentExceptions,
// eRethrowExceptions
// };
// size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
// {
// return aMallocSizeOf(this);
// }
// protected:
// virtual ~CallbackObject()
// {
// DropJSObjects();
// }
// explicit CallbackObject(CallbackObject* aCallbackObject)
// {
// Init(aCallbackObject->mCallback, aCallbackObject->mCreationStack,
// aCallbackObject->mIncumbentGlobal);
// }
// bool operator==(const CallbackObject& aOther) const
// {
// JSObject* wrappedThis = CallbackPreserveColor();
// JSObject* wrappedOther = aOther.CallbackPreserveColor();
// if (!wrappedThis || !wrappedOther) {
// return this == &aOther;
// }
// JSObject* thisObj = js::UncheckedUnwrap(wrappedThis);
// JSObject* otherObj = js::UncheckedUnwrap(wrappedOther);
// return thisObj == otherObj;
// }
// class JSObjectsDropper final
// {
// public:
// explicit JSObjectsDropper(CallbackObject* aHolder)
// : mHolder(aHolder)
// {}
// ~JSObjectsDropper()
// {
// mHolder->DropJSObjects();
// }
// private:
// RefPtr<CallbackObject> mHolder;
// };
// private:
// inline void InitNoHold(JSObject* aCallback, JSObject* aCreationStack,
// nsIGlobalObject* aIncumbentGlobal)
// {
// do { } while (0);
// mCallback = aCallback;
// mCreationStack = aCreationStack;
// if (aIncumbentGlobal) {
// mIncumbentGlobal = aIncumbentGlobal;
// mIncumbentJSGlobal = aIncumbentGlobal->GetGlobalJSObject();
// }
// }
// inline void Init(JSObject* aCallback, JSObject* aCreationStack,
// nsIGlobalObject* aIncumbentGlobal)
// {
// InitNoHold(aCallback, aCreationStack, aIncumbentGlobal);
// mozilla::HoldJSObjects(this);
// }
// inline void ClearJSReferences()
// {
// mCallback = nullptr;
// mCreationStack = nullptr;
// mIncumbentJSGlobal = nullptr;
// }
// CallbackObject(const CallbackObject&) = delete;
// CallbackObject& operator =(const CallbackObject&) = delete;
// protected:
// void DropJSObjects()
// {
// do { } while (0);
// if (mCallback) {
// ClearJSReferences();
// mozilla::DropJSObjects(this);
// }
// }
// void Trace(JSTracer* aTracer);
// void FinishSlowJSInitIfMoreThanOneOwner(JSContext* aCx);
// struct FastCallbackConstructor {
// };
// CallbackObject(JS::Handle<JSObject*> aCallback,
// const FastCallbackConstructor&)
// {
// InitNoHold(aCallback, nullptr, nullptr);
// }
// JS::Heap<JSObject*> mCallback;
// JS::Heap<JSObject*> mCreationStack;
// nsCOMPtr<nsIGlobalObject> mIncumbentGlobal;
// JS::TenuredHeap<JSObject*> mIncumbentJSGlobal;
// class CallSetup
// {
// public:
// CallSetup(CallbackObject* aCallback, ErrorResult& aRv,
// const char* aExecutionReason,
// ExceptionHandling aExceptionHandling,
// JSCompartment* aCompartment = nullptr,
// bool aIsJSImplementedWebIDL = false);
// ~CallSetup();
// JSContext* GetContext() const
// {
// return mCx;
// }
// private:
// CallSetup(const CallSetup&) = delete;
// bool ShouldRethrowException(JS::Handle<JS::Value> aException);
// JSContext* mCx;
// JSCompartment* mCompartment;
mozilla::Maybe<js::AutoEntryScript> mAutoEntryScript;
mozilla::Maybe<AutoIncumbentScript> mAutoIncumbentScript;
mozilla::Maybe<JS::Rooted<JSObject*> > mRootedCallable;
mozilla::Maybe<JS::Rooted<JSObject*>> mAsyncStack;
mozilla::Maybe<JS::AutoSetAsyncStackForNewCalls> mAsyncStackSetter;
mozilla::Maybe<JSAutoCompartment> mAc;
};
}
}