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-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-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-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
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
typedef bool
|
|
|
|
(* ResolveProperty)(JSContext* cx, JSObject* wrapper, jsid id, bool set,
|
|
|
|
JSPropertyDescriptor* desc);
|
|
|
|
typedef bool
|
2012-06-06 12:52:26 -07:00
|
|
|
(* EnumerateProperties)(JSContext* cx, JSObject* wrapper,
|
|
|
|
JS::AutoIdVector& props);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
struct NativePropertyHooks
|
|
|
|
{
|
2012-06-06 12:52:26 -07:00
|
|
|
ResolveProperty mResolveOwnProperty;
|
2012-03-30 21:42:20 -07:00
|
|
|
ResolveProperty mResolveProperty;
|
2012-06-06 12:52:26 -07:00
|
|
|
EnumerateProperties mEnumerateOwnProperties;
|
2012-03-30 21:42:20 -07:00
|
|
|
EnumerateProperties mEnumerateProperties;
|
|
|
|
|
|
|
|
const NativePropertyHooks *mProtoHooks;
|
|
|
|
};
|
|
|
|
|
2012-05-22 06:46:20 -07: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-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-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 */
|