2009-11-06 12:43:39 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sw=4 et tw=80:
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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/. */
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
#ifndef mozilla_jsipc_ObjectWrapperParent_h__
|
|
|
|
#define mozilla_jsipc_ObjectWrapperParent_h__
|
|
|
|
|
|
|
|
#include "mozilla/jsipc/PObjectWrapperParent.h"
|
|
|
|
#include "jsapi.h"
|
2011-09-20 11:40:24 -07:00
|
|
|
#include "jsclass.h"
|
2009-11-06 12:43:39 -08:00
|
|
|
#include "nsAutoJSValHolder.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace jsipc {
|
|
|
|
|
2010-01-20 18:24:14 -08:00
|
|
|
class ContextWrapperParent;
|
|
|
|
|
2010-01-22 12:52:57 -08:00
|
|
|
class OperationChecker {
|
|
|
|
public:
|
|
|
|
virtual void CheckOperation(JSContext* cx,
|
|
|
|
OperationStatus* status) = 0;
|
|
|
|
};
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
class ObjectWrapperParent
|
|
|
|
: public PObjectWrapperParent
|
2010-01-22 12:52:57 -08:00
|
|
|
, public OperationChecker
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
ObjectWrapperParent()
|
|
|
|
: mObj(NULL)
|
|
|
|
{}
|
|
|
|
|
|
|
|
JSObject* GetJSObject(JSContext* cx) const;
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
JSObject* GetJSObjectOrNull() const {
|
|
|
|
return mObj;
|
|
|
|
}
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
jsval GetJSVal(JSContext* cx) const {
|
|
|
|
return OBJECT_TO_JSVAL(GetJSObject(cx));
|
|
|
|
}
|
|
|
|
|
2010-01-22 12:52:57 -08:00
|
|
|
void CheckOperation(JSContext* cx,
|
|
|
|
OperationStatus* status);
|
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
static const js::Class sCPOW_JSClass;
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void ActorDestroy(ActorDestroyReason why);
|
|
|
|
|
2010-01-20 18:24:14 -08:00
|
|
|
ContextWrapperParent* Manager();
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
private:
|
|
|
|
|
|
|
|
mutable JSObject* mObj;
|
|
|
|
|
|
|
|
static JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
CPOW_AddProperty(JSContext *cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
static JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
CPOW_DelProperty(JSContext *cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
static JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
CPOW_GetProperty(JSContext *cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
static JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
CPOW_SetProperty(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool strict, JSMutableHandleValue vp);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
JSBool NewEnumerateInit(JSContext* cx, jsval* statep, jsid* idp);
|
|
|
|
JSBool NewEnumerateNext(JSContext* cx, jsval* statep, jsid* idp);
|
|
|
|
JSBool NewEnumerateDestroy(JSContext* cx, jsval state);
|
|
|
|
static JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
CPOW_NewEnumerate(JSContext *cx, JSHandleObject obj, JSIterateOp enum_op,
|
2009-11-06 12:43:39 -08:00
|
|
|
jsval *statep, jsid *idp);
|
|
|
|
|
|
|
|
static JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
CPOW_NewResolve(JSContext *cx, JSHandleObject obj, JSHandleId id, unsigned flags,
|
2012-07-04 11:12:16 -07:00
|
|
|
JSMutableHandleObject objp);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
static JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
CPOW_Convert(JSContext *cx, JSHandleObject obj, JSType type, JSMutableHandleValue vp);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
static void
|
2012-03-19 07:34:55 -07:00
|
|
|
CPOW_Finalize(js::FreeOp* fop, JSObject* obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
static JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
CPOW_Call(JSContext* cx, unsigned argc, jsval* vp);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
static JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
CPOW_Construct(JSContext *cx, unsigned argc, jsval *vp);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
static JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
CPOW_HasInstance(JSContext *cx, JSHandleObject obj, const jsval *v, JSBool *bp);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
static JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
CPOW_Equality(JSContext *cx, JSHandleObject obj, const jsval *v, JSBool *bp);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
static bool jsval_to_JSVariant(JSContext* cx, jsval from, JSVariant* to);
|
|
|
|
static bool jsval_from_JSVariant(JSContext* cx, const JSVariant& from,
|
|
|
|
jsval* to);
|
|
|
|
static bool
|
2012-02-05 12:07:23 -08:00
|
|
|
JSObject_to_PObjectWrapperParent(JSObject* from, PObjectWrapperParent** to);
|
2009-11-06 12:43:39 -08:00
|
|
|
static bool
|
|
|
|
JSObject_from_PObjectWrapperParent(JSContext* cx,
|
|
|
|
const PObjectWrapperParent* from,
|
2012-07-04 11:12:16 -07:00
|
|
|
JSMutableHandleObject to);
|
2009-11-06 12:43:39 -08:00
|
|
|
static bool
|
|
|
|
jsval_from_PObjectWrapperParent(JSContext* cx,
|
|
|
|
const PObjectWrapperParent* from,
|
|
|
|
jsval* to);
|
|
|
|
};
|
|
|
|
|
2010-01-22 12:52:57 -08:00
|
|
|
template <class StatusOwnerPolicy>
|
|
|
|
class AutoCheckOperationBase
|
|
|
|
: public StatusOwnerPolicy
|
|
|
|
{
|
|
|
|
JSContext* const mContext;
|
|
|
|
OperationChecker* const mChecker;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
AutoCheckOperationBase(JSContext* cx,
|
|
|
|
OperationChecker* checker)
|
|
|
|
: mContext(cx)
|
|
|
|
, mChecker(checker)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual ~AutoCheckOperationBase() {
|
|
|
|
mChecker->CheckOperation(mContext, StatusOwnerPolicy::StatusPtr());
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool Ok() {
|
|
|
|
return (StatusOwnerPolicy::StatusPtr()->type() == OperationStatus::TJSBool &&
|
|
|
|
StatusOwnerPolicy::StatusPtr()->get_JSBool());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
}}
|
2010-01-22 12:52:57 -08:00
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
#endif
|