зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1016053 - document.createElement('StorageEvent') must be supported, r=smaug
This commit is contained in:
Родитель
9ca7ade729
Коммит
0f7ee6d1fd
|
@ -16,6 +16,7 @@
|
|||
#include "GeneratedEvents.h"
|
||||
#include "mozilla/ContentEvents.h"
|
||||
#include "mozilla/dom/EventTarget.h"
|
||||
#include "mozilla/dom/StorageEvent.h"
|
||||
#include "mozilla/dom/TouchEvent.h"
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
#include "mozilla/EventListenerManager.h"
|
||||
|
@ -832,6 +833,10 @@ EventDispatcher::CreateEvent(EventTarget* aOwner,
|
|||
return NS_NewDOMMozSmsEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
||||
if (aEventType.LowerCaseEqualsLiteral("mozmmsevent"))
|
||||
return NS_NewDOMMozMmsEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
||||
if (aEventType.LowerCaseEqualsLiteral("storageevent")) {
|
||||
return NS_NewDOMStorageEvent(aDOMEvent, aOwner);
|
||||
}
|
||||
|
||||
|
||||
// NEW EVENT TYPES SHOULD NOT BE ADDED HERE; THEY SHOULD USE ONLY EVENT
|
||||
// CONSTRUCTORS
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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/StorageEvent.h"
|
||||
#include "nsIDOMStorage.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(StorageEvent)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(StorageEvent, Event)
|
||||
NS_IMPL_RELEASE_INHERITED(StorageEvent, Event)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(StorageEvent, Event)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStorageArea)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(StorageEvent, Event)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(StorageEvent, Event)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStorageArea)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(StorageEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(Event)
|
||||
|
||||
StorageEvent::StorageEvent(EventTarget* aOwner)
|
||||
: Event(aOwner, nullptr, nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
StorageEvent::~StorageEvent()
|
||||
{
|
||||
}
|
||||
|
||||
StorageEvent*
|
||||
StorageEvent::AsStorageEvent()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
JSObject*
|
||||
StorageEvent::WrapObject(JSContext* aCx)
|
||||
{
|
||||
return StorageEventBinding::Wrap(aCx, this);
|
||||
}
|
||||
|
||||
already_AddRefed<StorageEvent>
|
||||
StorageEvent::Constructor(EventTarget* aOwner,
|
||||
const nsAString& aType,
|
||||
const StorageEventInit& aEventInitDict)
|
||||
{
|
||||
nsRefPtr<StorageEvent> e = new StorageEvent(aOwner);
|
||||
|
||||
bool trusted = e->Init(aOwner);
|
||||
e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
|
||||
e->mKey = aEventInitDict.mKey;
|
||||
e->mOldValue = aEventInitDict.mOldValue;
|
||||
e->mNewValue = aEventInitDict.mNewValue;
|
||||
e->mUrl = aEventInitDict.mUrl;
|
||||
e->mStorageArea = aEventInitDict.mStorageArea;
|
||||
e->SetTrusted(trusted);
|
||||
|
||||
return e.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<StorageEvent>
|
||||
StorageEvent::Constructor(const GlobalObject& aGlobal,
|
||||
const nsAString& aType,
|
||||
const StorageEventInit& aEventInitDict,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
return Constructor(owner, aType, aEventInitDict);
|
||||
}
|
||||
|
||||
void
|
||||
StorageEvent::InitStorageEvent(const nsAString& aType, bool aCanBubble,
|
||||
bool aCancelable, const nsAString& aKey,
|
||||
const nsAString& aOldValue,
|
||||
const nsAString& aNewValue,
|
||||
const nsAString& aURL,
|
||||
nsIDOMStorage* aStorageArea,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
aRv = InitEvent(aType, aCanBubble, aCancelable);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mKey = aKey;
|
||||
mOldValue = aOldValue;
|
||||
mNewValue = aNewValue;
|
||||
mUrl = aURL;
|
||||
mStorageArea = aStorageArea;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
nsresult
|
||||
NS_NewDOMStorageEvent(nsIDOMEvent** aDOMEvent,
|
||||
mozilla::dom::EventTarget* aOwner)
|
||||
{
|
||||
nsRefPtr<mozilla::dom::StorageEvent> e =
|
||||
new mozilla::dom::StorageEvent(aOwner);
|
||||
|
||||
e->SetTrusted(e->Init(aOwner));
|
||||
e.forget(aDOMEvent);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_StorageEvent_h
|
||||
#define mozilla_dom_StorageEvent_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/Event.h"
|
||||
#include "mozilla/dom/StorageEventBinding.h"
|
||||
|
||||
class nsIDOMStorage;
|
||||
|
||||
// Helper for EventDispatcher.
|
||||
nsresult NS_NewDOMStorageEvent(nsIDOMEvent** aDOMEvent,
|
||||
mozilla::dom::EventTarget* aOwner);
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class StorageEvent : public Event
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(StorageEvent, Event)
|
||||
|
||||
StorageEvent(EventTarget* aOwner);
|
||||
virtual ~StorageEvent();
|
||||
|
||||
protected:
|
||||
nsString mKey;
|
||||
nsString mOldValue;
|
||||
nsString mNewValue;
|
||||
nsString mUrl;
|
||||
nsCOMPtr<nsIDOMStorage> mStorageArea;
|
||||
|
||||
public:
|
||||
virtual StorageEvent* AsStorageEvent();
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
||||
|
||||
static already_AddRefed<StorageEvent>
|
||||
Constructor(EventTarget* aOwner, const nsAString& aType,
|
||||
const StorageEventInit& aEventInitDict);
|
||||
|
||||
static already_AddRefed<StorageEvent>
|
||||
Constructor(const GlobalObject& aGlobal, const nsAString& aType,
|
||||
const StorageEventInit& aEventInitDict, ErrorResult& aRv);
|
||||
|
||||
void InitStorageEvent(const nsAString& aType, bool aCanBubble,
|
||||
bool aCancelable, const nsAString& aKey,
|
||||
const nsAString& aOldValue,
|
||||
const nsAString& aNewValue,
|
||||
const nsAString& aURL,
|
||||
nsIDOMStorage* aStorageArea,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void GetKey(nsString& aRetVal) const
|
||||
{
|
||||
aRetVal = mKey;
|
||||
}
|
||||
|
||||
void GetOldValue(nsString& aRetVal) const
|
||||
{
|
||||
aRetVal = mOldValue;
|
||||
}
|
||||
|
||||
void GetNewValue(nsString& aRetVal) const
|
||||
{
|
||||
aRetVal = mNewValue;
|
||||
}
|
||||
|
||||
void GetUrl(nsString& aRetVal) const
|
||||
{
|
||||
aRetVal = mUrl;
|
||||
}
|
||||
|
||||
nsIDOMStorage* GetStorageArea() const
|
||||
{
|
||||
return mStorageArea;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_StorageEvent_h
|
|
@ -54,6 +54,7 @@ EXPORTS.mozilla.dom += [
|
|||
'PointerEvent.h',
|
||||
'ScrollAreaEvent.h',
|
||||
'SimpleGestureEvent.h',
|
||||
'StorageEvent.h',
|
||||
'Touch.h',
|
||||
'TouchEvent.h',
|
||||
'TransitionEvent.h',
|
||||
|
@ -98,6 +99,7 @@ UNIFIED_SOURCES += [
|
|||
'PointerEvent.cpp',
|
||||
'ScrollAreaEvent.cpp',
|
||||
'SimpleGestureEvent.cpp',
|
||||
'StorageEvent.cpp',
|
||||
'TextComposition.cpp',
|
||||
'Touch.cpp',
|
||||
'TouchEvent.cpp',
|
||||
|
|
|
@ -155,3 +155,4 @@ skip-if = toolkit == 'android' #CRASH_DUMP, RANDOM
|
|||
[test_wheel_default_action.html]
|
||||
skip-if = buildapp == 'b2g' || e10s
|
||||
[test_bug985988.html]
|
||||
[test_dom_storage_event.html]
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for DOM StorageEvent</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
const kTests = [
|
||||
{ createEventArg: "StorageEvent",
|
||||
type: "aaa", bubbles: true, cancelable: true,
|
||||
key: null, oldValue: 'a', newValue: 'b', url: 'c', storageArea: null },
|
||||
|
||||
{ createEventArg: "storageevent",
|
||||
type: "bbb", bubbles: false, cancelable: true,
|
||||
key: 'key', oldValue: null, newValue: 'b', url: 'c', storageArea: null },
|
||||
|
||||
{ createEventArg: "Storageevent",
|
||||
type: "ccc", bubbles: true, cancelable: false,
|
||||
key: 'key', oldValue: 'a', newValue: null, url: 'c', storageArea: null },
|
||||
|
||||
{ createEventArg: "storageEvent",
|
||||
type: "ddd", bubbles: false, cancelable: false,
|
||||
key: 'key', oldValue: 'a', newValue: 'b', url: null, storageArea: null },
|
||||
|
||||
{ createEventArg: "StorageEvent",
|
||||
type: "eee", bubbles: true, cancelable: true,
|
||||
key: 'key', oldValue: 'a', newValue: 'b', url: 'c', storageArea: null },
|
||||
|
||||
{ createEventArg: "storageevent",
|
||||
type: "fff", bubbles: false, cancelable: true,
|
||||
key: null, oldValue: null, newValue: null, url: null, storageArea: null },
|
||||
];
|
||||
|
||||
for (var i = 0; i < kTests.length; i++) {
|
||||
var description = "test, Index: " + i + ", ";
|
||||
const kTest = kTests[i];
|
||||
var e = document.createEvent(kTest.createEventArg);
|
||||
e.initStorageEvent(kTest.type, kTest.bubbles, kTest.cancelable,
|
||||
kTest.key, kTest.oldValue, kTest.newValue, kTest.url,
|
||||
kTest.storageArea);
|
||||
|
||||
for (var attr in kTest) {
|
||||
if (attr == 'createEventArg')
|
||||
continue;
|
||||
|
||||
is(e[attr], kTest[attr], description + attr + " returns wrong value");
|
||||
}
|
||||
is(e.isTrusted, false, description + "isTrusted returns wrong value");
|
||||
}
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -559,6 +559,9 @@ is(receivedEvent, e, "Wrong event!");
|
|||
|
||||
// StorageEvent
|
||||
|
||||
e = document.createEvent("StorageEvent");
|
||||
ok(e, "Should have created an event!");
|
||||
|
||||
try {
|
||||
e = new StorageEvent();
|
||||
} catch(exp) {
|
||||
|
|
|
@ -19,6 +19,17 @@ interface StorageEvent : Event
|
|||
readonly attribute DOMString? newValue;
|
||||
readonly attribute DOMString? url;
|
||||
readonly attribute Storage? storageArea;
|
||||
|
||||
// Bug 1016053 - This is not spec compliant.
|
||||
[Throws]
|
||||
void initStorageEvent(DOMString type,
|
||||
boolean canBubble,
|
||||
boolean cancelable,
|
||||
DOMString? key,
|
||||
DOMString? oldValue,
|
||||
DOMString? newValue,
|
||||
DOMString? url,
|
||||
Storage? storageArea);
|
||||
};
|
||||
|
||||
dictionary StorageEventInit : EventInit
|
||||
|
|
|
@ -314,6 +314,7 @@ WEBIDL_FILES = [
|
|||
'SimpleGestureEvent.webidl',
|
||||
'SourceBuffer.webidl',
|
||||
'SourceBufferList.webidl',
|
||||
'StorageEvent.webidl',
|
||||
'StorageType.webidl',
|
||||
'StyleSheet.webidl',
|
||||
'StyleSheetList.webidl',
|
||||
|
@ -640,7 +641,6 @@ GENERATED_EVENTS_WEBIDL_FILES = [
|
|||
'RTCPeerConnectionIceEvent.webidl',
|
||||
'RTCPeerConnectionIdentityErrorEvent.webidl',
|
||||
'RTCPeerConnectionIdentityEvent.webidl',
|
||||
'StorageEvent.webidl',
|
||||
'TrackEvent.webidl',
|
||||
'UserProximityEvent.webidl',
|
||||
'USSDReceivedEvent.webidl',
|
||||
|
|
Загрузка…
Ссылка в новой задаче