2010-07-03 01:09:48 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-07-03 01:09:48 +04:00
|
|
|
|
|
|
|
#include "nsJSPrincipals.h"
|
|
|
|
|
|
|
|
#include "XPCWrapper.h"
|
|
|
|
|
2012-07-16 21:22:51 +04:00
|
|
|
#include "WaiveXrayWrapper.h"
|
2011-08-07 01:05:25 +04:00
|
|
|
#include "AccessCheck.h"
|
2010-10-11 02:48:29 +04:00
|
|
|
#include "WrapperFactory.h"
|
|
|
|
|
2013-04-20 13:41:47 +04:00
|
|
|
using namespace JS;
|
|
|
|
|
2010-07-03 01:09:48 +04:00
|
|
|
namespace xpc {
|
|
|
|
|
2013-04-03 22:41:22 +04:00
|
|
|
static bool
|
2013-07-26 09:52:59 +04:00
|
|
|
WaiveAccessors(JSContext *cx, JS::MutableHandle<JSPropertyDescriptor> desc)
|
2013-04-03 22:41:22 +04:00
|
|
|
{
|
2013-04-30 21:29:40 +04:00
|
|
|
if (desc.hasGetterObject() && desc.getterObject()) {
|
|
|
|
RootedValue v(cx, JS::ObjectValue(*desc.getterObject()));
|
2013-04-20 13:41:47 +04:00
|
|
|
if (!WrapperFactory::WaiveXrayAndWrap(cx, v.address()))
|
2013-04-03 22:41:22 +04:00
|
|
|
return false;
|
2013-04-30 21:29:40 +04:00
|
|
|
desc.setGetterObject(&v.toObject());
|
2013-04-03 22:41:22 +04:00
|
|
|
}
|
|
|
|
|
2013-04-30 21:29:40 +04:00
|
|
|
if (desc.hasSetterObject() && desc.setterObject()) {
|
|
|
|
RootedValue v(cx, JS::ObjectValue(*desc.setterObject()));
|
2013-04-20 13:41:47 +04:00
|
|
|
if (!WrapperFactory::WaiveXrayAndWrap(cx, v.address()))
|
2013-04-03 22:41:22 +04:00
|
|
|
return false;
|
2013-04-30 21:29:40 +04:00
|
|
|
desc.setSetterObject(&v.toObject());
|
2013-04-03 22:41:22 +04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-16 19:53:16 +04:00
|
|
|
WaiveXrayWrapper::WaiveXrayWrapper(unsigned flags) : js::CrossCompartmentWrapper(flags)
|
2010-07-03 01:09:48 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-16 19:53:16 +04:00
|
|
|
WaiveXrayWrapper::~WaiveXrayWrapper()
|
2010-07-03 01:09:48 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-11 02:48:29 +04:00
|
|
|
bool
|
2013-04-20 13:41:47 +04:00
|
|
|
WaiveXrayWrapper::getPropertyDescriptor(JSContext *cx, HandleObject wrapper,
|
2013-07-26 09:52:59 +04:00
|
|
|
HandleId id, JS::MutableHandle<JSPropertyDescriptor> desc,
|
2013-03-22 02:23:47 +04:00
|
|
|
unsigned flags)
|
2010-10-11 02:48:29 +04:00
|
|
|
{
|
2013-01-04 01:31:36 +04:00
|
|
|
return CrossCompartmentWrapper::getPropertyDescriptor(cx, wrapper, id, desc, flags) &&
|
2013-04-30 21:29:40 +04:00
|
|
|
WrapperFactory::WaiveXrayAndWrap(cx, desc.value().address()) && WaiveAccessors(cx, desc);
|
2010-10-11 02:48:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-04-20 13:41:47 +04:00
|
|
|
WaiveXrayWrapper::getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper,
|
2013-07-26 09:52:59 +04:00
|
|
|
HandleId id, JS::MutableHandle<JSPropertyDescriptor> desc,
|
2013-03-22 02:23:47 +04:00
|
|
|
unsigned flags)
|
2010-10-11 02:48:29 +04:00
|
|
|
{
|
2013-01-04 01:31:36 +04:00
|
|
|
return CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, desc, flags) &&
|
2013-04-30 21:29:40 +04:00
|
|
|
WrapperFactory::WaiveXrayAndWrap(cx, desc.value().address()) && WaiveAccessors(cx, desc);
|
2010-10-11 02:48:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-04-20 13:41:47 +04:00
|
|
|
WaiveXrayWrapper::get(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject receiver, HandleId id,
|
|
|
|
MutableHandleValue vp)
|
2010-10-11 02:48:29 +04:00
|
|
|
{
|
2011-09-09 07:29:15 +04:00
|
|
|
return CrossCompartmentWrapper::get(cx, wrapper, receiver, id, vp) &&
|
2013-03-22 02:23:48 +04:00
|
|
|
WrapperFactory::WaiveXrayAndWrap(cx, vp.address());
|
2010-10-11 02:48:29 +04:00
|
|
|
}
|
|
|
|
|
2010-12-04 06:00:23 +03:00
|
|
|
bool
|
2013-04-20 13:41:47 +04:00
|
|
|
WaiveXrayWrapper::call(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args)
|
2010-12-04 06:00:23 +03:00
|
|
|
{
|
2013-04-04 11:02:24 +04:00
|
|
|
return CrossCompartmentWrapper::call(cx, wrapper, args) &&
|
|
|
|
WrapperFactory::WaiveXrayAndWrap(cx, args.rval().address());
|
2010-12-04 06:00:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-04-20 13:41:47 +04:00
|
|
|
WaiveXrayWrapper::construct(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args)
|
2010-12-04 06:00:23 +03:00
|
|
|
{
|
2013-04-04 11:02:24 +04:00
|
|
|
return CrossCompartmentWrapper::construct(cx, wrapper, args) &&
|
|
|
|
WrapperFactory::WaiveXrayAndWrap(cx, args.rval().address());
|
2010-12-04 06:00:23 +03:00
|
|
|
}
|
|
|
|
|
2013-04-03 22:41:23 +04:00
|
|
|
// NB: This is important as the other side of a handshake with FieldGetter. See
|
|
|
|
// nsXBLProtoImplField.cpp.
|
|
|
|
bool
|
|
|
|
WaiveXrayWrapper::nativeCall(JSContext *cx, JS::IsAcceptableThis test,
|
|
|
|
JS::NativeImpl impl, JS::CallArgs args)
|
|
|
|
{
|
|
|
|
return CrossCompartmentWrapper::nativeCall(cx, test, impl, args) &&
|
|
|
|
WrapperFactory::WaiveXrayAndWrap(cx, args.rval().address());
|
|
|
|
}
|
|
|
|
|
2010-07-03 01:09:48 +04:00
|
|
|
}
|