2012-03-30 21:42:20 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
|
|
/* 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-02 21:35:38 -07:00
|
|
|
#ifndef mozilla_dom_DOMJSClass_h
|
|
|
|
#define mozilla_dom_DOMJSClass_h
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jsfriendapi.h"
|
2012-10-09 11:50:27 -07:00
|
|
|
#include "mozilla/Assertions.h"
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-05-02 21:35:38 -07:00
|
|
|
#include "mozilla/dom/PrototypeList.h" // auto-generated
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-09-26 11:12:15 -07:00
|
|
|
class nsCycleCollectionParticipant;
|
|
|
|
|
2012-06-06 12:59:46 -07:00
|
|
|
// We use slot 0 for holding the raw object. This is safe for both
|
|
|
|
// globals and non-globals.
|
2012-03-30 21:42:20 -07:00
|
|
|
#define DOM_OBJECT_SLOT 0
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
// We use slot 1 for holding the expando object. This is not safe for globals
|
|
|
|
// until bug 760095 is fixed, so that bug blocks converting Window to new
|
|
|
|
// bindings.
|
|
|
|
#define DOM_XRAY_EXPANDO_SLOT 1
|
|
|
|
|
2012-09-12 13:29:30 -07:00
|
|
|
// We use slot 2 for holding either a JS::ObjectValue which points to the cached
|
|
|
|
// SOW or JS::UndefinedValue if this class doesn't need SOWs. This is not safe
|
|
|
|
// for globals until bug 760095 is fixed, so that bug blocks converting Window
|
|
|
|
// to new bindings.
|
|
|
|
#define DOM_OBJECT_SLOT_SOW 2
|
|
|
|
|
2012-10-25 08:01:09 -07:00
|
|
|
// All DOM globals must have a slot at DOM_PROTOTYPE_SLOT.
|
|
|
|
#define DOM_PROTOTYPE_SLOT JSCLASS_GLOBAL_SLOT_COUNT
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
// We use these flag bits for the new bindings.
|
2012-07-11 20:55:19 -07:00
|
|
|
#define JSCLASS_DOM_GLOBAL JSCLASS_USERBIT1
|
2012-10-09 11:50:27 -07:00
|
|
|
#define JSCLASS_IS_DOMIFACEANDPROTOJSCLASS JSCLASS_USERBIT2
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-08-07 22:26:18 -07:00
|
|
|
// NOTE: This is baked into the Ion JIT as 0 in codegen for LGetDOMProperty and
|
|
|
|
// LSetDOMProperty. Those constants need to be changed accordingly if this value
|
|
|
|
// changes.
|
|
|
|
#define DOM_PROTO_INSTANCE_CLASS_SLOT 0
|
|
|
|
|
2013-01-22 02:51:15 -08:00
|
|
|
// Interface objects store a number of reserved slots equal to
|
|
|
|
// DOM_INTERFACE_BASE_SLOTS + number of named constructors.
|
|
|
|
#define DOM_INTERFACE_SLOTS_BASE (DOM_XRAY_EXPANDO_SLOT + 1)
|
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
MOZ_STATIC_ASSERT(DOM_PROTO_INSTANCE_CLASS_SLOT != DOM_XRAY_EXPANDO_SLOT,
|
|
|
|
"Interface prototype object use both of these, so they must "
|
|
|
|
"not be the same slot.");
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
typedef bool
|
2012-10-09 11:50:27 -07:00
|
|
|
(* ResolveOwnProperty)(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id,
|
2013-01-03 13:31:36 -08:00
|
|
|
JSPropertyDescriptor* desc, unsigned flags);
|
2012-10-09 11:50:27 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
typedef bool
|
2012-10-09 11:50:27 -07:00
|
|
|
(* EnumerateOwnProperties)(JSContext* cx, JSObject* wrapper, JSObject* obj,
|
|
|
|
JS::AutoIdVector& props);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
struct ConstantSpec
|
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
JS::Value value;
|
|
|
|
};
|
|
|
|
|
2013-02-19 08:54:40 -08:00
|
|
|
typedef bool (*PropertyEnabled)(JSContext* cx, JSObject* global);
|
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
template<typename T>
|
|
|
|
struct Prefable {
|
2013-04-02 17:20:38 -07:00
|
|
|
inline bool isEnabled(JSContext* cx, JSObject* obj) const {
|
2013-02-19 08:54:40 -08:00
|
|
|
return enabled &&
|
|
|
|
(!enabledFunc ||
|
|
|
|
enabledFunc(cx, js::GetGlobalForObjectCrossCompartment(obj)));
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
// A boolean indicating whether this set of specs is enabled
|
|
|
|
bool enabled;
|
2013-02-19 08:54:40 -08: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
|
|
|
|
// "enabled" is used as-is.
|
|
|
|
PropertyEnabled enabledFunc;
|
2012-10-09 11:50:27 -07: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-02 17:20:38 -07:00
|
|
|
const T* specs;
|
2012-10-09 11:50:27 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NativeProperties
|
|
|
|
{
|
2013-04-02 17:20:38 -07:00
|
|
|
const Prefable<const JSFunctionSpec>* staticMethods;
|
2012-10-09 11:50:27 -07:00
|
|
|
jsid* staticMethodIds;
|
2013-04-02 17:20:38 -07:00
|
|
|
const JSFunctionSpec* staticMethodsSpecs;
|
|
|
|
const Prefable<const JSPropertySpec>* staticAttributes;
|
2012-10-19 00:34:28 -07:00
|
|
|
jsid* staticAttributeIds;
|
2013-04-02 17:20:38 -07:00
|
|
|
const JSPropertySpec* staticAttributeSpecs;
|
|
|
|
const Prefable<const JSFunctionSpec>* methods;
|
2012-10-09 11:50:27 -07:00
|
|
|
jsid* methodIds;
|
2013-04-02 17:20:38 -07:00
|
|
|
const JSFunctionSpec* methodsSpecs;
|
|
|
|
const Prefable<const JSPropertySpec>* attributes;
|
2012-10-09 11:50:27 -07:00
|
|
|
jsid* attributeIds;
|
2013-04-02 17:20:38 -07:00
|
|
|
const JSPropertySpec* attributeSpecs;
|
|
|
|
const Prefable<const JSPropertySpec>* unforgeableAttributes;
|
2012-10-09 11:50:27 -07:00
|
|
|
jsid* unforgeableAttributeIds;
|
2013-04-02 17:20:38 -07:00
|
|
|
const JSPropertySpec* unforgeableAttributeSpecs;
|
|
|
|
const Prefable<const ConstantSpec>* constants;
|
2012-10-09 11:50:27 -07:00
|
|
|
jsid* constantIds;
|
2013-04-02 17:20:38 -07:00
|
|
|
const ConstantSpec* constantSpecs;
|
2012-10-09 11:50:27 -07:00
|
|
|
};
|
|
|
|
|
2012-10-09 11:50:27 -07: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-30 21:42:20 -07:00
|
|
|
struct NativePropertyHooks
|
|
|
|
{
|
2012-10-09 11:50:27 -07: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;
|
|
|
|
|
|
|
|
// The NativePropertyHooks instance for the parent interface.
|
|
|
|
const NativePropertyHooks* mProtoHooks;
|
|
|
|
};
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
enum DOMObjectType {
|
|
|
|
eInstance,
|
|
|
|
eInterface,
|
|
|
|
eInterfacePrototype
|
2012-03-30 21:42:20 -07:00
|
|
|
};
|
|
|
|
|
2012-09-26 07:17:46 -07:00
|
|
|
typedef JSObject* (*ParentGetter)(JSContext* aCx, JSObject* aObj);
|
|
|
|
typedef JSObject* (*ProtoGetter)(JSContext* aCx, JSObject* aGlobal);
|
|
|
|
|
2012-05-22 06:46:20 -07:00
|
|
|
struct DOMClass
|
|
|
|
{
|
|
|
|
// A list of interfaces that this object implements, in order of decreasing
|
|
|
|
// derivedness.
|
2012-12-13 08:01:00 -08:00
|
|
|
const prototypes::ID mInterfaceChain[MAX_PROTOTYPE_CHAIN_LENGTH];
|
2012-05-22 06:46:20 -07: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 11:12:15 -07:00
|
|
|
|
2012-09-26 07:17:46 -07:00
|
|
|
ParentGetter mGetParent;
|
|
|
|
ProtoGetter mGetProto;
|
|
|
|
|
2012-09-26 11:12:15 -07:00
|
|
|
// This stores the CC participant for the native, null if this class is for a
|
|
|
|
// worker or for a native inheriting from nsISupports (we can get the CC
|
|
|
|
// participant by QI'ing in that case).
|
|
|
|
nsCycleCollectionParticipant* mParticipant;
|
2012-05-22 06:46:20 -07:00
|
|
|
};
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
// Special JSClass for reflected DOM objects.
|
|
|
|
struct DOMJSClass
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
JSClass mBase;
|
|
|
|
|
2012-05-22 06:46:20 -07:00
|
|
|
DOMClass mClass;
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
static DOMJSClass* FromJSClass(JSClass* base) {
|
|
|
|
MOZ_ASSERT(base->flags & JSCLASS_IS_DOMJSCLASS);
|
|
|
|
return reinterpret_cast<DOMJSClass*>(base);
|
|
|
|
}
|
|
|
|
static const DOMJSClass* FromJSClass(const JSClass* base) {
|
|
|
|
MOZ_ASSERT(base->flags & JSCLASS_IS_DOMJSCLASS);
|
|
|
|
return reinterpret_cast<const DOMJSClass*>(base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DOMJSClass* FromJSClass(js::Class* base) {
|
|
|
|
return FromJSClass(Jsvalify(base));
|
|
|
|
}
|
|
|
|
static const DOMJSClass* FromJSClass(const js::Class* base) {
|
|
|
|
return FromJSClass(Jsvalify(base));
|
|
|
|
}
|
|
|
|
|
|
|
|
JSClass* ToJSClass() { return &mBase; }
|
|
|
|
};
|
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
// Special JSClass for DOM interface and interface prototype objects.
|
|
|
|
struct DOMIfaceAndProtoJSClass
|
|
|
|
{
|
|
|
|
// It would be nice to just inherit from JSClass, but that precludes pure
|
|
|
|
// compile-time initialization of the form
|
|
|
|
// |DOMJSInterfaceAndPrototypeClass = {...};|, since C++ only allows brace
|
|
|
|
// initialization for aggregate/POD types.
|
|
|
|
JSClass mBase;
|
|
|
|
|
|
|
|
// Either eInterface or eInterfacePrototype
|
|
|
|
DOMObjectType mType;
|
|
|
|
|
|
|
|
const NativePropertyHooks* mNativeHooks;
|
|
|
|
|
2013-02-01 06:33:58 -08:00
|
|
|
// The value to return for toString() on this interface or interface prototype
|
|
|
|
// object.
|
|
|
|
const char* mToString;
|
|
|
|
|
2013-01-08 10:05:36 -08:00
|
|
|
const prototypes::ID mPrototypeID;
|
|
|
|
const uint32_t mDepth;
|
|
|
|
|
2012-10-09 11:50:27 -07: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));
|
|
|
|
}
|
|
|
|
|
|
|
|
JSClass* ToJSClass() { return &mBase; }
|
|
|
|
};
|
|
|
|
|
2012-06-18 17:04:38 -07:00
|
|
|
inline bool
|
2012-10-09 11:50:27 -07:00
|
|
|
HasProtoAndIfaceArray(JSObject* global)
|
2012-06-18 17:04:38 -07: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();
|
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
inline JSObject**
|
2012-10-09 11:50:27 -07:00
|
|
|
GetProtoAndIfaceArray(JSObject* global)
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL);
|
|
|
|
return static_cast<JSObject**>(
|
|
|
|
js::GetReservedSlot(global, DOM_PROTOTYPE_SLOT).toPrivate());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-05-02 21:35:38 -07:00
|
|
|
#endif /* mozilla_dom_DOMJSClass_h */
|