From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/base/DocumentType.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 dom/base/DocumentType.cpp (limited to 'dom/base/DocumentType.cpp') diff --git a/dom/base/DocumentType.cpp b/dom/base/DocumentType.cpp new file mode 100644 index 0000000000..21cea2c8e8 --- /dev/null +++ b/dom/base/DocumentType.cpp @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implementation of DOM Core's DocumentType node. + */ + +#include "mozilla/dom/DocumentType.h" +#include "nsGkAtoms.h" +#include "nsCOMPtr.h" +#include "nsDOMString.h" +#include "nsNodeInfoManager.h" +#include "xpcpublic.h" +#include "nsWrapperCacheInlines.h" +#include "mozilla/dom/DocumentTypeBinding.h" + +already_AddRefed NS_NewDOMDocumentType( + nsNodeInfoManager* aNodeInfoManager, nsAtom* aName, + const nsAString& aPublicId, const nsAString& aSystemId, + const nsAString& aInternalSubset) { + MOZ_ASSERT(aName, "Must have a name"); + + RefPtr ni = aNodeInfoManager->GetNodeInfo( + nsGkAtoms::documentTypeNodeName, nullptr, kNameSpaceID_None, + nsINode::DOCUMENT_TYPE_NODE, aName); + + RefPtr docType = + new (aNodeInfoManager) mozilla::dom::DocumentType( + ni.forget(), aPublicId, aSystemId, aInternalSubset); + return docType.forget(); +} + +namespace mozilla::dom { + +JSObject* DocumentType::WrapNode(JSContext* cx, + JS::Handle aGivenProto) { + return DocumentType_Binding::Wrap(cx, this, aGivenProto); +} + +DocumentType::DocumentType(already_AddRefed&& aNodeInfo, + const nsAString& aPublicId, + const nsAString& aSystemId, + const nsAString& aInternalSubset) + : CharacterData(std::move(aNodeInfo)), + mPublicId(aPublicId), + mSystemId(aSystemId), + mInternalSubset(aInternalSubset) { + MOZ_ASSERT(mNodeInfo->NodeType() == DOCUMENT_TYPE_NODE, + "Bad NodeType in aNodeInfo"); + MOZ_ASSERT(!IsCharacterData()); +} + +DocumentType::~DocumentType() = default; + +const nsTextFragment* DocumentType::GetText() { return nullptr; } + +void DocumentType::GetName(nsAString& aName) const { aName = NodeName(); } + +void DocumentType::GetPublicId(nsAString& aPublicId) const { + aPublicId = mPublicId; +} + +void DocumentType::GetSystemId(nsAString& aSystemId) const { + aSystemId = mSystemId; +} + +void DocumentType::GetInternalSubset(nsAString& aInternalSubset) const { + aInternalSubset = mInternalSubset; +} + +already_AddRefed DocumentType::CloneDataNode( + mozilla::dom::NodeInfo* aNodeInfo, bool aCloneText) const { + return do_AddRef(new (aNodeInfo->NodeInfoManager()) DocumentType( + do_AddRef(aNodeInfo), mPublicId, mSystemId, mInternalSubset)); +} + +} // namespace mozilla::dom -- cgit v1.2.3