gecko/js/xpconnect/wrappers/XrayWrapper.h

104 lines
4.0 KiB
C
Raw Normal View History

2010-07-02 14:09:48 -07: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 04:12:37 -07: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-02 14:09:48 -07:00
#include "jsapi.h"
#include "jswrapper.h"
// Xray wrappers re-resolve the original native properties on the native
// object and always directly access to those properties.
// Because they work so differently from the rest of the wrapper hierarchy,
// we pull them out of the Wrapper inheritance hierarchy and create a
// little world around them.
2010-07-02 14:09:48 -07:00
class XPCWrappedNative;
2010-07-02 14:09:48 -07:00
namespace xpc {
JSBool
holder_get(JSContext *cx, JSHandleObject holder, JSHandleId id, jsval *vp);
JSBool
holder_set(JSContext *cx, JSHandleObject holder, JSHandleId id, JSBool strict, jsval *vp);
namespace XrayUtils {
2010-07-02 14:09:48 -07:00
extern JSClass HolderClass;
bool CloneExpandoChain(JSContext *cx, JSObject *src, JSObject *dst);
JSObject *createHolder(JSContext *cx, JSObject *wrappedNative, JSObject *parent);
bool
IsTransparent(JSContext *cx, JSObject *wrapper);
JSObject *
GetNativePropertiesObject(JSContext *cx, JSObject *wrapper);
}
2010-07-02 14:09:48 -07:00
class XPCWrappedNativeXrayTraits;
class ProxyXrayTraits;
class DOMXrayTraits;
// NB: Base *must* derive from JSProxyHandler
template <typename Base, typename Traits = XPCWrappedNativeXrayTraits >
2010-07-02 14:09:48 -07:00
class XrayWrapper : public Base {
public:
XrayWrapper(unsigned flags);
2010-07-02 14:09:48 -07:00
virtual ~XrayWrapper();
/* Fundamental proxy traps. */
2010-07-02 14:09:48 -07:00
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
bool set, js::PropertyDescriptor *desc);
2010-07-02 14:09:48 -07:00
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
bool set, js::PropertyDescriptor *desc);
virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
js::PropertyDescriptor *desc);
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper,
js::AutoIdVector &props);
virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
virtual bool enumerate(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props);
/* Derived proxy traps. */
virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id,
js::Value *vp);
virtual bool set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id,
bool strict, js::Value *vp);
2010-07-02 14:09:48 -07:00
virtual bool has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
virtual bool hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
virtual bool keys(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props);
virtual bool iterate(JSContext *cx, JSObject *wrapper, unsigned flags, js::Value *vp);
2010-07-02 14:09:48 -07:00
virtual bool call(JSContext *cx, JSObject *wrapper, unsigned argc, js::Value *vp);
virtual bool construct(JSContext *cx, JSObject *wrapper,
unsigned argc, js::Value *argv, js::Value *rval);
2010-07-02 14:09:48 -07:00
static XrayWrapper singleton;
private:
bool enumerate(JSContext *cx, JSObject *wrapper, unsigned flags,
JS::AutoIdVector &props);
2010-07-02 14:09:48 -07:00
};
typedef XrayWrapper<js::CrossCompartmentWrapper, ProxyXrayTraits > XrayProxy;
typedef XrayWrapper<js::CrossCompartmentWrapper, DOMXrayTraits > XrayDOM;
class SandboxProxyHandler : public js::IndirectWrapper {
public:
SandboxProxyHandler() : js::IndirectWrapper(0)
{
}
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id,
bool set, js::PropertyDescriptor *desc);
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy,
jsid id, bool set,
js::PropertyDescriptor *desc);
};
extern SandboxProxyHandler sandboxProxyHandler;
2010-07-02 14:09:48 -07:00
}