mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-28 13:40:17 -10:00
Bug 1880826 - avoid static constructors for XMLHttpRequest::EventType classes with constexpr; r=sergesanspaille
Differential Revision: https://phabricator.services.mozilla.com/D202177
This commit is contained in:
1 parent
29f25898b7
commit
1357085ee1
1 file changed
+40
-39
+40
-39
@@ -29,9 +29,12 @@ class XMLHttpRequest : public XMLHttpRequestEventTarget {
|
||||
const char* cStr;
|
||||
const char16_t* str;
|
||||
|
||||
EventType(const char* name, const char16_t* uname)
|
||||
constexpr EventType(const char* name, const char16_t* uname)
|
||||
: cStr(name), str(uname) {}
|
||||
|
||||
constexpr EventType(const EventType& other)
|
||||
: cStr(other.cStr), str(other.str) {}
|
||||
|
||||
operator const nsDependentString() const { return nsDependentString(str); }
|
||||
|
||||
friend bool operator==(const EventType& a, const EventType& b) {
|
||||
@@ -56,55 +59,26 @@ class XMLHttpRequest : public XMLHttpRequestEventTarget {
|
||||
};
|
||||
|
||||
struct ProgressEventType : public EventType {
|
||||
ProgressEventType(const char* name, const char16_t* uname)
|
||||
constexpr ProgressEventType(const char* name, const char16_t* uname)
|
||||
: EventType(name, uname) {}
|
||||
};
|
||||
|
||||
struct ErrorProgressEventType : public ProgressEventType {
|
||||
const nsresult errorCode;
|
||||
|
||||
ErrorProgressEventType(const char* name, const char16_t* uname,
|
||||
const nsresult code)
|
||||
constexpr ErrorProgressEventType(const char* name, const char16_t* uname,
|
||||
const nsresult code)
|
||||
: ProgressEventType(name, uname), errorCode(code) {}
|
||||
};
|
||||
|
||||
#define DECL_EVENT(NAME) \
|
||||
static inline const EventType NAME = EventType(#NAME, u## #NAME);
|
||||
#define DECL_EVENT(NAME) static constexpr EventType NAME{#NAME, u## #NAME};
|
||||
|
||||
#define DECL_PROGRESSEVENT(NAME) \
|
||||
static inline const ProgressEventType NAME = \
|
||||
ProgressEventType(#NAME, u## #NAME);
|
||||
#define DECL_PROGRESSEVENT(NAME) \
|
||||
static constexpr ProgressEventType NAME { #NAME, u## #NAME }
|
||||
|
||||
#define DECL_ERRORPROGRESSEVENT(NAME, ERR) \
|
||||
static inline const ErrorProgressEventType NAME = \
|
||||
ErrorProgressEventType(#NAME, u## #NAME, ERR);
|
||||
#define DECL_ERRORPROGRESSEVENT(NAME, ERR) \
|
||||
static constexpr ErrorProgressEventType NAME{#NAME, u## #NAME, ERR};
|
||||
|
||||
struct Events {
|
||||
DECL_EVENT(readystatechange);
|
||||
DECL_PROGRESSEVENT(loadstart);
|
||||
DECL_PROGRESSEVENT(progress);
|
||||
DECL_ERRORPROGRESSEVENT(error, NS_ERROR_DOM_NETWORK_ERR);
|
||||
DECL_ERRORPROGRESSEVENT(abort, NS_ERROR_DOM_ABORT_ERR);
|
||||
DECL_ERRORPROGRESSEVENT(timeout, NS_ERROR_DOM_TIMEOUT_ERR);
|
||||
DECL_PROGRESSEVENT(load);
|
||||
DECL_PROGRESSEVENT(loadend);
|
||||
|
||||
static inline const EventType* All[]{
|
||||
&readystatechange, &loadstart, &progress, &error, &abort,
|
||||
&timeout, &load, &loadend};
|
||||
|
||||
static inline const EventType* ProgressEvents[]{
|
||||
&loadstart, &progress, &error, &abort, &timeout, &load, &loadend};
|
||||
|
||||
static inline const EventType* Find(const nsString& name) {
|
||||
for (const EventType* type : Events::All) {
|
||||
if (*type == name) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
struct Events;
|
||||
|
||||
static already_AddRefed<XMLHttpRequest> Constructor(
|
||||
const GlobalObject& aGlobal, const MozXMLHttpRequestParameters& aParams,
|
||||
@@ -216,6 +190,33 @@ class XMLHttpRequest : public XMLHttpRequestEventTarget {
|
||||
: XMLHttpRequestEventTarget(aGlobalObject) {}
|
||||
};
|
||||
|
||||
struct XMLHttpRequest::Events {
|
||||
DECL_EVENT(readystatechange);
|
||||
DECL_PROGRESSEVENT(loadstart);
|
||||
DECL_PROGRESSEVENT(progress);
|
||||
DECL_ERRORPROGRESSEVENT(error, NS_ERROR_DOM_NETWORK_ERR);
|
||||
DECL_ERRORPROGRESSEVENT(abort, NS_ERROR_DOM_ABORT_ERR);
|
||||
DECL_ERRORPROGRESSEVENT(timeout, NS_ERROR_DOM_TIMEOUT_ERR);
|
||||
DECL_PROGRESSEVENT(load);
|
||||
DECL_PROGRESSEVENT(loadend);
|
||||
|
||||
static inline const EventType* All[]{
|
||||
&readystatechange, &loadstart, &progress, &error, &abort,
|
||||
&timeout, &load, &loadend};
|
||||
|
||||
static inline const EventType* ProgressEvents[]{
|
||||
&loadstart, &progress, &error, &abort, &timeout, &load, &loadend};
|
||||
|
||||
static inline const EventType* Find(const nsString& name) {
|
||||
for (const EventType* type : Events::All) {
|
||||
if (*type == name) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mozilla::dom
|
||||
|
||||
#endif // mozilla_dom_XMLHttpRequest_h
|
||||
Reference in new issue
Block a user