mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 874758. Make DOMStringMap use [OverrideBuiltins]. r=peterv
This commit is contained in:
parent
8a0915646b
commit
b1208ea2a6
@ -10,6 +10,7 @@
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/dom/DOMStringMapBinding.h"
|
||||
#include "nsIDOMMutationEvent.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
@ -24,16 +25,23 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMStringMap)
|
||||
if (tmp->mElement) {
|
||||
// Call back to element to null out weak reference to this object.
|
||||
tmp->mElement->ClearDataset();
|
||||
tmp->mElement->RemoveMutationObserver(tmp);
|
||||
tmp->mElement = nullptr;
|
||||
}
|
||||
++tmp->mExpandoAndGeneration.generation;
|
||||
tmp->mExpandoAndGeneration.expando = JS::UndefinedValue();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMStringMap)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
||||
if (tmp->PreservingWrapper()) {
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mExpandoAndGeneration.expando);
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMStringMap)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
@ -45,6 +53,8 @@ nsDOMStringMap::nsDOMStringMap(nsGenericHTMLElement* aElement)
|
||||
mRemovingProp(false)
|
||||
{
|
||||
SetIsDOMBinding();
|
||||
|
||||
mElement->AddMutationObserver(this);
|
||||
}
|
||||
|
||||
nsDOMStringMap::~nsDOMStringMap()
|
||||
@ -53,6 +63,7 @@ nsDOMStringMap::~nsDOMStringMap()
|
||||
if (mElement) {
|
||||
// Call back to element to null out weak reference to this object.
|
||||
mElement->ClearDataset();
|
||||
mElement->RemoveMutationObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,3 +246,17 @@ bool nsDOMStringMap::AttrToDataProp(const nsAString& aAttr,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMStringMap::AttributeChanged(nsIDocument *aDocument, Element* aElement,
|
||||
int32_t aNameSpaceID, nsIAtom* aAttribute,
|
||||
int32_t aModType)
|
||||
{
|
||||
if ((aModType == nsIDOMMutationEvent::ADDITION ||
|
||||
aModType == nsIDOMMutationEvent::REMOVAL) &&
|
||||
aNameSpaceID == kNameSpaceID_None &&
|
||||
StringBeginsWith(nsDependentAtomString(aAttribute),
|
||||
NS_LITERAL_STRING("data-"))) {
|
||||
++mExpandoAndGeneration.generation;
|
||||
}
|
||||
}
|
||||
|
@ -13,18 +13,21 @@
|
||||
#include "nsString.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "jsfriendapi.h"
|
||||
|
||||
namespace mozilla {
|
||||
class ErrorResult;
|
||||
}
|
||||
|
||||
class nsDOMStringMap : public nsISupports,
|
||||
class nsDOMStringMap : public nsStubMutationObserver,
|
||||
public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMStringMap)
|
||||
|
||||
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
||||
|
||||
nsINode* GetParentObject()
|
||||
{
|
||||
return mElement;
|
||||
@ -42,6 +45,8 @@ public:
|
||||
void NamedDeleter(const nsAString& aProp, bool &found);
|
||||
void GetSupportedNames(nsTArray<nsString>& aNames);
|
||||
|
||||
js::ExpandoAndGeneration mExpandoAndGeneration;
|
||||
|
||||
private:
|
||||
virtual ~nsDOMStringMap();
|
||||
|
||||
|
@ -358,6 +358,7 @@ MOCHITEST_FILES = \
|
||||
wakelock.ogv \
|
||||
test_bug869040.html \
|
||||
allowMedia.sjs \
|
||||
test_bug874758.html \
|
||||
$(NULL)
|
||||
|
||||
MOCHITEST_CHROME_FILES = \
|
||||
|
31
content/html/content/test/test_bug874758.html
Normal file
31
content/html/content/test/test_bug874758.html
Normal file
@ -0,0 +1,31 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html data-expando-prop="xyz">
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=874758
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 874758</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 874758 **/
|
||||
Object.prototype.expandoProp = 5;
|
||||
is({}.expandoProp, 5, "Should see this on random objects");
|
||||
|
||||
is(document.head.dataset.expandoProp, 5, "Should see this on dataset too");
|
||||
is(document.documentElement.dataset.expandoProp, "xyz",
|
||||
"But if the dataset has it, we should get it from there");
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=874758">Mozilla Bug 874758</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -11,6 +11,7 @@
|
||||
* and create derivative works of this document.
|
||||
*/
|
||||
|
||||
[OverrideBuiltins]
|
||||
interface DOMStringMap {
|
||||
getter DOMString (DOMString name);
|
||||
[Throws]
|
||||
|
Loading…
x
Reference in New Issue
Block a user