Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / ChromeNodeList.cpp
blob86df0ce52672336018a0877c46d9524ca0cc1256
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 #include "mozilla/dom/ChromeNodeList.h"
9 #include <new>
10 #include <utility>
11 #include "mozilla/ErrorResult.h"
12 #include "mozilla/RefPtr.h"
13 #include "mozilla/dom/BindingDeclarations.h"
14 #include "mozilla/dom/ChromeNodeListBinding.h"
15 #include "mozilla/dom/Document.h"
16 #include "nsCOMPtr.h"
17 #include "nsINode.h"
18 #include "nsISupports.h"
19 #include "nsPIDOMWindow.h"
20 #include "nsString.h"
21 #include "nsTArray.h"
23 using namespace mozilla;
24 using namespace mozilla::dom;
26 already_AddRefed<ChromeNodeList> ChromeNodeList::Constructor(
27 const GlobalObject& aGlobal) {
28 nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobal.GetAsSupports());
29 Document* root = win ? win->GetExtantDoc() : nullptr;
30 RefPtr<ChromeNodeList> list = new ChromeNodeList(root);
31 return list.forget();
34 JSObject* ChromeNodeList::WrapObject(JSContext* aCx,
35 JS::Handle<JSObject*> aGivenProto) {
36 return ChromeNodeList_Binding::Wrap(aCx, this, aGivenProto);
39 void ChromeNodeList::Append(nsINode& aNode, ErrorResult& aError) {
40 if (!aNode.IsContent()) {
41 // nsINodeList deals with nsIContent objects only, so need to
42 // filter out other nodes for now.
43 aError.ThrowTypeError("The node passed in is not a ChildNode");
44 return;
47 AppendElement(aNode.AsContent());
50 void ChromeNodeList::Remove(nsINode& aNode, ErrorResult& aError) {
51 if (!aNode.IsContent()) {
52 aError.ThrowTypeError("The node passed in is not a ChildNode");
53 return;
56 RemoveElement(aNode.AsContent());