Skip to content

Commit

Permalink
Bug 742217. Reduce the use of nested namespaces in our binding code. …
Browse files Browse the repository at this point in the history
…r=peterv,bent

In the new setup, all per-interface DOM binding files are exported into
mozilla/dom.  General files not specific to an interface are also exported into
mozilla/dom.

In terms of namespaces, most things now live in mozilla::dom.  Each interface
Foo that has generated code has a mozilla::dom::FooBinding namespace for said
generated code (and possibly a mozilla::bindings::FooBinding_workers if there's
separate codegen for workers).

IDL enums are a bit weird: since the name of the enum and the names of its
entries all end up in the same namespace, we still generate a C++ namespace
with the name of the IDL enum type with "Values" appended to it, with a
::valuelist inside for the actual C++ enum.  We then typedef
EnumFooValues::valuelist to EnumFoo.  That makes it a bit more difficult to
refer to the values, but means that values from different enums don't collide
with each other.

The enums with the proto and constructor IDs in them now live under the
mozilla::dom::prototypes and mozilla::dom::constructors namespaces respectively.
Again, this lets us deal sanely with the whole "enum value names are flattened
into the namespace the enum is in" deal.

The main benefit of this setup (and the reason "Binding" got appended to the
per-interface namespaces) is that this way "using mozilla::dom" should Just
Work for consumers and still allow C++ code to sanely use the IDL interface
names for concrete classes, which is fairly desirable.

--HG--
rename : dom/bindings/Utils.cpp => dom/bindings/BindingUtils.cpp
rename : dom/bindings/Utils.h => dom/bindings/BindingUtils.h
  • Loading branch information
bzbarsky committed May 3, 2012
1 parent 2a6ac82 commit 76b5075
Show file tree
Hide file tree
Showing 36 changed files with 172 additions and 164 deletions.
6 changes: 3 additions & 3 deletions caps/src/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
#include "nsIContentSecurityPolicy.h"
#include "nsIAsyncVerifyRedirectCallback.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/bindings/Utils.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/StandardInteger.h"

using namespace mozilla;
Expand Down Expand Up @@ -2483,8 +2483,8 @@ nsScriptSecurityManager::doGetObjectPrincipal(JSObject *aObj
JSCLASS_PRIVATE_IS_NSISUPPORTS))) {
priv = (nsISupports *) js::GetObjectPrivate(aObj);
} else if ((jsClass->flags & JSCLASS_IS_DOMJSCLASS) &&
bindings::DOMJSClass::FromJSClass(jsClass)->mDOMObjectIsISupports) {
priv = bindings::UnwrapDOMObject<nsISupports>(aObj, jsClass);
DOMJSClass::FromJSClass(jsClass)->mDOMObjectIsISupports) {
priv = UnwrapDOMObject<nsISupports>(aObj, jsClass);
} else {
priv = nsnull;
}
Expand Down
6 changes: 3 additions & 3 deletions content/base/src/nsXMLHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
#include "mozilla/Telemetry.h"
#include "jsfriendapi.h"
#include "sampler.h"
#include "mozilla/dom/bindings/XMLHttpRequestBinding.h"
#include "mozilla/dom/XMLHttpRequestBinding.h"
#include "nsIDOMFormData.h"

#include "nsWrapperCacheInlines.h"
Expand Down Expand Up @@ -1091,8 +1091,8 @@ nsXMLHttpRequest::StaticAssertions()
{
#define ASSERT_ENUM_EQUAL(_lc, _uc) \
MOZ_STATIC_ASSERT(\
bindings::prototypes::XMLHttpRequestResponseType::_lc \
== bindings::prototypes::XMLHttpRequestResponseType::value(XML_HTTP_RESPONSE_TYPE_ ## _uc), \
XMLHttpRequestResponseTypeValues::_lc \
== XMLHttpRequestResponseType(XML_HTTP_RESPONSE_TYPE_ ## _uc), \
#_uc " should match")

ASSERT_ENUM_EQUAL(_empty, DEFAULT);
Expand Down
10 changes: 5 additions & 5 deletions content/base/src/nsXMLHttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
#include "nsDOMBlobBuilder.h"
#include "nsIPrincipal.h"
#include "nsIScriptObjectPrincipal.h"
#include "mozilla/dom/bindings/XMLHttpRequestBinding.h"
#include "mozilla/dom/bindings/XMLHttpRequestUploadBinding.h"
#include "mozilla/dom/XMLHttpRequestBinding.h"
#include "mozilla/dom/XMLHttpRequestUploadBinding.h"

#include "mozilla/Assertions.h"

Expand All @@ -95,7 +95,7 @@ class nsXHREventTarget : public nsDOMEventTargetHelper,
public nsIXMLHttpRequestEventTarget
{
public:
typedef mozilla::dom::bindings::prototypes::XMLHttpRequestResponseType::value
typedef mozilla::dom::XMLHttpRequestResponseType
XMLHttpRequestResponseType;

virtual ~nsXHREventTarget() {}
Expand Down Expand Up @@ -170,7 +170,7 @@ class nsXMLHttpRequestUpload : public nsXHREventTarget,
virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
bool *triedToWrap)
{
return mozilla::dom::bindings::prototypes::XMLHttpRequestUpload::Wrap(cx, scope, this, triedToWrap);
return mozilla::dom::XMLHttpRequestUploadBinding::Wrap(cx, scope, this, triedToWrap);
}
nsISupports* GetParentObject()
{
Expand Down Expand Up @@ -202,7 +202,7 @@ class nsXMLHttpRequest : public nsXHREventTarget,
virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
bool *triedToWrap)
{
return mozilla::dom::bindings::prototypes::XMLHttpRequest::Wrap(cx, scope, this, triedToWrap);
return mozilla::dom::XMLHttpRequestBinding::Wrap(cx, scope, this, triedToWrap);
}
nsISupports* GetParentObject()
{
Expand Down
4 changes: 2 additions & 2 deletions content/xbl/src/nsXBLDocumentInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
#include "mozilla/scache/StartupCache.h"
#include "mozilla/scache/StartupCacheUtils.h"
#include "nsCCUncollectableMarker.h"
#include "mozilla/dom/bindings/Utils.h"
#include "mozilla/dom/BindingUtils.h"

using namespace mozilla::scache;
using namespace mozilla;

using mozilla::dom::bindings::DestroyProtoOrIfaceCache;
using mozilla::dom::DestroyProtoOrIfaceCache;

static const char kXBLCachePrefix[] = "xblcache";

Expand Down
4 changes: 2 additions & 2 deletions content/xul/document/src/nsXULPrototypeDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
#include "nsCCUncollectableMarker.h"
#include "nsDOMJSUtils.h" // for GetScriptContextFromJSContext
#include "xpcpublic.h"
#include "mozilla/dom/bindings/Utils.h"
#include "mozilla/dom/BindingUtils.h"

using mozilla::dom::bindings::DestroyProtoOrIfaceCache;
using mozilla::dom::DestroyProtoOrIfaceCache;

static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsDOMClassInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#include "xpcprivate.h"
#include "XPCWrapper.h"

#include "mozilla/dom/bindings/Common.h"
#include "mozilla/dom/RegisterBindings.h"

#include "nscore.h"
#include "nsDOMClassInfo.h"
Expand Down Expand Up @@ -4491,7 +4491,7 @@ nsDOMClassInfo::Init()
mozilla::dom::binding::Register(nameSpaceManager);

// Non-proxy bindings
mozilla::dom::bindings::Register(nameSpaceManager);
mozilla::dom::Register(nameSpaceManager);

sIsInitialized = true;

Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsJSEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
#include "mozilla/FunctionTimer.h"
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
#include "mozilla/dom/bindings/Utils.h"
#include "mozilla/dom/BindingUtils.h"

#include "sampler.h"

Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsJSUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

#include "nsDOMJSUtils.h" // for GetScriptContextFromJSContext

#include "mozilla/dom/bindings/Utils.h"
#include "mozilla/dom/BindingUtils.h"

JSBool
nsJSUtils::GetCallingLocation(JSContext* aContext, const char* *aFilename,
Expand Down
4 changes: 1 addition & 3 deletions dom/bindings/Utils.cpp → dom/bindings/BindingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
* 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 "Utils.h"
#include "BindingUtils.h"

namespace mozilla {
namespace dom {
namespace bindings {

static bool
DefineConstants(JSContext* cx, JSObject* obj, ConstantSpec* cs)
Expand Down Expand Up @@ -240,6 +239,5 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
return true;
}

} // namespace bindings
} // namespace dom
} // namespace mozilla
17 changes: 8 additions & 9 deletions dom/bindings/Utils.h → dom/bindings/BindingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* 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_bindings_Utils_h__
#define mozilla_dom_bindings_Utils_h__
#ifndef mozilla_dom_BindingUtils_h__
#define mozilla_dom_BindingUtils_h__

#include "mozilla/dom/bindings/DOMJSClass.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/workers/Workers.h"

#include "jsapi.h"
Expand All @@ -18,9 +18,12 @@
#include "nsTraceRefcnt.h"
#include "nsWrapperCacheInlines.h"

// nsGlobalWindow implements nsWrapperCache, but doesn't always use it. Don't
// try to use it without fixing that first.
class nsGlobalWindow;

namespace mozilla {
namespace dom {
namespace bindings {

template<bool mainThread>
inline bool
Expand Down Expand Up @@ -377,9 +380,6 @@ GetWrapperCache(nsWrapperCache* cache)
return cache;
}

// nsGlobalWindow implements nsWrapperCache, but doesn't always use it. Don't
// try to use it without fixing that first.
class nsGlobalWindow;
inline nsWrapperCache*
GetWrapperCache(nsGlobalWindow* not_allowed);

Expand Down Expand Up @@ -508,8 +508,7 @@ InitIds(JSContext* cx, Spec* specs, jsid* ids)
JSBool
QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp);

} // namespace bindings
} // namespace dom
} // namespace mozilla

#endif /* mozilla_dom_bindings_Utils_h__ */
#endif /* mozilla_dom_BindingUtils_h__ */
Loading

0 comments on commit 76b5075

Please sign in to comment.