2012-12-25 22:00:15 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
|
|
/* vim: set ts=2 sw=2 et tw=79: */
|
|
|
|
/* 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 header for declaring various things that binding implementation headers
|
|
|
|
* might need. The idea is to make binding implementation headers safe to
|
|
|
|
* include anywhere without running into include hell like we do with
|
|
|
|
* BindingUtils.h
|
|
|
|
*/
|
|
|
|
#ifndef mozilla_dom_BindingDeclarations_h__
|
|
|
|
#define mozilla_dom_BindingDeclarations_h__
|
|
|
|
|
|
|
|
#include "nsStringGlue.h"
|
2013-08-17 22:50:18 +00:00
|
|
|
#include "js/Value.h"
|
|
|
|
#include "js/RootingAPI.h"
|
2013-08-27 22:10:28 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2012-12-03 16:07:49 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2013-02-06 09:56:15 +00:00
|
|
|
#include "nsTArray.h"
|
2013-04-17 20:17:44 +00:00
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr member variables
|
2013-10-11 16:28:23 +00:00
|
|
|
#include "mozilla/dom/DOMString.h"
|
2013-09-10 16:06:46 +00:00
|
|
|
#include "mozilla/dom/OwningNonNull.h"
|
2012-12-25 22:00:15 +00:00
|
|
|
|
2013-03-17 14:42:59 +00:00
|
|
|
class nsWrapperCache;
|
|
|
|
|
2012-12-25 22:00:15 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-05-16 16:36:55 +00:00
|
|
|
// Struct that serves as a base class for all dictionaries. Particularly useful
|
|
|
|
// so we can use IsBaseOf to detect dictionary template arguments.
|
|
|
|
struct DictionaryBase
|
|
|
|
{
|
2014-02-07 02:08:28 +00:00
|
|
|
protected:
|
|
|
|
bool ParseJSON(JSContext* aCx, const nsAString& aJSON,
|
|
|
|
JS::MutableHandle<JS::Value> aVal);
|
2014-08-01 03:50:19 +00:00
|
|
|
|
|
|
|
bool StringifyToJSON(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aValue,
|
2014-09-09 18:00:22 +00:00
|
|
|
nsAString& aJSON) const;
|
2014-08-01 03:50:19 +00:00
|
|
|
private:
|
|
|
|
// aString is expected to actually be an nsAString*. Should only be
|
|
|
|
// called from StringifyToJSON.
|
2014-07-22 04:43:21 +00:00
|
|
|
static bool AppendJSONToString(const char16_t* aJSONData,
|
|
|
|
uint32_t aDataLength, void* aString);
|
2013-05-16 16:36:55 +00:00
|
|
|
};
|
|
|
|
|
2013-08-05 17:40:02 +00:00
|
|
|
// Struct that serves as a base class for all typed arrays and array buffers and
|
|
|
|
// array buffer views. Particularly useful so we can use IsBaseOf to detect
|
|
|
|
// typed array/buffer/view template arguments.
|
|
|
|
struct AllTypedArraysBase {
|
|
|
|
};
|
|
|
|
|
2014-03-14 18:51:22 +00:00
|
|
|
// Struct that serves as a base class for all owning unions.
|
|
|
|
// Particularly useful so we can use IsBaseOf to detect owning union
|
|
|
|
// template arguments.
|
|
|
|
struct AllOwningUnionBase {
|
|
|
|
};
|
|
|
|
|
2013-08-05 17:40:02 +00:00
|
|
|
|
2012-12-25 22:00:15 +00:00
|
|
|
struct EnumEntry {
|
|
|
|
const char* value;
|
|
|
|
size_t length;
|
|
|
|
};
|
|
|
|
|
2013-04-12 03:20:18 +00:00
|
|
|
class MOZ_STACK_CLASS GlobalObject
|
2012-12-03 16:07:49 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GlobalObject(JSContext* aCx, JSObject* aObject);
|
|
|
|
|
|
|
|
JSObject* Get() const
|
|
|
|
{
|
|
|
|
return mGlobalJSObject;
|
|
|
|
}
|
2013-08-23 05:17:08 +00:00
|
|
|
|
|
|
|
nsISupports* GetAsSupports() const;
|
|
|
|
|
2012-12-03 16:07:49 +00:00
|
|
|
// The context that this returns is not guaranteed to be in the compartment of
|
|
|
|
// the object returned from Get(), in fact it's generally in the caller's
|
|
|
|
// compartment.
|
2014-06-16 18:08:00 +00:00
|
|
|
JSContext* Context() const
|
2012-12-03 16:07:49 +00:00
|
|
|
{
|
|
|
|
return mCx;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Failed() const
|
|
|
|
{
|
|
|
|
return !Get();
|
|
|
|
}
|
|
|
|
|
2013-08-23 05:17:08 +00:00
|
|
|
protected:
|
2013-11-11 08:04:41 +00:00
|
|
|
JS::Rooted<JSObject*> mGlobalJSObject;
|
2012-12-03 16:07:49 +00:00
|
|
|
JSContext* mCx;
|
2015-01-05 20:46:37 +00:00
|
|
|
mutable nsISupports* MOZ_UNSAFE_REF("Valid because GlobalObject is a stack "
|
|
|
|
"class, and mGlobalObject points to the "
|
|
|
|
"global, so it won't be destroyed as long "
|
|
|
|
"as GlobalObject lives on the stack") mGlobalObject;
|
2012-12-03 16:07:49 +00:00
|
|
|
};
|
|
|
|
|
2013-02-06 09:56:15 +00:00
|
|
|
// Class for representing optional arguments.
|
2013-05-16 16:36:56 +00:00
|
|
|
template<typename T, typename InternalType>
|
|
|
|
class Optional_base
|
2013-02-06 09:56:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-05-16 16:36:56 +00:00
|
|
|
Optional_base()
|
2013-02-06 09:56:15 +00:00
|
|
|
{}
|
|
|
|
|
2013-05-16 16:36:56 +00:00
|
|
|
explicit Optional_base(const T& aValue)
|
2013-04-24 12:36:10 +00:00
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
mImpl.emplace(aValue);
|
2013-04-24 12:36:10 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 16:36:56 +00:00
|
|
|
template<typename T1, typename T2>
|
|
|
|
explicit Optional_base(const T1& aValue1, const T2& aValue2)
|
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
mImpl.emplace(aValue1, aValue2);
|
2013-05-16 16:36:56 +00:00
|
|
|
}
|
|
|
|
|
2013-02-06 09:56:15 +00:00
|
|
|
bool WasPassed() const
|
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
return mImpl.isSome();
|
2013-02-06 09:56:15 +00:00
|
|
|
}
|
|
|
|
|
2014-04-10 06:03:29 +00:00
|
|
|
// Return InternalType here so we can work with it usefully.
|
|
|
|
InternalType& Construct()
|
2013-02-06 09:56:15 +00:00
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
mImpl.emplace();
|
|
|
|
return *mImpl;
|
2013-02-06 09:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T1>
|
2014-04-10 06:03:29 +00:00
|
|
|
InternalType& Construct(const T1 &t1)
|
2013-02-06 09:56:15 +00:00
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
mImpl.emplace(t1);
|
|
|
|
return *mImpl;
|
2013-02-06 09:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T1, class T2>
|
2014-04-10 06:03:29 +00:00
|
|
|
InternalType& Construct(const T1 &t1, const T2 &t2)
|
2013-02-06 09:56:15 +00:00
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
mImpl.emplace(t1, t2);
|
|
|
|
return *mImpl;
|
2013-02-06 09:56:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 17:21:59 +00:00
|
|
|
void Reset()
|
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
mImpl.reset();
|
2013-09-13 17:21:59 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:48:43 +00:00
|
|
|
const T& Value() const
|
2013-02-06 09:56:15 +00:00
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
return *mImpl;
|
2013-02-06 09:56:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:48:43 +00:00
|
|
|
// Return InternalType here so we can work with it usefully.
|
2013-05-16 16:36:56 +00:00
|
|
|
InternalType& Value()
|
2013-02-06 09:56:15 +00:00
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
return *mImpl;
|
2013-02-06 09:56:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:48:43 +00:00
|
|
|
// And an explicit way to get the InternalType even if we're const.
|
|
|
|
const InternalType& InternalValue() const
|
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
return *mImpl;
|
2013-06-19 18:48:43 +00:00
|
|
|
}
|
|
|
|
|
2013-02-06 09:56:15 +00:00
|
|
|
// If we ever decide to add conversion operators for optional arrays
|
|
|
|
// like the ones Nullable has, we'll need to ensure that Maybe<> has
|
|
|
|
// the boolean before the actual data.
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Forbid copy-construction and assignment
|
2015-01-06 23:35:02 +00:00
|
|
|
Optional_base(const Optional_base& other) = delete;
|
|
|
|
const Optional_base &operator=(const Optional_base &other) = delete;
|
2013-05-16 16:36:56 +00:00
|
|
|
|
2013-06-19 18:48:43 +00:00
|
|
|
protected:
|
2013-05-16 16:36:56 +00:00
|
|
|
Maybe<InternalType> mImpl;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class Optional : public Optional_base<T, T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Optional() :
|
|
|
|
Optional_base<T, T>()
|
|
|
|
{}
|
|
|
|
|
|
|
|
explicit Optional(const T& aValue) :
|
|
|
|
Optional_base<T, T>(aValue)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class Optional<JS::Handle<T> > :
|
|
|
|
public Optional_base<JS::Handle<T>, JS::Rooted<T> >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Optional() :
|
|
|
|
Optional_base<JS::Handle<T>, JS::Rooted<T> >()
|
|
|
|
{}
|
2013-02-06 09:56:15 +00:00
|
|
|
|
2014-07-28 17:17:51 +00:00
|
|
|
explicit Optional(JSContext* cx) :
|
2013-06-12 01:41:21 +00:00
|
|
|
Optional_base<JS::Handle<T>, JS::Rooted<T> >()
|
|
|
|
{
|
|
|
|
this->Construct(cx);
|
|
|
|
}
|
|
|
|
|
2013-05-16 16:36:56 +00:00
|
|
|
Optional(JSContext* cx, const T& aValue) :
|
|
|
|
Optional_base<JS::Handle<T>, JS::Rooted<T> >(cx, aValue)
|
|
|
|
{}
|
2013-06-19 18:48:43 +00:00
|
|
|
|
|
|
|
// Override the const Value() to return the right thing so we're not
|
|
|
|
// returning references to temporaries.
|
|
|
|
JS::Handle<T> Value() const
|
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
return *this->mImpl;
|
2013-06-19 18:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// And we have to override the non-const one too, since we're
|
|
|
|
// shadowing the one on the superclass.
|
|
|
|
JS::Rooted<T>& Value()
|
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
return *this->mImpl;
|
2013-06-19 18:48:43 +00:00
|
|
|
}
|
2013-02-06 09:56:15 +00:00
|
|
|
};
|
|
|
|
|
2013-05-21 18:15:30 +00:00
|
|
|
// A specialization of Optional for JSObject* to make sure that when someone
|
|
|
|
// calls Construct() on it we will pre-initialized the JSObject* to nullptr so
|
|
|
|
// it can be traced safely.
|
|
|
|
template<>
|
|
|
|
class Optional<JSObject*> : public Optional_base<JSObject*, JSObject*>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Optional() :
|
|
|
|
Optional_base<JSObject*, JSObject*>()
|
|
|
|
{}
|
|
|
|
|
|
|
|
explicit Optional(JSObject* aValue) :
|
|
|
|
Optional_base<JSObject*, JSObject*>(aValue)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Don't allow us to have an uninitialized JSObject*
|
2014-04-10 06:03:29 +00:00
|
|
|
JSObject*& Construct()
|
2013-05-21 18:15:30 +00:00
|
|
|
{
|
|
|
|
// The Android compiler sucks and thinks we're trying to construct
|
|
|
|
// a JSObject* from an int if we don't cast here. :(
|
2014-04-10 06:03:29 +00:00
|
|
|
return Optional_base<JSObject*, JSObject*>::Construct(
|
2013-05-21 18:15:30 +00:00
|
|
|
static_cast<JSObject*>(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T1>
|
2014-04-10 06:03:29 +00:00
|
|
|
JSObject*& Construct(const T1& t1)
|
2013-05-21 18:15:30 +00:00
|
|
|
{
|
2014-04-10 06:03:29 +00:00
|
|
|
return Optional_base<JSObject*, JSObject*>::Construct(t1);
|
2013-05-21 18:15:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-19 15:13:38 +00:00
|
|
|
// A specialization of Optional for JS::Value to make sure no one ever uses it.
|
2013-05-21 18:15:30 +00:00
|
|
|
template<>
|
2014-02-19 15:13:38 +00:00
|
|
|
class Optional<JS::Value>
|
2013-05-21 18:15:30 +00:00
|
|
|
{
|
2014-02-19 15:13:38 +00:00
|
|
|
private:
|
2015-01-06 23:35:02 +00:00
|
|
|
Optional() = delete;
|
2013-05-21 18:15:30 +00:00
|
|
|
|
2015-01-06 23:35:02 +00:00
|
|
|
explicit Optional(JS::Value aValue) = delete;
|
2013-05-21 18:15:30 +00:00
|
|
|
};
|
|
|
|
|
2013-06-19 18:48:43 +00:00
|
|
|
// A specialization of Optional for NonNull that lets us get a T& from Value()
|
|
|
|
template<typename U> class NonNull;
|
|
|
|
template<typename T>
|
|
|
|
class Optional<NonNull<T> > : public Optional_base<T, NonNull<T> >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// We want our Value to actually return a non-const reference, even
|
|
|
|
// if we're const. At least for things that are normally pointer
|
|
|
|
// types...
|
|
|
|
T& Value() const
|
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
return *this->mImpl->get();
|
2013-06-19 18:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// And we have to override the non-const one too, since we're
|
|
|
|
// shadowing the one on the superclass.
|
|
|
|
NonNull<T>& Value()
|
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
return *this->mImpl;
|
2013-06-19 18:48:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// A specialization of Optional for OwningNonNull that lets us get a
|
|
|
|
// T& from Value()
|
|
|
|
template<typename T>
|
|
|
|
class Optional<OwningNonNull<T> > : public Optional_base<T, OwningNonNull<T> >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// We want our Value to actually return a non-const reference, even
|
|
|
|
// if we're const. At least for things that are normally pointer
|
|
|
|
// types...
|
|
|
|
T& Value() const
|
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
return *this->mImpl->get();
|
2013-06-19 18:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// And we have to override the non-const one too, since we're
|
|
|
|
// shadowing the one on the superclass.
|
|
|
|
OwningNonNull<T>& Value()
|
|
|
|
{
|
2014-08-13 22:39:41 +00:00
|
|
|
return *this->mImpl;
|
2013-06-19 18:48:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-06 09:56:15 +00:00
|
|
|
// Specialization for strings.
|
2014-07-03 08:03:56 +00:00
|
|
|
// XXXbz we can't pull in FakeString here, because it depends on internal
|
|
|
|
// strings. So we just have to forward-declare it and reimplement its
|
2013-02-06 09:56:15 +00:00
|
|
|
// ToAStringPtr.
|
|
|
|
|
2014-01-22 19:37:10 +00:00
|
|
|
namespace binding_detail {
|
2014-07-03 08:03:56 +00:00
|
|
|
struct FakeString;
|
2014-01-22 19:37:10 +00:00
|
|
|
} // namespace binding_detail
|
2013-02-06 09:56:15 +00:00
|
|
|
|
|
|
|
template<>
|
|
|
|
class Optional<nsAString>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Optional() : mPassed(false) {}
|
|
|
|
|
|
|
|
bool WasPassed() const
|
|
|
|
{
|
|
|
|
return mPassed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator=(const nsAString* str)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(str);
|
|
|
|
mStr = str;
|
|
|
|
mPassed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this code ever goes away, remove the comment pointing to it in the
|
2014-07-03 08:03:56 +00:00
|
|
|
// FakeString class in BindingUtils.h.
|
|
|
|
void operator=(const binding_detail::FakeString* str)
|
2013-02-06 09:56:15 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(str);
|
2014-07-03 08:03:56 +00:00
|
|
|
mStr = reinterpret_cast<const nsString*>(str);
|
2013-02-06 09:56:15 +00:00
|
|
|
mPassed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAString& Value() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(WasPassed());
|
|
|
|
return *mStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Forbid copy-construction and assignment
|
2015-01-06 23:35:02 +00:00
|
|
|
Optional(const Optional& other) = delete;
|
|
|
|
const Optional &operator=(const Optional &other) = delete;
|
2013-02-06 09:56:15 +00:00
|
|
|
|
|
|
|
bool mPassed;
|
|
|
|
const nsAString* mStr;
|
|
|
|
};
|
|
|
|
|
2013-06-19 14:24:37 +00:00
|
|
|
template<class T>
|
|
|
|
class NonNull
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NonNull()
|
|
|
|
#ifdef DEBUG
|
|
|
|
: inited(false)
|
|
|
|
#endif
|
|
|
|
{}
|
|
|
|
|
2014-06-23 20:03:57 +00:00
|
|
|
// This is no worse than get() in terms of const handling.
|
|
|
|
operator T&() const {
|
2013-06-19 14:24:37 +00:00
|
|
|
MOZ_ASSERT(inited);
|
|
|
|
MOZ_ASSERT(ptr, "NonNull<T> was set to null");
|
|
|
|
return *ptr;
|
|
|
|
}
|
|
|
|
|
2014-06-23 20:03:57 +00:00
|
|
|
operator T*() const {
|
2013-12-20 08:51:03 +00:00
|
|
|
MOZ_ASSERT(inited);
|
|
|
|
MOZ_ASSERT(ptr, "NonNull<T> was set to null");
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2013-06-19 14:24:37 +00:00
|
|
|
void operator=(T* t) {
|
|
|
|
ptr = t;
|
|
|
|
MOZ_ASSERT(ptr);
|
|
|
|
#ifdef DEBUG
|
|
|
|
inited = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
void operator=(U* t) {
|
|
|
|
ptr = t->ToAStringPtr();
|
|
|
|
MOZ_ASSERT(ptr);
|
|
|
|
#ifdef DEBUG
|
|
|
|
inited = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
T** Slot() {
|
|
|
|
#ifdef DEBUG
|
|
|
|
inited = true;
|
|
|
|
#endif
|
|
|
|
return &ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* Ptr() {
|
|
|
|
MOZ_ASSERT(inited);
|
|
|
|
MOZ_ASSERT(ptr, "NonNull<T> was set to null");
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make us work with smart-ptr helpers that expect a get()
|
|
|
|
T* get() const {
|
|
|
|
MOZ_ASSERT(inited);
|
|
|
|
MOZ_ASSERT(ptr);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T* ptr;
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool inited;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2013-03-02 06:07:43 +00:00
|
|
|
// Class for representing sequences in arguments. We use a non-auto array
|
|
|
|
// because that allows us to use sequences of sequences and the like. This
|
|
|
|
// needs to be fallible because web content controls the length of the array,
|
|
|
|
// and can easily try to create very large lengths.
|
2013-02-06 09:56:15 +00:00
|
|
|
template<typename T>
|
2013-03-02 06:07:43 +00:00
|
|
|
class Sequence : public FallibleTArray<T>
|
2013-02-06 09:56:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-03-02 06:07:43 +00:00
|
|
|
Sequence() : FallibleTArray<T>()
|
2013-02-06 09:56:15 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2013-03-17 14:42:59 +00:00
|
|
|
inline nsWrapperCache*
|
|
|
|
GetWrapperCache(nsWrapperCache* cache)
|
|
|
|
{
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsWrapperCache*
|
|
|
|
GetWrapperCache(void* p)
|
|
|
|
{
|
2013-10-28 14:04:12 +00:00
|
|
|
return nullptr;
|
2013-03-17 14:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Helper template for smart pointers to resolve ambiguity between
|
|
|
|
// GetWrappeCache(void*) and GetWrapperCache(const ParentObject&).
|
|
|
|
template <template <typename> class SmartPtr, typename T>
|
|
|
|
inline nsWrapperCache*
|
|
|
|
GetWrapperCache(const SmartPtr<T>& aObject)
|
|
|
|
{
|
|
|
|
return GetWrapperCache(aObject.get());
|
|
|
|
}
|
|
|
|
|
2015-01-18 19:11:34 +00:00
|
|
|
struct MOZ_STACK_CLASS ParentObject {
|
2013-03-17 14:42:59 +00:00
|
|
|
template<class T>
|
|
|
|
ParentObject(T* aObject) :
|
|
|
|
mObject(aObject),
|
2014-03-19 16:35:45 +00:00
|
|
|
mWrapperCache(GetWrapperCache(aObject)),
|
|
|
|
mUseXBLScope(false)
|
2013-03-17 14:42:59 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<class T, template<typename> class SmartPtr>
|
|
|
|
ParentObject(const SmartPtr<T>& aObject) :
|
|
|
|
mObject(aObject.get()),
|
2014-03-19 16:35:45 +00:00
|
|
|
mWrapperCache(GetWrapperCache(aObject.get())),
|
|
|
|
mUseXBLScope(false)
|
2013-03-17 14:42:59 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
ParentObject(nsISupports* aObject, nsWrapperCache* aCache) :
|
|
|
|
mObject(aObject),
|
2014-03-19 16:35:45 +00:00
|
|
|
mWrapperCache(aCache),
|
|
|
|
mUseXBLScope(false)
|
2013-03-17 14:42:59 +00:00
|
|
|
{}
|
|
|
|
|
2015-01-18 19:11:34 +00:00
|
|
|
// We don't want to make this an nsCOMPtr because of performance reasons, but
|
|
|
|
// it's safe because ParentObject is a stack class.
|
|
|
|
nsISupports* const MOZ_NON_OWNING_REF mObject;
|
2013-03-17 14:42:59 +00:00
|
|
|
nsWrapperCache* const mWrapperCache;
|
2014-03-19 16:35:45 +00:00
|
|
|
bool mUseXBLScope;
|
2013-03-17 14:42:59 +00:00
|
|
|
};
|
|
|
|
|
2012-12-25 22:00:15 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-10-11 16:28:23 +00:00
|
|
|
#endif // mozilla_dom_BindingDeclarations_h__
|