2014-05-16 23:40:36 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 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/. */
|
|
|
|
|
|
|
|
#include "WrapperOwner.h"
|
2014-05-29 01:05:22 +00:00
|
|
|
#include "JavaScriptLogging.h"
|
2014-05-16 23:40:37 +00:00
|
|
|
#include "mozilla/unused.h"
|
2014-05-16 23:40:36 +00:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
|
|
#include "jsfriendapi.h"
|
2015-03-10 21:36:01 +00:00
|
|
|
#include "js/CharacterEncoding.h"
|
2014-05-16 23:40:36 +00:00
|
|
|
#include "xpcprivate.h"
|
2014-11-19 23:54:34 +00:00
|
|
|
#include "CPOWTimer.h"
|
2014-09-25 11:13:29 +00:00
|
|
|
#include "WrapperFactory.h"
|
2014-05-16 23:40:36 +00:00
|
|
|
|
2014-11-05 01:40:08 +00:00
|
|
|
#include "nsIRemoteTagService.h"
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
using namespace js;
|
|
|
|
using namespace JS;
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::jsipc;
|
|
|
|
|
2014-11-05 01:39:34 +00:00
|
|
|
struct AuxCPOWData
|
|
|
|
{
|
|
|
|
ObjectId id;
|
|
|
|
bool isCallable;
|
|
|
|
bool isConstructor;
|
2015-03-10 21:36:01 +00:00
|
|
|
bool isDOMObject;
|
2014-11-05 01:39:34 +00:00
|
|
|
|
2014-11-05 01:40:08 +00:00
|
|
|
// The object tag is just some auxilliary information that clients can use
|
|
|
|
// however they see fit.
|
|
|
|
nsCString objectTag;
|
|
|
|
|
2015-03-27 20:12:37 +00:00
|
|
|
// The class name for WrapperOwner::className, below.
|
|
|
|
nsCString className;
|
|
|
|
|
2015-03-10 21:36:01 +00:00
|
|
|
AuxCPOWData(ObjectId id,
|
|
|
|
bool isCallable,
|
|
|
|
bool isConstructor,
|
|
|
|
bool isDOMObject,
|
2015-03-28 22:22:11 +00:00
|
|
|
const nsACString& objectTag)
|
2014-11-05 01:39:34 +00:00
|
|
|
: id(id),
|
|
|
|
isCallable(isCallable),
|
2014-11-05 01:40:08 +00:00
|
|
|
isConstructor(isConstructor),
|
2015-03-10 21:36:01 +00:00
|
|
|
isDOMObject(isDOMObject),
|
2014-11-05 01:40:08 +00:00
|
|
|
objectTag(objectTag)
|
2014-11-05 01:39:34 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::WrapperOwner(JSRuntime* rt)
|
2014-05-16 23:40:37 +00:00
|
|
|
: JavaScriptShared(rt),
|
|
|
|
inactive_(false)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
static inline AuxCPOWData*
|
|
|
|
AuxCPOWDataOf(JSObject* obj)
|
2014-11-05 01:39:34 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsCPOW(obj));
|
2015-03-28 22:22:11 +00:00
|
|
|
return static_cast<AuxCPOWData*>(GetProxyExtra(obj, 1).toPrivate());
|
2014-11-05 01:39:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
static inline WrapperOwner*
|
|
|
|
OwnerOf(JSObject* obj)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsCPOW(obj));
|
2015-03-28 22:22:11 +00:00
|
|
|
return reinterpret_cast<WrapperOwner*>(GetProxyExtra(obj, 0).toPrivate());
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectId
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::idOfUnchecked(JSObject* obj)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsCPOW(obj));
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
AuxCPOWData* aux = AuxCPOWDataOf(obj);
|
2014-11-05 01:39:34 +00:00
|
|
|
MOZ_ASSERT(!aux->id.isNull());
|
|
|
|
return aux->id;
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 11:54:11 +00:00
|
|
|
ObjectId
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::idOf(JSObject* obj)
|
2014-09-24 11:54:11 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOfUnchecked(obj);
|
|
|
|
MOZ_ASSERT(findCPOWById(objId) == obj);
|
|
|
|
return objId;
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
class CPOWProxyHandler : public BaseProxyHandler
|
|
|
|
{
|
|
|
|
public:
|
2014-08-28 20:47:16 +00:00
|
|
|
MOZ_CONSTEXPR CPOWProxyHandler()
|
2014-08-28 00:09:06 +00:00
|
|
|
: BaseProxyHandler(&family) {}
|
2014-05-16 23:40:36 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool finalizeInBackground(Value priv) const override {
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool getOwnPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
2015-03-21 16:28:04 +00:00
|
|
|
MutableHandle<JSPropertyDescriptor> desc) const override;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool defineProperty(JSContext* cx, HandleObject proxy, HandleId id,
|
2015-02-17 17:58:43 +00:00
|
|
|
Handle<JSPropertyDescriptor> desc,
|
2015-03-28 22:22:11 +00:00
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool ownPropertyKeys(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const override;
|
|
|
|
virtual bool delete_(JSContext* cx, HandleObject proxy, HandleId id,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool enumerate(JSContext* cx, HandleObject proxy, MutableHandleObject objp) const override;
|
|
|
|
virtual bool preventExtensions(JSContext* cx, HandleObject proxy,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool isExtensible(JSContext* cx, HandleObject proxy, bool* extensible) const override;
|
|
|
|
virtual bool has(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) const override;
|
2015-09-17 22:14:41 +00:00
|
|
|
virtual bool get(JSContext* cx, HandleObject proxy, HandleValue receiver,
|
2015-03-21 16:28:04 +00:00
|
|
|
HandleId id, MutableHandleValue vp) const override;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool set(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::HandleValue v,
|
|
|
|
JS::HandleValue receiver, JS::ObjectOpResult& result) const override;
|
|
|
|
virtual bool call(JSContext* cx, HandleObject proxy, const CallArgs& args) const override;
|
|
|
|
virtual bool construct(JSContext* cx, HandleObject proxy, const CallArgs& args) const override;
|
2014-10-08 17:09:08 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool getPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
2015-03-21 16:28:04 +00:00
|
|
|
MutableHandle<JSPropertyDescriptor> desc) const override;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool hasOwn(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) const override;
|
|
|
|
virtual bool getOwnEnumerablePropertyKeys(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const override;
|
|
|
|
virtual bool hasInstance(JSContext* cx, HandleObject proxy,
|
|
|
|
MutableHandleValue v, bool* bp) const override;
|
2015-08-29 04:55:40 +00:00
|
|
|
virtual bool getBuiltinClass(JSContext* cx, HandleObject obj,
|
|
|
|
js::ESClassValue* classValue) const override;
|
2015-08-23 08:10:24 +00:00
|
|
|
virtual bool isArray(JSContext* cx, HandleObject obj,
|
|
|
|
IsArrayAnswer* answer) const override;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual const char* className(JSContext* cx, HandleObject proxy) const override;
|
|
|
|
virtual bool regexp_toShared(JSContext* cx, HandleObject proxy, RegExpGuard* g) const override;
|
|
|
|
virtual void finalize(JSFreeOp* fop, JSObject* proxy) const override;
|
|
|
|
virtual void objectMoved(JSObject* proxy, const JSObject* old) const override;
|
|
|
|
virtual bool isCallable(JSObject* obj) const override;
|
|
|
|
virtual bool isConstructor(JSObject* obj) const override;
|
|
|
|
virtual bool getPrototype(JSContext* cx, HandleObject proxy, MutableHandleObject protop) const override;
|
2014-05-16 23:40:36 +00:00
|
|
|
|
2014-08-28 00:09:06 +00:00
|
|
|
static const char family;
|
2014-06-27 11:44:04 +00:00
|
|
|
static const CPOWProxyHandler singleton;
|
2014-05-16 23:40:36 +00:00
|
|
|
};
|
|
|
|
|
2014-08-28 00:09:06 +00:00
|
|
|
const char CPOWProxyHandler::family = 0;
|
2014-06-27 11:44:04 +00:00
|
|
|
const CPOWProxyHandler CPOWProxyHandler::singleton;
|
2014-05-16 23:40:36 +00:00
|
|
|
|
|
|
|
#define FORWARD(call, args) \
|
2016-01-15 10:38:03 +00:00
|
|
|
PROFILER_LABEL_FUNC(js::ProfileEntry::Category::JS); \
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner* owner = OwnerOf(proxy); \
|
2014-05-16 23:40:36 +00:00
|
|
|
if (!owner->active()) { \
|
|
|
|
JS_ReportError(cx, "cannot use a CPOW whose process is gone"); \
|
|
|
|
return false; \
|
|
|
|
} \
|
2015-10-23 23:31:54 +00:00
|
|
|
if (!owner->allowMessage(cx)) { \
|
|
|
|
return false; \
|
|
|
|
} \
|
2014-11-19 23:54:34 +00:00
|
|
|
{ \
|
2015-06-04 11:12:07 +00:00
|
|
|
CPOWTimer timer(cx); \
|
2014-11-19 23:54:34 +00:00
|
|
|
return owner->call args; \
|
|
|
|
}
|
2014-05-16 23:40:36 +00:00
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::getPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
2014-06-27 11:44:06 +00:00
|
|
|
MutableHandle<JSPropertyDescriptor> desc) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
FORWARD(getPropertyDescriptor, (cx, proxy, id, desc));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::getPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
2015-03-10 21:36:01 +00:00
|
|
|
MutableHandle<JSPropertyDescriptor> desc)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
2014-10-07 09:29:02 +00:00
|
|
|
JSIDVariant idVar;
|
|
|
|
if (!toJSIDVariant(cx, id, &idVar))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ReturnStatus status;
|
|
|
|
PPropertyDescriptor result;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendGetPropertyDescriptor(objId, idVar, &status, &result))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
2014-05-29 01:05:22 +00:00
|
|
|
|
|
|
|
LOG_STACK();
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
if (!ok(cx, status))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return toDescriptor(cx, result, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::getOwnPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
2014-06-27 11:44:06 +00:00
|
|
|
MutableHandle<JSPropertyDescriptor> desc) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
FORWARD(getOwnPropertyDescriptor, (cx, proxy, id, desc));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::getOwnPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
2015-03-10 21:36:01 +00:00
|
|
|
MutableHandle<JSPropertyDescriptor> desc)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
2014-10-07 09:29:02 +00:00
|
|
|
JSIDVariant idVar;
|
|
|
|
if (!toJSIDVariant(cx, id, &idVar))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ReturnStatus status;
|
|
|
|
PPropertyDescriptor result;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendGetOwnPropertyDescriptor(objId, idVar, &status, &result))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
2014-05-29 01:05:22 +00:00
|
|
|
|
|
|
|
LOG_STACK();
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
if (!ok(cx, status))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return toDescriptor(cx, result, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::defineProperty(JSContext* cx, HandleObject proxy, HandleId id,
|
2015-02-17 17:58:43 +00:00
|
|
|
Handle<JSPropertyDescriptor> desc,
|
2015-03-28 22:22:11 +00:00
|
|
|
ObjectOpResult& result) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2015-01-30 17:37:07 +00:00
|
|
|
FORWARD(defineProperty, (cx, proxy, id, desc, result));
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::defineProperty(JSContext* cx, HandleObject proxy, HandleId id,
|
2015-02-17 17:58:43 +00:00
|
|
|
Handle<JSPropertyDescriptor> desc,
|
2015-03-28 22:22:11 +00:00
|
|
|
ObjectOpResult& result)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
2014-10-07 09:29:02 +00:00
|
|
|
JSIDVariant idVar;
|
|
|
|
if (!toJSIDVariant(cx, id, &idVar))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
PPropertyDescriptor descriptor;
|
|
|
|
if (!fromDescriptor(cx, desc, &descriptor))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ReturnStatus status;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendDefineProperty(objId, idVar, descriptor, &status))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
2014-05-29 01:05:22 +00:00
|
|
|
LOG_STACK();
|
|
|
|
|
2015-01-30 17:37:07 +00:00
|
|
|
return ok(cx, status, result);
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::ownPropertyKeys(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2014-09-26 20:16:36 +00:00
|
|
|
FORWARD(ownPropertyKeys, (cx, proxy, props));
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::ownPropertyKeys(JSContext* cx, HandleObject proxy, AutoIdVector& props)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2014-10-16 16:39:38 +00:00
|
|
|
return getPropertyKeys(cx, proxy, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, props);
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::delete_(JSContext* cx, HandleObject proxy, HandleId id,
|
|
|
|
ObjectOpResult& result) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2015-02-04 16:20:04 +00:00
|
|
|
FORWARD(delete_, (cx, proxy, id, result));
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::delete_(JSContext* cx, HandleObject proxy, HandleId id, ObjectOpResult& result)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
2014-10-07 09:29:02 +00:00
|
|
|
JSIDVariant idVar;
|
|
|
|
if (!toJSIDVariant(cx, id, &idVar))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ReturnStatus status;
|
2015-02-04 16:20:04 +00:00
|
|
|
if (!SendDelete(objId, idVar, &status))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
2014-05-29 01:05:22 +00:00
|
|
|
LOG_STACK();
|
|
|
|
|
2015-02-04 16:20:04 +00:00
|
|
|
return ok(cx, status, result);
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 23:28:38 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::enumerate(JSContext* cx, HandleObject proxy, MutableHandleObject objp) const
|
2014-12-16 23:28:38 +00:00
|
|
|
{
|
|
|
|
// Using a CPOW for the Iterator would slow down for .. in performance, instead
|
2014-12-16 23:28:38 +00:00
|
|
|
// call the base hook, that will use our implementation of getOwnEnumerablePropertyKeys
|
|
|
|
// and follow the proto chain.
|
2014-12-16 23:28:38 +00:00
|
|
|
return BaseProxyHandler::enumerate(cx, proxy, objp);
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::has(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
FORWARD(has, (cx, proxy, id, bp));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::has(JSContext* cx, HandleObject proxy, HandleId id, bool* bp)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
2014-10-07 09:29:02 +00:00
|
|
|
JSIDVariant idVar;
|
|
|
|
if (!toJSIDVariant(cx, id, &idVar))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ReturnStatus status;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendHas(objId, idVar, &status, bp))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
2014-05-29 01:05:22 +00:00
|
|
|
LOG_STACK();
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
return ok(cx, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::hasOwn(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
FORWARD(hasOwn, (cx, proxy, id, bp));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::hasOwn(JSContext* cx, HandleObject proxy, HandleId id, bool* bp)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
2014-10-07 09:29:02 +00:00
|
|
|
JSIDVariant idVar;
|
|
|
|
if (!toJSIDVariant(cx, id, &idVar))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ReturnStatus status;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendHasOwn(objId, idVar, &status, bp))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
2014-05-29 01:05:22 +00:00
|
|
|
LOG_STACK();
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
return !!ok(cx, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-09-17 22:14:41 +00:00
|
|
|
CPOWProxyHandler::get(JSContext* cx, HandleObject proxy, HandleValue receiver,
|
2014-06-27 11:44:06 +00:00
|
|
|
HandleId id, MutableHandleValue vp) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
FORWARD(get, (cx, proxy, receiver, id, vp));
|
|
|
|
}
|
|
|
|
|
2015-03-10 21:36:01 +00:00
|
|
|
static bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWDOMQI(JSContext* cx, unsigned argc, Value* vp)
|
2015-03-10 21:36:01 +00:00
|
|
|
{
|
|
|
|
CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
if (!args.thisv().isObject() || !IsCPOW(&args.thisv().toObject())) {
|
|
|
|
JS_ReportError(cx, "bad this object passed to special QI");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RootedObject proxy(cx, &args.thisv().toObject());
|
|
|
|
FORWARD(DOMQI, (cx, proxy, args));
|
|
|
|
}
|
|
|
|
|
2014-05-29 01:05:23 +00:00
|
|
|
static bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWToString(JSContext* cx, unsigned argc, Value* vp)
|
2014-05-29 01:05:23 +00:00
|
|
|
{
|
|
|
|
CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
RootedObject callee(cx, &args.callee());
|
|
|
|
RootedValue cpowValue(cx);
|
2014-12-16 23:28:39 +00:00
|
|
|
if (!JS_GetProperty(cx, callee, "__cpow__", &cpowValue))
|
2014-05-29 01:05:23 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!cpowValue.isObject() || !IsCPOW(&cpowValue.toObject())) {
|
|
|
|
JS_ReportError(cx, "CPOWToString called on an incompatible object");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RootedObject proxy(cx, &cpowValue.toObject());
|
|
|
|
FORWARD(toString, (cx, proxy, args));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::toString(JSContext* cx, HandleObject cpow, JS::CallArgs& args)
|
2014-05-29 01:05:23 +00:00
|
|
|
{
|
|
|
|
// Ask the other side to call its toString method. Update the callee so that
|
|
|
|
// it points to the CPOW and not to the synthesized CPOWToString function.
|
|
|
|
args.setCallee(ObjectValue(*cpow));
|
2014-07-01 00:50:58 +00:00
|
|
|
if (!callOrConstruct(cx, cpow, args, false))
|
2014-05-29 01:05:23 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!args.rval().isString())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
RootedString cpowResult(cx, args.rval().toString());
|
2014-07-05 15:30:54 +00:00
|
|
|
nsAutoJSString toStringResult;
|
2014-05-29 01:05:23 +00:00
|
|
|
if (!toStringResult.init(cx, cpowResult))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// We don't want to wrap toString() results for things like the location
|
|
|
|
// object, where toString() is supposed to return a URL and nothing else.
|
|
|
|
nsAutoString result;
|
|
|
|
if (toStringResult[0] == '[') {
|
|
|
|
result.AppendLiteral("[object CPOW ");
|
|
|
|
result += toStringResult;
|
|
|
|
result.AppendLiteral("]");
|
|
|
|
} else {
|
|
|
|
result += toStringResult;
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
JSString* str = JS_NewUCStringCopyN(cx, result.get(), result.Length());
|
2014-05-29 01:05:23 +00:00
|
|
|
if (!str)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
args.rval().setString(str);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-10 21:36:01 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::DOMQI(JSContext* cx, JS::HandleObject proxy, JS::CallArgs& args)
|
2015-03-10 21:36:01 +00:00
|
|
|
{
|
|
|
|
// Someone's calling us, handle nsISupports specially to avoid unnecessary
|
|
|
|
// CPOW traffic.
|
|
|
|
HandleValue id = args[0];
|
|
|
|
if (id.isObject()) {
|
|
|
|
RootedObject idobj(cx, &id.toObject());
|
|
|
|
nsCOMPtr<nsIJSID> jsid;
|
|
|
|
|
|
|
|
nsresult rv = UnwrapArg<nsIJSID>(idobj, getter_AddRefs(jsid));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
MOZ_ASSERT(jsid, "bad wrapJS");
|
2015-03-28 22:22:11 +00:00
|
|
|
const nsID* idptr = jsid->GetID();
|
2015-03-10 21:36:01 +00:00
|
|
|
if (idptr->Equals(NS_GET_IID(nsISupports))) {
|
|
|
|
args.rval().set(args.thisv());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Webidl-implemented DOM objects never have nsIClassInfo.
|
|
|
|
if (idptr->Equals(NS_GET_IID(nsIClassInfo)))
|
|
|
|
return Throw(cx, NS_ERROR_NO_INTERFACE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// It wasn't nsISupports, call into the other process to do the QI for us
|
|
|
|
// (since we don't know what other interfaces our object supports). Note
|
|
|
|
// that we have to use JS_GetPropertyDescriptor here to avoid infinite
|
|
|
|
// recursion back into CPOWDOMQI via WrapperOwner::get().
|
|
|
|
// We could stash the actual QI function on our own function object to avoid
|
|
|
|
// if we're called multiple times, but since we're transient, there's no
|
|
|
|
// point right now.
|
|
|
|
JS::Rooted<JSPropertyDescriptor> propDesc(cx);
|
|
|
|
if (!JS_GetPropertyDescriptor(cx, proxy, "QueryInterface", &propDesc))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!propDesc.value().isObject()) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("We didn't get QueryInterface off a node");
|
|
|
|
return Throw(cx, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
return JS_CallFunctionValue(cx, proxy, propDesc.value(), args, args.rval());
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
bool
|
2015-09-17 22:14:41 +00:00
|
|
|
WrapperOwner::get(JSContext* cx, HandleObject proxy, HandleValue receiver,
|
2014-10-07 09:29:02 +00:00
|
|
|
HandleId id, MutableHandleValue vp)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
2014-07-01 00:48:09 +00:00
|
|
|
|
2015-09-17 22:14:41 +00:00
|
|
|
JSVariant receiverVar;
|
|
|
|
if (!toVariant(cx, receiver, &receiverVar))
|
2014-07-01 00:48:09 +00:00
|
|
|
return false;
|
2014-05-16 23:40:36 +00:00
|
|
|
|
2014-10-07 09:29:02 +00:00
|
|
|
JSIDVariant idVar;
|
|
|
|
if (!toJSIDVariant(cx, id, &idVar))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
AuxCPOWData* data = AuxCPOWDataOf(proxy);
|
2015-03-10 21:36:01 +00:00
|
|
|
if (data->isDOMObject &&
|
|
|
|
idVar.type() == JSIDVariant::TnsString &&
|
|
|
|
idVar.get_nsString().EqualsLiteral("QueryInterface"))
|
|
|
|
{
|
|
|
|
// Handle QueryInterface on DOM Objects specially since we can assume
|
|
|
|
// certain things about their implementation.
|
|
|
|
RootedFunction qi(cx, JS_NewFunction(cx, CPOWDOMQI, 1, 0,
|
|
|
|
"QueryInterface"));
|
|
|
|
if (!qi)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
vp.set(ObjectValue(*JS_GetFunctionObject(qi)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
JSVariant val;
|
|
|
|
ReturnStatus status;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendGet(objId, receiverVar, idVar, &status, &val))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
2014-05-29 01:05:22 +00:00
|
|
|
LOG_STACK();
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
if (!ok(cx, status))
|
|
|
|
return false;
|
|
|
|
|
2014-05-29 01:05:23 +00:00
|
|
|
if (!fromVariant(cx, val, vp))
|
|
|
|
return false;
|
|
|
|
|
2014-10-07 09:29:02 +00:00
|
|
|
if (idVar.type() == JSIDVariant::TnsString &&
|
|
|
|
idVar.get_nsString().EqualsLiteral("toString")) {
|
2015-03-09 16:50:03 +00:00
|
|
|
RootedFunction toString(cx, JS_NewFunction(cx, CPOWToString, 0, 0,
|
|
|
|
"toString"));
|
2014-05-29 01:05:23 +00:00
|
|
|
if (!toString)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
RootedObject toStringObj(cx, JS_GetFunctionObject(toString));
|
|
|
|
|
|
|
|
if (!JS_DefineProperty(cx, toStringObj, "__cpow__", vp, JSPROP_PERMANENT | JSPROP_READONLY))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
vp.set(ObjectValue(*toStringObj));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::set(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::HandleValue v,
|
|
|
|
JS::HandleValue receiver, JS::ObjectOpResult& result) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
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
|
|
|
FORWARD(set, (cx, proxy, id, v, receiver, result));
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::set(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::HandleValue v,
|
|
|
|
JS::HandleValue receiver, JS::ObjectOpResult& result)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
2014-07-01 00:48:09 +00:00
|
|
|
|
2014-10-07 09:29:02 +00:00
|
|
|
JSIDVariant idVar;
|
|
|
|
if (!toJSIDVariant(cx, id, &idVar))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
JSVariant val;
|
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
|
|
|
if (!toVariant(cx, v, &val))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSVariant receiverVar;
|
|
|
|
if (!toVariant(cx, receiver, &receiverVar))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ReturnStatus status;
|
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
|
|
|
if (!SendSet(objId, idVar, val, receiverVar, &status))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
2014-05-29 01:05:22 +00:00
|
|
|
LOG_STACK();
|
|
|
|
|
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 ok(cx, status, result);
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::getOwnEnumerablePropertyKeys(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2014-10-09 03:01:55 +00:00
|
|
|
FORWARD(getOwnEnumerablePropertyKeys, (cx, proxy, props));
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::getOwnEnumerablePropertyKeys(JSContext* cx, HandleObject proxy, AutoIdVector& props)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2014-09-26 20:16:36 +00:00
|
|
|
return getPropertyKeys(cx, proxy, JSITER_OWNONLY, props);
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 18:40:04 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::preventExtensions(JSContext* cx, HandleObject proxy, ObjectOpResult& result) const
|
2014-10-21 18:40:04 +00:00
|
|
|
{
|
2015-02-04 18:01:01 +00:00
|
|
|
FORWARD(preventExtensions, (cx, proxy, result));
|
2014-10-21 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::preventExtensions(JSContext* cx, HandleObject proxy, ObjectOpResult& result)
|
2014-10-21 18:40:04 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
|
|
|
ReturnStatus status;
|
2015-02-04 18:01:01 +00:00
|
|
|
if (!SendPreventExtensions(objId, &status))
|
2014-10-21 18:40:04 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
|
|
|
LOG_STACK();
|
|
|
|
|
2015-02-04 18:01:01 +00:00
|
|
|
return ok(cx, status, result);
|
2014-10-21 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::isExtensible(JSContext* cx, HandleObject proxy, bool* extensible) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
FORWARD(isExtensible, (cx, proxy, extensible));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::isExtensible(JSContext* cx, HandleObject proxy, bool* extensible)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
|
|
|
ReturnStatus status;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendIsExtensible(objId, &status, extensible))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
2014-05-29 01:05:22 +00:00
|
|
|
LOG_STACK();
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
return ok(cx, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::call(JSContext* cx, HandleObject proxy, const CallArgs& args) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2014-07-01 00:50:58 +00:00
|
|
|
FORWARD(callOrConstruct, (cx, proxy, args, false));
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::construct(JSContext* cx, HandleObject proxy, const CallArgs& args) const
|
2014-07-01 00:50:58 +00:00
|
|
|
{
|
|
|
|
FORWARD(callOrConstruct, (cx, proxy, args, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::callOrConstruct(JSContext* cx, HandleObject proxy, const CallArgs& args,
|
2014-07-01 00:50:58 +00:00
|
|
|
bool construct)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
|
|
|
InfallibleTArray<JSParam> vals;
|
|
|
|
AutoValueVector outobjects(cx);
|
|
|
|
|
|
|
|
RootedValue v(cx);
|
|
|
|
for (size_t i = 0; i < args.length() + 2; i++) {
|
2014-07-01 00:50:58 +00:00
|
|
|
// The |this| value for constructors is a magic value that we won't be
|
|
|
|
// able to convert, so skip it.
|
|
|
|
if (i == 1 && construct)
|
|
|
|
v = UndefinedValue();
|
|
|
|
else
|
|
|
|
v = args.base()[i];
|
2014-05-16 23:40:36 +00:00
|
|
|
if (v.isObject()) {
|
|
|
|
RootedObject obj(cx, &v.toObject());
|
|
|
|
if (xpc::IsOutObject(cx, obj)) {
|
|
|
|
// Make sure it is not an in-out object.
|
|
|
|
bool found;
|
|
|
|
if (!JS_HasProperty(cx, obj, "value", &found))
|
|
|
|
return false;
|
|
|
|
if (found) {
|
|
|
|
JS_ReportError(cx, "in-out objects cannot be sent via CPOWs yet");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
vals.AppendElement(JSParam(void_t()));
|
|
|
|
if (!outobjects.append(ObjectValue(*obj)))
|
|
|
|
return false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSVariant val;
|
|
|
|
if (!toVariant(cx, v, &val))
|
|
|
|
return false;
|
|
|
|
vals.AppendElement(JSParam(val));
|
|
|
|
}
|
|
|
|
|
|
|
|
JSVariant result;
|
|
|
|
ReturnStatus status;
|
|
|
|
InfallibleTArray<JSParam> outparams;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendCallOrConstruct(objId, vals, construct, &status, &result, &outparams))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
2014-05-29 01:05:22 +00:00
|
|
|
|
|
|
|
LOG_STACK();
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
if (!ok(cx, status))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (outparams.Length() != outobjects.length())
|
|
|
|
return ipcfail(cx);
|
|
|
|
|
|
|
|
RootedObject obj(cx);
|
|
|
|
for (size_t i = 0; i < outparams.Length(); i++) {
|
|
|
|
// Don't bother doing anything for outparams that weren't set.
|
|
|
|
if (outparams[i].type() == JSParam::Tvoid_t)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Take the value the child process returned, and set it on the XPC
|
|
|
|
// object.
|
|
|
|
if (!fromVariant(cx, outparams[i], &v))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
obj = &outobjects[i].toObject();
|
|
|
|
if (!JS_SetProperty(cx, obj, "value", v))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fromVariant(cx, result, args.rval()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-11 00:15:40 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::hasInstance(JSContext* cx, HandleObject proxy, MutableHandleValue v, bool* bp) const
|
2014-09-11 00:15:40 +00:00
|
|
|
{
|
|
|
|
FORWARD(hasInstance, (cx, proxy, v, bp));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::hasInstance(JSContext* cx, HandleObject proxy, MutableHandleValue v, bool* bp)
|
2014-09-11 00:15:40 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
|
|
|
JSVariant vVar;
|
|
|
|
if (!toVariant(cx, v, &vVar))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ReturnStatus status;
|
|
|
|
JSVariant result;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendHasInstance(objId, vVar, &status, bp))
|
2014-09-11 00:15:40 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
|
|
|
LOG_STACK();
|
|
|
|
|
|
|
|
return ok(cx, status);
|
|
|
|
}
|
2014-05-16 23:40:36 +00:00
|
|
|
|
|
|
|
bool
|
2015-08-29 04:55:40 +00:00
|
|
|
CPOWProxyHandler::getBuiltinClass(JSContext* cx, HandleObject proxy,
|
|
|
|
js::ESClassValue* classValue) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2015-08-29 04:55:40 +00:00
|
|
|
FORWARD(getBuiltinClass, (cx, proxy, classValue));
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-08-29 04:55:40 +00:00
|
|
|
WrapperOwner::getBuiltinClass(JSContext* cx, HandleObject proxy,
|
|
|
|
js::ESClassValue* classValue)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
2015-08-29 04:55:40 +00:00
|
|
|
uint32_t cls = ESClass_Other;
|
|
|
|
ReturnStatus status;
|
|
|
|
if (!SendGetBuiltinClass(objId, &status, &cls))
|
|
|
|
return ipcfail(cx);
|
|
|
|
*classValue = ESClassValue(cls);
|
2014-05-16 23:40:36 +00:00
|
|
|
|
2014-05-29 01:05:22 +00:00
|
|
|
LOG_STACK();
|
|
|
|
|
2015-08-29 04:55:40 +00:00
|
|
|
return ok(cx, status);
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 08:10:24 +00:00
|
|
|
bool
|
|
|
|
CPOWProxyHandler::isArray(JSContext* cx, HandleObject proxy,
|
|
|
|
IsArrayAnswer* answer) const
|
|
|
|
{
|
|
|
|
FORWARD(isArray, (cx, proxy, answer));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WrapperOwner::isArray(JSContext* cx, HandleObject proxy, IsArrayAnswer* answer)
|
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
|
|
|
uint32_t ans;
|
|
|
|
ReturnStatus status;
|
|
|
|
if (!SendIsArray(objId, &status, &ans))
|
|
|
|
return ipcfail(cx);
|
|
|
|
|
|
|
|
LOG_STACK();
|
|
|
|
|
|
|
|
*answer = IsArrayAnswer(ans);
|
|
|
|
MOZ_ASSERT(*answer == IsArrayAnswer::Array ||
|
|
|
|
*answer == IsArrayAnswer::NotArray ||
|
|
|
|
*answer == IsArrayAnswer::RevokedProxy);
|
|
|
|
|
|
|
|
return ok(cx, status);
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
const char*
|
|
|
|
CPOWProxyHandler::className(JSContext* cx, HandleObject proxy) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner* parent = OwnerOf(proxy);
|
2014-05-16 23:40:36 +00:00
|
|
|
if (!parent->active())
|
|
|
|
return "<dead CPOW>";
|
|
|
|
return parent->className(cx, proxy);
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
const char*
|
|
|
|
WrapperOwner::className(JSContext* cx, HandleObject proxy)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
AuxCPOWData* data = AuxCPOWDataOf(proxy);
|
2015-03-27 20:12:37 +00:00
|
|
|
if (data->className.IsEmpty()) {
|
|
|
|
ObjectId objId = idOf(proxy);
|
2014-05-16 23:40:36 +00:00
|
|
|
|
2015-03-27 20:12:37 +00:00
|
|
|
if (!SendClassName(objId, &data->className))
|
|
|
|
return "<error>";
|
2014-05-16 23:40:36 +00:00
|
|
|
|
2015-03-27 20:12:37 +00:00
|
|
|
LOG_STACK();
|
|
|
|
}
|
2014-05-29 01:05:22 +00:00
|
|
|
|
2015-03-27 20:12:37 +00:00
|
|
|
return data->className.get();
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
2015-02-10 15:29:41 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::getPrototype(JSContext* cx, HandleObject proxy, MutableHandleObject objp) const
|
2015-02-10 15:29:41 +00:00
|
|
|
{
|
2015-02-05 22:36:50 +00:00
|
|
|
FORWARD(getPrototype, (cx, proxy, objp));
|
2015-02-10 15:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::getPrototype(JSContext* cx, HandleObject proxy, MutableHandleObject objp)
|
2015-02-10 15:29:41 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
|
|
|
ObjectOrNullVariant val;
|
|
|
|
ReturnStatus status;
|
2015-02-05 22:36:50 +00:00
|
|
|
if (!SendGetPrototype(objId, &status, &val))
|
2015-02-10 15:29:41 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
|
|
|
LOG_STACK();
|
|
|
|
|
|
|
|
if (!ok(cx, status))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
objp.set(fromObjectOrNullVariant(cx, val));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-01 15:22:15 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::regexp_toShared(JSContext* cx, HandleObject proxy, RegExpGuard* g) const
|
2014-10-01 15:22:15 +00:00
|
|
|
{
|
|
|
|
FORWARD(regexp_toShared, (cx, proxy, g));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::regexp_toShared(JSContext* cx, HandleObject proxy, RegExpGuard* g)
|
2014-10-01 15:22:15 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
|
|
|
ReturnStatus status;
|
|
|
|
nsString source;
|
|
|
|
unsigned flags = 0;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendRegExpToShared(objId, &status, &source, &flags))
|
2014-10-01 15:22:15 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
|
|
|
LOG_STACK();
|
|
|
|
|
|
|
|
if (!ok(cx, status))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
RootedObject regexp(cx);
|
|
|
|
RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
|
|
|
|
regexp = JS_NewUCRegExpObject(cx, global, source.get(), source.Length(), flags);
|
|
|
|
if (!regexp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return js::RegExpToSharedNonInline(cx, regexp, g);
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
void
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
AuxCPOWData* aux = AuxCPOWDataOf(proxy);
|
2014-11-06 01:52:38 +00:00
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
OwnerOf(proxy)->drop(proxy);
|
2014-11-05 01:39:34 +00:00
|
|
|
|
|
|
|
if (aux)
|
|
|
|
delete aux;
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 11:54:11 +00:00
|
|
|
void
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::objectMoved(JSObject* proxy, const JSObject* old) const
|
2014-09-24 11:54:11 +00:00
|
|
|
{
|
|
|
|
OwnerOf(proxy)->updatePointer(proxy, old);
|
|
|
|
}
|
|
|
|
|
2014-09-10 22:52:36 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::isCallable(JSObject* proxy) const
|
2014-09-10 22:52:36 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
AuxCPOWData* aux = AuxCPOWDataOf(proxy);
|
2014-11-05 01:39:34 +00:00
|
|
|
return aux->isCallable;
|
2014-09-10 22:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
CPOWProxyHandler::isConstructor(JSObject* proxy) const
|
2014-09-25 11:13:29 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
AuxCPOWData* aux = AuxCPOWDataOf(proxy);
|
2014-11-05 01:39:34 +00:00
|
|
|
return aux->isConstructor;
|
2014-09-10 22:52:36 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:37 +00:00
|
|
|
void
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::drop(JSObject* obj)
|
2014-05-16 23:40:37 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(obj);
|
|
|
|
|
|
|
|
cpows_.remove(objId);
|
|
|
|
if (active())
|
2015-11-02 05:53:26 +00:00
|
|
|
Unused << SendDropObject(objId);
|
2014-05-16 23:40:37 +00:00
|
|
|
decref();
|
|
|
|
}
|
|
|
|
|
2014-09-24 11:54:11 +00:00
|
|
|
void
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::updatePointer(JSObject* obj, const JSObject* old)
|
2014-09-24 11:54:11 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOfUnchecked(obj);
|
|
|
|
MOZ_ASSERT(findCPOWById(objId) == old);
|
|
|
|
cpows_.add(objId, obj);
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
bool
|
|
|
|
WrapperOwner::init()
|
|
|
|
{
|
|
|
|
if (!JavaScriptShared::init())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::getPropertyKeys(JSContext* cx, HandleObject proxy, uint32_t flags, AutoIdVector& props)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(proxy);
|
|
|
|
|
|
|
|
ReturnStatus status;
|
2014-10-16 16:39:38 +00:00
|
|
|
InfallibleTArray<JSIDVariant> ids;
|
|
|
|
if (!SendGetPropertyKeys(objId, flags, &status, &ids))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
2014-05-29 01:05:22 +00:00
|
|
|
|
|
|
|
LOG_STACK();
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
if (!ok(cx, status))
|
|
|
|
return false;
|
|
|
|
|
2014-10-16 16:39:38 +00:00
|
|
|
for (size_t i = 0; i < ids.Length(); i++) {
|
|
|
|
RootedId id(cx);
|
|
|
|
if (!fromJSIDVariant(cx, ids[i], &id))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
2014-10-16 16:39:38 +00:00
|
|
|
if (!props.append(id))
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace jsipc {
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
IsCPOW(JSObject* obj)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
return IsProxy(obj) && GetProxyHandler(obj) == &CPOWProxyHandler::singleton;
|
|
|
|
}
|
|
|
|
|
2014-07-10 23:47:04 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
IsWrappedCPOW(JSObject* obj)
|
2014-07-10 23:47:04 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
JSObject* unwrapped = js::UncheckedUnwrap(obj, true);
|
2014-07-10 23:47:04 +00:00
|
|
|
if (!unwrapped)
|
|
|
|
return false;
|
|
|
|
return IsCPOW(unwrapped);
|
|
|
|
}
|
|
|
|
|
2014-11-05 01:40:08 +00:00
|
|
|
void
|
2015-03-28 22:22:11 +00:00
|
|
|
GetWrappedCPOWTag(JSObject* obj, nsACString& out)
|
2014-11-05 01:40:08 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
JSObject* unwrapped = js::UncheckedUnwrap(obj, true);
|
2014-11-05 01:40:08 +00:00
|
|
|
MOZ_ASSERT(IsCPOW(unwrapped));
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
AuxCPOWData* aux = AuxCPOWDataOf(unwrapped);
|
2014-11-05 01:40:08 +00:00
|
|
|
if (aux)
|
|
|
|
out = aux->objectTag;
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
nsresult
|
2015-03-28 22:22:11 +00:00
|
|
|
InstanceOf(JSObject* proxy, const nsID* id, bool* bp)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner* parent = OwnerOf(proxy);
|
2014-05-16 23:40:36 +00:00
|
|
|
if (!parent->active())
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
return parent->instanceOf(proxy, id, bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-10-23 23:31:54 +00:00
|
|
|
DOMInstanceOf(JSContext* cx, JSObject* proxyArg, int prototypeID, int depth, bool* bp)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2015-10-23 23:31:54 +00:00
|
|
|
RootedObject proxy(cx, proxyArg);
|
2014-05-16 23:40:36 +00:00
|
|
|
FORWARD(domInstanceOf, (cx, proxy, prototypeID, depth, bp));
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace jsipc */
|
|
|
|
} /* namespace mozilla */
|
|
|
|
|
|
|
|
nsresult
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::instanceOf(JSObject* obj, const nsID* id, bool* bp)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(obj);
|
|
|
|
|
|
|
|
JSIID iid;
|
|
|
|
ConvertID(*id, &iid);
|
|
|
|
|
|
|
|
ReturnStatus status;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendInstanceOf(objId, iid, &status, bp))
|
2014-05-16 23:40:36 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
if (status.type() != ReturnStatus::TReturnSuccess)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::domInstanceOf(JSContext* cx, JSObject* obj, int prototypeID, int depth, bool* bp)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
ObjectId objId = idOf(obj);
|
|
|
|
|
|
|
|
ReturnStatus status;
|
2014-10-08 04:32:45 +00:00
|
|
|
if (!SendDOMInstanceOf(objId, prototypeID, depth, &status, bp))
|
2014-05-16 23:40:36 +00:00
|
|
|
return ipcfail(cx);
|
|
|
|
|
2014-05-29 01:05:22 +00:00
|
|
|
LOG_STACK();
|
|
|
|
|
2014-05-16 23:40:36 +00:00
|
|
|
return ok(cx, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WrapperOwner::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
inactive_ = true;
|
2015-01-16 17:56:30 +00:00
|
|
|
|
|
|
|
objects_.clear();
|
|
|
|
unwaivedObjectIds_.clear();
|
|
|
|
waivedObjectIds_.clear();
|
2014-05-16 23:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::ipcfail(JSContext* cx)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
2015-06-24 00:52:01 +00:00
|
|
|
JS_ReportError(cx, "cross-process JS call failed");
|
2014-05-16 23:40:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::ok(JSContext* cx, const ReturnStatus& status)
|
2014-05-16 23:40:36 +00:00
|
|
|
{
|
|
|
|
if (status.type() == ReturnStatus::TReturnSuccess)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (status.type() == ReturnStatus::TReturnStopIteration)
|
|
|
|
return JS_ThrowStopIteration(cx);
|
|
|
|
|
|
|
|
RootedValue exn(cx);
|
|
|
|
if (!fromVariant(cx, status.get_ReturnException().exn(), &exn))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JS_SetPendingException(cx, exn);
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-16 23:40:37 +00:00
|
|
|
|
2015-01-30 17:37:07 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::ok(JSContext* cx, const ReturnStatus& status, ObjectOpResult& result)
|
2015-01-30 17:37:07 +00:00
|
|
|
{
|
|
|
|
if (status.type() == ReturnStatus::TReturnObjectOpResult)
|
|
|
|
return result.fail(status.get_ReturnObjectOpResult().code());
|
|
|
|
if (!ok(cx, status))
|
|
|
|
return false;
|
|
|
|
return result.succeed();
|
|
|
|
}
|
|
|
|
|
2014-11-05 01:39:34 +00:00
|
|
|
static RemoteObject
|
2015-03-28 22:22:11 +00:00
|
|
|
MakeRemoteObject(JSContext* cx, ObjectId id, HandleObject obj)
|
2014-11-05 01:39:34 +00:00
|
|
|
{
|
2014-11-05 01:40:08 +00:00
|
|
|
nsCString objectTag;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRemoteTagService> service =
|
|
|
|
do_GetService("@mozilla.org/addons/remote-tag-service;1");
|
|
|
|
if (service) {
|
|
|
|
RootedValue objVal(cx, ObjectValue(*obj));
|
|
|
|
service->GetRemoteObjectTag(objVal, objectTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
return RemoteObject(id.serialize(),
|
|
|
|
JS::IsCallable(obj),
|
|
|
|
JS::IsConstructor(obj),
|
2015-03-10 21:36:01 +00:00
|
|
|
dom::IsDOMObject(obj),
|
2014-11-05 01:40:08 +00:00
|
|
|
objectTag);
|
2014-11-05 01:39:34 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:37 +00:00
|
|
|
bool
|
2015-03-28 22:22:11 +00:00
|
|
|
WrapperOwner::toObjectVariant(JSContext* cx, JSObject* objArg, ObjectVariant* objVarp)
|
2014-05-16 23:40:37 +00:00
|
|
|
{
|
2014-05-16 23:40:37 +00:00
|
|
|
RootedObject obj(cx, objArg);
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(obj);
|
2014-05-16 23:40:37 +00:00
|
|
|
|
|
|
|
// We always save objects unwrapped in the CPOW table. If we stored
|
|
|
|
// wrappers, then the wrapper might be GCed while the target remained alive.
|
|
|
|
// Whenever operating on an object that comes from the table, we wrap it
|
|
|
|
// in findObjectById.
|
2014-09-25 11:13:29 +00:00
|
|
|
unsigned wrapperFlags = 0;
|
2014-12-19 01:34:24 +00:00
|
|
|
obj = js::UncheckedUnwrap(obj, true, &wrapperFlags);
|
2014-05-16 23:40:37 +00:00
|
|
|
if (obj && IsCPOW(obj) && OwnerOf(obj) == this) {
|
2014-09-25 11:13:29 +00:00
|
|
|
*objVarp = LocalObject(idOf(obj).serialize());
|
2014-05-16 23:40:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-09-25 11:13:29 +00:00
|
|
|
bool waiveXray = wrapperFlags & xpc::WrapperFactory::WAIVE_XRAY_WRAPPER_FLAG;
|
2014-05-16 23:40:37 +00:00
|
|
|
|
2014-09-25 11:13:29 +00:00
|
|
|
ObjectId id = objectIdMap(waiveXray).find(obj);
|
2014-09-25 11:13:29 +00:00
|
|
|
if (!id.isNull()) {
|
2014-09-25 11:13:29 +00:00
|
|
|
MOZ_ASSERT(id.hasXrayWaiver() == waiveXray);
|
2014-11-05 01:40:08 +00:00
|
|
|
*objVarp = MakeRemoteObject(cx, id, obj);
|
2014-05-16 23:40:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:40:37 +00:00
|
|
|
// Need to call PreserveWrapper on |obj| in case it's a reflector.
|
|
|
|
// FIXME: What if it's an XPCWrappedNative?
|
|
|
|
if (mozilla::dom::IsDOMObject(obj))
|
|
|
|
mozilla::dom::TryPreserveWrapper(obj);
|
|
|
|
|
2014-09-25 11:13:29 +00:00
|
|
|
id = ObjectId(nextSerialNumber_++, waiveXray);
|
2014-05-16 23:40:37 +00:00
|
|
|
if (!objects_.add(id, obj))
|
|
|
|
return false;
|
2014-09-25 11:13:29 +00:00
|
|
|
if (!objectIdMap(waiveXray).add(cx, obj, id))
|
2014-05-16 23:40:37 +00:00
|
|
|
return false;
|
|
|
|
|
2014-11-05 01:40:08 +00:00
|
|
|
*objVarp = MakeRemoteObject(cx, id, obj);
|
2014-05-16 23:40:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
JSObject*
|
|
|
|
WrapperOwner::fromObjectVariant(JSContext* cx, ObjectVariant objVar)
|
2014-05-16 23:40:37 +00:00
|
|
|
{
|
|
|
|
if (objVar.type() == ObjectVariant::TRemoteObject) {
|
|
|
|
return fromRemoteObjectVariant(cx, objVar.get_RemoteObject());
|
|
|
|
} else {
|
|
|
|
return fromLocalObjectVariant(cx, objVar.get_LocalObject());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
JSObject*
|
|
|
|
WrapperOwner::fromRemoteObjectVariant(JSContext* cx, RemoteObject objVar)
|
2014-05-16 23:40:37 +00:00
|
|
|
{
|
2014-09-25 11:13:29 +00:00
|
|
|
ObjectId objId = ObjectId::deserialize(objVar.serializedId());
|
2014-05-16 23:40:37 +00:00
|
|
|
RootedObject obj(cx, findCPOWById(objId));
|
2014-09-13 00:41:18 +00:00
|
|
|
if (!obj) {
|
2014-05-16 23:40:37 +00:00
|
|
|
|
2014-09-13 00:41:18 +00:00
|
|
|
// All CPOWs live in the privileged junk scope.
|
|
|
|
RootedObject junkScope(cx, xpc::PrivilegedJunkScope());
|
|
|
|
JSAutoCompartment ac(cx, junkScope);
|
|
|
|
RootedValue v(cx, UndefinedValue());
|
2015-02-05 22:36:50 +00:00
|
|
|
// We need to setLazyProto for the getPrototype hook.
|
2015-02-10 15:29:41 +00:00
|
|
|
ProxyOptions options;
|
|
|
|
options.setLazyProto(true);
|
2014-09-13 00:41:18 +00:00
|
|
|
obj = NewProxyObject(cx,
|
|
|
|
&CPOWProxyHandler::singleton,
|
|
|
|
v,
|
|
|
|
nullptr,
|
2015-02-10 15:29:41 +00:00
|
|
|
options);
|
2014-09-13 00:41:18 +00:00
|
|
|
if (!obj)
|
|
|
|
return nullptr;
|
2014-05-16 23:40:37 +00:00
|
|
|
|
2014-09-13 00:41:18 +00:00
|
|
|
if (!cpows_.add(objId, obj))
|
|
|
|
return nullptr;
|
2014-05-16 23:40:37 +00:00
|
|
|
|
2014-09-13 00:41:18 +00:00
|
|
|
// Incref once we know the decref will be called.
|
|
|
|
incref();
|
2014-05-16 23:40:37 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
AuxCPOWData* aux = new AuxCPOWData(objId,
|
2014-11-05 01:40:08 +00:00
|
|
|
objVar.isCallable(),
|
|
|
|
objVar.isConstructor(),
|
2015-03-10 21:36:01 +00:00
|
|
|
objVar.isDOMObject(),
|
2014-11-05 01:40:08 +00:00
|
|
|
objVar.objectTag());
|
2014-11-05 01:39:34 +00:00
|
|
|
|
2014-09-13 00:41:18 +00:00
|
|
|
SetProxyExtra(obj, 0, PrivateValue(this));
|
2014-11-05 01:39:34 +00:00
|
|
|
SetProxyExtra(obj, 1, PrivateValue(aux));
|
2014-09-13 00:41:18 +00:00
|
|
|
}
|
2014-05-16 23:40:37 +00:00
|
|
|
|
2014-09-13 00:41:18 +00:00
|
|
|
if (!JS_WrapObject(cx, &obj))
|
|
|
|
return nullptr;
|
2014-05-16 23:40:37 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
JSObject*
|
|
|
|
WrapperOwner::fromLocalObjectVariant(JSContext* cx, LocalObject objVar)
|
2014-05-16 23:40:37 +00:00
|
|
|
{
|
2014-09-25 11:13:29 +00:00
|
|
|
ObjectId id = ObjectId::deserialize(objVar.serializedId());
|
2014-05-16 23:40:37 +00:00
|
|
|
Rooted<JSObject*> obj(cx, findObjectById(cx, id));
|
|
|
|
if (!obj)
|
|
|
|
return nullptr;
|
|
|
|
if (!JS_WrapObject(cx, &obj))
|
|
|
|
return nullptr;
|
|
|
|
return obj;
|
|
|
|
}
|