Bug 702437 - Implement MOZ_OVERRIDE to encapsulate support for the contextual override keyword on virtual member functions. r=cjones

This commit is contained in:
Jeff Walden 2011-11-14 10:31:46 -08:00
parent 77ab034b6a
commit 3a9bae8669
3 changed files with 133 additions and 64 deletions

View File

@ -43,6 +43,8 @@
#include "mozilla/layers/PLayersParent.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/Types.h"
#include "ipc/ShadowLayerChild.h"
#include "BasicLayers.h"
@ -2209,17 +2211,17 @@ private:
return static_cast<BasicShadowLayerManager*>(mManager);
}
NS_OVERRIDE virtual void
virtual void
PaintBuffer(gfxContext* aContext,
const nsIntRegion& aRegionToDraw,
const nsIntRegion& aExtendedRegionToDraw,
const nsIntRegion& aRegionToInvalidate,
bool aDidSelfCopy,
LayerManager::DrawThebesLayerCallback aCallback,
void* aCallbackData);
void* aCallbackData) MOZ_OVERRIDE;
NS_OVERRIDE virtual already_AddRefed<gfxASurface>
CreateBuffer(Buffer::ContentType aType, const nsIntSize& aSize);
virtual already_AddRefed<gfxASurface>
CreateBuffer(Buffer::ContentType aType, const nsIntSize& aSize) MOZ_OVERRIDE;
void DestroyBackBuffer()
{

View File

@ -42,6 +42,8 @@
#ifndef jswrapper_h___
#define jswrapper_h___
#include "mozilla/Types.h"
#include "jsapi.h"
#include "jsproxy.h"
@ -62,37 +64,37 @@ class JS_FRIEND_API(Wrapper) : public ProxyHandler
/* ES5 Harmony fundamental wrapper traps. */
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
PropertyDescriptor *desc);
PropertyDescriptor *desc) MOZ_OVERRIDE;
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
PropertyDescriptor *desc);
PropertyDescriptor *desc) MOZ_OVERRIDE;
virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
PropertyDescriptor *desc);
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
virtual bool enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
virtual bool fix(JSContext *cx, JSObject *wrapper, Value *vp);
PropertyDescriptor *desc) MOZ_OVERRIDE;
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE;
virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) MOZ_OVERRIDE;
virtual bool enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE;
virtual bool fix(JSContext *cx, JSObject *wrapper, Value *vp) MOZ_OVERRIDE;
/* ES5 Harmony derived wrapper traps. */
virtual bool has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
virtual bool hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, Value *vp);
virtual bool has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) MOZ_OVERRIDE;
virtual bool hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) MOZ_OVERRIDE;
virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, Value *vp) MOZ_OVERRIDE;
virtual bool set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, bool strict,
Value *vp);
virtual bool keys(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
virtual bool iterate(JSContext *cx, JSObject *wrapper, uintN flags, Value *vp);
Value *vp) MOZ_OVERRIDE;
virtual bool keys(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE;
virtual bool iterate(JSContext *cx, JSObject *wrapper, uintN flags, Value *vp) MOZ_OVERRIDE;
/* Spidermonkey extensions. */
virtual bool call(JSContext *cx, JSObject *wrapper, uintN argc, Value *vp);
virtual bool construct(JSContext *cx, JSObject *wrapper, uintN argc, Value *argv, Value *rval);
virtual bool nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs args);
virtual bool hasInstance(JSContext *cx, JSObject *wrapper, const Value *vp, bool *bp);
virtual JSType typeOf(JSContext *cx, JSObject *proxy);
virtual bool objectClassIs(JSObject *obj, ESClassValue classValue, JSContext *cx);
virtual JSString *obj_toString(JSContext *cx, JSObject *wrapper);
virtual JSString *fun_toString(JSContext *cx, JSObject *wrapper, uintN indent);
virtual bool defaultValue(JSContext *cx, JSObject *wrapper, JSType hint, Value *vp);
virtual bool call(JSContext *cx, JSObject *wrapper, uintN argc, Value *vp) MOZ_OVERRIDE;
virtual bool construct(JSContext *cx, JSObject *wrapper, uintN argc, Value *argv, Value *rval) MOZ_OVERRIDE;
virtual bool nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs args) MOZ_OVERRIDE;
virtual bool hasInstance(JSContext *cx, JSObject *wrapper, const Value *vp, bool *bp) MOZ_OVERRIDE;
virtual JSType typeOf(JSContext *cx, JSObject *proxy) MOZ_OVERRIDE;
virtual bool objectClassIs(JSObject *obj, ESClassValue classValue, JSContext *cx) MOZ_OVERRIDE;
virtual JSString *obj_toString(JSContext *cx, JSObject *wrapper) MOZ_OVERRIDE;
virtual JSString *fun_toString(JSContext *cx, JSObject *wrapper, uintN indent) MOZ_OVERRIDE;
virtual bool defaultValue(JSContext *cx, JSObject *wrapper, JSType hint, Value *vp) MOZ_OVERRIDE;
virtual void trace(JSTracer *trc, JSObject *wrapper);
virtual void trace(JSTracer *trc, JSObject *wrapper) MOZ_OVERRIDE;
/* Policy enforcement traps. */
enum Action { GET, SET, CALL };
@ -125,34 +127,34 @@ class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper
/* ES5 Harmony fundamental wrapper traps. */
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
PropertyDescriptor *desc);
PropertyDescriptor *desc) MOZ_OVERRIDE;
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
PropertyDescriptor *desc);
PropertyDescriptor *desc) MOZ_OVERRIDE;
virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
PropertyDescriptor *desc);
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
virtual bool enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
PropertyDescriptor *desc) MOZ_OVERRIDE;
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE;
virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) MOZ_OVERRIDE;
virtual bool enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE;
/* ES5 Harmony derived wrapper traps. */
virtual bool has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
virtual bool hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, Value *vp);
virtual bool has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) MOZ_OVERRIDE;
virtual bool hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) MOZ_OVERRIDE;
virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, Value *vp) MOZ_OVERRIDE;
virtual bool set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, bool strict,
Value *vp);
virtual bool keys(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
virtual bool iterate(JSContext *cx, JSObject *wrapper, uintN flags, Value *vp);
Value *vp) MOZ_OVERRIDE;
virtual bool keys(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE;
virtual bool iterate(JSContext *cx, JSObject *wrapper, uintN flags, Value *vp) MOZ_OVERRIDE;
/* Spidermonkey extensions. */
virtual bool call(JSContext *cx, JSObject *wrapper, uintN argc, Value *vp);
virtual bool construct(JSContext *cx, JSObject *wrapper, uintN argc, Value *argv, Value *rval);
virtual bool nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs args);
virtual bool hasInstance(JSContext *cx, JSObject *wrapper, const Value *vp, bool *bp);
virtual JSString *obj_toString(JSContext *cx, JSObject *wrapper);
virtual JSString *fun_toString(JSContext *cx, JSObject *wrapper, uintN indent);
virtual bool defaultValue(JSContext *cx, JSObject *wrapper, JSType hint, Value *vp);
virtual bool call(JSContext *cx, JSObject *wrapper, uintN argc, Value *vp) MOZ_OVERRIDE;
virtual bool construct(JSContext *cx, JSObject *wrapper, uintN argc, Value *argv, Value *rval) MOZ_OVERRIDE;
virtual bool nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs args) MOZ_OVERRIDE;
virtual bool hasInstance(JSContext *cx, JSObject *wrapper, const Value *vp, bool *bp) MOZ_OVERRIDE;
virtual JSString *obj_toString(JSContext *cx, JSObject *wrapper) MOZ_OVERRIDE;
virtual JSString *fun_toString(JSContext *cx, JSObject *wrapper, uintN indent) MOZ_OVERRIDE;
virtual bool defaultValue(JSContext *cx, JSObject *wrapper, JSType hint, Value *vp) MOZ_OVERRIDE;
virtual void trace(JSTracer *trc, JSObject *wrapper);
virtual void trace(JSTracer *trc, JSObject *wrapper) MOZ_OVERRIDE;
static CrossCompartmentWrapper singleton;
};
@ -172,8 +174,8 @@ class JS_FRIEND_API(SecurityWrapper) : public Base
public:
SecurityWrapper(uintN flags);
virtual bool nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs args);
virtual bool objectClassIs(JSObject *obj, ESClassValue classValue, JSContext *cx);
virtual bool nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs args) MOZ_OVERRIDE;
virtual bool objectClassIs(JSObject *obj, ESClassValue classValue, JSContext *cx) MOZ_OVERRIDE;
};
typedef SecurityWrapper<Wrapper> SameCompartmentSecurityWrapper;

View File

@ -90,6 +90,43 @@
#ifdef __cplusplus
/*
* g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality
* without warnings (functionality used by the macros below). These modes are
* detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, more
* standardly, by checking whether __cplusplus has a C++11 or greater value.
* Current versions of g++ do not correctly set __cplusplus, so we check both
* for forward compatibility.
*/
#if defined(__clang__)
# if __clang_major__ >= 3
# define MOZ_HAVE_CXX11_DELETE
# define MOZ_HAVE_CXX11_OVERRIDE
# elif __clang_major__ == 2
# if __clang_minor__ >= 9
# define MOZ_HAVE_CXX11_DELETE
# endif
# endif
#elif defined(__GNUC__)
# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
# if __GNUC__ > 4
# define MOZ_HAVE_CXX11_DELETE
# define MOZ_HAVE_CXX11_OVERRIDE
# elif __GNUC__ == 4
# if __GNUC_MINOR__ >= 7
# define MOZ_HAVE_CXX11_OVERRIDE
# endif
# if __GNUC_MINOR__ >= 4
# define MOZ_HAVE_CXX11_DELETE
# endif
# endif
# endif
#elif defined(_MSC_VER)
# if _MSC_VER >= 1400
# define MOZ_HAVE_CXX11_OVERRIDE
# endif
#endif
/*
* MOZ_DELETE, specified immediately prior to the ';' terminating an undefined-
* method declaration, attempts to delete that method from the corresponding
@ -112,23 +149,51 @@
* MOZ_DELETE relies on C++11 functionality not universally implemented. As a
* backstop, method declarations using MOZ_DELETE should be private.
*/
#if defined(__clang__) && (__clang_major__ >= 3 || (__clang_major__ == 2 && __clang_minor__ >= 9))
#if defined(MOZ_HAVE_CXX11_DELETE)
# define MOZ_DELETE = delete
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
/*
* g++ >= 4.4 requires -std=c++0x or -std=gnu++0x to support deleted functions
* without warnings. These modes are detectable by the experimental macro used
* below or, more standardly, by checking whether __cplusplus has a C++11 or
* greater value. Current versions of g++ do not correctly set __cplusplus, so
* we check both for forward compatibility.
*/
# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
# define MOZ_DELETE = delete
# else
# define MOZ_DELETE /* = delete */
# endif
#else
# define MOZ_DELETE /* no = delete support, or unknown support */
# define MOZ_DELETE /* no support */
#endif
/*
* MOZ_OVERRIDE explicitly indicates that a virtual member function in a class
* overrides a member function of a base class, rather than potentially being a
* new member function. MOZ_OVERRIDE should be placed immediately before the
* ';' terminating the member function's declaration, or before '= 0;' if the
* member function is pure. If the member function is defined in the class
* definition, it should appear before the opening brace of the function body.
*
* class Base
* {
* public:
* virtual void f() = 0;
* };
* class Derived1 : public Base
* {
* public:
* virtual void f() MOZ_OVERRIDE;
* };
* class Derived2 : public Base
* {
* public:
* virtual void f() MOZ_OVERRIDE = 0;
* };
* class Derived3 : public Base
* {
* public:
* virtual void f() MOZ_OVERRIDE { }
* };
*
* In compilers supporting C++11 override controls, MOZ_OVERRIDE *requires* that
* the function marked with it override a member function of a base class: it
* is a compile error if it does not. Otherwise MOZ_OVERRIDE does not affect
* semantics and merely documents the override relationship to the reader (but
* of course must still be used correctly to not break C++11 compilers).
*/
#if defined(MOZ_HAVE_CXX11_OVERRIDE)
# define MOZ_OVERRIDE override
#else
# define MOZ_OVERRIDE /* no support */
#endif
#endif /* __cplusplus */