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
|
|
|
|
|
|
|
#include "mozilla/jsipc/ObjectWrapperParent.h"
|
|
|
|
#include "mozilla/jsipc/ContextWrapperParent.h"
|
|
|
|
#include "mozilla/jsipc/CPOWTypes.h"
|
2010-07-19 11:33:33 -07:00
|
|
|
#include "mozilla/unused.h"
|
2010-12-03 00:24:17 -08:00
|
|
|
#include "nsJSUtils.h"
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
#include "jsutil.h"
|
2011-10-04 07:06:54 -07:00
|
|
|
#include "jsfriendapi.h"
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
using namespace mozilla::jsipc;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Only need one reserved slot because the ObjectWrapperParent* is
|
|
|
|
// stored in the private slot.
|
2012-02-28 15:11:11 -08:00
|
|
|
static const unsigned sFlagsSlot = 0;
|
|
|
|
static const unsigned sNumSlots = 1;
|
|
|
|
static const unsigned CPOW_FLAG_RESOLVING = 1 << 0;
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
class AutoResolveFlag
|
|
|
|
{
|
|
|
|
JSObject* mObj;
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned mOldFlags;
|
2010-11-23 23:33:03 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2009-11-06 12:43:39 -08:00
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
static unsigned GetFlags(JSObject* obj) {
|
2012-02-05 12:07:23 -08:00
|
|
|
jsval v = JS_GetReservedSlot(obj, sFlagsSlot);
|
2009-11-06 12:43:39 -08:00
|
|
|
return JSVAL_TO_INT(v);
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
static unsigned SetFlags(JSObject* obj, unsigned flags) {
|
|
|
|
unsigned oldFlags = GetFlags(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (oldFlags != flags)
|
2012-02-05 12:07:23 -08:00
|
|
|
JS_SetReservedSlot(obj, sFlagsSlot, INT_TO_JSVAL(flags));
|
2009-11-06 12:43:39 -08:00
|
|
|
return oldFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
AutoResolveFlag(JSObject* obj
|
2009-11-06 12:43:39 -08:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-02-05 12:07:23 -08:00
|
|
|
: mObj(obj)
|
|
|
|
, mOldFlags(SetFlags(obj, GetFlags(obj) | CPOW_FLAG_RESOLVING))
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoResolveFlag() {
|
2012-02-05 12:07:23 -08:00
|
|
|
SetFlags(mObj, mOldFlags);
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
static JSBool IsSet(JSObject* obj) {
|
|
|
|
return GetFlags(obj) & CPOW_FLAG_RESOLVING;
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-01-22 12:52:57 -08:00
|
|
|
class StatusMemberOwner
|
|
|
|
{
|
|
|
|
OperationStatus mStatus;
|
|
|
|
public:
|
|
|
|
StatusMemberOwner() : mStatus(JS_FALSE) {}
|
|
|
|
OperationStatus* StatusPtr() {
|
|
|
|
return &mStatus;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef AutoCheckOperationBase<StatusMemberOwner> ACOBase;
|
|
|
|
|
|
|
|
class AutoCheckOperation : public ACOBase
|
|
|
|
{
|
2010-11-23 23:33:03 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2010-01-22 12:52:57 -08:00
|
|
|
public:
|
|
|
|
AutoCheckOperation(JSContext* cx,
|
|
|
|
ObjectWrapperParent* owp
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: ACOBase(cx, owp)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ObjectWrapperParent::CheckOperation(JSContext* cx,
|
|
|
|
OperationStatus* status)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(status->type() != OperationStatus::T__None,
|
|
|
|
"Checking an uninitialized operation.");
|
|
|
|
|
|
|
|
switch (status->type()) {
|
|
|
|
case OperationStatus::TJSVariant:
|
|
|
|
{
|
|
|
|
jsval thrown;
|
|
|
|
if (jsval_from_JSVariant(cx, status->get_JSVariant(), &thrown))
|
|
|
|
JS_SetPendingException(cx, thrown);
|
|
|
|
*status = JS_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OperationStatus::TJSBool:
|
|
|
|
if (!status->get_JSBool() && !JS_IsExceptionPending(cx)) {
|
|
|
|
NS_WARNING("CPOW operation failed without setting an exception.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Invalid or uninitialized OperationStatus type.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename RType>
|
|
|
|
static RType
|
|
|
|
with_error(JSContext* cx,
|
|
|
|
RType rval,
|
|
|
|
const char* error = NULL)
|
|
|
|
{
|
|
|
|
if (!JS_IsExceptionPending(cx))
|
|
|
|
JS_ReportError(cx, error ? error : "Unspecified CPOW error");
|
|
|
|
return rval;
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
const js::Class ObjectWrapperParent::sCPOW_JSClass = {
|
|
|
|
"CrossProcessObjectWrapper",
|
|
|
|
JSCLASS_NEW_RESOLVE | JSCLASS_NEW_ENUMERATE |
|
2009-11-06 12:43:39 -08:00
|
|
|
JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(sNumSlots),
|
2011-09-20 11:40:24 -07:00
|
|
|
ObjectWrapperParent::CPOW_AddProperty,
|
|
|
|
ObjectWrapperParent::CPOW_DelProperty,
|
|
|
|
ObjectWrapperParent::CPOW_GetProperty,
|
|
|
|
ObjectWrapperParent::CPOW_SetProperty,
|
2009-11-06 12:43:39 -08:00
|
|
|
(JSEnumerateOp) ObjectWrapperParent::CPOW_NewEnumerate,
|
2010-06-12 09:29:04 -07:00
|
|
|
(JSResolveOp) ObjectWrapperParent::CPOW_NewResolve,
|
2011-09-20 11:40:24 -07:00
|
|
|
ObjectWrapperParent::CPOW_Convert,
|
2009-11-06 12:43:39 -08:00
|
|
|
ObjectWrapperParent::CPOW_Finalize,
|
|
|
|
nsnull, // checkAccess
|
2011-09-20 11:40:24 -07:00
|
|
|
ObjectWrapperParent::CPOW_Call,
|
|
|
|
ObjectWrapperParent::CPOW_HasInstance,
|
2012-05-07 12:44:08 -07:00
|
|
|
ObjectWrapperParent::CPOW_Construct,
|
2012-02-13 00:02:21 -08:00
|
|
|
nsnull, // trace
|
2010-06-12 09:29:04 -07:00
|
|
|
{
|
2011-09-20 11:40:24 -07:00
|
|
|
ObjectWrapperParent::CPOW_Equality,
|
2010-06-12 09:29:04 -07:00
|
|
|
nsnull, // outerObject
|
|
|
|
nsnull, // innerObject
|
|
|
|
nsnull, // iteratorObject
|
|
|
|
nsnull, // wrappedObject
|
|
|
|
}
|
2009-11-06 12:43:39 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ObjectWrapperParent::ActorDestroy(ActorDestroyReason)
|
|
|
|
{
|
2010-03-30 21:40:58 -07:00
|
|
|
if (mObj) {
|
2012-02-05 12:07:23 -08:00
|
|
|
JS_SetPrivate(mObj, NULL);
|
2010-03-30 21:40:58 -07:00
|
|
|
mObj = NULL;
|
|
|
|
}
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
2010-01-20 18:24:14 -08:00
|
|
|
|
|
|
|
ContextWrapperParent*
|
|
|
|
ObjectWrapperParent::Manager()
|
|
|
|
{
|
|
|
|
PContextWrapperParent* pcwp = PObjectWrapperParent::Manager();
|
|
|
|
return static_cast<ContextWrapperParent*>(pcwp);
|
|
|
|
}
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
JSObject*
|
|
|
|
ObjectWrapperParent::GetJSObject(JSContext* cx) const
|
|
|
|
{
|
2012-02-05 12:07:23 -08:00
|
|
|
if (!mObj) {
|
|
|
|
js::Class *clasp = const_cast<js::Class *>(&ObjectWrapperParent::sCPOW_JSClass);
|
|
|
|
mObj = JS_NewObject(cx, js::Jsvalify(clasp), NULL, NULL);
|
|
|
|
if (mObj) {
|
|
|
|
JS_SetPrivate(mObj, (void*)this);
|
|
|
|
JS_SetReservedSlot(mObj, sFlagsSlot, JSVAL_ZERO);
|
|
|
|
}
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
|
|
|
return mObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ObjectWrapperParent*
|
2012-02-05 12:07:23 -08:00
|
|
|
Unwrap(JSObject* obj)
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
2011-10-04 07:06:54 -07:00
|
|
|
while (js::GetObjectClass(obj) != &ObjectWrapperParent::sCPOW_JSClass)
|
|
|
|
if (!(obj = js::GetObjectProto(obj)))
|
2009-11-06 12:43:39 -08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ObjectWrapperParent* self =
|
2012-02-05 12:07:23 -08:00
|
|
|
static_cast<ObjectWrapperParent*>(JS_GetPrivate(obj));
|
2009-11-06 12:43:39 -08:00
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
NS_ASSERTION(!self || self->GetJSObjectOrNull() == obj,
|
2009-11-06 12:43:39 -08:00
|
|
|
"Wrapper and wrapped object disagree?");
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
ObjectWrapperParent::jsval_to_JSVariant(JSContext* cx, jsval from,
|
|
|
|
JSVariant* to)
|
|
|
|
{
|
|
|
|
switch (JS_TypeOfValue(cx, from)) {
|
|
|
|
case JSTYPE_VOID:
|
|
|
|
*to = void_t();
|
|
|
|
return true;
|
|
|
|
case JSTYPE_NULL:
|
|
|
|
if (from != JSVAL_NULL)
|
|
|
|
return false;
|
|
|
|
// fall through
|
|
|
|
case JSTYPE_FUNCTION:
|
|
|
|
// CPOWs can fool JS_TypeOfValue into returning JSTYPE_FUNCTION
|
|
|
|
// because they have a call hook, but CPOWs are really objects, so
|
|
|
|
// fall through to the JSTYPE_OBJECT case:
|
|
|
|
case JSTYPE_OBJECT:
|
|
|
|
{
|
|
|
|
PObjectWrapperParent* powp;
|
2012-02-05 12:07:23 -08:00
|
|
|
if (!JSObject_to_PObjectWrapperParent(JSVAL_TO_OBJECT(from), &powp))
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, false, "Cannot pass parent-created object to child");
|
2009-11-06 12:43:39 -08:00
|
|
|
*to = powp;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case JSTYPE_STRING:
|
2010-12-03 00:24:17 -08:00
|
|
|
{
|
|
|
|
nsDependentJSString depStr;
|
|
|
|
if (!depStr.init(cx, from))
|
|
|
|
return false;
|
|
|
|
*to = depStr;
|
|
|
|
}
|
2009-11-06 12:43:39 -08:00
|
|
|
return true;
|
|
|
|
case JSTYPE_NUMBER:
|
|
|
|
if (JSVAL_IS_INT(from))
|
|
|
|
*to = JSVAL_TO_INT(from);
|
|
|
|
else if (JSVAL_IS_DOUBLE(from))
|
2010-07-14 23:19:36 -07:00
|
|
|
*to = JSVAL_TO_DOUBLE(from);
|
2009-11-06 12:43:39 -08:00
|
|
|
else return false;
|
|
|
|
return true;
|
|
|
|
case JSTYPE_BOOLEAN:
|
|
|
|
*to = !!JSVAL_TO_BOOLEAN(from);
|
|
|
|
return true;
|
|
|
|
case JSTYPE_XML:
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, false, "CPOWs currently cannot handle JSTYPE_XML");
|
2009-11-06 12:43:39 -08:00
|
|
|
default:
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, false, "Bad jsval type");
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
ObjectWrapperParent::jsval_from_JSVariant(JSContext* cx, const JSVariant& from,
|
|
|
|
jsval* to)
|
|
|
|
{
|
|
|
|
switch (from.type()) {
|
|
|
|
case JSVariant::Tvoid_t:
|
|
|
|
*to = JSVAL_VOID;
|
|
|
|
return true;
|
|
|
|
case JSVariant::TPObjectWrapperParent:
|
|
|
|
return jsval_from_PObjectWrapperParent(cx, from.get_PObjectWrapperParent(), to);
|
|
|
|
case JSVariant::TnsString:
|
|
|
|
{
|
|
|
|
JSString* str = JS_NewUCStringCopyZ(cx, from.get_nsString().BeginReading());
|
|
|
|
if (!str)
|
|
|
|
return false;
|
|
|
|
*to = STRING_TO_JSVAL(str);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case JSVariant::Tint:
|
|
|
|
*to = INT_TO_JSVAL(from.get_int());
|
|
|
|
return true;
|
|
|
|
case JSVariant::Tdouble:
|
2010-07-14 23:19:36 -07:00
|
|
|
return !!JS_NewNumberValue(cx, from.get_double(), to);
|
2009-11-06 12:43:39 -08:00
|
|
|
case JSVariant::Tbool:
|
|
|
|
*to = BOOLEAN_TO_JSVAL(from.get_bool());
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
ObjectWrapperParent::
|
2012-02-05 12:07:23 -08:00
|
|
|
JSObject_to_PObjectWrapperParent(JSObject* from, PObjectWrapperParent** to)
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
|
|
|
if (!from) {
|
|
|
|
*to = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* owp = Unwrap(from);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!owp)
|
|
|
|
return false;
|
|
|
|
*to = owp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
ObjectWrapperParent::
|
|
|
|
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
|
|
|
{
|
|
|
|
const ObjectWrapperParent* owp =
|
|
|
|
static_cast<const ObjectWrapperParent*>(from);
|
2012-07-04 11:12:16 -07:00
|
|
|
to.set(owp
|
|
|
|
? owp->GetJSObject(cx)
|
|
|
|
: JSVAL_TO_OBJECT(JSVAL_NULL));
|
2009-11-06 12:43:39 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
ObjectWrapperParent::
|
|
|
|
jsval_from_PObjectWrapperParent(JSContext* cx,
|
|
|
|
const PObjectWrapperParent* from,
|
|
|
|
jsval* to)
|
|
|
|
{
|
2012-07-04 11:12:16 -07:00
|
|
|
JS::RootedObject obj(cx);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!JSObject_from_PObjectWrapperParent(cx, from, &obj))
|
|
|
|
return false;
|
|
|
|
*to = OBJECT_TO_JSVAL(obj);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
jsid_from_int(JSContext* cx, int from, jsid* to)
|
|
|
|
{
|
|
|
|
jsval v = INT_TO_JSVAL(from);
|
|
|
|
return JS_ValueToId(cx, v, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
jsid_from_nsString(JSContext* cx, const nsString& from, jsid* to)
|
|
|
|
{
|
|
|
|
JSString* str = JS_NewUCStringCopyZ(cx, from.BeginReading());
|
|
|
|
if (!str)
|
|
|
|
return false;
|
|
|
|
return JS_ValueToId(cx, STRING_TO_JSVAL(str), to);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2010-07-14 23:19:36 -07:00
|
|
|
jsval_to_nsString(JSContext* cx, jsid from, nsString* to)
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
|
|
|
JSString* str;
|
2010-12-03 00:24:17 -08:00
|
|
|
const jschar* chars;
|
2010-07-14 23:19:36 -07:00
|
|
|
jsval idval;
|
|
|
|
if (JS_IdToValue(cx, from, &idval) &&
|
2010-12-03 00:24:17 -08:00
|
|
|
(str = JS_ValueToString(cx, idval)) &&
|
|
|
|
(chars = JS_GetStringCharsZ(cx, str))) {
|
|
|
|
*to = chars;
|
2009-11-06 12:43:39 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
ObjectWrapperParent::CPOW_AddProperty(JSContext *cx, JSHandleObject obj, JSHandleId id,
|
2009-11-06 12:43:39 -08:00
|
|
|
jsval *vp)
|
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_AddProperty (%s)...",
|
|
|
|
JSVAL_TO_CSTR(cx, id)));
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* self = Unwrap(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!self)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_AddProperty");
|
2009-11-06 12:43:39 -08:00
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
if (AutoResolveFlag::IsSet(obj))
|
2009-11-06 12:43:39 -08:00
|
|
|
return JS_TRUE;
|
2010-01-22 12:52:57 -08:00
|
|
|
|
|
|
|
AutoCheckOperation aco(cx, self);
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
nsString in_id;
|
|
|
|
|
|
|
|
if (!jsval_to_nsString(cx, id, &in_id))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
2010-01-20 18:24:14 -08:00
|
|
|
return (self->Manager()->RequestRunToCompletion() &&
|
|
|
|
self->CallAddProperty(in_id,
|
2010-01-22 12:52:57 -08:00
|
|
|
aco.StatusPtr()) &&
|
|
|
|
aco.Ok());
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
ObjectWrapperParent::CPOW_GetProperty(JSContext *cx, JSHandleObject obj, JSHandleId id,
|
2009-11-06 12:43:39 -08:00
|
|
|
jsval *vp)
|
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_GetProperty (%s)...",
|
|
|
|
JSVAL_TO_CSTR(cx, id)));
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* self = Unwrap(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!self)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_GetProperty");
|
|
|
|
|
|
|
|
AutoCheckOperation aco(cx, self);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
nsString in_id;
|
|
|
|
|
|
|
|
if (!jsval_to_nsString(cx, id, &in_id))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
JSVariant out_v;
|
|
|
|
|
2010-01-20 18:24:14 -08:00
|
|
|
return (self->Manager()->RequestRunToCompletion() &&
|
|
|
|
self->CallGetProperty(in_id,
|
2010-01-22 12:52:57 -08:00
|
|
|
aco.StatusPtr(), &out_v) &&
|
|
|
|
aco.Ok() &&
|
2009-11-06 12:43:39 -08:00
|
|
|
self->jsval_from_JSVariant(cx, out_v, vp));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
ObjectWrapperParent::CPOW_SetProperty(JSContext *cx, JSHandleObject obj, JSHandleId id,
|
2011-02-09 11:31:40 -08:00
|
|
|
JSBool strict, jsval *vp)
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_SetProperty (%s)...",
|
|
|
|
JSVAL_TO_CSTR(cx, id)));
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* self = Unwrap(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!self)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_SetProperty");
|
|
|
|
|
|
|
|
AutoCheckOperation aco(cx, self);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
nsString in_id;
|
|
|
|
JSVariant in_v;
|
|
|
|
|
|
|
|
if (!jsval_to_nsString(cx, id, &in_id) ||
|
|
|
|
!self->jsval_to_JSVariant(cx, *vp, &in_v))
|
|
|
|
return JS_FALSE;
|
2010-01-22 12:52:57 -08:00
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
JSVariant out_v;
|
|
|
|
|
2010-01-20 18:24:14 -08:00
|
|
|
return (self->Manager()->RequestRunToCompletion() &&
|
|
|
|
self->CallSetProperty(in_id, in_v,
|
2010-01-22 12:52:57 -08:00
|
|
|
aco.StatusPtr(), &out_v) &&
|
|
|
|
aco.Ok() &&
|
2009-11-06 12:43:39 -08:00
|
|
|
self->jsval_from_JSVariant(cx, out_v, vp));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
ObjectWrapperParent::CPOW_DelProperty(JSContext *cx, JSHandleObject obj, JSHandleId id,
|
2009-11-06 12:43:39 -08:00
|
|
|
jsval *vp)
|
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_DelProperty (%s)...",
|
|
|
|
JSVAL_TO_CSTR(cx, id)));
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* self = Unwrap(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!self)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_DelProperty");
|
|
|
|
|
|
|
|
AutoCheckOperation aco(cx, self);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
nsString in_id;
|
|
|
|
|
|
|
|
if (!jsval_to_nsString(cx, id, &in_id))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
JSVariant out_v;
|
|
|
|
|
2010-01-20 18:24:14 -08:00
|
|
|
return (self->Manager()->RequestRunToCompletion() &&
|
|
|
|
self->CallDelProperty(in_id,
|
2010-01-22 12:52:57 -08:00
|
|
|
aco.StatusPtr(), &out_v) &&
|
|
|
|
aco.Ok() &&
|
2009-11-06 12:43:39 -08:00
|
|
|
jsval_from_JSVariant(cx, out_v, vp));
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
ObjectWrapperParent::NewEnumerateInit(JSContext* cx, jsval* statep, jsid* idp)
|
|
|
|
{
|
2010-01-22 12:52:57 -08:00
|
|
|
AutoCheckOperation aco(cx, this);
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
JSVariant out_state;
|
|
|
|
int out_id;
|
|
|
|
|
2010-01-22 12:52:57 -08:00
|
|
|
return (CallNewEnumerateInit(aco.StatusPtr(), &out_state, &out_id) &&
|
|
|
|
aco.Ok() &&
|
2009-11-06 12:43:39 -08:00
|
|
|
jsval_from_JSVariant(cx, out_state, statep) &&
|
|
|
|
(!idp || jsid_from_int(cx, out_id, idp)));
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
ObjectWrapperParent::NewEnumerateNext(JSContext* cx, jsval* statep, jsid* idp)
|
|
|
|
{
|
2010-01-22 12:52:57 -08:00
|
|
|
AutoCheckOperation aco(cx, this);
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
JSVariant in_state;
|
2010-01-22 12:52:57 -08:00
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!jsval_to_JSVariant(cx, *statep, &in_state))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
JSVariant out_state;
|
|
|
|
nsString out_id;
|
|
|
|
|
|
|
|
if (CallNewEnumerateNext(in_state,
|
2010-01-22 12:52:57 -08:00
|
|
|
aco.StatusPtr(), &out_state, &out_id) &&
|
|
|
|
aco.Ok() &&
|
2009-11-06 12:43:39 -08:00
|
|
|
jsval_from_JSVariant(cx, out_state, statep) &&
|
|
|
|
jsid_from_nsString(cx, out_id, idp))
|
|
|
|
{
|
|
|
|
JSObject* obj = GetJSObject(cx);
|
2012-02-05 12:07:23 -08:00
|
|
|
AutoResolveFlag arf(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
return JS_DefinePropertyById(cx, obj, *idp, JSVAL_VOID, NULL, NULL,
|
|
|
|
JSPROP_ENUMERATE);
|
|
|
|
}
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
ObjectWrapperParent::NewEnumerateDestroy(JSContext* cx, jsval state)
|
|
|
|
{
|
2010-01-22 12:52:57 -08:00
|
|
|
AutoCheckOperation aco(cx, this);
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
JSVariant in_state;
|
2010-01-22 12:52:57 -08:00
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!jsval_to_JSVariant(cx, state, &in_state))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
return SendNewEnumerateDestroy(in_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
ObjectWrapperParent::CPOW_NewEnumerate(JSContext *cx, JSHandleObject obj,
|
2009-11-06 12:43:39 -08:00
|
|
|
JSIterateOp enum_op, jsval *statep,
|
|
|
|
jsid *idp)
|
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_NewEnumerate..."));
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* self = Unwrap(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!self)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_NewEnumerate");
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
switch (enum_op) {
|
|
|
|
case JSENUMERATE_INIT:
|
2010-07-07 15:11:17 -07:00
|
|
|
case JSENUMERATE_INIT_ALL:
|
2010-01-20 18:24:14 -08:00
|
|
|
self->Manager()->RequestRunToCompletion();
|
2009-11-06 12:43:39 -08:00
|
|
|
return self->NewEnumerateInit(cx, statep, idp);
|
|
|
|
case JSENUMERATE_NEXT:
|
|
|
|
return self->NewEnumerateNext(cx, statep, idp);
|
|
|
|
case JSENUMERATE_DESTROY:
|
|
|
|
return self->NewEnumerateDestroy(cx, *statep);
|
|
|
|
}
|
|
|
|
|
2010-01-22 12:52:57 -08:00
|
|
|
NS_NOTREACHED("Unknown enum_op value in CPOW_NewEnumerate");
|
2009-11-06 12:43:39 -08:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
ObjectWrapperParent::CPOW_NewResolve(JSContext *cx, JSHandleObject obj, JSHandleId id,
|
2012-07-04 11:12:16 -07:00
|
|
|
unsigned flags, JSMutableHandleObject objp)
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_NewResolve (%s)...",
|
|
|
|
JSVAL_TO_CSTR(cx, id)));
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* self = Unwrap(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!self)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_NewResolve");
|
|
|
|
|
|
|
|
AutoCheckOperation aco(cx, self);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
nsString in_id;
|
|
|
|
|
|
|
|
if (!jsval_to_nsString(cx, id, &in_id))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
PObjectWrapperParent* out_pobj;
|
|
|
|
|
2010-01-20 18:24:14 -08:00
|
|
|
if (!self->Manager()->RequestRunToCompletion() ||
|
|
|
|
!self->CallNewResolve(in_id, flags,
|
2010-01-22 12:52:57 -08:00
|
|
|
aco.StatusPtr(), &out_pobj) ||
|
|
|
|
!aco.Ok() ||
|
2009-11-06 12:43:39 -08:00
|
|
|
!JSObject_from_PObjectWrapperParent(cx, out_pobj, objp))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
2012-07-04 11:12:16 -07:00
|
|
|
if (objp) {
|
|
|
|
AutoResolveFlag arf(objp);
|
|
|
|
JS::RootedObject obj2(cx, objp);
|
|
|
|
JS_DefinePropertyById(cx, obj2, id, JSVAL_VOID, NULL, NULL,
|
2009-11-06 12:43:39 -08:00
|
|
|
JSPROP_ENUMERATE);
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
ObjectWrapperParent::CPOW_Convert(JSContext *cx, JSHandleObject obj, JSType type,
|
2009-11-06 12:43:39 -08:00
|
|
|
jsval *vp)
|
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_Convert (to %s)...",
|
|
|
|
JS_GetTypeName(cx, type)));
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* self = Unwrap(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!self)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_Convert");
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
*vp = OBJECT_TO_JSVAL(obj);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
2012-03-19 07:34:55 -07:00
|
|
|
ObjectWrapperParent::CPOW_Finalize(js::FreeOp* fop, JSObject* obj)
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_Finalize..."));
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* self = Unwrap(obj);
|
2010-03-30 21:40:58 -07:00
|
|
|
if (self) {
|
|
|
|
self->mObj = NULL;
|
2010-07-19 11:33:33 -07:00
|
|
|
unused << ObjectWrapperParent::Send__delete__(self);
|
2010-03-30 21:40:58 -07:00
|
|
|
}
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
ObjectWrapperParent::CPOW_Call(JSContext* cx, unsigned argc, jsval* vp)
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_Call..."));
|
|
|
|
|
2010-08-16 12:35:04 -07:00
|
|
|
JSObject* thisobj = JS_THIS_OBJECT(cx, vp);
|
|
|
|
if (!thisobj)
|
|
|
|
return JS_FALSE;
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
ObjectWrapperParent* function =
|
2012-02-05 12:07:23 -08:00
|
|
|
Unwrap(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!function)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Could not unwrap CPOW function");
|
|
|
|
|
|
|
|
AutoCheckOperation aco(cx, function);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* receiver = Unwrap(thisobj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!receiver) {
|
|
|
|
// Substitute child global for parent global object.
|
|
|
|
// TODO First make sure we're really replacing the global object?
|
|
|
|
ContextWrapperParent* manager =
|
|
|
|
static_cast<ContextWrapperParent*>(function->Manager());
|
|
|
|
receiver = manager->GetGlobalObjectWrapper();
|
|
|
|
}
|
|
|
|
|
2010-11-08 18:49:00 -08:00
|
|
|
InfallibleTArray<JSVariant> in_argv(argc);
|
2010-08-16 12:35:04 -07:00
|
|
|
jsval* argv = JS_ARGV(cx, vp);
|
2012-02-28 15:11:11 -08:00
|
|
|
for (unsigned i = 0; i < argc; i++)
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!jsval_to_JSVariant(cx, argv[i], in_argv.AppendElement()))
|
|
|
|
return JS_FALSE;
|
2010-01-22 12:52:57 -08:00
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
JSVariant out_rval;
|
|
|
|
|
2010-01-20 18:24:14 -08:00
|
|
|
return (function->Manager()->RequestRunToCompletion() &&
|
|
|
|
function->CallCall(receiver, in_argv,
|
2010-01-22 12:52:57 -08:00
|
|
|
aco.StatusPtr(), &out_rval) &&
|
|
|
|
aco.Ok() &&
|
2010-08-16 12:35:04 -07:00
|
|
|
jsval_from_JSVariant(cx, out_rval, vp));
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
ObjectWrapperParent::CPOW_Construct(JSContext* cx, unsigned argc, jsval* vp)
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_Construct..."));
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* constructor = Unwrap(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!constructor)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Could not unwrap CPOW constructor function");
|
|
|
|
|
|
|
|
AutoCheckOperation aco(cx, constructor);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
2010-11-08 18:49:00 -08:00
|
|
|
InfallibleTArray<JSVariant> in_argv(argc);
|
2010-08-16 12:35:04 -07:00
|
|
|
jsval* argv = JS_ARGV(cx, vp);
|
2012-02-28 15:11:11 -08:00
|
|
|
for (unsigned i = 0; i < argc; i++)
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!jsval_to_JSVariant(cx, argv[i], in_argv.AppendElement()))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
PObjectWrapperParent* out_powp;
|
|
|
|
|
2010-01-20 18:24:14 -08:00
|
|
|
return (constructor->Manager()->RequestRunToCompletion() &&
|
2010-08-16 12:35:04 -07:00
|
|
|
constructor->CallConstruct(in_argv, aco.StatusPtr(), &out_powp) &&
|
2010-01-22 12:52:57 -08:00
|
|
|
aco.Ok() &&
|
2010-08-16 12:35:04 -07:00
|
|
|
jsval_from_PObjectWrapperParent(cx, out_powp, vp));
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
ObjectWrapperParent::CPOW_HasInstance(JSContext *cx, JSHandleObject obj, const jsval *v,
|
2009-11-06 12:43:39 -08:00
|
|
|
JSBool *bp)
|
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_HasInstance..."));
|
|
|
|
|
|
|
|
*bp = JS_FALSE;
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* self = Unwrap(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!self)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_HasInstance");
|
|
|
|
|
|
|
|
AutoCheckOperation aco(cx, self);
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
JSVariant in_v;
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
if (!jsval_to_JSVariant(cx, *v, &in_v))
|
2009-11-06 12:43:39 -08:00
|
|
|
return JS_FALSE;
|
|
|
|
|
2010-01-20 18:24:14 -08:00
|
|
|
return (self->Manager()->RequestRunToCompletion() &&
|
|
|
|
self->CallHasInstance(in_v,
|
2010-01-22 12:52:57 -08:00
|
|
|
aco.StatusPtr(), bp) &&
|
|
|
|
aco.Ok());
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
ObjectWrapperParent::CPOW_Equality(JSContext *cx, JSHandleObject obj, const jsval *v,
|
2009-11-06 12:43:39 -08:00
|
|
|
JSBool *bp)
|
|
|
|
{
|
|
|
|
CPOW_LOG(("Calling CPOW_Equality..."));
|
|
|
|
|
|
|
|
*bp = JS_FALSE;
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* self = Unwrap(obj);
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!self)
|
2010-01-22 12:52:57 -08:00
|
|
|
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_Equality");
|
2009-11-06 12:43:39 -08:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
if (JSVAL_IS_PRIMITIVE(*v))
|
2009-11-06 12:43:39 -08:00
|
|
|
return JS_TRUE;
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
ObjectWrapperParent* other = Unwrap(JSVAL_TO_OBJECT(*v));
|
2009-11-06 12:43:39 -08:00
|
|
|
if (!other)
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
*bp = (self == other);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|