2014-05-17 03:40:36 +04:00
|
|
|
/* -*- 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_WrapperOwner_h__
|
|
|
|
#define mozilla_jsipc_WrapperOwner_h__
|
|
|
|
|
|
|
|
#include "JavaScriptShared.h"
|
|
|
|
#include "mozilla/ipc/ProtocolUtils.h"
|
2015-01-27 00:32:18 +03:00
|
|
|
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
|
2014-05-17 03:40:36 +04:00
|
|
|
#include "js/Class.h"
|
2015-02-10 21:58:18 +03:00
|
|
|
#include "js/Proxy.h"
|
2014-05-17 03:40:36 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace jsipc {
|
|
|
|
|
2014-05-17 03:40:36 +04:00
|
|
|
class WrapperOwner : public virtual JavaScriptShared
|
2014-05-17 03:40:36 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-10-29 07:26:21 +03:00
|
|
|
typedef mozilla::ipc::IProtocol::ActorDestroyReason
|
2014-05-17 03:40:36 +04:00
|
|
|
ActorDestroyReason;
|
|
|
|
|
2016-08-11 15:39:23 +03:00
|
|
|
WrapperOwner();
|
2014-05-17 03:40:36 +04:00
|
|
|
bool init();
|
|
|
|
|
2014-10-08 21:09:08 +04:00
|
|
|
// Standard internal methods.
|
2015-02-10 21:58:18 +03:00
|
|
|
// (The traps should be in the same order like js/Proxy.h)
|
2015-03-29 01:22:11 +03:00
|
|
|
bool getOwnPropertyDescriptor(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> desc);
|
2015-03-29 01:22:11 +03:00
|
|
|
bool defineProperty(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::Handle<JS::PropertyDescriptor> desc,
|
2015-03-29 01:22:11 +03:00
|
|
|
JS::ObjectOpResult& result);
|
|
|
|
bool ownPropertyKeys(JSContext* cx, JS::HandleObject proxy, JS::AutoIdVector& props);
|
|
|
|
bool delete_(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
|
|
|
|
JS::ObjectOpResult& result);
|
|
|
|
bool preventExtensions(JSContext* cx, JS::HandleObject proxy, JS::ObjectOpResult& result);
|
|
|
|
bool isExtensible(JSContext* cx, JS::HandleObject proxy, bool* extensible);
|
|
|
|
bool has(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, bool* bp);
|
2015-09-18 01:14:41 +03:00
|
|
|
bool get(JSContext* cx, JS::HandleObject proxy, JS::HandleValue receiver,
|
2014-05-17 03:40:36 +04:00
|
|
|
JS::HandleId id, JS::MutableHandleValue vp);
|
2015-03-29 01:22:11 +03:00
|
|
|
bool set(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::HandleValue v,
|
|
|
|
JS::HandleValue receiver, JS::ObjectOpResult& result);
|
|
|
|
bool callOrConstruct(JSContext* cx, JS::HandleObject proxy, const JS::CallArgs& args,
|
2014-07-01 04:50:58 +04:00
|
|
|
bool construct);
|
2014-10-08 21:09:08 +04:00
|
|
|
|
|
|
|
// SpiderMonkey extensions.
|
2015-03-29 01:22:11 +03:00
|
|
|
bool getPropertyDescriptor(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> desc);
|
2015-03-29 01:22:11 +03:00
|
|
|
bool hasOwn(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, bool* bp);
|
|
|
|
bool getOwnEnumerablePropertyKeys(JSContext* cx, JS::HandleObject proxy,
|
|
|
|
JS::AutoIdVector& props);
|
|
|
|
bool hasInstance(JSContext* cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool* bp);
|
2016-06-30 01:04:56 +03:00
|
|
|
bool getBuiltinClass(JSContext* cx, JS::HandleObject proxy, js::ESClass* cls);
|
2015-08-23 11:10:24 +03:00
|
|
|
bool isArray(JSContext* cx, JS::HandleObject proxy, JS::IsArrayAnswer* answer);
|
2015-03-29 01:22:11 +03:00
|
|
|
const char* className(JSContext* cx, JS::HandleObject proxy);
|
|
|
|
bool getPrototype(JSContext* cx, JS::HandleObject proxy, JS::MutableHandleObject protop);
|
2016-02-24 00:42:30 +03:00
|
|
|
bool getPrototypeIfOrdinary(JSContext* cx, JS::HandleObject proxy, bool* isOrdinary,
|
|
|
|
JS::MutableHandleObject protop);
|
2015-02-10 18:29:41 +03:00
|
|
|
|
2017-07-11 12:31:12 +03:00
|
|
|
js::RegExpShared* regexp_toShared(JSContext* cx, JS::HandleObject proxy);
|
2014-05-17 03:40:36 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
nsresult instanceOf(JSObject* obj, const nsID* id, bool* bp);
|
2014-05-17 03:40:36 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
bool toString(JSContext* cx, JS::HandleObject callee, JS::CallArgs& args);
|
|
|
|
bool DOMQI(JSContext* cx, JS::HandleObject callee, JS::CallArgs& args);
|
2014-05-29 05:05:23 +04:00
|
|
|
|
2014-05-17 03:40:36 +04:00
|
|
|
/*
|
|
|
|
* Check that |obj| is a DOM wrapper whose prototype chain contains
|
|
|
|
* |prototypeID| at depth |depth|.
|
|
|
|
*/
|
2015-03-29 01:22:11 +03:00
|
|
|
bool domInstanceOf(JSContext* cx, JSObject* obj, int prototypeID, int depth, bool* bp);
|
2014-05-17 03:40:36 +04:00
|
|
|
|
|
|
|
bool active() { return !inactive_; }
|
|
|
|
|
2015-10-24 02:31:54 +03:00
|
|
|
virtual bool allowMessage(JSContext* cx) = 0;
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void drop(JSObject* obj);
|
|
|
|
void updatePointer(JSObject* obj, const JSObject* old);
|
2014-05-17 03:40:36 +04:00
|
|
|
|
|
|
|
virtual void ActorDestroy(ActorDestroyReason why);
|
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual bool toObjectVariant(JSContext* cx, JSObject* obj, ObjectVariant* objVarp) override;
|
|
|
|
virtual JSObject* fromObjectVariant(JSContext* cx, const ObjectVariant& objVar) override;
|
2016-10-20 23:37:26 +03:00
|
|
|
JSObject* fromRemoteObjectVariant(JSContext* cx, const RemoteObject& objVar);
|
|
|
|
JSObject* fromLocalObjectVariant(JSContext* cx, const LocalObject& objVar);
|
2014-05-17 03:40:37 +04:00
|
|
|
|
2014-05-17 03:40:36 +04:00
|
|
|
protected:
|
2015-03-29 01:22:11 +03:00
|
|
|
ObjectId idOf(JSObject* obj);
|
2014-05-17 03:40:36 +04:00
|
|
|
|
|
|
|
private:
|
2015-03-29 01:22:11 +03:00
|
|
|
ObjectId idOfUnchecked(JSObject* obj);
|
2014-09-24 15:54:11 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
bool getPropertyKeys(JSContext* cx, JS::HandleObject proxy, uint32_t flags,
|
|
|
|
JS::AutoIdVector& props);
|
2014-05-17 03:40:36 +04:00
|
|
|
|
|
|
|
// Catastrophic IPC failure.
|
2015-03-29 01:22:11 +03:00
|
|
|
bool ipcfail(JSContext* cx);
|
2014-05-17 03:40:36 +04:00
|
|
|
|
|
|
|
// Check whether a return status is okay, and if not, propagate its error.
|
2015-01-30 20:37:07 +03:00
|
|
|
//
|
|
|
|
// If 'status' might be a ReturnObjectOpResult, which is only possible for
|
|
|
|
// a subset of the operations below, 'result' must be passed.
|
2015-03-29 01:22:11 +03:00
|
|
|
bool ok(JSContext* cx, const ReturnStatus& status, JS::ObjectOpResult& result);
|
|
|
|
bool ok(JSContext* cx, const ReturnStatus& status);
|
2014-05-17 03:40:36 +04:00
|
|
|
|
|
|
|
bool inactive_;
|
|
|
|
|
|
|
|
/*** Dummy call handlers ***/
|
|
|
|
public:
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool SendDropObject(const ObjectId& objId) = 0;
|
|
|
|
virtual bool SendPreventExtensions(const ObjectId& objId, ReturnStatus* rs) = 0;
|
|
|
|
virtual bool SendGetPropertyDescriptor(const ObjectId& objId, const JSIDVariant& id,
|
|
|
|
ReturnStatus* rs,
|
|
|
|
PPropertyDescriptor* out) = 0;
|
|
|
|
virtual bool SendGetOwnPropertyDescriptor(const ObjectId& objId,
|
|
|
|
const JSIDVariant& id,
|
|
|
|
ReturnStatus* rs,
|
|
|
|
PPropertyDescriptor* out) = 0;
|
|
|
|
virtual bool SendDefineProperty(const ObjectId& objId, const JSIDVariant& id,
|
|
|
|
const PPropertyDescriptor& flags,
|
|
|
|
ReturnStatus* rs) = 0;
|
|
|
|
virtual bool SendDelete(const ObjectId& objId, const JSIDVariant& id,
|
|
|
|
ReturnStatus* rs) = 0;
|
|
|
|
|
|
|
|
virtual bool SendHas(const ObjectId& objId, const JSIDVariant& id,
|
|
|
|
ReturnStatus* rs, bool* bp) = 0;
|
|
|
|
virtual bool SendHasOwn(const ObjectId& objId, const JSIDVariant& id,
|
|
|
|
ReturnStatus* rs, bool* bp) = 0;
|
2015-09-18 01:14:41 +03:00
|
|
|
virtual bool SendGet(const ObjectId& objId, const JSVariant& receiverVar,
|
2015-03-29 01:22:11 +03:00
|
|
|
const JSIDVariant& id,
|
|
|
|
ReturnStatus* rs, JSVariant* result) = 0;
|
|
|
|
virtual bool SendSet(const ObjectId& objId, const JSIDVariant& id, const JSVariant& value,
|
|
|
|
const JSVariant& receiverVar, ReturnStatus* rs) = 0;
|
|
|
|
|
|
|
|
virtual bool SendIsExtensible(const ObjectId& objId, ReturnStatus* rs,
|
|
|
|
bool* result) = 0;
|
|
|
|
virtual bool SendCallOrConstruct(const ObjectId& objId, const nsTArray<JSParam>& argv,
|
|
|
|
const bool& construct, ReturnStatus* rs, JSVariant* result,
|
|
|
|
nsTArray<JSParam>* outparams) = 0;
|
|
|
|
virtual bool SendHasInstance(const ObjectId& objId, const JSVariant& v,
|
|
|
|
ReturnStatus* rs, bool* bp) = 0;
|
2015-08-29 07:55:40 +03:00
|
|
|
virtual bool SendGetBuiltinClass(const ObjectId& objId, ReturnStatus* rs,
|
|
|
|
uint32_t* classValue) = 0;
|
2015-08-23 11:10:24 +03:00
|
|
|
virtual bool SendIsArray(const ObjectId& objId, ReturnStatus* rs,
|
|
|
|
uint32_t* answer) = 0;
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool SendClassName(const ObjectId& objId, nsCString* result) = 0;
|
|
|
|
virtual bool SendGetPrototype(const ObjectId& objId, ReturnStatus* rs, ObjectOrNullVariant* result) = 0;
|
2016-02-24 00:42:30 +03:00
|
|
|
virtual bool SendGetPrototypeIfOrdinary(const ObjectId& objId, ReturnStatus* rs, bool* isOrdinary,
|
|
|
|
ObjectOrNullVariant* result) = 0;
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool SendRegExpToShared(const ObjectId& objId, ReturnStatus* rs, nsString* source,
|
|
|
|
uint32_t* flags) = 0;
|
|
|
|
|
|
|
|
virtual bool SendGetPropertyKeys(const ObjectId& objId, const uint32_t& flags,
|
|
|
|
ReturnStatus* rs, nsTArray<JSIDVariant>* ids) = 0;
|
|
|
|
virtual bool SendInstanceOf(const ObjectId& objId, const JSIID& iid,
|
|
|
|
ReturnStatus* rs, bool* instanceof) = 0;
|
|
|
|
virtual bool SendDOMInstanceOf(const ObjectId& objId, const int& prototypeID, const int& depth,
|
|
|
|
ReturnStatus* rs, bool* instanceof) = 0;
|
2014-05-17 03:40:36 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace jsipc
|
|
|
|
} // namespace mozilla
|
2014-05-17 03:40:36 +04:00
|
|
|
|
|
|
|
#endif // mozilla_jsipc_WrapperOwner_h__
|