2012-03-31 08:42:20 +04: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-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 "jsapi.h"
|
|
|
|
#include "jsfriendapi.h"
|
|
|
|
|
2012-05-03 08:35:38 +04:00
|
|
|
#include "mozilla/dom/PrototypeList.h" // auto-generated
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-06-06 23:59:46 +04:00
|
|
|
// We use slot 0 for holding the raw object. This is safe for both
|
|
|
|
// globals and non-globals.
|
2012-03-31 08:42:20 +04:00
|
|
|
#define DOM_OBJECT_SLOT 0
|
|
|
|
|
2012-06-06 23:59:46 +04:00
|
|
|
// All DOM globals must have a slot at DOM_PROTOTYPE_SLOT. We have to
|
|
|
|
// start at 1 past JSCLASS_GLOBAL_SLOT_COUNT because XPConnect uses
|
|
|
|
// that one.
|
|
|
|
#define DOM_PROTOTYPE_SLOT (JSCLASS_GLOBAL_SLOT_COUNT + 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-03-31 08:42:20 +04:00
|
|
|
|
2012-08-08 09:26:18 +04: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
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
typedef bool
|
|
|
|
(* ResolveProperty)(JSContext* cx, JSObject* wrapper, jsid id, bool set,
|
|
|
|
JSPropertyDescriptor* desc);
|
|
|
|
typedef bool
|
|
|
|
(* EnumerateProperties)(JS::AutoIdVector& props);
|
|
|
|
|
|
|
|
struct NativePropertyHooks
|
|
|
|
{
|
|
|
|
ResolveProperty mResolveProperty;
|
|
|
|
EnumerateProperties mEnumerateProperties;
|
|
|
|
|
|
|
|
const NativePropertyHooks *mProtoHooks;
|
|
|
|
};
|
|
|
|
|
2012-05-22 17:46:20 +04:00
|
|
|
struct DOMClass
|
|
|
|
{
|
|
|
|
// A list of interfaces that this object implements, in order of decreasing
|
|
|
|
// derivedness.
|
|
|
|
const prototypes::ID mInterfaceChain[prototypes::id::_ID_Count];
|
|
|
|
|
|
|
|
// 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-03-31 08:42:20 +04: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 17:46:20 +04:00
|
|
|
DOMClass mClass;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
// We cache the VTable index of GetWrapperCache for objects that support it.
|
|
|
|
//
|
|
|
|
// -1 indicates that GetWrapperCache is not implemented on the underlying object.
|
|
|
|
// XXXkhuey this is unused and needs to die.
|
|
|
|
const int16_t mGetWrapperCacheVTableOffset;
|
|
|
|
|
|
|
|
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-06-19 04:04:38 +04:00
|
|
|
inline bool
|
|
|
|
HasProtoOrIfaceArray(JSObject* global)
|
|
|
|
{
|
|
|
|
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-31 08:42:20 +04:00
|
|
|
inline JSObject**
|
|
|
|
GetProtoOrIfaceArray(JSObject* global)
|
|
|
|
{
|
|
|
|
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-03 08:35:38 +04:00
|
|
|
#endif /* mozilla_dom_DOMJSClass_h */
|