Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / DocumentType.cpp
blob21cea2c8e86786507672f87157e3ce605a54a12d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * Implementation of DOM Core's DocumentType node.
9 */
11 #include "mozilla/dom/DocumentType.h"
12 #include "nsGkAtoms.h"
13 #include "nsCOMPtr.h"
14 #include "nsDOMString.h"
15 #include "nsNodeInfoManager.h"
16 #include "xpcpublic.h"
17 #include "nsWrapperCacheInlines.h"
18 #include "mozilla/dom/DocumentTypeBinding.h"
20 already_AddRefed<mozilla::dom::DocumentType> NS_NewDOMDocumentType(
21 nsNodeInfoManager* aNodeInfoManager, nsAtom* aName,
22 const nsAString& aPublicId, const nsAString& aSystemId,
23 const nsAString& aInternalSubset) {
24 MOZ_ASSERT(aName, "Must have a name");
26 RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfoManager->GetNodeInfo(
27 nsGkAtoms::documentTypeNodeName, nullptr, kNameSpaceID_None,
28 nsINode::DOCUMENT_TYPE_NODE, aName);
30 RefPtr<mozilla::dom::DocumentType> docType =
31 new (aNodeInfoManager) mozilla::dom::DocumentType(
32 ni.forget(), aPublicId, aSystemId, aInternalSubset);
33 return docType.forget();
36 namespace mozilla::dom {
38 JSObject* DocumentType::WrapNode(JSContext* cx,
39 JS::Handle<JSObject*> aGivenProto) {
40 return DocumentType_Binding::Wrap(cx, this, aGivenProto);
43 DocumentType::DocumentType(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
44 const nsAString& aPublicId,
45 const nsAString& aSystemId,
46 const nsAString& aInternalSubset)
47 : CharacterData(std::move(aNodeInfo)),
48 mPublicId(aPublicId),
49 mSystemId(aSystemId),
50 mInternalSubset(aInternalSubset) {
51 MOZ_ASSERT(mNodeInfo->NodeType() == DOCUMENT_TYPE_NODE,
52 "Bad NodeType in aNodeInfo");
53 MOZ_ASSERT(!IsCharacterData());
56 DocumentType::~DocumentType() = default;
58 const nsTextFragment* DocumentType::GetText() { return nullptr; }
60 void DocumentType::GetName(nsAString& aName) const { aName = NodeName(); }
62 void DocumentType::GetPublicId(nsAString& aPublicId) const {
63 aPublicId = mPublicId;
66 void DocumentType::GetSystemId(nsAString& aSystemId) const {
67 aSystemId = mSystemId;
70 void DocumentType::GetInternalSubset(nsAString& aInternalSubset) const {
71 aInternalSubset = mInternalSubset;
74 already_AddRefed<CharacterData> DocumentType::CloneDataNode(
75 mozilla::dom::NodeInfo* aNodeInfo, bool aCloneText) const {
76 return do_AddRef(new (aNodeInfo->NodeInfoManager()) DocumentType(
77 do_AddRef(aNodeInfo), mPublicId, mSystemId, mInternalSubset));
80 } // namespace mozilla::dom