2013-07-03 07:24:32 +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 "JavaScriptChild.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2013-08-01 23:45:17 +00:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-07-03 07:24:32 +00:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "xpcprivate.h"
|
|
|
|
#include "jsfriendapi.h"
|
|
|
|
#include "nsCxPusher.h"
|
|
|
|
|
|
|
|
using namespace JS;
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::jsipc;
|
|
|
|
|
|
|
|
using mozilla::AutoSafeJSContext;
|
|
|
|
|
|
|
|
JavaScriptChild::JavaScriptChild(JSRuntime *rt)
|
|
|
|
: lastId_(0),
|
|
|
|
rt_(rt)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Trace(JSTracer *trc, void *data)
|
|
|
|
{
|
|
|
|
reinterpret_cast<JavaScriptChild *>(data)->trace(trc);
|
|
|
|
}
|
|
|
|
|
|
|
|
JavaScriptChild::~JavaScriptChild()
|
|
|
|
{
|
|
|
|
JS_RemoveExtraGCRootsTracer(rt_, Trace, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JavaScriptChild::trace(JSTracer *trc)
|
|
|
|
{
|
|
|
|
objects_.trace(trc);
|
|
|
|
ids_.trace(trc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::init()
|
|
|
|
{
|
|
|
|
if (!JavaScriptShared::init())
|
|
|
|
return false;
|
|
|
|
if (!ids_.init())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JS_AddExtraGCRootsTracer(rt_, Trace, this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::RecvDropObject(const ObjectId &objId)
|
|
|
|
{
|
|
|
|
JSObject *obj = findObject(objId);
|
|
|
|
if (obj) {
|
|
|
|
ids_.remove(obj);
|
|
|
|
objects_.remove(objId);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::makeId(JSContext *cx, JSObject *obj, ObjectId *idp)
|
|
|
|
{
|
|
|
|
if (!obj) {
|
|
|
|
*idp = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectId id = ids_.find(obj);
|
|
|
|
if (id) {
|
|
|
|
*idp = id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
id = ++lastId_;
|
|
|
|
if (id > MAX_CPOW_IDS) {
|
|
|
|
JS_ReportError(cx, "CPOW id limit reached");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
id <<= OBJECT_EXTRA_BITS;
|
|
|
|
if (JS_ObjectIsCallable(cx, obj))
|
|
|
|
id |= OBJECT_IS_CALLABLE;
|
|
|
|
|
|
|
|
if (!objects_.add(id, obj))
|
|
|
|
return false;
|
2013-08-01 10:21:44 +00:00
|
|
|
if (!ids_.add(cx, obj, id))
|
2013-07-03 07:24:32 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
*idp = id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *
|
|
|
|
JavaScriptChild::unwrap(JSContext *cx, ObjectId id)
|
|
|
|
{
|
|
|
|
JSObject *obj = findObject(id);
|
|
|
|
MOZ_ASSERT(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::fail(JSContext *cx, ReturnStatus *rs)
|
|
|
|
{
|
|
|
|
// By default, we set |undefined| unless we can get a more meaningful
|
|
|
|
// exception.
|
2013-09-30 19:20:51 +00:00
|
|
|
*rs = ReturnStatus(ReturnException(JSVariant(void_t())));
|
2013-07-03 07:24:32 +00:00
|
|
|
|
|
|
|
// Note we always return true from this function, since this propagates
|
|
|
|
// to the IPC code, and we don't want a JS failure to cause the death
|
|
|
|
// of the child process.
|
|
|
|
|
2013-09-19 07:54:01 +00:00
|
|
|
RootedValue exn(cx);
|
2013-07-03 07:24:32 +00:00
|
|
|
if (!JS_GetPendingException(cx, &exn))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If we don't clear the pending exception, JS will try to wrap it as it
|
|
|
|
// leaves the current compartment. Since there is no previous compartment,
|
|
|
|
// that would crash.
|
|
|
|
JS_ClearPendingException(cx);
|
|
|
|
|
2013-09-30 19:20:51 +00:00
|
|
|
if (JS_IsStopIteration(exn)) {
|
|
|
|
*rs = ReturnStatus(ReturnStopIteration());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-12 05:02:24 +00:00
|
|
|
// If this fails, we still don't want to exit. Just return an invalid
|
|
|
|
// exception.
|
|
|
|
(void) toVariant(cx, exn, &rs->get_ReturnException().exn());
|
2013-07-03 07:24:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::ok(ReturnStatus *rs)
|
|
|
|
{
|
2013-09-30 19:20:51 +00:00
|
|
|
*rs = ReturnStatus(ReturnSuccess());
|
2013-07-03 07:24:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-11 15:23:34 +00:00
|
|
|
JavaScriptChild::AnswerPreventExtensions(const ObjectId &objId, ReturnStatus *rs)
|
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
if (!JS_PreventExtensions(cx, obj))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
EmptyDesc(PPropertyDescriptor *desc)
|
|
|
|
{
|
|
|
|
desc->objId() = 0;
|
|
|
|
desc->attrs() = 0;
|
|
|
|
desc->shortid() = 0;
|
|
|
|
desc->value() = void_t();
|
|
|
|
desc->getter() = 0;
|
|
|
|
desc->setter() = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::AnswerGetPropertyDescriptor(const ObjectId &objId, const nsString &id,
|
|
|
|
const uint32_t &flags, ReturnStatus *rs,
|
|
|
|
PPropertyDescriptor *out)
|
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
EmptyDesc(out);
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
|
|
|
RootedId internedId(cx);
|
|
|
|
if (!convertGeckoStringToId(cx, id, &internedId))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
2013-04-30 17:29:40 +00:00
|
|
|
Rooted<JSPropertyDescriptor> desc(cx);
|
2013-08-12 11:09:14 +00:00
|
|
|
if (!JS_GetPropertyDescriptorById(cx, obj, internedId, flags, &desc))
|
2013-07-11 15:23:34 +00:00
|
|
|
return fail(cx, rs);
|
|
|
|
|
2013-04-30 17:29:40 +00:00
|
|
|
if (!desc.object())
|
2013-07-11 15:23:34 +00:00
|
|
|
return ok(rs);
|
|
|
|
|
|
|
|
if (!fromDescriptor(cx, desc, out))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::AnswerGetOwnPropertyDescriptor(const ObjectId &objId, const nsString &id,
|
|
|
|
const uint32_t &flags, ReturnStatus *rs,
|
|
|
|
PPropertyDescriptor *out)
|
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
EmptyDesc(out);
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
|
|
|
RootedId internedId(cx);
|
|
|
|
if (!convertGeckoStringToId(cx, id, &internedId))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
2013-04-30 17:29:40 +00:00
|
|
|
Rooted<JSPropertyDescriptor> desc(cx);
|
2013-08-12 11:09:14 +00:00
|
|
|
if (!JS_GetPropertyDescriptorById(cx, obj, internedId, flags, &desc))
|
2013-07-11 15:23:34 +00:00
|
|
|
return fail(cx, rs);
|
|
|
|
|
2013-04-30 17:29:40 +00:00
|
|
|
if (desc.object() != obj)
|
2013-07-11 15:23:34 +00:00
|
|
|
return ok(rs);
|
|
|
|
|
|
|
|
if (!fromDescriptor(cx, desc, out))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::AnswerDefineProperty(const ObjectId &objId, const nsString &id,
|
|
|
|
const PPropertyDescriptor &descriptor, ReturnStatus *rs)
|
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
|
|
|
RootedId internedId(cx);
|
|
|
|
if (!convertGeckoStringToId(cx, id, &internedId))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
2013-08-07 23:15:57 +00:00
|
|
|
Rooted<JSPropertyDescriptor> desc(cx);
|
2013-04-30 17:29:40 +00:00
|
|
|
if (!toDescriptor(cx, descriptor, &desc))
|
2013-07-11 15:23:34 +00:00
|
|
|
return false;
|
|
|
|
|
2013-08-07 23:15:57 +00:00
|
|
|
if (!js::CheckDefineProperty(cx, obj, internedId, desc.value(), desc.getter(),
|
|
|
|
desc.setter(), desc.attributes()))
|
|
|
|
{
|
|
|
|
return fail(cx, rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JS_DefinePropertyById(cx, obj, internedId, desc.value(), desc.getter(),
|
|
|
|
desc.setter(), desc.attributes()))
|
2013-07-11 15:23:34 +00:00
|
|
|
{
|
|
|
|
return fail(cx, rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::AnswerDelete(const ObjectId &objId, const nsString &id, ReturnStatus *rs,
|
|
|
|
bool *success)
|
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
2013-07-17 13:27:49 +00:00
|
|
|
*success = false;
|
|
|
|
|
2013-07-11 15:23:34 +00:00
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
|
|
|
RootedId internedId(cx);
|
|
|
|
if (!convertGeckoStringToId(cx, id, &internedId))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
2013-08-05 13:01:53 +00:00
|
|
|
if (!JS_DeletePropertyById2(cx, obj, internedId, success))
|
2013-07-11 15:23:34 +00:00
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::AnswerHas(const ObjectId &objId, const nsString &id, ReturnStatus *rs, bool *bp)
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
2013-07-17 13:27:49 +00:00
|
|
|
*bp = false;
|
|
|
|
|
2013-07-03 07:24:32 +00:00
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
|
|
|
RootedId internedId(cx);
|
|
|
|
if (!convertGeckoStringToId(cx, id, &internedId))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
bool found;
|
2013-07-03 07:24:32 +00:00
|
|
|
if (!JS_HasPropertyById(cx, obj, internedId, &found))
|
|
|
|
return fail(cx, rs);
|
|
|
|
*bp = !!found;
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-11 15:23:34 +00:00
|
|
|
JavaScriptChild::AnswerHasOwn(const ObjectId &objId, const nsString &id, ReturnStatus *rs, bool *bp)
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
2013-07-17 13:27:49 +00:00
|
|
|
*bp = false;
|
|
|
|
|
2013-07-03 07:24:32 +00:00
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
|
|
|
RootedId internedId(cx);
|
|
|
|
if (!convertGeckoStringToId(cx, id, &internedId))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
2013-08-12 11:09:14 +00:00
|
|
|
Rooted<JSPropertyDescriptor> desc(cx);
|
2013-07-03 07:24:32 +00:00
|
|
|
if (!JS_GetPropertyDescriptorById(cx, obj, internedId, 0, &desc))
|
|
|
|
return fail(cx, rs);
|
2013-08-12 11:09:14 +00:00
|
|
|
*bp = (desc.object() == obj);
|
2013-07-03 07:24:32 +00:00
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-11 15:23:34 +00:00
|
|
|
JavaScriptChild::AnswerGet(const ObjectId &objId, const ObjectId &receiverId, const nsString &id,
|
|
|
|
ReturnStatus *rs, JSVariant *result)
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
2013-07-10 22:05:39 +00:00
|
|
|
// The outparam will be written to the buffer, so it must be set even if
|
|
|
|
// the parent won't read it.
|
2013-07-11 15:23:34 +00:00
|
|
|
*result = void_t();
|
|
|
|
|
2013-07-03 07:24:32 +00:00
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
RootedObject receiver(cx, findObject(receiverId));
|
|
|
|
if (!receiver)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
|
|
|
RootedId internedId(cx);
|
|
|
|
if (!convertGeckoStringToId(cx, id, &internedId))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
2013-10-12 05:02:24 +00:00
|
|
|
JS::RootedValue val(cx);
|
2013-07-03 07:24:32 +00:00
|
|
|
if (!JS_ForwardGetPropertyTo(cx, obj, internedId, receiver, &val))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
if (!toVariant(cx, val, result))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-11 15:23:34 +00:00
|
|
|
JavaScriptChild::AnswerSet(const ObjectId &objId, const ObjectId &receiverId, const nsString &id,
|
|
|
|
const bool &strict, const JSVariant &value, ReturnStatus *rs,
|
|
|
|
JSVariant *result)
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
// The outparam will be written to the buffer, so it must be set even if
|
|
|
|
// the parent won't read it.
|
|
|
|
*result = void_t();
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
RootedObject receiver(cx, findObject(receiverId));
|
|
|
|
if (!receiver)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
|
|
|
RootedId internedId(cx);
|
|
|
|
if (!convertGeckoStringToId(cx, id, &internedId))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
MOZ_ASSERT(obj == receiver);
|
|
|
|
|
|
|
|
RootedValue val(cx);
|
|
|
|
if (!toValue(cx, value, &val))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
2013-07-26 09:00:38 +00:00
|
|
|
if (!JS_SetPropertyById(cx, obj, internedId, val))
|
2013-07-03 07:24:32 +00:00
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
if (!toVariant(cx, val, result))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-11 15:23:34 +00:00
|
|
|
JavaScriptChild::AnswerIsExtensible(const ObjectId &objId, ReturnStatus *rs, bool *result)
|
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
*result = false;
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
bool extensible;
|
2013-07-11 15:23:34 +00:00
|
|
|
if (!JS_IsExtensible(cx, obj, &extensible))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
*result = !!extensible;
|
2013-07-17 13:27:49 +00:00
|
|
|
return ok(rs);
|
2013-07-11 15:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::AnswerCall(const ObjectId &objId, const nsTArray<JSParam> &argv, ReturnStatus *rs,
|
|
|
|
JSVariant *result, nsTArray<JSParam> *outparams)
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
// The outparam will be written to the buffer, so it must be set even if
|
|
|
|
// the parent won't read it.
|
|
|
|
*result = void_t();
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MOZ_ASSERT(argv.Length() >= 2);
|
|
|
|
|
|
|
|
RootedValue objv(cx);
|
|
|
|
if (!toValue(cx, argv[0], &objv))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, &objv.toObject());
|
|
|
|
|
|
|
|
*result = JSVariant(void_t());
|
|
|
|
|
2013-07-11 15:23:34 +00:00
|
|
|
AutoValueVector vals(cx);
|
|
|
|
AutoValueVector outobjects(cx);
|
2013-07-03 07:24:32 +00:00
|
|
|
for (size_t i = 0; i < argv.Length(); i++) {
|
|
|
|
if (argv[i].type() == JSParam::Tvoid_t) {
|
|
|
|
// This is an outparam.
|
|
|
|
JSCompartment *compartment = js::GetContextCompartment(cx);
|
|
|
|
RootedObject global(cx, JS_GetGlobalForCompartmentOrNull(cx, compartment));
|
|
|
|
RootedObject obj(cx, xpc::NewOutObject(cx, global));
|
|
|
|
if (!obj)
|
|
|
|
return fail(cx, rs);
|
|
|
|
if (!outobjects.append(ObjectValue(*obj)))
|
|
|
|
return fail(cx, rs);
|
|
|
|
if (!vals.append(ObjectValue(*obj)))
|
|
|
|
return fail(cx, rs);
|
|
|
|
} else {
|
|
|
|
RootedValue v(cx);
|
|
|
|
if (!toValue(cx, argv[i].get_JSVariant(), &v))
|
|
|
|
return fail(cx, rs);
|
|
|
|
if (!vals.append(v))
|
|
|
|
return fail(cx, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 07:40:01 +00:00
|
|
|
RootedValue rval(cx);
|
2013-10-28 11:59:04 +00:00
|
|
|
{
|
|
|
|
AutoSaveContextOptions asco(cx);
|
|
|
|
ContextOptionsRef(cx).setDontReportUncaught(true);
|
2013-07-03 07:24:32 +00:00
|
|
|
|
2014-02-11 10:59:16 +00:00
|
|
|
HandleValueArray args = HandleValueArray::subarray(vals, 2, vals.length() - 2);
|
|
|
|
bool success = JS::Call(cx, vals[1], vals[0], args, &rval);
|
2013-10-28 11:59:04 +00:00
|
|
|
if (!success)
|
|
|
|
return fail(cx, rs);
|
|
|
|
}
|
2013-07-03 07:24:32 +00:00
|
|
|
|
|
|
|
if (!toVariant(cx, rval, result))
|
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
// Prefill everything with a dummy jsval.
|
|
|
|
for (size_t i = 0; i < outobjects.length(); i++)
|
|
|
|
outparams->AppendElement(JSParam(void_t()));
|
|
|
|
|
|
|
|
// Go through each argument that was an outparam, retrieve the "value"
|
|
|
|
// field, and add it to a temporary list. We need to do this separately
|
|
|
|
// because the outparams vector is not rooted.
|
|
|
|
vals.clear();
|
|
|
|
for (size_t i = 0; i < outobjects.length(); i++) {
|
|
|
|
RootedObject obj(cx, &outobjects[i].toObject());
|
|
|
|
|
2013-07-26 09:00:38 +00:00
|
|
|
RootedValue v(cx);
|
2013-08-08 22:53:04 +00:00
|
|
|
bool found;
|
2013-07-03 07:24:32 +00:00
|
|
|
if (JS_HasProperty(cx, obj, "value", &found)) {
|
|
|
|
if (!JS_GetProperty(cx, obj, "value", &v))
|
|
|
|
return fail(cx, rs);
|
|
|
|
} else {
|
|
|
|
v = UndefinedValue();
|
|
|
|
}
|
|
|
|
if (!vals.append(v))
|
|
|
|
return fail(cx, rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the outparams. If any outparam is already set to a void_t, we
|
|
|
|
// treat this as the outparam never having been set.
|
|
|
|
for (size_t i = 0; i < vals.length(); i++) {
|
|
|
|
JSVariant variant;
|
2013-10-12 05:02:24 +00:00
|
|
|
if (!toVariant(cx, vals.handleAt(i), &variant))
|
2013-07-03 07:24:32 +00:00
|
|
|
return fail(cx, rs);
|
|
|
|
outparams->ReplaceElementAt(i, JSParam(variant));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-11 15:23:34 +00:00
|
|
|
JavaScriptChild::AnswerObjectClassIs(const ObjectId &objId, const uint32_t &classValue,
|
|
|
|
bool *result)
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
2013-07-11 15:23:34 +00:00
|
|
|
*result = js_ObjectClassIs(cx, obj, (js::ESClassValue)classValue);
|
|
|
|
return true;
|
2013-07-03 07:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-11 15:23:34 +00:00
|
|
|
JavaScriptChild::AnswerClassName(const ObjectId &objId, nsString *name)
|
2013-07-10 02:45:08 +00:00
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
2013-07-11 15:23:34 +00:00
|
|
|
*name = NS_ConvertASCIItoUTF16(js_ObjectClassName(cx, obj));
|
|
|
|
return true;
|
2013-07-10 02:45:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::AnswerGetPropertyNames(const ObjectId &objId, const uint32_t &flags,
|
|
|
|
ReturnStatus *rs, nsTArray<nsString> *names)
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
|
|
|
AutoIdVector props(cx);
|
2013-07-10 02:45:08 +00:00
|
|
|
if (!js::GetPropertyNames(cx, obj, flags, &props))
|
2013-07-03 07:24:32 +00:00
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < props.length(); i++) {
|
|
|
|
nsString name;
|
|
|
|
if (!convertIdToGeckoString(cx, props.handleAt(i), &name))
|
2013-07-17 13:27:49 +00:00
|
|
|
return fail(cx, rs);
|
2013-07-03 07:24:32 +00:00
|
|
|
|
|
|
|
names->AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-11 15:23:34 +00:00
|
|
|
JavaScriptChild::AnswerInstanceOf(const ObjectId &objId, const JSIID &iid, ReturnStatus *rs,
|
|
|
|
bool *instanceof)
|
2013-07-03 07:24:32 +00:00
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
2013-07-17 13:27:49 +00:00
|
|
|
*instanceof = false;
|
|
|
|
|
2013-07-03 07:24:32 +00:00
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
2013-07-10 02:45:08 +00:00
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
2013-07-11 15:23:34 +00:00
|
|
|
nsID nsiid;
|
|
|
|
ConvertID(iid, &nsiid);
|
2013-07-10 02:45:08 +00:00
|
|
|
|
2013-07-11 15:23:34 +00:00
|
|
|
nsresult rv = xpc::HasInstance(cx, obj, &nsiid, instanceof);
|
|
|
|
if (rv != NS_OK)
|
2013-07-10 02:45:08 +00:00
|
|
|
return fail(cx, rs);
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|
2013-08-01 23:45:17 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
JavaScriptChild::AnswerDOMInstanceOf(const ObjectId &objId, const int &prototypeID,
|
|
|
|
const int &depth,
|
|
|
|
ReturnStatus *rs, bool *instanceof)
|
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoRequest request(cx);
|
|
|
|
|
|
|
|
*instanceof = false;
|
|
|
|
|
|
|
|
RootedObject obj(cx, findObject(objId));
|
|
|
|
if (!obj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSAutoCompartment comp(cx, obj);
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
bool tmp;
|
2013-08-01 23:45:17 +00:00
|
|
|
if (!mozilla::dom::InterfaceHasInstance(cx, prototypeID, depth, obj, &tmp))
|
|
|
|
return fail(cx, rs);
|
|
|
|
*instanceof = tmp;
|
|
|
|
|
|
|
|
return ok(rs);
|
|
|
|
}
|