зеркало из https://github.com/mozilla/gecko-dev.git
bug 120684, add ChromeNodeList so that chrome JS can create proper NodeList objects, r=baku
--HG-- extra : rebase_source : 7a06c3b8a9b485cd86c511fa0c2b13e9bd88106c
This commit is contained in:
Родитель
641d6dcaa6
Коммит
2e683ca304
|
@ -0,0 +1,50 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#include "mozilla/dom/ChromeNodeList.h"
|
||||
#include "mozilla/dom/ChromeNodeListBinding.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
already_AddRefed<ChromeNodeList>
|
||||
ChromeNodeList::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
nsIDocument* root = win ? win->GetExtantDoc() : nullptr;
|
||||
RefPtr<ChromeNodeList> list = new ChromeNodeList(root);
|
||||
return list.forget();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
ChromeNodeList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return ChromeNodeListBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
void
|
||||
ChromeNodeList::Append(nsINode& aNode, ErrorResult& aError)
|
||||
{
|
||||
if (!aNode.IsContent()) {
|
||||
// nsINodeList deals with nsIContent objects only, so need to
|
||||
// filter out other nodes for now.
|
||||
aError.Throw(NS_ERROR_DOM_TYPE_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
AppendElement(aNode.AsContent());
|
||||
}
|
||||
|
||||
void
|
||||
ChromeNodeList::Remove(nsINode& aNode, ErrorResult& aError)
|
||||
{
|
||||
if (!aNode.IsContent()) {
|
||||
aError.Throw(NS_ERROR_DOM_TYPE_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
RemoveElement(aNode.AsContent());
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsContentList.h"
|
||||
|
||||
namespace mozilla {
|
||||
class ErrorResult;
|
||||
|
||||
namespace dom {
|
||||
class GlobalObject;
|
||||
|
||||
class ChromeNodeList final : public nsSimpleContentList
|
||||
{
|
||||
public:
|
||||
explicit ChromeNodeList(nsINode* aOwner)
|
||||
: nsSimpleContentList(aOwner)
|
||||
{
|
||||
}
|
||||
|
||||
static already_AddRefed<ChromeNodeList>
|
||||
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
void Append(nsINode& aNode, ErrorResult& aError);
|
||||
void Remove(nsINode& aNode, ErrorResult& aError);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -154,6 +154,7 @@ EXPORTS.mozilla.dom += [
|
|||
'BarProps.h',
|
||||
'BlobSet.h',
|
||||
'ChildIterator.h',
|
||||
'ChromeNodeList.h',
|
||||
'ChromeUtils.h',
|
||||
'Comment.h',
|
||||
'Console.h',
|
||||
|
@ -217,6 +218,7 @@ UNIFIED_SOURCES += [
|
|||
'Attr.cpp',
|
||||
'BarProps.cpp',
|
||||
'ChildIterator.cpp',
|
||||
'ChromeNodeList.cpp',
|
||||
'ChromeUtils.cpp',
|
||||
'Comment.cpp',
|
||||
'Console.cpp',
|
||||
|
|
|
@ -26,6 +26,7 @@ support-files =
|
|||
window_nsITextInputProcessor.xul
|
||||
title_window.xul
|
||||
|
||||
[test_bug120684.xul]
|
||||
[test_bug206691.xul]
|
||||
[test_bug339494.xul]
|
||||
[test_bug357450.xul]
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
|
||||
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=120684
|
||||
-->
|
||||
<window title="Mozilla Bug 120684"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
||||
|
||||
<!-- test results are displayed in the html:body -->
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=120684"
|
||||
target="_blank">Mozilla Bug 120684</a>
|
||||
</body>
|
||||
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
/** Test for Bug 120684 **/
|
||||
|
||||
var list = new ChromeNodeList();
|
||||
is(list.length, 0, "Length should be initially 0.");
|
||||
|
||||
ok(list instanceof NodeList, "ChromeNodeList object should be an instance of NodeList.");
|
||||
|
||||
try {
|
||||
list.append(document);
|
||||
ok(false, "should have throw!");
|
||||
} catch(ex) {
|
||||
ok(true, "ChromeNodeList supports only nsIContent objects for now.");
|
||||
}
|
||||
|
||||
try {
|
||||
list.remove(document);
|
||||
ok(false, "should have throw!");
|
||||
} catch(ex) {
|
||||
ok(true, "ChromeNodeList supports only nsIContent objects for now.");
|
||||
}
|
||||
is(list.length, 0, "Length should be 0.");
|
||||
|
||||
list.append(document.documentElement);
|
||||
is(list.length, 1, "Length should be 1.");
|
||||
is(list[0], document.documentElement);
|
||||
is(list[1], undefined);
|
||||
|
||||
// Removing element which isn't in the list shouldn't do anything.
|
||||
list.remove(document.createElement("foo"));
|
||||
is(list.length, 1, "Length should be 1.");
|
||||
is(list[0], document.documentElement);
|
||||
|
||||
list.remove(document.documentElement);
|
||||
is(list.length, 0, "Length should be 0.");
|
||||
is(list[0], undefined);
|
||||
|
||||
var e1 = document.createElement("foo");
|
||||
var e2 = document.createElement("foo");
|
||||
var e3 = document.createElement("foo");
|
||||
|
||||
list.append(e1);
|
||||
list.append(e2);
|
||||
list.append(e3);
|
||||
|
||||
is(list[0], e1);
|
||||
is(list[1], e2);
|
||||
is(list[2], e3);
|
||||
is(list.length, 3);
|
||||
|
||||
list.remove(e2);
|
||||
is(list[0], e1);
|
||||
is(list[1], e3);
|
||||
is(list[2], undefined);
|
||||
is(list.length, 2);
|
||||
|
||||
// A leak test.
|
||||
list.expando = list;
|
||||
|
||||
]]>
|
||||
</script>
|
||||
</window>
|
|
@ -0,0 +1,13 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/.
|
||||
*/
|
||||
|
||||
[ChromeOnly, Constructor]
|
||||
interface ChromeNodeList : NodeList {
|
||||
[Throws]
|
||||
void append(Node aNode);
|
||||
[Throws]
|
||||
void remove(Node aNode);
|
||||
};
|
|
@ -75,6 +75,7 @@ WEBIDL_FILES = [
|
|||
'ChannelSplitterNode.webidl',
|
||||
'CharacterData.webidl',
|
||||
'ChildNode.webidl',
|
||||
'ChromeNodeList.webidl',
|
||||
'ChromeNotifications.webidl',
|
||||
'ChromeUtils.webidl',
|
||||
'Client.webidl',
|
||||
|
|
Загрузка…
Ссылка в новой задаче