2015-05-03 19:32:37 +00: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-25 22:00:15 +00: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-17 22:50:18 +00:00
|
|
|
#include "js/RootingAPI.h"
|
2015-08-06 12:45:21 +00:00
|
|
|
#include "js/Value.h"
|
|
|
|
|
2013-08-27 22:10:28 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2016-05-18 16:23:35 +00:00
|
|
|
#include "mozilla/RootedOwningNonNull.h"
|
|
|
|
#include "mozilla/RootedRefPtr.h"
|
2015-08-06 12:45:21 +00:00
|
|
|
|
|
|
|
#include "mozilla/dom/DOMString.h"
|
|
|
|
|
2012-12-03 16:07:49 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2017-12-07 00:52:51 +00:00
|
|
|
#include "nsString.h"
|
2013-02-06 09:56:15 +00:00
|
|
|
#include "nsTArray.h"
|
2012-12-25 22:00:15 +00:00
|
|
|
|
2016-09-30 17:54:13 +00:00
|
|
|
class nsIPrincipal;
|
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,
|
2016-02-11 04:31:33 +00:00
|
|
|
JS::Handle<JSObject*> aObj,
|
2014-09-09 18:00:22 +00:00
|
|
|
nsAString& aJSON) const;
|
2015-02-19 19:36:26 +00: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 {
|
|
|
|
};
|
|
|
|
|
2016-02-24 18:45:46 +00:00
|
|
|
bool mIsAnyMemberPresent = false;
|
|
|
|
|
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);
|
2016-02-24 18:45:46 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool IsAnyMemberPresent() const
|
|
|
|
{
|
|
|
|
return mIsAnyMemberPresent;
|
|
|
|
}
|
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;
|
|
|
|
};
|
|
|
|
|
2016-12-07 09:41:52 +00:00
|
|
|
enum class CallerType : uint32_t;
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-09-30 17:54:13 +00:00
|
|
|
// It returns the subjectPrincipal if called on the main-thread, otherwise
|
|
|
|
// a nullptr is returned.
|
|
|
|
nsIPrincipal* GetSubjectPrincipal() const;
|
|
|
|
|
2016-12-07 09:41:52 +00:00
|
|
|
// Get the caller type. Note that this needs to be called before anyone has
|
|
|
|
// had a chance to mess with the JSContext.
|
|
|
|
dom::CallerType CallerType() const;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-07-07 22:44:07 +00:00
|
|
|
bool operator==(const Optional_base<T, InternalType>& aOther) const
|
|
|
|
{
|
|
|
|
return mImpl == aOther.mImpl;
|
|
|
|
}
|
|
|
|
|
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.
|
2015-11-20 18:36:45 +00:00
|
|
|
template<typename... Args>
|
|
|
|
InternalType& Construct(Args&&... aArgs)
|
2013-02-06 09:56:15 +00:00
|
|
|
{
|
2015-11-20 18:36:45 +00:00
|
|
|
mImpl.emplace(Forward<Args>(aArgs)...);
|
2014-08-13 22:39:41 +00:00
|
|
|
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
|
|
|
|
2016-09-11 09:15:24 +00:00
|
|
|
explicit Optional(const 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:
|
2017-09-22 10:35:07 +00:00
|
|
|
Optional()
|
|
|
|
: mStr(nullptr)
|
|
|
|
{}
|
2013-02-06 09:56:15 +00:00
|
|
|
|
|
|
|
bool WasPassed() const
|
|
|
|
{
|
2017-09-22 10:35:07 +00:00
|
|
|
return !!mStr;
|
2013-02-06 09:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator=(const nsAString* str)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(str);
|
|
|
|
mStr = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
const nsAString* mStr;
|
|
|
|
};
|
|
|
|
|
2013-06-19 14:24:37 +00:00
|
|
|
template<class T>
|
|
|
|
class NonNull
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NonNull()
|
|
|
|
#ifdef DEBUG
|
2018-01-05 21:44:25 +00:00
|
|
|
: inited(false)
|
2013-06-19 14:24:37 +00:00
|
|
|
#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:
|
2018-01-05 20:37:42 +00:00
|
|
|
// ptr is left uninitialized for optimization purposes.
|
2013-06-19 14:24:37 +00:00
|
|
|
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>
|
2015-07-28 01:15:04 +00:00
|
|
|
MOZ_IMPLICIT ParentObject(T* aObject) :
|
2013-03-17 14:42:59 +00:00
|
|
|
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>
|
2015-07-28 01:15:04 +00:00
|
|
|
MOZ_IMPLICIT ParentObject(const SmartPtr<T>& aObject) :
|
2013-03-17 14:42:59 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2016-09-01 10:10:54 +00:00
|
|
|
namespace binding_detail {
|
|
|
|
|
|
|
|
// Class for simple sequence arguments, only used internally by codegen.
|
|
|
|
template<typename T>
|
|
|
|
class AutoSequence : public AutoTArray<T, 16>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoSequence() : AutoTArray<T, 16>()
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Allow converting to const sequences as needed
|
|
|
|
operator const Sequence<T>&() const {
|
|
|
|
return *reinterpret_cast<const Sequence<T>*>(this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace binding_detail
|
|
|
|
|
2016-11-11 21:09:05 +00:00
|
|
|
// Enum to represent a system or non-system caller type.
|
2016-11-17 18:49:27 +00:00
|
|
|
enum class CallerType : uint32_t {
|
2016-11-11 21:09:05 +00:00
|
|
|
System,
|
|
|
|
NonSystem
|
|
|
|
};
|
|
|
|
|
2017-02-01 20:43:36 +00:00
|
|
|
// A class that can be passed (by value or const reference) to indicate that the
|
|
|
|
// caller is always a system caller. This can be used as the type of an
|
|
|
|
// argument to force only system callers to call a function.
|
|
|
|
class SystemCallerGuarantee {
|
|
|
|
public:
|
|
|
|
operator CallerType() const { return CallerType::System; }
|
|
|
|
};
|
|
|
|
|
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__
|