2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-12-26 02:00:15 +04:00
|
|
|
/* 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__
|
|
|
|
|
2013-08-18 02:50:18 +04:00
|
|
|
#include "js/RootingAPI.h"
|
2015-08-06 15:45:21 +03:00
|
|
|
#include "js/Value.h"
|
|
|
|
|
2013-08-28 02:10:28 +04:00
|
|
|
#include "mozilla/Maybe.h"
|
2015-08-06 15:45:21 +03:00
|
|
|
#include "mozilla/OwningNonNull.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/DOMString.h"
|
|
|
|
|
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr member variables
|
2012-12-03 20:07:49 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2015-08-06 15:45:21 +03:00
|
|
|
#include "nsStringGlue.h"
|
2013-02-06 13:56:15 +04:00
|
|
|
#include "nsTArray.h"
|
2012-12-26 02:00:15 +04:00
|
|
|
|
2013-03-17 18:42:59 +04:00
|
|
|
class nsWrapperCache;
|
|
|
|
|
2012-12-26 02:00:15 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-05-16 20:36:55 +04: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 06:08:28 +04:00
|
|
|
protected:
|
|
|
|
bool ParseJSON(JSContext* aCx, const nsAString& aJSON,
|
|
|
|
JS::MutableHandle<JS::Value> aVal);
|
2014-08-01 07:50:19 +04:00
|
|
|
|
|
|
|
bool StringifyToJSON(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aValue,
|
2014-09-09 22:00:22 +04:00
|
|
|
nsAString& aJSON) const;
|
2015-02-19 22:36:26 +03:00
|
|
|
|
|
|
|
// Struct used as a way to force a dictionary constructor to not init the
|
|
|
|
// dictionary (via constructing from a pointer to this class). We're putting
|
|
|
|
// it here so that all the dictionaries will have access to it, but outside
|
|
|
|
// code will not.
|
|
|
|
struct FastDictionaryInitializer {
|
|
|
|
};
|
|
|
|
|
2014-08-01 07:50:19 +04:00
|
|
|
private:
|
|
|
|
// aString is expected to actually be an nsAString*. Should only be
|
|
|
|
// called from StringifyToJSON.
|
2014-07-22 08:43:21 +04:00
|
|
|
static bool AppendJSONToString(const char16_t* aJSONData,
|
|
|
|
uint32_t aDataLength, void* aString);
|
2013-05-16 20:36:55 +04:00
|
|
|
};
|
|
|
|
|
2013-08-05 21:40:02 +04: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 22:51:22 +04: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 21:40:02 +04:00
|
|
|
|
2012-12-26 02:00:15 +04:00
|
|
|
struct EnumEntry {
|
|
|
|
const char* value;
|
|
|
|
size_t length;
|
|
|
|
};
|
|
|
|
|
2013-04-12 07:20:18 +04:00
|
|
|
class MOZ_STACK_CLASS GlobalObject
|
2012-12-03 20:07:49 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GlobalObject(JSContext* aCx, JSObject* aObject);
|
|
|
|
|
|
|
|
JSObject* Get() const
|
|
|
|
{
|
|
|
|
return mGlobalJSObject;
|
|
|
|
}
|
2013-08-23 09:17:08 +04:00
|
|
|
|
|
|
|
nsISupports* GetAsSupports() const;
|
|
|
|
|
2012-12-03 20:07:49 +04: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 22:08:00 +04:00
|
|
|
JSContext* Context() const
|
2012-12-03 20:07:49 +04:00
|
|
|
{
|
|
|
|
return mCx;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Failed() const
|
|
|
|
{
|
|
|
|
return !Get();
|
|
|
|
}
|
|
|
|
|
2013-08-23 09:17:08 +04:00
|
|
|
protected:
|
2013-11-11 12:04:41 +04:00
|
|
|
JS::Rooted<JSObject*> mGlobalJSObject;
|
2012-12-03 20:07:49 +04:00
|
|
|
JSContext* mCx;
|
2015-01-05 23:46:37 +03: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 20:07:49 +04:00
|
|
|
};
|
|
|
|
|
2013-02-06 13:56:15 +04:00
|
|
|
// Class for representing optional arguments.
|
2013-05-16 20:36:56 +04:00
|
|
|
template<typename T, typename InternalType>
|
|
|
|
class Optional_base
|
2013-02-06 13:56:15 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-05-16 20:36:56 +04:00
|
|
|
Optional_base()
|
2013-02-06 13:56:15 +04:00
|
|
|
{}
|
|
|
|
|
2013-05-16 20:36:56 +04:00
|
|
|
explicit Optional_base(const T& aValue)
|
2013-04-24 16:36:10 +04:00
|
|
|
{
|
2014-08-14 02:39:41 +04:00
|
|
|
mImpl.emplace(aValue);
|
2013-04-24 16:36:10 +04:00
|
|
|
}
|
|
|
|
|
2015-07-08 01:44:07 +03:00
|
|
|
bool operator==(const Optional_base<T, InternalType>& aOther) const
|
|
|
|
{
|
|
|
|
return mImpl == aOther.mImpl;
|
|
|
|
}
|
|
|
|
|
2013-05-16 20:36:56 +04:00
|
|
|
template<typename T1, typename T2>
|
|
|
|
explicit Optional_base(const T1& aValue1, const T2& aValue2)
|
|
|
|
{
|
2014-08-14 02:39:41 +04:00
|
|
|
mImpl.emplace(aValue1, aValue2);
|
2013-05-16 20:36:56 +04:00
|
|
|
}
|
|
|
|
|
2013-02-06 13:56:15 +04:00
|
|
|
bool WasPassed() const
|
|
|
|
{
|
2014-08-14 02:39:41 +04:00
|
|
|
return mImpl.isSome();
|
2013-02-06 13:56:15 +04:00
|
|
|
}
|
|
|
|
|
2014-04-10 10:03:29 +04:00
|
|
|
// Return InternalType here so we can work with it usefully.
|
2015-11-20 21:36:45 +03:00
|
|
|
template<typename... Args>
|
|
|
|
InternalType& Construct(Args&&... aArgs)
|
2013-02-06 13:56:15 +04:00
|
|
|
{
|
2015-11-20 21:36:45 +03:00
|
|
|
mImpl.emplace(Forward<Args>(aArgs)...);
|
2014-08-14 02:39:41 +04:00
|
|
|
return *mImpl;
|
2013-02-06 13:56:15 +04:00
|
|
|
}
|
|
|
|
|
2013-09-13 21:21:59 +04:00
|
|
|
void Reset()
|
|
|
|
{
|
2014-08-14 02:39:41 +04:00
|
|
|
mImpl.reset();
|
2013-09-13 21:21:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 22:48:43 +04:00
|
|
|
const T& Value() const
|
2013-02-06 13:56:15 +04:00
|
|
|
{
|
2014-08-14 02:39:41 +04:00
|
|
|
return *mImpl;
|
2013-02-06 13:56:15 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 22:48:43 +04:00
|
|
|
// Return InternalType here so we can work with it usefully.
|
2013-05-16 20:36:56 +04:00
|
|
|
InternalType& Value()
|
2013-02-06 13:56:15 +04:00
|
|
|
{
|
2014-08-14 02:39:41 +04:00
|
|
|
return *mImpl;
|
2013-02-06 13:56:15 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 22:48:43 +04:00
|
|
|
// And an explicit way to get the InternalType even if we're const.
|
|
|
|
const InternalType& InternalValue() const
|
|
|
|
{
|
2014-08-14 02:39:41 +04:00
|
|
|
return *mImpl;
|
2013-06-19 22:48:43 +04:00
|
|
|
}
|
|
|
|
|
2013-02-06 13:56:15 +04: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-07 02:35:02 +03:00
|
|
|
Optional_base(const Optional_base& other) = delete;
|
|
|
|
const Optional_base &operator=(const Optional_base &other) = delete;
|
2013-05-16 20:36:56 +04:00
|
|
|
|
2013-06-19 22:48:43 +04:00
|
|
|
protected:
|
2013-05-16 20:36:56 +04: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 13:56:15 +04:00
|
|
|
|
2014-07-28 21:17:51 +04:00
|
|
|
explicit Optional(JSContext* cx) :
|
2013-06-12 05:41:21 +04:00
|
|
|
Optional_base<JS::Handle<T>, JS::Rooted<T> >()
|
|
|
|
{
|
|
|
|
this->Construct(cx);
|
|
|
|
}
|
|
|
|
|
2013-05-16 20:36:56 +04:00
|
|
|
Optional(JSContext* cx, const T& aValue) :
|
|
|
|
Optional_base<JS::Handle<T>, JS::Rooted<T> >(cx, aValue)
|
|
|
|
{}
|
2013-06-19 22:48:43 +04: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-14 02:39:41 +04:00
|
|
|
return *this->mImpl;
|
2013-06-19 22:48:43 +04: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-14 02:39:41 +04:00
|
|
|
return *this->mImpl;
|
2013-06-19 22:48:43 +04:00
|
|
|
}
|
2013-02-06 13:56:15 +04:00
|
|
|
};
|
|
|
|
|
2013-05-21 22:15:30 +04: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 10:03:29 +04:00
|
|
|
JSObject*& Construct()
|
2013-05-21 22:15:30 +04: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 10:03:29 +04:00
|
|
|
return Optional_base<JSObject*, JSObject*>::Construct(
|
2013-05-21 22:15:30 +04:00
|
|
|
static_cast<JSObject*>(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T1>
|
2014-04-10 10:03:29 +04:00
|
|
|
JSObject*& Construct(const T1& t1)
|
2013-05-21 22:15:30 +04:00
|
|
|
{
|
2014-04-10 10:03:29 +04:00
|
|
|
return Optional_base<JSObject*, JSObject*>::Construct(t1);
|
2013-05-21 22:15:30 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-19 19:13:38 +04:00
|
|
|
// A specialization of Optional for JS::Value to make sure no one ever uses it.
|
2013-05-21 22:15:30 +04:00
|
|
|
template<>
|
2014-02-19 19:13:38 +04:00
|
|
|
class Optional<JS::Value>
|
2013-05-21 22:15:30 +04:00
|
|
|
{
|
2014-02-19 19:13:38 +04:00
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
Optional() = delete;
|
2013-05-21 22:15:30 +04:00
|
|
|
|
2015-01-07 02:35:02 +03:00
|
|
|
explicit Optional(JS::Value aValue) = delete;
|
2013-05-21 22:15:30 +04:00
|
|
|
};
|
|
|
|
|
2013-06-19 22:48:43 +04: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-14 02:39:41 +04:00
|
|
|
return *this->mImpl->get();
|
2013-06-19 22:48:43 +04: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-14 02:39:41 +04:00
|
|
|
return *this->mImpl;
|
2013-06-19 22:48:43 +04: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-14 02:39:41 +04:00
|
|
|
return *this->mImpl->get();
|
2013-06-19 22:48:43 +04: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-14 02:39:41 +04:00
|
|
|
return *this->mImpl;
|
2013-06-19 22:48:43 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-06 13:56:15 +04:00
|
|
|
// Specialization for strings.
|
2014-07-03 12:03:56 +04: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 13:56:15 +04:00
|
|
|
// ToAStringPtr.
|
|
|
|
|
2014-01-22 23:37:10 +04:00
|
|
|
namespace binding_detail {
|
2014-07-03 12:03:56 +04:00
|
|
|
struct FakeString;
|
2014-01-22 23:37:10 +04:00
|
|
|
} // namespace binding_detail
|
2013-02-06 13:56:15 +04: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 12:03:56 +04:00
|
|
|
// FakeString class in BindingUtils.h.
|
|
|
|
void operator=(const binding_detail::FakeString* str)
|
2013-02-06 13:56:15 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(str);
|
2014-07-03 12:03:56 +04:00
|
|
|
mStr = reinterpret_cast<const nsString*>(str);
|
2013-02-06 13:56:15 +04:00
|
|
|
mPassed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAString& Value() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(WasPassed());
|
|
|
|
return *mStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Forbid copy-construction and assignment
|
2015-01-07 02:35:02 +03:00
|
|
|
Optional(const Optional& other) = delete;
|
|
|
|
const Optional &operator=(const Optional &other) = delete;
|
2013-02-06 13:56:15 +04:00
|
|
|
|
|
|
|
bool mPassed;
|
|
|
|
const nsAString* mStr;
|
|
|
|
};
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
template<class T>
|
|
|
|
class NonNull
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NonNull()
|
|
|
|
#ifdef DEBUG
|
|
|
|
: inited(false)
|
|
|
|
#endif
|
|
|
|
{}
|
|
|
|
|
2014-06-24 00:03:57 +04:00
|
|
|
// This is no worse than get() in terms of const handling.
|
|
|
|
operator T&() const {
|
2013-06-19 18:24:37 +04:00
|
|
|
MOZ_ASSERT(inited);
|
|
|
|
MOZ_ASSERT(ptr, "NonNull<T> was set to null");
|
|
|
|
return *ptr;
|
|
|
|
}
|
|
|
|
|
2014-06-24 00:03:57 +04:00
|
|
|
operator T*() const {
|
2013-12-20 12:51:03 +04:00
|
|
|
MOZ_ASSERT(inited);
|
|
|
|
MOZ_ASSERT(ptr, "NonNull<T> was set to null");
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04: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 10:07:43 +04: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 13:56:15 +04:00
|
|
|
template<typename T>
|
2013-03-02 10:07:43 +04:00
|
|
|
class Sequence : public FallibleTArray<T>
|
2013-02-06 13:56:15 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-03-02 10:07:43 +04:00
|
|
|
Sequence() : FallibleTArray<T>()
|
2013-02-06 13:56:15 +04:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2013-03-17 18:42:59 +04:00
|
|
|
inline nsWrapperCache*
|
|
|
|
GetWrapperCache(nsWrapperCache* cache)
|
|
|
|
{
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsWrapperCache*
|
|
|
|
GetWrapperCache(void* p)
|
|
|
|
{
|
2013-10-28 18:04:12 +04:00
|
|
|
return nullptr;
|
2013-03-17 18:42:59 +04: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 22:11:34 +03:00
|
|
|
struct MOZ_STACK_CLASS ParentObject {
|
2013-03-17 18:42:59 +04:00
|
|
|
template<class T>
|
2015-07-28 04:15:04 +03:00
|
|
|
MOZ_IMPLICIT ParentObject(T* aObject) :
|
2013-03-17 18:42:59 +04:00
|
|
|
mObject(aObject),
|
2014-03-19 20:35:45 +04:00
|
|
|
mWrapperCache(GetWrapperCache(aObject)),
|
|
|
|
mUseXBLScope(false)
|
2013-03-17 18:42:59 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<class T, template<typename> class SmartPtr>
|
2015-07-28 04:15:04 +03:00
|
|
|
MOZ_IMPLICIT ParentObject(const SmartPtr<T>& aObject) :
|
2013-03-17 18:42:59 +04:00
|
|
|
mObject(aObject.get()),
|
2014-03-19 20:35:45 +04:00
|
|
|
mWrapperCache(GetWrapperCache(aObject.get())),
|
|
|
|
mUseXBLScope(false)
|
2013-03-17 18:42:59 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
ParentObject(nsISupports* aObject, nsWrapperCache* aCache) :
|
|
|
|
mObject(aObject),
|
2014-03-19 20:35:45 +04:00
|
|
|
mWrapperCache(aCache),
|
|
|
|
mUseXBLScope(false)
|
2013-03-17 18:42:59 +04:00
|
|
|
{}
|
|
|
|
|
2015-01-18 22:11:34 +03: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 18:42:59 +04:00
|
|
|
nsWrapperCache* const mWrapperCache;
|
2014-03-19 20:35:45 +04:00
|
|
|
bool mUseXBLScope;
|
2013-03-17 18:42:59 +04:00
|
|
|
};
|
|
|
|
|
2012-12-26 02:00:15 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-10-11 20:28:23 +04:00
|
|
|
#endif // mozilla_dom_BindingDeclarations_h__
|