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-03-31 08:42:20 +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/. */
|
|
|
|
|
2012-05-03 08:35:38 +04:00
|
|
|
#ifndef mozilla_dom_DOMJSClass_h
|
|
|
|
#define mozilla_dom_DOMJSClass_h
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
#include "jsfriendapi.h"
|
2012-10-09 22:50:27 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-05-03 08:35:38 +04:00
|
|
|
#include "mozilla/dom/PrototypeList.h" // auto-generated
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-08-24 06:42:39 +04:00
|
|
|
#include "mozilla/dom/JSSlots.h"
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-08-24 06:42:39 +04:00
|
|
|
class nsCycleCollectionParticipant;
|
2012-09-13 00:29:30 +04:00
|
|
|
|
2012-10-25 19:01:09 +04:00
|
|
|
// All DOM globals must have a slot at DOM_PROTOTYPE_SLOT.
|
|
|
|
#define DOM_PROTOTYPE_SLOT JSCLASS_GLOBAL_SLOT_COUNT
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-08-21 08:21:00 +04:00
|
|
|
// Keep this count up to date with any extra global slots added above.
|
|
|
|
#define DOM_GLOBAL_SLOTS 1
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
// We use these flag bits for the new bindings.
|
2012-07-12 07:55:19 +04:00
|
|
|
#define JSCLASS_DOM_GLOBAL JSCLASS_USERBIT1
|
2012-10-09 22:50:27 +04:00
|
|
|
#define JSCLASS_IS_DOMIFACEANDPROTOJSCLASS JSCLASS_USERBIT2
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
typedef bool
|
2013-05-04 03:29:08 +04:00
|
|
|
(* ResolveOwnProperty)(JSContext* cx, JS::Handle<JSObject*> wrapper,
|
|
|
|
JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
|
2014-04-26 01:11:02 +04:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> desc);
|
2012-10-09 22:50:27 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
typedef bool
|
2013-05-04 03:29:08 +04:00
|
|
|
(* EnumerateOwnProperties)(JSContext* cx, JS::Handle<JSObject*> wrapper,
|
|
|
|
JS::Handle<JSObject*> obj,
|
2012-10-09 22:50:27 +04:00
|
|
|
JS::AutoIdVector& props);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2014-05-25 22:31:07 +04:00
|
|
|
bool
|
2015-07-14 05:25:26 +03:00
|
|
|
CheckAnyPermissions(JSContext* aCx, JSObject* aObj, const char* const aPermissions[]);
|
2014-05-25 22:31:07 +04:00
|
|
|
|
2015-07-03 11:03:35 +03:00
|
|
|
bool
|
|
|
|
CheckAllPermissions(JSContext* aCx, JSObject* aObj, const char* const aPermissions[]);
|
|
|
|
|
2012-10-09 22:50:27 +04:00
|
|
|
struct ConstantSpec
|
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
JS::Value value;
|
|
|
|
};
|
|
|
|
|
2013-02-19 20:54:40 +04:00
|
|
|
typedef bool (*PropertyEnabled)(JSContext* cx, JSObject* global);
|
|
|
|
|
2012-10-09 22:50:27 +04:00
|
|
|
template<typename T>
|
|
|
|
struct Prefable {
|
2015-06-16 00:22:00 +03:00
|
|
|
inline bool isEnabled(JSContext* cx, JS::Handle<JSObject*> obj) const {
|
2014-02-05 22:38:17 +04:00
|
|
|
if (!enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-14 05:25:26 +03:00
|
|
|
if (!enabledFunc && !availableFunc && !checkAnyPermissions && !checkAllPermissions) {
|
2014-02-05 22:38:17 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (enabledFunc &&
|
2015-06-16 00:22:00 +03:00
|
|
|
!enabledFunc(cx, js::GetGlobalForObjectCrossCompartment(obj))) {
|
2014-02-05 22:38:17 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (availableFunc &&
|
2015-06-16 00:22:00 +03:00
|
|
|
!availableFunc(cx, js::GetGlobalForObjectCrossCompartment(obj))) {
|
2014-02-05 22:38:17 +04:00
|
|
|
return false;
|
|
|
|
}
|
2015-07-14 05:25:26 +03:00
|
|
|
if (checkAnyPermissions &&
|
|
|
|
!CheckAnyPermissions(cx, js::GetGlobalForObjectCrossCompartment(obj),
|
|
|
|
checkAnyPermissions)) {
|
2014-05-25 22:31:07 +04:00
|
|
|
return false;
|
|
|
|
}
|
2015-07-03 11:03:35 +03:00
|
|
|
if (checkAllPermissions &&
|
|
|
|
!CheckAllPermissions(cx, js::GetGlobalForObjectCrossCompartment(obj),
|
|
|
|
checkAllPermissions)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-05 22:38:17 +04:00
|
|
|
return true;
|
2013-02-19 20:54:40 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 22:50:27 +04:00
|
|
|
// A boolean indicating whether this set of specs is enabled
|
|
|
|
bool enabled;
|
2013-02-19 20:54:40 +04:00
|
|
|
// A function pointer to a function that can say the property is disabled
|
|
|
|
// even if "enabled" is set to true. If the pointer is null the value of
|
2014-02-05 22:38:17 +04:00
|
|
|
// "enabled" is used as-is unless availableFunc overrides.
|
2013-02-19 20:54:40 +04:00
|
|
|
PropertyEnabled enabledFunc;
|
2014-02-05 22:38:17 +04:00
|
|
|
// A function pointer to a function that can be used to disable a
|
|
|
|
// property even if "enabled" is true and enabledFunc allowed. This
|
|
|
|
// is basically a hack to avoid having to codegen PropertyEnabled
|
|
|
|
// implementations in case when we need to do two separate checks.
|
|
|
|
PropertyEnabled availableFunc;
|
2015-07-14 05:25:26 +03:00
|
|
|
const char* const* checkAnyPermissions;
|
2015-07-03 11:03:35 +03:00
|
|
|
const char* const* checkAllPermissions;
|
2012-10-09 22:50:27 +04:00
|
|
|
// Array of specs, terminated in whatever way is customary for T.
|
|
|
|
// Null to indicate a end-of-array for Prefable, when such an
|
|
|
|
// indicator is needed.
|
2013-04-03 04:20:38 +04:00
|
|
|
const T* specs;
|
2012-10-09 22:50:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NativeProperties
|
|
|
|
{
|
2013-04-03 04:20:38 +04:00
|
|
|
const Prefable<const JSFunctionSpec>* staticMethods;
|
2012-10-09 22:50:27 +04:00
|
|
|
jsid* staticMethodIds;
|
2014-07-23 23:36:21 +04:00
|
|
|
const JSFunctionSpec* staticMethodSpecs;
|
2014-07-04 17:02:10 +04:00
|
|
|
|
2013-04-03 04:20:38 +04:00
|
|
|
const Prefable<const JSPropertySpec>* staticAttributes;
|
2012-10-19 11:34:28 +04:00
|
|
|
jsid* staticAttributeIds;
|
2013-04-03 04:20:38 +04:00
|
|
|
const JSPropertySpec* staticAttributeSpecs;
|
2014-07-04 17:02:10 +04:00
|
|
|
|
2013-04-03 04:20:38 +04:00
|
|
|
const Prefable<const JSFunctionSpec>* methods;
|
2012-10-09 22:50:27 +04:00
|
|
|
jsid* methodIds;
|
2014-07-23 23:36:21 +04:00
|
|
|
const JSFunctionSpec* methodSpecs;
|
2014-07-04 17:02:10 +04:00
|
|
|
|
2013-04-03 04:20:38 +04:00
|
|
|
const Prefable<const JSPropertySpec>* attributes;
|
2012-10-09 22:50:27 +04:00
|
|
|
jsid* attributeIds;
|
2013-04-03 04:20:38 +04:00
|
|
|
const JSPropertySpec* attributeSpecs;
|
2014-07-04 17:02:10 +04:00
|
|
|
|
|
|
|
const Prefable<const JSFunctionSpec>* unforgeableMethods;
|
|
|
|
jsid* unforgeableMethodIds;
|
|
|
|
const JSFunctionSpec* unforgeableMethodSpecs;
|
|
|
|
|
2013-04-03 04:20:38 +04:00
|
|
|
const Prefable<const JSPropertySpec>* unforgeableAttributes;
|
2012-10-09 22:50:27 +04:00
|
|
|
jsid* unforgeableAttributeIds;
|
2013-04-03 04:20:38 +04:00
|
|
|
const JSPropertySpec* unforgeableAttributeSpecs;
|
2014-07-04 17:02:10 +04:00
|
|
|
|
2013-04-03 04:20:38 +04:00
|
|
|
const Prefable<const ConstantSpec>* constants;
|
2012-10-09 22:50:27 +04:00
|
|
|
jsid* constantIds;
|
2013-04-03 04:20:38 +04:00
|
|
|
const ConstantSpec* constantSpecs;
|
2015-03-28 03:44:44 +03:00
|
|
|
|
|
|
|
// Index into methods for the entry that is [Alias="@@iterator"], -1 if none
|
|
|
|
int32_t iteratorAliasMethodIndex;
|
2012-10-09 22:50:27 +04:00
|
|
|
};
|
|
|
|
|
2012-10-09 22:50:27 +04:00
|
|
|
struct NativePropertiesHolder
|
|
|
|
{
|
|
|
|
const NativeProperties* regular;
|
|
|
|
const NativeProperties* chromeOnly;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper structure for Xrays for DOM binding objects. The same instance is used
|
|
|
|
// for instances, interface objects and interface prototype objects of a
|
|
|
|
// specific interface.
|
2012-03-31 08:42:20 +04:00
|
|
|
struct NativePropertyHooks
|
|
|
|
{
|
2012-10-09 22:50:27 +04:00
|
|
|
// The hook to call for resolving indexed or named properties. May be null if
|
|
|
|
// there can't be any.
|
|
|
|
ResolveOwnProperty mResolveOwnProperty;
|
|
|
|
// The hook to call for enumerating indexed or named properties. May be null
|
|
|
|
// if there can't be any.
|
|
|
|
EnumerateOwnProperties mEnumerateOwnProperties;
|
|
|
|
|
|
|
|
// The property arrays for this interface.
|
|
|
|
NativePropertiesHolder mNativeProperties;
|
|
|
|
|
|
|
|
// This will be set to the ID of the interface prototype object for the
|
|
|
|
// interface, if it has one. If it doesn't have one it will be set to
|
|
|
|
// prototypes::id::_ID_Count.
|
|
|
|
prototypes::ID mPrototypeID;
|
|
|
|
|
|
|
|
// This will be set to the ID of the interface object for the interface, if it
|
|
|
|
// has one. If it doesn't have one it will be set to
|
|
|
|
// constructors::id::_ID_Count.
|
|
|
|
constructors::ID mConstructorID;
|
|
|
|
|
2014-09-15 18:51:40 +04:00
|
|
|
// The NativePropertyHooks instance for the parent interface (for
|
|
|
|
// ShimInterfaceInfo).
|
2012-10-09 22:50:27 +04:00
|
|
|
const NativePropertyHooks* mProtoHooks;
|
|
|
|
};
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-10-09 22:50:27 +04:00
|
|
|
enum DOMObjectType {
|
|
|
|
eInstance,
|
2014-09-15 18:51:40 +04:00
|
|
|
eGlobalInstance,
|
2012-10-09 22:50:27 +04:00
|
|
|
eInterface,
|
2014-09-09 17:19:10 +04:00
|
|
|
eInterfacePrototype,
|
2014-09-15 18:51:40 +04:00
|
|
|
eGlobalInterfacePrototype,
|
2014-09-09 17:19:10 +04:00
|
|
|
eNamedPropertiesObject
|
2012-03-31 08:42:20 +04:00
|
|
|
};
|
|
|
|
|
2014-09-15 18:51:40 +04:00
|
|
|
inline
|
|
|
|
bool
|
|
|
|
IsInstance(DOMObjectType type)
|
|
|
|
{
|
|
|
|
return type == eInstance || type == eGlobalInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool
|
|
|
|
IsInterfacePrototype(DOMObjectType type)
|
|
|
|
{
|
|
|
|
return type == eInterfacePrototype || type == eGlobalInterfacePrototype;
|
|
|
|
}
|
|
|
|
|
2013-04-25 20:29:53 +04:00
|
|
|
typedef JSObject* (*ParentGetter)(JSContext* aCx, JS::Handle<JSObject*> aObj);
|
2014-09-09 17:19:10 +04:00
|
|
|
|
|
|
|
typedef JSObject* (*ProtoGetter)(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGlobal);
|
2013-05-02 07:44:11 +04:00
|
|
|
/**
|
|
|
|
* Returns a handle to the relevent WebIDL prototype object for the given global
|
|
|
|
* (which may be a handle to null on out of memory). Once allocated, the
|
|
|
|
* prototype object is guaranteed to exist as long as the global does, since the
|
|
|
|
* global traces its array of WebIDL prototypes and constructors.
|
|
|
|
*/
|
2014-09-09 17:19:10 +04:00
|
|
|
typedef JS::Handle<JSObject*> (*ProtoHandleGetter)(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGlobal);
|
2012-09-26 18:17:46 +04:00
|
|
|
|
2014-06-19 00:19:19 +04:00
|
|
|
// Special JSClass for reflected DOM objects.
|
|
|
|
struct DOMJSClass
|
2012-05-22 17:46:20 +04:00
|
|
|
{
|
2014-06-19 00:19:19 +04:00
|
|
|
// It would be nice to just inherit from JSClass, but that precludes pure
|
|
|
|
// compile-time initialization of the form |DOMJSClass = {...};|, since C++
|
|
|
|
// only allows brace initialization for aggregate/POD types.
|
|
|
|
const js::Class mBase;
|
|
|
|
|
2012-05-22 17:46:20 +04:00
|
|
|
// A list of interfaces that this object implements, in order of decreasing
|
|
|
|
// derivedness.
|
2012-12-13 20:01:00 +04:00
|
|
|
const prototypes::ID mInterfaceChain[MAX_PROTOTYPE_CHAIN_LENGTH];
|
2012-05-22 17:46:20 +04:00
|
|
|
|
|
|
|
// We store the DOM object in reserved slot with index DOM_OBJECT_SLOT or in
|
|
|
|
// the proxy private if we use a proxy object.
|
|
|
|
// Sometimes it's an nsISupports and sometimes it's not; this class tells
|
|
|
|
// us which it is.
|
|
|
|
const bool mDOMObjectIsISupports;
|
|
|
|
|
|
|
|
const NativePropertyHooks* mNativeHooks;
|
2012-09-26 22:12:15 +04:00
|
|
|
|
2012-09-26 18:17:46 +04:00
|
|
|
ParentGetter mGetParent;
|
2014-09-09 17:19:10 +04:00
|
|
|
ProtoHandleGetter mGetProto;
|
2012-09-26 18:17:46 +04:00
|
|
|
|
2015-09-14 17:08:02 +03:00
|
|
|
// This stores the CC participant for the native, null if this class does not
|
|
|
|
// implement cycle collection or if it inherits from nsISupports (we can get
|
|
|
|
// the CC participant by QI'ing in that case).
|
2012-09-26 22:12:15 +04:00
|
|
|
nsCycleCollectionParticipant* mParticipant;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
static const DOMJSClass* FromJSClass(const JSClass* base) {
|
|
|
|
MOZ_ASSERT(base->flags & JSCLASS_IS_DOMJSCLASS);
|
|
|
|
return reinterpret_cast<const DOMJSClass*>(base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const DOMJSClass* FromJSClass(const js::Class* base) {
|
|
|
|
return FromJSClass(Jsvalify(base));
|
|
|
|
}
|
|
|
|
|
2014-02-01 12:29:50 +04:00
|
|
|
const JSClass* ToJSClass() const { return Jsvalify(&mBase); }
|
2012-03-31 08:42:20 +04:00
|
|
|
};
|
|
|
|
|
2012-10-09 22:50:27 +04:00
|
|
|
// Special JSClass for DOM interface and interface prototype objects.
|
|
|
|
struct DOMIfaceAndProtoJSClass
|
|
|
|
{
|
2014-08-05 14:46:42 +04:00
|
|
|
// It would be nice to just inherit from js::Class, but that precludes pure
|
2012-10-09 22:50:27 +04:00
|
|
|
// compile-time initialization of the form
|
|
|
|
// |DOMJSInterfaceAndPrototypeClass = {...};|, since C++ only allows brace
|
|
|
|
// initialization for aggregate/POD types.
|
2014-08-05 14:46:42 +04:00
|
|
|
const js::Class mBase;
|
2012-10-09 22:50:27 +04:00
|
|
|
|
2014-09-15 18:51:40 +04:00
|
|
|
// Either eInterface, eInterfacePrototype, eGlobalInterfacePrototype or
|
|
|
|
// eNamedPropertiesObject.
|
2012-10-09 22:50:27 +04:00
|
|
|
DOMObjectType mType;
|
|
|
|
|
|
|
|
const NativePropertyHooks* mNativeHooks;
|
|
|
|
|
2013-02-01 18:33:58 +04:00
|
|
|
// The value to return for toString() on this interface or interface prototype
|
|
|
|
// object.
|
|
|
|
const char* mToString;
|
|
|
|
|
2013-01-08 22:05:36 +04:00
|
|
|
const prototypes::ID mPrototypeID;
|
|
|
|
const uint32_t mDepth;
|
|
|
|
|
2014-09-09 17:19:10 +04:00
|
|
|
ProtoGetter mGetParentProto;
|
|
|
|
|
2012-10-09 22:50:27 +04:00
|
|
|
static const DOMIfaceAndProtoJSClass* FromJSClass(const JSClass* base) {
|
|
|
|
MOZ_ASSERT(base->flags & JSCLASS_IS_DOMIFACEANDPROTOJSCLASS);
|
|
|
|
return reinterpret_cast<const DOMIfaceAndProtoJSClass*>(base);
|
|
|
|
}
|
|
|
|
static const DOMIfaceAndProtoJSClass* FromJSClass(const js::Class* base) {
|
|
|
|
return FromJSClass(Jsvalify(base));
|
|
|
|
}
|
|
|
|
|
2014-08-05 14:46:42 +04:00
|
|
|
const JSClass* ToJSClass() const { return Jsvalify(&mBase); }
|
2012-10-09 22:50:27 +04:00
|
|
|
};
|
|
|
|
|
2014-03-22 21:04:09 +04:00
|
|
|
class ProtoAndIfaceCache;
|
2013-11-19 23:28:09 +04:00
|
|
|
|
2012-06-19 04:04:38 +04:00
|
|
|
inline bool
|
2014-03-22 21:04:09 +04:00
|
|
|
HasProtoAndIfaceCache(JSObject* global)
|
2012-06-19 04:04:38 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL);
|
|
|
|
// This can be undefined if we GC while creating the global
|
|
|
|
return !js::GetReservedSlot(global, DOM_PROTOTYPE_SLOT).isUndefined();
|
|
|
|
}
|
|
|
|
|
2014-03-22 21:04:09 +04:00
|
|
|
inline ProtoAndIfaceCache*
|
|
|
|
GetProtoAndIfaceCache(JSObject* global)
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL);
|
2014-03-22 21:04:09 +04:00
|
|
|
return static_cast<ProtoAndIfaceCache*>(
|
2012-03-31 08:42:20 +04:00
|
|
|
js::GetReservedSlot(global, DOM_PROTOTYPE_SLOT).toPrivate());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-05-03 08:35:38 +04:00
|
|
|
#endif /* mozilla_dom_DOMJSClass_h */
|