Bug 913923 - Part b: Move OwningNonNull into its own header; r=dzbarsky

--HG--
rename : dom/bindings/BindingUtils.h => dom/bindings/OwningNonNull.h
This commit is contained in:
Ms2ger 2013-09-10 09:03:37 +02:00
parent 6a08b50f93
commit 4db82f5aba
9 changed files with 96 additions and 62 deletions

View File

@ -4,15 +4,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file, * 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/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsDOMMutationObserver.h" #include "nsDOMMutationObserver.h"
#include "nsDOMClassInfoID.h"
#include "mozilla/dom/OwningNonNull.h"
#include "nsError.h" #include "nsError.h"
#include "nsIScriptGlobalObject.h" #include "nsIScriptGlobalObject.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsIDOMMutationEvent.h" #include "nsIDOMMutationEvent.h"
#include "nsTextFragment.h" #include "nsTextFragment.h"
#include "jsapi.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
nsTArray<nsRefPtr<nsDOMMutationObserver> >* nsTArray<nsRefPtr<nsDOMMutationObserver> >*

View File

@ -190,11 +190,12 @@
#include "nsIAppsService.h" #include "nsIAppsService.h"
#include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DocumentFragment.h" #include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/WebComponentsBinding.h"
#include "mozilla/dom/HTMLBodyElement.h" #include "mozilla/dom/HTMLBodyElement.h"
#include "mozilla/dom/HTMLInputElement.h" #include "mozilla/dom/HTMLInputElement.h"
#include "mozilla/dom/NodeFilterBinding.h" #include "mozilla/dom/NodeFilterBinding.h"
#include "mozilla/dom/OwningNonNull.h"
#include "mozilla/dom/UndoManager.h" #include "mozilla/dom/UndoManager.h"
#include "mozilla/dom/WebComponentsBinding.h"
#include "nsFrame.h" #include "nsFrame.h"
#include "nsDOMCaretPosition.h" #include "nsDOMCaretPosition.h"
#include "nsIDOMHTMLTextAreaElement.h" #include "nsIDOMHTMLTextAreaElement.h"

View File

@ -5,12 +5,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AudioContext.h" #include "AudioContext.h"
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "mozilla/ErrorResult.h" #include "mozilla/ErrorResult.h"
#include "mozilla/dom/AnalyserNode.h" #include "mozilla/dom/AnalyserNode.h"
#include "mozilla/dom/AudioContextBinding.h" #include "mozilla/dom/AudioContextBinding.h"
#include "mozilla/dom/HTMLMediaElement.h" #include "mozilla/dom/HTMLMediaElement.h"
#include "mozilla/dom/OfflineAudioContextBinding.h" #include "mozilla/dom/OfflineAudioContextBinding.h"
#include "mozilla/dom/OwningNonNull.h"
#include "MediaStreamGraph.h" #include "MediaStreamGraph.h"
#include "AudioDestinationNode.h" #include "AudioDestinationNode.h"
#include "AudioBufferSourceNode.h" #include "AudioBufferSourceNode.h"

View File

@ -1423,60 +1423,6 @@ AppendNamedPropertyIds(JSContext* cx, JS::Handle<JSObject*> proxy,
nsTArray<nsString>& names, nsTArray<nsString>& names,
bool shadowPrototypeProperties, JS::AutoIdVector& props); bool shadowPrototypeProperties, JS::AutoIdVector& props);
template<class T>
class OwningNonNull
{
public:
OwningNonNull()
#ifdef DEBUG
: inited(false)
#endif
{}
operator T&() {
MOZ_ASSERT(inited);
MOZ_ASSERT(ptr, "OwningNonNull<T> was set to null");
return *ptr;
}
void operator=(T* t) {
init(t);
}
void operator=(const already_AddRefed<T>& t) {
init(t);
}
already_AddRefed<T> forget() {
#ifdef DEBUG
inited = false;
#endif
return ptr.forget();
}
// Make us work with smart-ptr helpers that expect a get()
T* get() const {
MOZ_ASSERT(inited);
MOZ_ASSERT(ptr);
return ptr;
}
protected:
template<typename U>
void init(U t) {
ptr = t;
MOZ_ASSERT(ptr);
#ifdef DEBUG
inited = true;
#endif
}
nsRefPtr<T> ptr;
#ifdef DEBUG
bool inited;
#endif
};
// A struct that has the same layout as an nsDependentString but much // A struct that has the same layout as an nsDependentString but much
// faster constructor and destructor behavior // faster constructor and destructor behavior
struct FakeDependentString { struct FakeDependentString {

View File

@ -8803,11 +8803,12 @@ class CGBindingRoot(CGThing):
enums = config.getEnums(webIDLFile) enums = config.getEnums(webIDLFile)
cgthings = [ CGEnum(e) for e in enums ] cgthings = [ CGEnum(e) for e in enums ]
bindingHeaders["mozilla/dom/BindingUtils.h"] = ( hasCode = (descriptors or callbackDescriptors or dictionaries or
descriptors or callbackDescriptors or dictionaries or mainCallbacks or workerCallbacks)
mainCallbacks or workerCallbacks) bindingHeaders["mozilla/dom/BindingUtils.h"] = hasCode
bindingHeaders["mozilla/dom/OwningNonNull.h"] = hasCode
bindingHeaders["mozilla/dom/BindingDeclarations.h"] = ( bindingHeaders["mozilla/dom/BindingDeclarations.h"] = (
not bindingHeaders["mozilla/dom/BindingUtils.h"] and enums) not hasCode and enums)
bindingHeaders["WrapperFactory.h"] = descriptors bindingHeaders["WrapperFactory.h"] = descriptors
bindingHeaders["mozilla/dom/DOMJSClass.h"] = descriptors bindingHeaders["mozilla/dom/DOMJSClass.h"] = descriptors
@ -10522,6 +10523,7 @@ struct PrototypeTraits;
config.getCallbacks(), config.getCallbacks(),
config) config)
includes.add("mozilla/dom/BindingUtils.h") includes.add("mozilla/dom/BindingUtils.h")
includes.add("mozilla/dom/OwningNonNull.h")
includes.add("mozilla/dom/UnionMember.h") includes.add("mozilla/dom/UnionMember.h")
# Wrap all of that in our namespaces. # Wrap all of that in our namespaces.

View File

@ -0,0 +1,80 @@
/* -*- 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/. */
/* A class for non-null strong pointers to reference-counted objects. */
#ifndef mozilla_dom_OwningNonNull_h
#define mozilla_dom_OwningNonNull_h
#include "nsAutoPtr.h"
namespace mozilla {
namespace dom {
template<class T>
class OwningNonNull
{
public:
OwningNonNull()
#ifdef DEBUG
: mInited(false)
#endif
{}
operator T&()
{
MOZ_ASSERT(mInited);
MOZ_ASSERT(mPtr, "OwningNonNull<T> was set to null");
return *mPtr;
}
void operator=(T* aValue)
{
init(aValue);
}
void operator=(const already_AddRefed<T>& aValue)
{
init(aValue);
}
already_AddRefed<T> forget()
{
#ifdef DEBUG
mInited = false;
#endif
return mPtr.forget();
}
// Make us work with smart pointer helpers that expect a get().
T* get() const
{
MOZ_ASSERT(mInited);
MOZ_ASSERT(mPtr);
return mPtr;
}
protected:
template<typename U>
void init(U aValue)
{
mPtr = aValue;
MOZ_ASSERT(mPtr);
#ifdef DEBUG
mInited = true;
#endif
}
nsRefPtr<T> mPtr;
#ifdef DEBUG
bool mInited;
#endif
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_OwningNonNull_h

View File

@ -25,6 +25,7 @@ EXPORTS.mozilla.dom += [
'JSSlots.h', 'JSSlots.h',
'NonRefcountedDOMObject.h', 'NonRefcountedDOMObject.h',
'Nullable.h', 'Nullable.h',
'OwningNonNull.h',
'PrimitiveConversions.h', 'PrimitiveConversions.h',
'TypedArray.h', 'TypedArray.h',
'UnionMember.h', 'UnionMember.h',

View File

@ -7,6 +7,7 @@
#include "mozilla/dom/Promise.h" #include "mozilla/dom/Promise.h"
#include "jsfriendapi.h" #include "jsfriendapi.h"
#include "mozilla/dom/OwningNonNull.h"
#include "mozilla/dom/PromiseBinding.h" #include "mozilla/dom/PromiseBinding.h"
#include "mozilla/dom/PromiseResolver.h" #include "mozilla/dom/PromiseResolver.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"

View File

@ -4,6 +4,7 @@
#include "PCOMContentPermissionRequestChild.h" #include "PCOMContentPermissionRequestChild.h"
#include "mozilla/dom/Notification.h" #include "mozilla/dom/Notification.h"
#include "mozilla/dom/OwningNonNull.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "TabChild.h" #include "TabChild.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"