зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1379688 part 2. Make the EventTarget interface constructible. r=smaug
MozReview-Commit-ID: 4xrSSqXna7F
This commit is contained in:
Родитель
3dd8d0e9c1
Коммит
b5de3264a2
|
@ -317,7 +317,6 @@ DOMInterfaces = {
|
|||
# We can also get rid of the UnwrapArg bits in
|
||||
# the dom QueryInterface (in BindingUtils.cpp) at that point.
|
||||
'hasXPConnectImpls': True,
|
||||
'concrete': False,
|
||||
'jsImplParent': 'mozilla::DOMEventTargetHelper',
|
||||
},
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/* -*- 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/ConstructibleEventTarget.h"
|
||||
#include "mozilla/dom/EventTargetBinding.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
JSObject*
|
||||
ConstructibleEventTarget::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return EventTargetBinding::Wrap(cx, this, aGivenProto);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -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/. */
|
||||
|
||||
#ifndef mozilla_dom_ConstructibleEventTarget_h_
|
||||
#define mozilla_dom_ConstructibleEventTarget_h_
|
||||
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "js/RootingAPI.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ConstructibleEventTarget : public DOMEventTargetHelper
|
||||
{
|
||||
public:
|
||||
// Not worrying about isupports and cycle collection here. This does mean
|
||||
// ConstructibleEventTarget will show up in CC and refcount logs as a
|
||||
// DOMEventTargetHelper, but that's probably OK.
|
||||
|
||||
explicit ConstructibleEventTarget(nsIGlobalObject* aGlobalObject)
|
||||
: DOMEventTargetHelper(aGlobalObject)
|
||||
{
|
||||
}
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* cx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_ConstructibleEventTarget_h_
|
|
@ -143,10 +143,7 @@ public:
|
|||
void BindToOwner(nsPIDOMWindowInner* aOwner);
|
||||
void BindToOwner(DOMEventTargetHelper* aOther);
|
||||
virtual void DisconnectFromOwner();
|
||||
nsIGlobalObject* GetParentObject() const
|
||||
{
|
||||
return GetOwnerGlobal();
|
||||
}
|
||||
using EventTarget::GetParentObject;
|
||||
virtual nsIGlobalObject* GetOwnerGlobal() const override
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> parentObject = do_QueryReferent(mParentObject);
|
||||
|
|
|
@ -7,11 +7,26 @@
|
|||
#include "mozilla/EventListenerManager.h"
|
||||
#include "mozilla/dom/EventTarget.h"
|
||||
#include "mozilla/dom/EventTargetBinding.h"
|
||||
#include "mozilla/dom/ConstructibleEventTarget.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/* static */
|
||||
already_AddRefed<EventTarget>
|
||||
EventTarget::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
if (!global) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<EventTarget> target = new ConstructibleEventTarget(global);
|
||||
return target.forget();
|
||||
}
|
||||
|
||||
void
|
||||
EventTarget::RemoveEventListener(const nsAString& aType,
|
||||
EventListener* aListener,
|
||||
|
|
|
@ -28,6 +28,7 @@ class Event;
|
|||
class EventListener;
|
||||
class EventListenerOptionsOrBoolean;
|
||||
class EventHandlerNonNull;
|
||||
class GlobalObject;
|
||||
|
||||
template <class T> struct Nullable;
|
||||
|
||||
|
@ -43,6 +44,8 @@ public:
|
|||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID)
|
||||
|
||||
// WebIDL API
|
||||
static already_AddRefed<EventTarget> Constructor(const GlobalObject& aGlobal,
|
||||
ErrorResult& aRv);
|
||||
using nsIDOMEventTarget::AddEventListener;
|
||||
using nsIDOMEventTarget::RemoveEventListener;
|
||||
using nsIDOMEventTarget::DispatchEvent;
|
||||
|
@ -57,6 +60,11 @@ public:
|
|||
ErrorResult& aRv);
|
||||
bool DispatchEvent(Event& aEvent, CallerType aCallerType, ErrorResult& aRv);
|
||||
|
||||
nsIGlobalObject* GetParentObject() const
|
||||
{
|
||||
return GetOwnerGlobal();
|
||||
}
|
||||
|
||||
// Note, this takes the type in onfoo form!
|
||||
EventHandlerNonNull* GetEventHandler(const nsAString& aType)
|
||||
{
|
||||
|
|
|
@ -45,6 +45,7 @@ EXPORTS.mozilla.dom += [
|
|||
'ClipboardEvent.h',
|
||||
'CommandEvent.h',
|
||||
'CompositionEvent.h',
|
||||
'ConstructibleEventTarget.h',
|
||||
'CustomEvent.h',
|
||||
'DataTransfer.h',
|
||||
'DataTransferItem.h',
|
||||
|
@ -87,6 +88,7 @@ UNIFIED_SOURCES += [
|
|||
'ClipboardEvent.cpp',
|
||||
'CommandEvent.cpp',
|
||||
'CompositionEvent.cpp',
|
||||
'ConstructibleEventTarget.cpp',
|
||||
'ContentEventHandler.cpp',
|
||||
'CustomEvent.cpp',
|
||||
'DataTransfer.cpp',
|
||||
|
|
|
@ -23,7 +23,8 @@ dictionary AddEventListenerOptions : EventListenerOptions {
|
|||
boolean once = false;
|
||||
};
|
||||
|
||||
[Exposed=(Window,Worker,WorkerDebugger,System)]
|
||||
[Constructor,
|
||||
Exposed=(Window,Worker,WorkerDebugger,System)]
|
||||
interface EventTarget {
|
||||
/* Passing null for wantsUntrusted means "default behavior", which
|
||||
differs in content and chrome. In content that default boolean
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
[EventTarget-constructible.any.html]
|
||||
type: testharness
|
||||
[A constructed EventTarget can be used as expected]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget can be subclassed]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[EventTarget-constructible.any.worker.html]
|
||||
type: testharness
|
||||
[A constructed EventTarget can be used as expected]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget can be subclassed]
|
||||
expected: FAIL
|
||||
|
|
@ -22,48 +22,9 @@
|
|||
[Text interface: document.createTextNode("abc") must inherit property "assignedSlot" with the proper type (2)]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget must be primary interface of new EventTarget()]
|
||||
expected: FAIL
|
||||
|
||||
[Stringification of new EventTarget()]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: new EventTarget() must inherit property "addEventListener" with the proper type (0)]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: calling addEventListener(DOMString,EventListener,[object Object\],[object Object\]) on new EventTarget() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: new EventTarget() must inherit property "removeEventListener" with the proper type (1)]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: calling removeEventListener(DOMString,EventListener,[object Object\],[object Object\]) on new EventTarget() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: new EventTarget() must inherit property "dispatchEvent" with the proper type (2)]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: calling dispatchEvent(Event) on new EventTarget() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[AbortSignal interface: new AbortController().signal must inherit property "onabort" with the proper type (1)]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: new EventTarget() must inherit property "addEventListener(DOMString, EventListener, [object Object\],[object Object\])" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: calling addEventListener(DOMString, EventListener, [object Object\],[object Object\]) on new EventTarget() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: new EventTarget() must inherit property "removeEventListener(DOMString, EventListener, [object Object\],[object Object\])" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: calling removeEventListener(DOMString, EventListener, [object Object\],[object Object\]) on new EventTarget() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[EventTarget interface: new EventTarget() must inherit property "dispatchEvent(Event)" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[AbortSignal interface: new AbortController().signal must inherit property "onabort" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<div id=log></div>
|
||||
|
||||
<script type=text/plain>
|
||||
[Exposed=(Window,Worker)]
|
||||
[Constructor(), Exposed=(Window,Worker)]
|
||||
interface EventTarget {
|
||||
void addEventListener(DOMString type, EventListener? listener, optional (AddEventListenerOptions or boolean) options);
|
||||
void removeEventListener(DOMString type, EventListener? listener, optional (EventListenerOptions or boolean) options);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// -----------------------------------------------------------------------------
|
||||
// DOM
|
||||
// -----------------------------------------------------------------------------
|
||||
[Exposed=(Window,Worker)]
|
||||
[Constructor(), Exposed=(Window,Worker)]
|
||||
interface EventTarget {
|
||||
void addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options);
|
||||
void removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options);
|
||||
|
|
|
@ -93,7 +93,7 @@ interface ServiceWorkerRegistration : EventTarget {
|
|||
attribute EventHandler onupdatefound;
|
||||
};
|
||||
|
||||
[Exposed=(Window,Worker)]
|
||||
[Constructor(), Exposed=(Window,Worker)]
|
||||
interface EventTarget {
|
||||
void addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options);
|
||||
void removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
<!-- The IDL is copied from the 22 September 2015 editors' draft. -->
|
||||
<script type="text/plain">
|
||||
[Constructor()]
|
||||
interface EventTarget {
|
||||
// Only a dummy definition is needed here.
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче