Bug 803068 - Remove IndirectWrapper. r=ejpbruel

We also take the opportunity to update the now-obsolete comment about the
wrapper hierarchy.

--HG--
extra : rebase_source : b756bf143d202daae4b5abcf99f7fb381e040641
This commit is contained in:
Bobby Holley 2012-10-29 16:52:53 +01:00
parent cf2bcfdc02
commit f107868927
2 changed files with 7 additions and 152 deletions

View File

@ -134,11 +134,6 @@ js::IsCrossCompartmentWrapper(RawObject wrapper)
!!(Wrapper::wrapperHandler(wrapper)->flags() & Wrapper::CROSS_COMPARTMENT);
}
IndirectWrapper::IndirectWrapper(unsigned flags) : Wrapper(flags),
IndirectProxyHandler(&sWrapperFamily)
{
}
#define CHECKED(op, act) \
JS_BEGIN_MACRO \
bool status; \
@ -150,93 +145,6 @@ IndirectWrapper::IndirectWrapper(unsigned flags) : Wrapper(flags),
#define SET(action) CHECKED(action, SET)
#define GET(action) CHECKED(action, GET)
bool
IndirectWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper,
jsid id, bool set,
PropertyDescriptor *desc)
{
desc->obj = NULL; // default result if we refuse to perform this action
CHECKED(IndirectProxyHandler::getPropertyDescriptor(cx, wrapper, id, set, desc),
set ? SET : GET);
}
bool
IndirectWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper,
jsid id, bool set,
PropertyDescriptor *desc)
{
desc->obj = NULL; // default result if we refuse to perform this action
CHECKED(IndirectProxyHandler::getOwnPropertyDescriptor(cx, wrapper, id, set, desc), GET);
}
bool
IndirectWrapper::defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
PropertyDescriptor *desc)
{
SET(IndirectProxyHandler::defineProperty(cx, wrapper, id, desc));
}
bool
IndirectWrapper::getOwnPropertyNames(JSContext *cx, JSObject *wrapper,
AutoIdVector &props)
{
// if we refuse to perform this action, props remains empty
jsid id = JSID_VOID;
GET(IndirectProxyHandler::getOwnPropertyNames(cx, wrapper, props));
}
bool
IndirectWrapper::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
{
*bp = true; // default result if we refuse to perform this action
SET(IndirectProxyHandler::delete_(cx, wrapper, id, bp));
}
bool
IndirectWrapper::enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
{
// if we refuse to perform this action, props remains empty
static jsid id = JSID_VOID;
GET(IndirectProxyHandler::enumerate(cx, wrapper, props));
}
/*
* Ordinarily, the convert trap would require a PUNCTURE. However, the default
* implementation of convert, JS_ConvertStub, obtains a default value by calling
* the toString/valueOf method on the wrapper, if any. Doing a PUNCTURE in this
* case would be overly conservative. To make matters worse, XPConnect sometimes
* installs a custom convert trap that obtains a default value by calling the
* toString method on the wrapper. Doing a puncture in this case would be overly
* conservative as well. We deal with these anomalies by clearing the pending
* exception and falling back to the DefaultValue algorithm whenever the
* PUNCTURE fails.
*/
bool
IndirectWrapper::defaultValue(JSContext *cx, JSObject *wrapper_, JSType hint, Value *vp)
{
RootedObject wrapper(cx, wrapper_);
bool status;
if (!enter(cx, wrapper_, JSID_VOID, PUNCTURE, &status)) {
RootedValue v(cx);
JS_ClearPendingException(cx);
if (!DefaultValue(cx, wrapper, hint, &v))
return false;
*vp = v;
return true;
}
/*
* We enter the compartment of the wrappee here, even if we're not a cross
* compartment wrapper. Moreover, cross compartment wrappers do not enter
* the compartment of the wrappee before calling this function. This is
* necessary because the DefaultValue algorithm above operates on the
* wrapper, not the wrappee, so we want to delay the decision to switch
* compartments until this point.
*/
AutoCompartment call(cx, wrappedObject(wrapper));
return IndirectProxyHandler::defaultValue(cx, wrapper_, hint, vp);
}
DirectWrapper::DirectWrapper(unsigned flags, bool hasPrototype) : Wrapper(flags),
DirectProxyHandler(&sWrapperFamily)
{

View File

@ -18,25 +18,13 @@ namespace js {
class DummyFrameGuard;
/*
* A wrapper is essentially a proxy that restricts access to certain traps. The
* way in which a wrapper restricts access to its traps depends on the
* particular policy for that wrapper. To allow a wrapper's policy to be
* customized, the Wrapper base class contains two functions, enter/leave, which
* are called as a policy enforcement check before/after each trap is forwarded.
*
* To minimize code duplication, a set of abstract wrapper classes is
* provided, from which other wrappers may inherit. These abstract classes are
* organized in the following hierarchy:
*
* BaseProxyHandler Wrapper
* | | |
* IndirectProxyHandler | |
* | | | |
* | IndirectWrapper |
* | |
* DirectProxyHandler |
* | |
* DirectWrapper
* A wrapper is a proxy with a target object to which it generally forwards
* operations, but may restrict access to certain operations or instrument
* the trap operations in various ways. A wrapper is distinct from a Direct Proxy
* Handler in the sense that it can be "unwrapped" in C++, exposing the underlying
* object (Direct Proxy Handlers have an underlying target object, but don't
* expect to expose this object via any kind of unwrapping operation). Callers
* should be careful to avoid unwrapping security wrappers in the wrong context.
*/
class JS_FRIEND_API(Wrapper)
{
@ -117,47 +105,6 @@ class JS_FRIEND_API(Wrapper)
bool *bp);
};
/*
* IndirectWrapper forwards its traps by forwarding them to
* IndirectProxyHandler. In effect, IndirectWrapper behaves the same as
* IndirectProxyHandler, except that it adds policy enforcement checks to each
* fundamental trap.
*/
class JS_FRIEND_API(IndirectWrapper) : public Wrapper,
public IndirectProxyHandler
{
public:
explicit IndirectWrapper(unsigned flags);
virtual BaseProxyHandler* toBaseProxyHandler() {
return this;
}
virtual Wrapper *toWrapper() {
return this;
}
/* ES5 Harmony fundamental wrapper traps. */
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper,
jsid id, bool set,
PropertyDescriptor *desc) MOZ_OVERRIDE;
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper,
jsid id, bool set,
PropertyDescriptor *desc) MOZ_OVERRIDE;
virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
PropertyDescriptor *desc) MOZ_OVERRIDE;
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper,
AutoIdVector &props) MOZ_OVERRIDE;
virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id,
bool *bp) MOZ_OVERRIDE;
virtual bool enumerate(JSContext *cx, JSObject *wrapper,
AutoIdVector &props) MOZ_OVERRIDE;
/* Spidermonkey extensions. */
virtual bool defaultValue(JSContext *cx, JSObject *wrapper_, JSType hint,
Value *vp) MOZ_OVERRIDE;
};
/*
* DirectWrapper forwards its traps by forwarding them to DirectProxyHandler.
* In effect, DirectWrapper behaves the same as DirectProxyHandler, except that