Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM Sanitizer.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "AtomList.h"
#include "MainThreadUtils.h"
#include "SanitizerBinding.h"
#include "WrapperFactory.h"
#include "js/Array.h"
#include "js/CallAndConstruct.h"
#include "js/Exception.h"
#include "js/ForOfIterator.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/StaticPrefs_dom.h"
#include "mozilla/UseCounter.h"
#include "mozilla/dom/BindingCallContext.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/PrimitiveConversions.h"
#include "mozilla/dom/Sanitizer.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/SimpleGlobalObject.h"
#include "mozilla/dom/WebIDLPrefs.h"
#include "mozilla/dom/XrayExpandoClass.h"
namespace mozilla::dom {
namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningDocumentFragmentOrDocument& aUnion, const char* aName, uint32_t aFlags)
{
if (aUnion.IsDocumentFragment()) {
ImplCycleCollectionTraverse(aCallback, aUnion.GetAsDocumentFragment(), "mDocumentFragment", aFlags);
} else if (aUnion.IsDocument()) {
ImplCycleCollectionTraverse(aCallback, aUnion.GetAsDocument(), "mDocument", aFlags);
}
}
void
ImplCycleCollectionUnlink(OwningDocumentFragmentOrDocument& aUnion)
{
aUnion.Uninit();
}
bool
DocumentFragmentOrDocument::TrySetToDocumentFragment(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
NonNull<mozilla::dom::DocumentFragment>& memberSlot = RawSetAsDocumentFragment();
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::DocumentFragment, mozilla::dom::DocumentFragment>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyDocumentFragment();
tryNext = true;
return true;
}
}
}
return true;
}
bool
DocumentFragmentOrDocument::TrySetToDocumentFragment(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToDocumentFragment(cx, value, tryNext, passedToJSImpl);
}
bool
DocumentFragmentOrDocument::TrySetToDocument(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
NonNull<mozilla::dom::Document>& memberSlot = RawSetAsDocument();
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::Document, mozilla::dom::Document>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyDocument();
tryNext = true;
return true;
}
}
}
return true;
}
bool
DocumentFragmentOrDocument::TrySetToDocument(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToDocument(cx, value, tryNext, passedToJSImpl);
}
bool
DocumentFragmentOrDocument::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToDocumentFragment(cx, value, tryNext, passedToJSImpl)) || !tryNext ||
(failed = !TrySetToDocument(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "DocumentFragment, Document");
return false;
}
return true;
}
bool
DocumentFragmentOrDocument::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
bool
DocumentFragmentOrDocument::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eDocumentFragment: {
if (!GetOrCreateDOMReflector(cx, mValue.mDocumentFragment.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
case eDocument: {
if (!GetOrCreateDOMReflector(cx, mValue.mDocument.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningDocumentFragmentOrDocument::OwningDocumentFragmentOrDocument(OwningDocumentFragmentOrDocument&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eDocumentFragment: {
mType = eDocumentFragment;
mValue.mDocumentFragment.SetValue(std::move(aOther.mValue.mDocumentFragment.Value()));
break;
}
case eDocument: {
mType = eDocument;
mValue.mDocument.SetValue(std::move(aOther.mValue.mDocument.Value()));
break;
}
}
}
bool
OwningDocumentFragmentOrDocument::TrySetToDocumentFragment(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
OwningNonNull<mozilla::dom::DocumentFragment>& memberSlot = RawSetAsDocumentFragment();
static_assert(IsRefcounted<mozilla::dom::DocumentFragment>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::DocumentFragment, mozilla::dom::DocumentFragment>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyDocumentFragment();
tryNext = true;
return true;
}
}
}
return true;
}
bool
OwningDocumentFragmentOrDocument::TrySetToDocumentFragment(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToDocumentFragment(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] OwningNonNull<mozilla::dom::DocumentFragment>&
OwningDocumentFragmentOrDocument::RawSetAsDocumentFragment()
{
if (mType == eDocumentFragment) {
return mValue.mDocumentFragment.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eDocumentFragment;
return mValue.mDocumentFragment.SetValue();
}
[[nodiscard]] OwningNonNull<mozilla::dom::DocumentFragment>&
OwningDocumentFragmentOrDocument::SetAsDocumentFragment()
{
if (mType == eDocumentFragment) {
return mValue.mDocumentFragment.Value();
}
Uninit();
mType = eDocumentFragment;
return mValue.mDocumentFragment.SetValue();
}
void
OwningDocumentFragmentOrDocument::DestroyDocumentFragment()
{
MOZ_RELEASE_ASSERT(IsDocumentFragment(), "Wrong type!");
mValue.mDocumentFragment.Destroy();
mType = eUninitialized;
}
bool
OwningDocumentFragmentOrDocument::TrySetToDocument(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
OwningNonNull<mozilla::dom::Document>& memberSlot = RawSetAsDocument();
static_assert(IsRefcounted<mozilla::dom::Document>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::Document, mozilla::dom::Document>(value, memberSlot, cx);
if (NS_FAILED(rv)) {
DestroyDocument();
tryNext = true;
return true;
}
}
}
return true;
}
bool
OwningDocumentFragmentOrDocument::TrySetToDocument(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToDocument(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] OwningNonNull<mozilla::dom::Document>&
OwningDocumentFragmentOrDocument::RawSetAsDocument()
{
if (mType == eDocument) {
return mValue.mDocument.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eDocument;
return mValue.mDocument.SetValue();
}
[[nodiscard]] OwningNonNull<mozilla::dom::Document>&
OwningDocumentFragmentOrDocument::SetAsDocument()
{
if (mType == eDocument) {
return mValue.mDocument.Value();
}
Uninit();
mType = eDocument;
return mValue.mDocument.SetValue();
}
void
OwningDocumentFragmentOrDocument::DestroyDocument()
{
MOZ_RELEASE_ASSERT(IsDocument(), "Wrong type!");
mValue.mDocument.Destroy();
mType = eUninitialized;
}
bool
OwningDocumentFragmentOrDocument::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (value.isObject()) {
done = (failed = !TrySetToDocumentFragment(cx, value, tryNext, passedToJSImpl)) || !tryNext ||
(failed = !TrySetToDocument(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "DocumentFragment, Document");
return false;
}
return true;
}
bool
OwningDocumentFragmentOrDocument::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningDocumentFragmentOrDocument::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eDocumentFragment: {
DestroyDocumentFragment();
break;
}
case eDocument: {
DestroyDocument();
break;
}
}
}
bool
OwningDocumentFragmentOrDocument::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
{
switch (mType) {
case eUninitialized: {
return false;
}
case eDocumentFragment: {
if (!GetOrCreateDOMReflector(cx, mValue.mDocumentFragment.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
case eDocument: {
if (!GetOrCreateDOMReflector(cx, mValue.mDocument.Value(), rval)) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
default: {
return false;
}
}
}
OwningDocumentFragmentOrDocument&
OwningDocumentFragmentOrDocument::operator=(OwningDocumentFragmentOrDocument&& aOther)
{
this->~OwningDocumentFragmentOrDocument();
new (this) OwningDocumentFragmentOrDocument (std::move(aOther));
return *this;
}
OwningDocumentFragmentOrDocument&
OwningDocumentFragmentOrDocument::operator=(const OwningDocumentFragmentOrDocument& aOther)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eDocumentFragment: {
SetAsDocumentFragment() = aOther.GetAsDocumentFragment();
break;
}
case eDocument: {
SetAsDocument() = aOther.GetAsDocument();
break;
}
}
return *this;
}
SanitizerAttributeNamespace::SanitizerAttributeNamespace()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
SanitizerAttributeNamespace::InitIds(JSContext* cx, SanitizerAttributeNamespaceAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->namespace_id.init(cx, "namespace") ||
!atomsCache->name_id.init(cx, "name")) {
return false;
}
return true;
}
bool
SanitizerAttributeNamespace::Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// Passing a null JSContext is OK only if we're initing from null,
// Since in that case we will not have to do any property gets
// Also evaluate isNullOrUndefined in order to avoid false-positive
// checkers by static analysis tools
MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
SanitizerAttributeNamespaceAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<SanitizerAttributeNamespaceAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
if (!IsConvertibleToDictionary(val)) {
return cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>(sourceDescription, "dictionary");
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
return false;
}
mIsAnyMemberPresent = true;
} else if (cx) {
// Don't error out if we have no cx. In that
// situation the caller is default-constructing us and we'll
// just assume they know what they're doing.
return cx.ThrowErrorMessage<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>("'name' member of SanitizerAttributeNamespace");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->namespace_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, mNamespace)) {
return false;
}
} else {
mNamespace.SetIsVoid(true);
}
mIsAnyMemberPresent = true;
return true;
}
bool
SanitizerAttributeNamespace::Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// We don't want to use sourceDescription for our context here;
// that's not really what it's formatted for.
BindingCallContext cx(cx_, nullptr);
return Init(cx, val, sourceDescription, passedToJSImpl);
}
void
SanitizerAttributeNamespace::TraceDictionary(JSTracer* trc)
{
}
SanitizerAttributeNamespace&
SanitizerAttributeNamespace::operator=(const SanitizerAttributeNamespace& aOther)
{
DictionaryBase::operator=(aOther);
mName = aOther.mName;
mNamespace = aOther.mNamespace;
return *this;
}
bool
SanitizerAttributeNamespace::operator==(const SanitizerAttributeNamespace& aOther) const
{
if (mName != aOther.mName) {
return false;
}
if (mNamespace != aOther.mNamespace) {
return false;
}
return true;
}
SanitizerElementNamespace::SanitizerElementNamespace()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
SanitizerElementNamespace::InitIds(JSContext* cx, SanitizerElementNamespaceAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->namespace_id.init(cx, "namespace") ||
!atomsCache->name_id.init(cx, "name")) {
return false;
}
return true;
}
bool
SanitizerElementNamespace::Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// Passing a null JSContext is OK only if we're initing from null,
// Since in that case we will not have to do any property gets
// Also evaluate isNullOrUndefined in order to avoid false-positive
// checkers by static analysis tools
MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
SanitizerElementNamespaceAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<SanitizerElementNamespaceAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
if (!IsConvertibleToDictionary(val)) {
return cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>(sourceDescription, "dictionary");
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
return false;
}
mIsAnyMemberPresent = true;
} else if (cx) {
// Don't error out if we have no cx. In that
// situation the caller is default-constructing us and we'll
// just assume they know what they're doing.
return cx.ThrowErrorMessage<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>("'name' member of SanitizerElementNamespace");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->namespace_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, mNamespace)) {
return false;
}
} else {
mNamespace.AssignLiteral(u"http://www.w3.org/1999/xhtml");
}
mIsAnyMemberPresent = true;
return true;
}
bool
SanitizerElementNamespace::Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// We don't want to use sourceDescription for our context here;
// that's not really what it's formatted for.
BindingCallContext cx(cx_, nullptr);
return Init(cx, val, sourceDescription, passedToJSImpl);
}
void
SanitizerElementNamespace::TraceDictionary(JSTracer* trc)
{
}
SanitizerElementNamespace&
SanitizerElementNamespace::operator=(const SanitizerElementNamespace& aOther)
{
DictionaryBase::operator=(aOther);
mName = aOther.mName;
mNamespace = aOther.mNamespace;
return *this;
}
bool
SanitizerElementNamespace::operator==(const SanitizerElementNamespace& aOther) const
{
if (mName != aOther.mName) {
return false;
}
if (mNamespace != aOther.mNamespace) {
return false;
}
return true;
}
bool
StringOrSanitizerAttributeNamespace::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
binding_detail::FakeString<char16_t>& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
bool
StringOrSanitizerAttributeNamespace::TrySetToSanitizerAttributeNamespace(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
binding_detail::FastSanitizerAttributeNamespace& memberSlot = RawSetAsSanitizerAttributeNamespace();
if (!IsConvertibleToDictionary(value)) {
DestroySanitizerAttributeNamespace();
tryNext = true;
return true;
}
if (!memberSlot.Init(cx, value, "SanitizerAttributeNamespace branch of (DOMString or SanitizerAttributeNamespace)", passedToJSImpl)) {
return false;
}
}
return true;
}
bool
StringOrSanitizerAttributeNamespace::TrySetToSanitizerAttributeNamespace(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToSanitizerAttributeNamespace(cx, value, tryNext, passedToJSImpl);
}
bool
StringOrSanitizerAttributeNamespace::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (!done) {
done = (failed = !TrySetToSanitizerAttributeNamespace(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "SanitizerAttributeNamespace");
return false;
}
return true;
}
bool
StringOrSanitizerAttributeNamespace::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
OwningStringOrSanitizerAttributeNamespace::OwningStringOrSanitizerAttributeNamespace(OwningStringOrSanitizerAttributeNamespace&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eString: {
mType = eString;
mValue.mString.SetValue(std::move(aOther.mValue.mString.Value()));
break;
}
case eSanitizerAttributeNamespace: {
mType = eSanitizerAttributeNamespace;
mValue.mSanitizerAttributeNamespace.SetValue(std::move(aOther.mValue.mSanitizerAttributeNamespace.Value()));
break;
}
}
}
bool
OwningStringOrSanitizerAttributeNamespace::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
nsString& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
[[nodiscard]] nsString&
OwningStringOrSanitizerAttributeNamespace::RawSetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eString;
return mValue.mString.SetValue();
}
[[nodiscard]] nsString&
OwningStringOrSanitizerAttributeNamespace::SetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
Uninit();
mType = eString;
return mValue.mString.SetValue();
}
void
OwningStringOrSanitizerAttributeNamespace::DestroyString()
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
mValue.mString.Destroy();
mType = eUninitialized;
}
bool
OwningStringOrSanitizerAttributeNamespace::TrySetToSanitizerAttributeNamespace(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
SanitizerAttributeNamespace& memberSlot = RawSetAsSanitizerAttributeNamespace();
if (!IsConvertibleToDictionary(value)) {
DestroySanitizerAttributeNamespace();
tryNext = true;
return true;
}
if (!memberSlot.Init(cx, value, "SanitizerAttributeNamespace branch of (DOMString or SanitizerAttributeNamespace)", passedToJSImpl)) {
return false;
}
}
return true;
}
bool
OwningStringOrSanitizerAttributeNamespace::TrySetToSanitizerAttributeNamespace(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToSanitizerAttributeNamespace(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] SanitizerAttributeNamespace&
OwningStringOrSanitizerAttributeNamespace::RawSetAsSanitizerAttributeNamespace()
{
if (mType == eSanitizerAttributeNamespace) {
return mValue.mSanitizerAttributeNamespace.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eSanitizerAttributeNamespace;
return mValue.mSanitizerAttributeNamespace.SetValue();
}
[[nodiscard]] SanitizerAttributeNamespace&
OwningStringOrSanitizerAttributeNamespace::SetAsSanitizerAttributeNamespace()
{
if (mType == eSanitizerAttributeNamespace) {
return mValue.mSanitizerAttributeNamespace.Value();
}
Uninit();
mType = eSanitizerAttributeNamespace;
return mValue.mSanitizerAttributeNamespace.SetValue();
}
void
OwningStringOrSanitizerAttributeNamespace::DestroySanitizerAttributeNamespace()
{
MOZ_RELEASE_ASSERT(IsSanitizerAttributeNamespace(), "Wrong type!");
mValue.mSanitizerAttributeNamespace.Destroy();
mType = eUninitialized;
}
bool
OwningStringOrSanitizerAttributeNamespace::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (!done) {
done = (failed = !TrySetToSanitizerAttributeNamespace(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "SanitizerAttributeNamespace");
return false;
}
return true;
}
bool
OwningStringOrSanitizerAttributeNamespace::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningStringOrSanitizerAttributeNamespace::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eString: {
DestroyString();
break;
}
case eSanitizerAttributeNamespace: {
DestroySanitizerAttributeNamespace();
break;
}
}
}
OwningStringOrSanitizerAttributeNamespace&
OwningStringOrSanitizerAttributeNamespace::operator=(OwningStringOrSanitizerAttributeNamespace&& aOther)
{
this->~OwningStringOrSanitizerAttributeNamespace();
new (this) OwningStringOrSanitizerAttributeNamespace (std::move(aOther));
return *this;
}
OwningStringOrSanitizerAttributeNamespace&
OwningStringOrSanitizerAttributeNamespace::operator=(const OwningStringOrSanitizerAttributeNamespace& aOther)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eString: {
SetAsString() = aOther.GetAsString();
break;
}
case eSanitizerAttributeNamespace: {
SetAsSanitizerAttributeNamespace() = aOther.GetAsSanitizerAttributeNamespace();
break;
}
}
return *this;
}
bool
StringOrSanitizerElementNamespace::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
binding_detail::FakeString<char16_t>& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
bool
StringOrSanitizerElementNamespace::TrySetToSanitizerElementNamespace(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
binding_detail::FastSanitizerElementNamespace& memberSlot = RawSetAsSanitizerElementNamespace();
if (!IsConvertibleToDictionary(value)) {
DestroySanitizerElementNamespace();
tryNext = true;
return true;
}
if (!memberSlot.Init(cx, value, "SanitizerElementNamespace branch of (DOMString or SanitizerElementNamespace)", passedToJSImpl)) {
return false;
}
}
return true;
}
bool
StringOrSanitizerElementNamespace::TrySetToSanitizerElementNamespace(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToSanitizerElementNamespace(cx, value, tryNext, passedToJSImpl);
}
bool
StringOrSanitizerElementNamespace::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (!done) {
done = (failed = !TrySetToSanitizerElementNamespace(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "SanitizerElementNamespace");
return false;
}
return true;
}
bool
StringOrSanitizerElementNamespace::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
OwningStringOrSanitizerElementNamespace::OwningStringOrSanitizerElementNamespace(OwningStringOrSanitizerElementNamespace&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eString: {
mType = eString;
mValue.mString.SetValue(std::move(aOther.mValue.mString.Value()));
break;
}
case eSanitizerElementNamespace: {
mType = eSanitizerElementNamespace;
mValue.mSanitizerElementNamespace.SetValue(std::move(aOther.mValue.mSanitizerElementNamespace.Value()));
break;
}
}
}
bool
OwningStringOrSanitizerElementNamespace::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
nsString& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
[[nodiscard]] nsString&
OwningStringOrSanitizerElementNamespace::RawSetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eString;
return mValue.mString.SetValue();
}
[[nodiscard]] nsString&
OwningStringOrSanitizerElementNamespace::SetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
Uninit();
mType = eString;
return mValue.mString.SetValue();
}
void
OwningStringOrSanitizerElementNamespace::DestroyString()
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
mValue.mString.Destroy();
mType = eUninitialized;
}
bool
OwningStringOrSanitizerElementNamespace::TrySetToSanitizerElementNamespace(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
SanitizerElementNamespace& memberSlot = RawSetAsSanitizerElementNamespace();
if (!IsConvertibleToDictionary(value)) {
DestroySanitizerElementNamespace();
tryNext = true;
return true;
}
if (!memberSlot.Init(cx, value, "SanitizerElementNamespace branch of (DOMString or SanitizerElementNamespace)", passedToJSImpl)) {
return false;
}
}
return true;
}
bool
OwningStringOrSanitizerElementNamespace::TrySetToSanitizerElementNamespace(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToSanitizerElementNamespace(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] SanitizerElementNamespace&
OwningStringOrSanitizerElementNamespace::RawSetAsSanitizerElementNamespace()
{
if (mType == eSanitizerElementNamespace) {
return mValue.mSanitizerElementNamespace.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eSanitizerElementNamespace;
return mValue.mSanitizerElementNamespace.SetValue();
}
[[nodiscard]] SanitizerElementNamespace&
OwningStringOrSanitizerElementNamespace::SetAsSanitizerElementNamespace()
{
if (mType == eSanitizerElementNamespace) {
return mValue.mSanitizerElementNamespace.Value();
}
Uninit();
mType = eSanitizerElementNamespace;
return mValue.mSanitizerElementNamespace.SetValue();
}
void
OwningStringOrSanitizerElementNamespace::DestroySanitizerElementNamespace()
{
MOZ_RELEASE_ASSERT(IsSanitizerElementNamespace(), "Wrong type!");
mValue.mSanitizerElementNamespace.Destroy();
mType = eUninitialized;
}
bool
OwningStringOrSanitizerElementNamespace::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (!done) {
done = (failed = !TrySetToSanitizerElementNamespace(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "SanitizerElementNamespace");
return false;
}
return true;
}
bool
OwningStringOrSanitizerElementNamespace::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningStringOrSanitizerElementNamespace::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eString: {
DestroyString();
break;
}
case eSanitizerElementNamespace: {
DestroySanitizerElementNamespace();
break;
}
}
}
OwningStringOrSanitizerElementNamespace&
OwningStringOrSanitizerElementNamespace::operator=(OwningStringOrSanitizerElementNamespace&& aOther)
{
this->~OwningStringOrSanitizerElementNamespace();
new (this) OwningStringOrSanitizerElementNamespace (std::move(aOther));
return *this;
}
OwningStringOrSanitizerElementNamespace&
OwningStringOrSanitizerElementNamespace::operator=(const OwningStringOrSanitizerElementNamespace& aOther)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eString: {
SetAsString() = aOther.GetAsString();
break;
}
case eSanitizerElementNamespace: {
SetAsSanitizerElementNamespace() = aOther.GetAsSanitizerElementNamespace();
break;
}
}
return *this;
}
SanitizerElementNamespaceWithAttributes::SanitizerElementNamespaceWithAttributes()
: SanitizerElementNamespace(FastDictionaryInitializer())
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
SanitizerElementNamespaceWithAttributes::InitIds(JSContext* cx, SanitizerElementNamespaceWithAttributesAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->removeAttributes_id.init(cx, "removeAttributes") ||
!atomsCache->attributes_id.init(cx, "attributes")) {
return false;
}
return true;
}
bool
SanitizerElementNamespaceWithAttributes::Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// Passing a null JSContext is OK only if we're initing from null,
// Since in that case we will not have to do any property gets
// Also evaluate isNullOrUndefined in order to avoid false-positive
// checkers by static analysis tools
MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
SanitizerElementNamespaceWithAttributesAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<SanitizerElementNamespaceWithAttributesAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
// Per spec, we init the parent's members first
if (!SanitizerElementNamespace::Init(cx, val)) {
return false;
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->attributes_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mAttributes.Construct();
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'attributes' member of SanitizerElementNamespaceWithAttributes", "sequence");
return false;
}
Sequence<OwningStringOrSanitizerAttributeNamespace> &arr = (mAttributes.Value());
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
OwningStringOrSanitizerAttributeNamespace* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
OwningStringOrSanitizerAttributeNamespace& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'attributes' member of SanitizerElementNamespaceWithAttributes", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'attributes' member of SanitizerElementNamespaceWithAttributes", "sequence");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->removeAttributes_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mRemoveAttributes.Construct();
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'removeAttributes' member of SanitizerElementNamespaceWithAttributes", "sequence");
return false;
}
Sequence<OwningStringOrSanitizerAttributeNamespace> &arr = (mRemoveAttributes.Value());
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
OwningStringOrSanitizerAttributeNamespace* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
OwningStringOrSanitizerAttributeNamespace& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'removeAttributes' member of SanitizerElementNamespaceWithAttributes", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'removeAttributes' member of SanitizerElementNamespaceWithAttributes", "sequence");
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
SanitizerElementNamespaceWithAttributes::Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// We don't want to use sourceDescription for our context here;
// that's not really what it's formatted for.
BindingCallContext cx(cx_, nullptr);
return Init(cx, val, sourceDescription, passedToJSImpl);
}
void
SanitizerElementNamespaceWithAttributes::TraceDictionary(JSTracer* trc)
{
SanitizerElementNamespace::TraceDictionary(trc);
}
SanitizerElementNamespaceWithAttributes&
SanitizerElementNamespaceWithAttributes::operator=(const SanitizerElementNamespaceWithAttributes& aOther)
{
SanitizerElementNamespace::operator=(aOther);
mAttributes.Reset();
if (aOther.mAttributes.WasPassed()) {
mAttributes.Construct(aOther.mAttributes.Value());
}
mRemoveAttributes.Reset();
if (aOther.mRemoveAttributes.WasPassed()) {
mRemoveAttributes.Construct(aOther.mRemoveAttributes.Value());
}
return *this;
}
bool
StringOrSanitizerElementNamespaceWithAttributes::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
binding_detail::FakeString<char16_t>& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
bool
StringOrSanitizerElementNamespaceWithAttributes::TrySetToSanitizerElementNamespaceWithAttributes(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
binding_detail::FastSanitizerElementNamespaceWithAttributes& memberSlot = RawSetAsSanitizerElementNamespaceWithAttributes();
if (!IsConvertibleToDictionary(value)) {
DestroySanitizerElementNamespaceWithAttributes();
tryNext = true;
return true;
}
if (!memberSlot.Init(cx, value, "SanitizerElementNamespaceWithAttributes branch of (DOMString or SanitizerElementNamespaceWithAttributes)", passedToJSImpl)) {
return false;
}
}
return true;
}
bool
StringOrSanitizerElementNamespaceWithAttributes::TrySetToSanitizerElementNamespaceWithAttributes(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToSanitizerElementNamespaceWithAttributes(cx, value, tryNext, passedToJSImpl);
}
bool
StringOrSanitizerElementNamespaceWithAttributes::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (!done) {
done = (failed = !TrySetToSanitizerElementNamespaceWithAttributes(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "SanitizerElementNamespaceWithAttributes");
return false;
}
return true;
}
bool
StringOrSanitizerElementNamespaceWithAttributes::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
OwningStringOrSanitizerElementNamespaceWithAttributes::OwningStringOrSanitizerElementNamespaceWithAttributes(OwningStringOrSanitizerElementNamespaceWithAttributes&& aOther)
: mType(eUninitialized)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eString: {
mType = eString;
mValue.mString.SetValue(std::move(aOther.mValue.mString.Value()));
break;
}
case eSanitizerElementNamespaceWithAttributes: {
mType = eSanitizerElementNamespaceWithAttributes;
mValue.mSanitizerElementNamespaceWithAttributes.SetValue(std::move(aOther.mValue.mSanitizerElementNamespaceWithAttributes.Value()));
break;
}
}
}
bool
OwningStringOrSanitizerElementNamespaceWithAttributes::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
nsString& memberSlot = RawSetAsString();
if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
return false;
}
}
return true;
}
[[nodiscard]] nsString&
OwningStringOrSanitizerElementNamespaceWithAttributes::RawSetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eString;
return mValue.mString.SetValue();
}
[[nodiscard]] nsString&
OwningStringOrSanitizerElementNamespaceWithAttributes::SetAsString()
{
if (mType == eString) {
return mValue.mString.Value();
}
Uninit();
mType = eString;
return mValue.mString.SetValue();
}
void
OwningStringOrSanitizerElementNamespaceWithAttributes::DestroyString()
{
MOZ_RELEASE_ASSERT(IsString(), "Wrong type!");
mValue.mString.Destroy();
mType = eUninitialized;
}
bool
OwningStringOrSanitizerElementNamespaceWithAttributes::TrySetToSanitizerElementNamespaceWithAttributes(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
tryNext = false;
{ // scope for memberSlot
SanitizerElementNamespaceWithAttributes& memberSlot = RawSetAsSanitizerElementNamespaceWithAttributes();
if (!IsConvertibleToDictionary(value)) {
DestroySanitizerElementNamespaceWithAttributes();
tryNext = true;
return true;
}
if (!memberSlot.Init(cx, value, "SanitizerElementNamespaceWithAttributes branch of (DOMString or SanitizerElementNamespaceWithAttributes)", passedToJSImpl)) {
return false;
}
}
return true;
}
bool
OwningStringOrSanitizerElementNamespaceWithAttributes::TrySetToSanitizerElementNamespaceWithAttributes(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return TrySetToSanitizerElementNamespaceWithAttributes(cx, value, tryNext, passedToJSImpl);
}
[[nodiscard]] SanitizerElementNamespaceWithAttributes&
OwningStringOrSanitizerElementNamespaceWithAttributes::RawSetAsSanitizerElementNamespaceWithAttributes()
{
if (mType == eSanitizerElementNamespaceWithAttributes) {
return mValue.mSanitizerElementNamespaceWithAttributes.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eSanitizerElementNamespaceWithAttributes;
return mValue.mSanitizerElementNamespaceWithAttributes.SetValue();
}
[[nodiscard]] SanitizerElementNamespaceWithAttributes&
OwningStringOrSanitizerElementNamespaceWithAttributes::SetAsSanitizerElementNamespaceWithAttributes()
{
if (mType == eSanitizerElementNamespaceWithAttributes) {
return mValue.mSanitizerElementNamespaceWithAttributes.Value();
}
Uninit();
mType = eSanitizerElementNamespaceWithAttributes;
return mValue.mSanitizerElementNamespaceWithAttributes.SetValue();
}
void
OwningStringOrSanitizerElementNamespaceWithAttributes::DestroySanitizerElementNamespaceWithAttributes()
{
MOZ_RELEASE_ASSERT(IsSanitizerElementNamespaceWithAttributes(), "Wrong type!");
mValue.mSanitizerElementNamespaceWithAttributes.Destroy();
mType = eUninitialized;
}
bool
OwningStringOrSanitizerElementNamespaceWithAttributes::Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
MOZ_ASSERT(mType == eUninitialized);
bool done = false, failed = false, tryNext;
if (!done) {
done = (failed = !TrySetToSanitizerElementNamespaceWithAttributes(cx, value, tryNext, passedToJSImpl)) || !tryNext;
}
if (!done) {
do {
done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext;
break;
} while (false);
}
if (failed) {
return false;
}
if (!done) {
cx.ThrowErrorMessage<MSG_NOT_IN_UNION>(sourceDescription, "SanitizerElementNamespaceWithAttributes");
return false;
}
return true;
}
bool
OwningStringOrSanitizerElementNamespaceWithAttributes::Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription, bool passedToJSImpl)
{
BindingCallContext cx(cx_, nullptr);
return Init(cx, value, sourceDescription, passedToJSImpl);
}
void
OwningStringOrSanitizerElementNamespaceWithAttributes::Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eString: {
DestroyString();
break;
}
case eSanitizerElementNamespaceWithAttributes: {
DestroySanitizerElementNamespaceWithAttributes();
break;
}
}
}
OwningStringOrSanitizerElementNamespaceWithAttributes&
OwningStringOrSanitizerElementNamespaceWithAttributes::operator=(OwningStringOrSanitizerElementNamespaceWithAttributes&& aOther)
{
this->~OwningStringOrSanitizerElementNamespaceWithAttributes();
new (this) OwningStringOrSanitizerElementNamespaceWithAttributes (std::move(aOther));
return *this;
}
OwningStringOrSanitizerElementNamespaceWithAttributes&
OwningStringOrSanitizerElementNamespaceWithAttributes::operator=(const OwningStringOrSanitizerElementNamespaceWithAttributes& aOther)
{
switch (aOther.mType) {
case eUninitialized: {
MOZ_ASSERT(mType == eUninitialized,
"We need to destroy ourselves?");
break;
}
case eString: {
SetAsString() = aOther.GetAsString();
break;
}
case eSanitizerElementNamespaceWithAttributes: {
SetAsSanitizerElementNamespaceWithAttributes() = aOther.GetAsSanitizerElementNamespaceWithAttributes();
break;
}
}
return *this;
}
SanitizerConfig::SanitizerConfig()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
SanitizerConfig::InitIds(JSContext* cx, SanitizerConfigAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->unknownMarkup_id.init(cx, "unknownMarkup") ||
!atomsCache->replaceWithChildrenElements_id.init(cx, "replaceWithChildrenElements") ||
!atomsCache->removeElements_id.init(cx, "removeElements") ||
!atomsCache->removeAttributes_id.init(cx, "removeAttributes") ||
!atomsCache->elements_id.init(cx, "elements") ||
!atomsCache->customElements_id.init(cx, "customElements") ||
!atomsCache->comments_id.init(cx, "comments") ||
!atomsCache->attributes_id.init(cx, "attributes")) {
return false;
}
return true;
}
bool
SanitizerConfig::Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// Passing a null JSContext is OK only if we're initing from null,
// Since in that case we will not have to do any property gets
// Also evaluate isNullOrUndefined in order to avoid false-positive
// checkers by static analysis tools
MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
SanitizerConfigAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<SanitizerConfigAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
if (!IsConvertibleToDictionary(val)) {
return cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>(sourceDescription, "dictionary");
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->attributes_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mAttributes.Construct();
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'attributes' member of SanitizerConfig", "sequence");
return false;
}
Sequence<OwningStringOrSanitizerAttributeNamespace> &arr = (mAttributes.Value());
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
OwningStringOrSanitizerAttributeNamespace* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
OwningStringOrSanitizerAttributeNamespace& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'attributes' member of SanitizerConfig", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'attributes' member of SanitizerConfig", "sequence");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->comments_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mComments.Construct();
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'comments' member of SanitizerConfig", &(mComments.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->customElements_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mCustomElements.Construct();
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'customElements' member of SanitizerConfig", &(mCustomElements.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->elements_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mElements.Construct();
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'elements' member of SanitizerConfig", "sequence");
return false;
}
Sequence<OwningStringOrSanitizerElementNamespaceWithAttributes> &arr = (mElements.Value());
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
OwningStringOrSanitizerElementNamespaceWithAttributes* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
OwningStringOrSanitizerElementNamespaceWithAttributes& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'elements' member of SanitizerConfig", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'elements' member of SanitizerConfig", "sequence");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->removeAttributes_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mRemoveAttributes.Construct();
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'removeAttributes' member of SanitizerConfig", "sequence");
return false;
}
Sequence<OwningStringOrSanitizerAttributeNamespace> &arr = (mRemoveAttributes.Value());
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
OwningStringOrSanitizerAttributeNamespace* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
OwningStringOrSanitizerAttributeNamespace& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'removeAttributes' member of SanitizerConfig", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'removeAttributes' member of SanitizerConfig", "sequence");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->removeElements_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mRemoveElements.Construct();
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'removeElements' member of SanitizerConfig", "sequence");
return false;
}
Sequence<OwningStringOrSanitizerElementNamespace> &arr = (mRemoveElements.Value());
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
OwningStringOrSanitizerElementNamespace* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
OwningStringOrSanitizerElementNamespace& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'removeElements' member of SanitizerConfig", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'removeElements' member of SanitizerConfig", "sequence");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->replaceWithChildrenElements_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mReplaceWithChildrenElements.Construct();
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'replaceWithChildrenElements' member of SanitizerConfig", "sequence");
return false;
}
Sequence<OwningStringOrSanitizerElementNamespace> &arr = (mReplaceWithChildrenElements.Value());
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
return false;
}
if (done) {
break;
}
OwningStringOrSanitizerElementNamespace* slotPtr = arr.AppendElement(mozilla::fallible);
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
return false;
}
OwningStringOrSanitizerElementNamespace& slot = *slotPtr;
if (!slot.Init(cx, temp, "Element of 'replaceWithChildrenElements' member of SanitizerConfig", passedToJSImpl)) {
return false;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'replaceWithChildrenElements' member of SanitizerConfig", "sequence");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->unknownMarkup_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mUnknownMarkup.Construct();
if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), "'unknownMarkup' member of SanitizerConfig", &(mUnknownMarkup.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
SanitizerConfig::Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
{
// We don't want to use sourceDescription for our context here;
// that's not really what it's formatted for.
BindingCallContext cx(cx_, nullptr);
return Init(cx, val, sourceDescription, passedToJSImpl);
}
void
SanitizerConfig::TraceDictionary(JSTracer* trc)
{
}
SanitizerConfig&
SanitizerConfig::operator=(const SanitizerConfig& aOther)
{
DictionaryBase::operator=(aOther);
mAttributes.Reset();
if (aOther.mAttributes.WasPassed()) {
mAttributes.Construct(aOther.mAttributes.Value());
}
mComments.Reset();
if (aOther.mComments.WasPassed()) {
mComments.Construct(aOther.mComments.Value());
}
mCustomElements.Reset();
if (aOther.mCustomElements.WasPassed()) {
mCustomElements.Construct(aOther.mCustomElements.Value());
}
mElements.Reset();
if (aOther.mElements.WasPassed()) {
mElements.Construct(aOther.mElements.Value());
}
mRemoveAttributes.Reset();
if (aOther.mRemoveAttributes.WasPassed()) {
mRemoveAttributes.Construct(aOther.mRemoveAttributes.Value());
}
mRemoveElements.Reset();
if (aOther.mRemoveElements.WasPassed()) {
mRemoveElements.Construct(aOther.mRemoveElements.Value());
}
mReplaceWithChildrenElements.Reset();
if (aOther.mReplaceWithChildrenElements.WasPassed()) {
mReplaceWithChildrenElements.Construct(aOther.mReplaceWithChildrenElements.Value());
}
mUnknownMarkup.Reset();
if (aOther.mUnknownMarkup.WasPassed()) {
mUnknownMarkup.Construct(aOther.mUnknownMarkup.Value());
}
return *this;
}
namespace Sanitizer_Binding {
MOZ_CAN_RUN_SCRIPT static bool
sanitize(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "Sanitizer.sanitize");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"Sanitizer", "sanitize", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::Sanitizer*>(void_self);
if (!args.requireAtLeast(cx, "Sanitizer.sanitize", 1)) {
return false;
}
DocumentFragmentOrDocument arg0;
if (!arg0.Init(cx, args[0], "Argument 1", false)) {
return false;
}
FastErrorResult rv;
auto result(StrongOrRawPtr<mozilla::dom::DocumentFragment>(MOZ_KnownLive(self)->Sanitize(Constify(arg0), rv)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "Sanitizer.sanitize"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
SetUseCounter(obj, eUseCounter_Sanitizer_sanitize);
if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
MOZ_ASSERT(JS_IsExceptionPending(cx));
return false;
}
return true;
}
static const JSJitInfo sanitize_methodinfo = {
{ (JSJitGetterOp)sanitize },
{ prototypes::id::Sanitizer },
{ PrototypeTraits<prototypes::id::Sanitizer>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_OBJECT, /* 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. */
};
static bool
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
{
mozilla::dom::Sanitizer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Sanitizer>(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::Sanitizer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Sanitizer>(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::Sanitizer>(self);
}
}
static nsWrapperCache*
_getWrapperCache(JS::Handle<JSObject*> obj)
{
mozilla::dom::Sanitizer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Sanitizer>(obj);
return self;
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::Sanitizer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Sanitizer>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sMethods_specs[] = {
JS_FNSPEC("sanitize", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sanitize_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
JS_FS_END
};
static const PrefableDisablers sMethods_disablers0 = {
WebIDLPrefIndex::NoPref, 0, true, OriginTrial(0), nullptr
};
static const Prefable<const JSFunctionSpec> sMethods[] = {
{ &sMethods_disablers0, &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(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 sNativeProperties_sortedPropertyIndices[1];
static PropertyInfo sNativeProperties_propertyInfos[1];
static const NativePropertiesN<1> sNativeProperties = {
false, 0,
false, 0,
true, 0 /* sMethods */,
false, 0,
false, 0,
false, 0,
false, 0,
-1,
1,
sNativeProperties_sortedPropertyIndices,
{
{ sMethods, &sNativeProperties_propertyInfos[0] }
}
};
static_assert(1 < 1ull << (CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount)),
"We have a property info count that is oversized");
bool sNativePropertiesInited = false;
const NativePropertyHooks sNativePropertyHooks = {
nullptr,
{ sNativeProperties.Upcast(), nullptr, &sNativePropertiesInited },
prototypes::id::Sanitizer,
constructors::id::Sanitizer,
&DefaultXrayExpandoObjectClass
};
static bool
_constructor(JSContext* cx_, unsigned argc, JS::Value* vp)
{
BindingCallContext cx(cx_, "Sanitizer constructor");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"Sanitizer", "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, "Sanitizer");
}
JS::Rooted<JSObject*> desiredProto(cx);
if (!GetDesiredProto(cx, args,
prototypes::id::Sanitizer,
CreateInterfaceObjects,
&desiredProto)) {
return false;
}
GlobalObject global(cx, obj);
if (global.Failed()) {
return false;
}
bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
binding_detail::FastSanitizerConfig arg0;
if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1", false)) {
return false;
}
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::Sanitizer>(mozilla::dom::Sanitizer::Constructor(global, Constify(arg0), rv)));
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "Sanitizer constructor"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
SetUseCounter(obj, eUseCounter_Sanitizer_constructor);
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 },
JS::GetRealmFunctionPrototype,
prototypes::id::Sanitizer,
PrototypeTraits<prototypes::id::Sanitizer>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"SanitizerPrototype",
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::Sanitizer,
PrototypeTraits<prototypes::id::Sanitizer>::Depth,
&sNativePropertyHooks,
JS::GetRealmObjectPrototype
};
bool
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
return StaticPrefs::dom_security_sanitizer_enabled() &&
mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
}
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 = {
{ "Sanitizer",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::Sanitizer, 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, mozilla::dom::Sanitizer>,
&sNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::Sanitizer>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::Sanitizer>::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::Sanitizer* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(!std::is_base_of_v<NonRefcountedDOMObject, mozilla::dom::Sanitizer>,
"Shouldn't have wrappercached things that are not refcounted.");
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::Sanitizer*>);
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::Sanitizer> 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::Sanitizer);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Sanitizer);
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,
"Sanitizer", aDefineOnGlobal,
nullptr,
false,
nullptr);
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace Sanitizer_Binding
} // namespace mozilla::dom