gecko-dev/js/ipc/JavaScriptBase.h

221 lines
10 KiB
C
Raw Normal View History

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sw=4 et tw=80:
*
* 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/. */
#ifndef mozilla_jsipc_JavaScriptBase_h__
#define mozilla_jsipc_JavaScriptBase_h__
#include "WrapperAnswer.h"
#include "WrapperOwner.h"
#include "mozilla/dom/DOMTypes.h"
#include "mozilla/jsipc/PJavaScript.h"
namespace mozilla {
namespace jsipc {
template<class Base>
class JavaScriptBase : public WrapperOwner, public WrapperAnswer, public Base
{
typedef WrapperAnswer Answer;
public:
explicit JavaScriptBase(JSRuntime* rt)
: JavaScriptShared(rt),
WrapperOwner(rt),
WrapperAnswer(rt)
{}
virtual ~JavaScriptBase() {}
virtual void ActorDestroy(WrapperOwner::ActorDestroyReason why) {
WrapperOwner::ActorDestroy(why);
}
/*** IPC handlers ***/
bool RecvPreventExtensions(const uint64_t& objId, ReturnStatus* rs) {
return Answer::RecvPreventExtensions(ObjectId::deserialize(objId), rs);
}
bool RecvGetPropertyDescriptor(const uint64_t& objId, const JSIDVariant& id,
ReturnStatus* rs,
PPropertyDescriptor* out) {
return Answer::RecvGetPropertyDescriptor(ObjectId::deserialize(objId), id, rs, out);
}
bool RecvGetOwnPropertyDescriptor(const uint64_t& objId,
const JSIDVariant& id,
ReturnStatus* rs,
PPropertyDescriptor* out) {
return Answer::RecvGetOwnPropertyDescriptor(ObjectId::deserialize(objId), id, rs, out);
}
bool RecvDefineProperty(const uint64_t& objId, const JSIDVariant& id,
const PPropertyDescriptor& flags, ReturnStatus* rs) {
return Answer::RecvDefineProperty(ObjectId::deserialize(objId), id, flags, rs);
}
bool RecvDelete(const uint64_t& objId, const JSIDVariant& id,
ReturnStatus* rs) {
return Answer::RecvDelete(ObjectId::deserialize(objId), id, rs);
}
bool RecvHas(const uint64_t& objId, const JSIDVariant& id,
ReturnStatus* rs, bool* bp) {
return Answer::RecvHas(ObjectId::deserialize(objId), id, rs, bp);
}
bool RecvHasOwn(const uint64_t& objId, const JSIDVariant& id,
ReturnStatus* rs, bool* bp) {
return Answer::RecvHasOwn(ObjectId::deserialize(objId), id, rs, bp);
}
bool RecvGet(const uint64_t& objId, const JSVariant& receiverVar, const JSIDVariant& id,
ReturnStatus* rs, JSVariant* result) {
return Answer::RecvGet(ObjectId::deserialize(objId), receiverVar, id, rs, result);
}
bool RecvSet(const uint64_t& objId, const JSIDVariant& id, const JSVariant& value,
const JSVariant& receiverVar, ReturnStatus* rs) {
Bug 1142794 - Change 'receiver' argument to SetProperty functions and ProxyHandler::set methods to be a HandleValue. r=Waldo. Also: Change signature of these functions and methods to all have the same arguments in the same order: (cx, obj, id, v, receiver). Also change v from MutableHandleValue to HandleValue. There is no change in behavior. In fact the new error message `JSMSG_SET_NON_OBJECT_RECEIVER` is impossible to trigger from scripts for now, I think (after re-reading the whole patch with this in mind). JS_ForwardSetPropertyTo is the only way to get a non-object receiver into the engine, but no caller currently does so. We're installing new pipes here, and they should work, but for now it's the same cold water flowing through as before. Actually hooking up the hot water is left for another bug (one with tests, not to put too fine a point on it). Notes: * InvokeGetterOrSetter had to be split into two functions: InvokeGetter takes a MutableHandleValue out-param, InvokeSetter a HandleValue in-param. * Watchpoints can still tamper with values being assigned. So can JSSetterOps. I'm pleased we can support this craziness in a way that doesn't have to spread via the type system to encompass the entire codebase. * Change in GlobalObject::setIntrinsicValue is not really a change. Yes, it asserted before, but an exception thrown during self-hosting initialization is not going to go unnoticed either. * Since the receiver argument to js::SetProperty() is at the end now, it makes sense for it to be optional. Some callers look nicer. --HG-- extra : rebase_source : e89f916fe267800bc73890e11aceef5c4855b272
2015-03-01 19:16:19 +00:00
return Answer::RecvSet(ObjectId::deserialize(objId), id, value, receiverVar, rs);
}
bool RecvIsExtensible(const uint64_t& objId, ReturnStatus* rs,
bool* result) {
return Answer::RecvIsExtensible(ObjectId::deserialize(objId), rs, result);
}
bool RecvCallOrConstruct(const uint64_t& objId, InfallibleTArray<JSParam>&& argv,
const bool& construct, ReturnStatus* rs, JSVariant* result,
nsTArray<JSParam>* outparams) {
return Answer::RecvCallOrConstruct(ObjectId::deserialize(objId), Move(argv), construct, rs, result, outparams);
}
bool RecvHasInstance(const uint64_t& objId, const JSVariant& v, ReturnStatus* rs, bool* bp) {
return Answer::RecvHasInstance(ObjectId::deserialize(objId), v, rs, bp);
}
bool RecvObjectClassIs(const uint64_t& objId, const uint32_t& classValue,
bool* result) {
return Answer::RecvObjectClassIs(ObjectId::deserialize(objId), classValue, result);
}
bool RecvClassName(const uint64_t& objId, nsCString* result) {
return Answer::RecvClassName(ObjectId::deserialize(objId), result);
}
bool RecvGetPrototype(const uint64_t& objId, ReturnStatus* rs, ObjectOrNullVariant* result) {
return Answer::RecvGetPrototype(ObjectId::deserialize(objId), rs, result);
}
bool RecvRegExpToShared(const uint64_t& objId, ReturnStatus* rs, nsString* source, uint32_t* flags) {
return Answer::RecvRegExpToShared(ObjectId::deserialize(objId), rs, source, flags);
}
bool RecvGetPropertyKeys(const uint64_t& objId, const uint32_t& flags,
ReturnStatus* rs, nsTArray<JSIDVariant>* ids) {
return Answer::RecvGetPropertyKeys(ObjectId::deserialize(objId), flags, rs, ids);
}
bool RecvInstanceOf(const uint64_t& objId, const JSIID& iid,
ReturnStatus* rs, bool* instanceof) {
return Answer::RecvInstanceOf(ObjectId::deserialize(objId), iid, rs, instanceof);
}
bool RecvDOMInstanceOf(const uint64_t& objId, const int& prototypeID, const int& depth,
ReturnStatus* rs, bool* instanceof) {
return Answer::RecvDOMInstanceOf(ObjectId::deserialize(objId), prototypeID, depth, rs, instanceof);
}
bool RecvDropObject(const uint64_t& objId) {
return Answer::RecvDropObject(ObjectId::deserialize(objId));
}
/*** Dummy call handlers ***/
bool SendDropObject(const ObjectId& objId) {
return Base::SendDropObject(objId.serialize());
}
bool SendPreventExtensions(const ObjectId& objId, ReturnStatus* rs) {
return Base::SendPreventExtensions(objId.serialize(), rs);
}
bool SendGetPropertyDescriptor(const ObjectId& objId, const JSIDVariant& id,
ReturnStatus* rs,
PPropertyDescriptor* out) {
return Base::SendGetPropertyDescriptor(objId.serialize(), id, rs, out);
}
bool SendGetOwnPropertyDescriptor(const ObjectId& objId,
const JSIDVariant& id,
ReturnStatus* rs,
PPropertyDescriptor* out) {
return Base::SendGetOwnPropertyDescriptor(objId.serialize(), id, rs, out);
}
bool SendDefineProperty(const ObjectId& objId, const JSIDVariant& id,
const PPropertyDescriptor& flags,
ReturnStatus* rs) {
return Base::SendDefineProperty(objId.serialize(), id, flags, rs);
}
bool SendDelete(const ObjectId& objId, const JSIDVariant& id, ReturnStatus* rs) {
return Base::SendDelete(objId.serialize(), id, rs);
}
bool SendHas(const ObjectId& objId, const JSIDVariant& id,
ReturnStatus* rs, bool* bp) {
return Base::SendHas(objId.serialize(), id, rs, bp);
}
bool SendHasOwn(const ObjectId& objId, const JSIDVariant& id,
ReturnStatus* rs, bool* bp) {
return Base::SendHasOwn(objId.serialize(), id, rs, bp);
}
bool SendGet(const ObjectId& objId, const JSVariant& receiverVar, const JSIDVariant& id,
ReturnStatus* rs, JSVariant* result) {
return Base::SendGet(objId.serialize(), receiverVar, id, rs, result);
}
bool SendSet(const ObjectId& objId, const JSIDVariant& id, const JSVariant& value,
const JSVariant& receiverVar, ReturnStatus* rs) {
Bug 1142794 - Change 'receiver' argument to SetProperty functions and ProxyHandler::set methods to be a HandleValue. r=Waldo. Also: Change signature of these functions and methods to all have the same arguments in the same order: (cx, obj, id, v, receiver). Also change v from MutableHandleValue to HandleValue. There is no change in behavior. In fact the new error message `JSMSG_SET_NON_OBJECT_RECEIVER` is impossible to trigger from scripts for now, I think (after re-reading the whole patch with this in mind). JS_ForwardSetPropertyTo is the only way to get a non-object receiver into the engine, but no caller currently does so. We're installing new pipes here, and they should work, but for now it's the same cold water flowing through as before. Actually hooking up the hot water is left for another bug (one with tests, not to put too fine a point on it). Notes: * InvokeGetterOrSetter had to be split into two functions: InvokeGetter takes a MutableHandleValue out-param, InvokeSetter a HandleValue in-param. * Watchpoints can still tamper with values being assigned. So can JSSetterOps. I'm pleased we can support this craziness in a way that doesn't have to spread via the type system to encompass the entire codebase. * Change in GlobalObject::setIntrinsicValue is not really a change. Yes, it asserted before, but an exception thrown during self-hosting initialization is not going to go unnoticed either. * Since the receiver argument to js::SetProperty() is at the end now, it makes sense for it to be optional. Some callers look nicer. --HG-- extra : rebase_source : e89f916fe267800bc73890e11aceef5c4855b272
2015-03-01 19:16:19 +00:00
return Base::SendSet(objId.serialize(), id, value, receiverVar, rs);
}
bool SendIsExtensible(const ObjectId& objId, ReturnStatus* rs,
bool* result) {
return Base::SendIsExtensible(objId.serialize(), rs, result);
}
bool SendCallOrConstruct(const ObjectId& objId, const nsTArray<JSParam>& argv,
const bool& construct, ReturnStatus* rs, JSVariant* result,
nsTArray<JSParam>* outparams) {
return Base::SendCallOrConstruct(objId.serialize(), argv, construct, rs, result, outparams);
}
bool SendHasInstance(const ObjectId& objId, const JSVariant& v, ReturnStatus* rs, bool* bp) {
return Base::SendHasInstance(objId.serialize(), v, rs, bp);
}
bool SendObjectClassIs(const ObjectId& objId, const uint32_t& classValue,
bool* result) {
return Base::SendObjectClassIs(objId.serialize(), classValue, result);
}
bool SendClassName(const ObjectId& objId, nsCString* result) {
return Base::SendClassName(objId.serialize(), result);
}
bool SendGetPrototype(const ObjectId& objId, ReturnStatus* rs, ObjectOrNullVariant* result) {
return Base::SendGetPrototype(objId.serialize(), rs, result);
}
bool SendRegExpToShared(const ObjectId& objId, ReturnStatus* rs,
nsString* source, uint32_t* flags) {
return Base::SendRegExpToShared(objId.serialize(), rs, source, flags);
}
bool SendGetPropertyKeys(const ObjectId& objId, const uint32_t& flags,
ReturnStatus* rs, nsTArray<JSIDVariant>* ids) {
return Base::SendGetPropertyKeys(objId.serialize(), flags, rs, ids);
}
bool SendInstanceOf(const ObjectId& objId, const JSIID& iid,
ReturnStatus* rs, bool* instanceof) {
return Base::SendInstanceOf(objId.serialize(), iid, rs, instanceof);
}
bool SendDOMInstanceOf(const ObjectId& objId, const int& prototypeID, const int& depth,
ReturnStatus* rs, bool* instanceof) {
return Base::SendDOMInstanceOf(objId.serialize(), prototypeID, depth, rs, instanceof);
}
/* The following code is needed to suppress a bogus MSVC warning (C4250). */
virtual bool toObjectVariant(JSContext* cx, JSObject* obj, ObjectVariant* objVarp) {
return WrapperOwner::toObjectVariant(cx, obj, objVarp);
}
virtual JSObject* fromObjectVariant(JSContext* cx, ObjectVariant objVar) {
return WrapperOwner::fromObjectVariant(cx, objVar);
}
};
} // namespace jsipc
} // namespace mozilla
#endif