Bug 1027402 - Part 4: Mark Proxy Handler uses const. (r=jorendorff, r=bz)

This commit is contained in:
Eric Faust 2014-06-27 04:44:08 -07:00
parent 292636680c
commit 82556410aa
12 changed files with 49 additions and 54 deletions

View File

@ -1272,10 +1272,7 @@ XrayDefineProperty(JSContext* cx, JS::Handle<JSObject*> wrapper,
if (!js::IsProxy(obj))
return true;
MOZ_ASSERT(IsDOMProxy(obj), "What kind of proxy is this?");
DOMProxyHandler* handler =
static_cast<DOMProxyHandler*>(js::GetProxyHandler(obj));
const DOMProxyHandler* handler = GetDOMProxyHandler(obj);
return handler->defineProperty(cx, wrapper, id, desc, defined);
}

View File

@ -131,11 +131,11 @@ public:
JS::Handle<JSObject*> obj);
};
inline DOMProxyHandler*
inline const DOMProxyHandler*
GetDOMProxyHandler(JSObject* obj)
{
MOZ_ASSERT(IsDOMProxy(obj));
return static_cast<DOMProxyHandler*>(js::GetProxyHandler(obj));
return static_cast<const DOMProxyHandler*>(js::GetProxyHandler(obj));
}
extern jsid s_length_id;

View File

@ -10361,7 +10361,7 @@ ICCall_ScriptedFunCall::Clone(JSContext *, ICStubSpace *space, ICStub *firstMoni
ICGetPropCallDOMProxyNativeStub::ICGetPropCallDOMProxyNativeStub(Kind kind, JitCode *stubCode,
ICStub *firstMonitorStub,
HandleShape shape,
BaseProxyHandler *proxyHandler,
const BaseProxyHandler *proxyHandler,
HandleShape expandoShape,
HandleObject holder,
HandleShape holderShape,
@ -10427,7 +10427,7 @@ ICGetProp_CallDOMProxyWithGenerationNative::Clone(JSContext *cx, ICStubSpace *sp
ICGetProp_DOMProxyShadowed::ICGetProp_DOMProxyShadowed(JitCode *stubCode,
ICStub *firstMonitorStub,
HandleShape shape,
BaseProxyHandler *proxyHandler,
const BaseProxyHandler *proxyHandler,
HandlePropertyName name,
uint32_t pcOffset)
: ICMonitoredStub(ICStub::GetProp_DOMProxyShadowed, stubCode, firstMonitorStub),

View File

@ -4684,7 +4684,7 @@ class ICGetPropCallDOMProxyNativeStub : public ICMonitoredStub
HeapPtrShape shape_;
// Proxy handler to check against.
BaseProxyHandler *proxyHandler_;
const BaseProxyHandler *proxyHandler_;
// Object shape of expected expando object. (nullptr if no expando object should be there)
HeapPtrShape expandoShape_;
@ -4701,7 +4701,7 @@ class ICGetPropCallDOMProxyNativeStub : public ICMonitoredStub
ICGetPropCallDOMProxyNativeStub(ICStub::Kind kind, JitCode *stubCode,
ICStub *firstMonitorStub, HandleShape shape,
BaseProxyHandler *proxyHandler, HandleShape expandoShape,
const BaseProxyHandler *proxyHandler, HandleShape expandoShape,
HandleObject holder, HandleShape holderShape,
HandleFunction getter, uint32_t pcOffset);
@ -4752,7 +4752,7 @@ class ICGetProp_CallDOMProxyNative : public ICGetPropCallDOMProxyNativeStub
{
friend class ICStubSpace;
ICGetProp_CallDOMProxyNative(JitCode *stubCode, ICStub *firstMonitorStub, HandleShape shape,
BaseProxyHandler *proxyHandler, HandleShape expandoShape,
const BaseProxyHandler *proxyHandler, HandleShape expandoShape,
HandleObject holder, HandleShape holderShape,
HandleFunction getter, uint32_t pcOffset)
: ICGetPropCallDOMProxyNativeStub(ICStub::GetProp_CallDOMProxyNative, stubCode,
@ -4763,7 +4763,7 @@ class ICGetProp_CallDOMProxyNative : public ICGetPropCallDOMProxyNativeStub
public:
static inline ICGetProp_CallDOMProxyNative *New(
ICStubSpace *space, JitCode *code, ICStub *firstMonitorStub,
HandleShape shape, BaseProxyHandler *proxyHandler,
HandleShape shape, const BaseProxyHandler *proxyHandler,
HandleShape expandoShape, HandleObject holder, HandleShape holderShape,
HandleFunction getter, uint32_t pcOffset)
{
@ -4787,7 +4787,7 @@ class ICGetProp_CallDOMProxyWithGenerationNative : public ICGetPropCallDOMProxyN
public:
ICGetProp_CallDOMProxyWithGenerationNative(JitCode *stubCode, ICStub *firstMonitorStub,
HandleShape shape, BaseProxyHandler *proxyHandler,
HandleShape shape, const BaseProxyHandler *proxyHandler,
ExpandoAndGeneration *expandoAndGeneration,
uint32_t generation, HandleShape expandoShape,
HandleObject holder, HandleShape holderShape,
@ -4802,7 +4802,7 @@ class ICGetProp_CallDOMProxyWithGenerationNative : public ICGetPropCallDOMProxyN
static inline ICGetProp_CallDOMProxyWithGenerationNative *New(
ICStubSpace *space, JitCode *code, ICStub *firstMonitorStub,
HandleShape shape, BaseProxyHandler *proxyHandler,
HandleShape shape, const BaseProxyHandler *proxyHandler,
ExpandoAndGeneration *expandoAndGeneration, uint32_t generation,
HandleShape expandoShape, HandleObject holder, HandleShape holderShape,
HandleFunction getter, uint32_t pcOffset)
@ -4863,18 +4863,18 @@ class ICGetProp_DOMProxyShadowed : public ICMonitoredStub
friend class ICStubSpace;
protected:
HeapPtrShape shape_;
BaseProxyHandler *proxyHandler_;
const BaseProxyHandler *proxyHandler_;
HeapPtrPropertyName name_;
uint32_t pcOffset_;
ICGetProp_DOMProxyShadowed(JitCode *stubCode, ICStub *firstMonitorStub, HandleShape shape,
BaseProxyHandler *proxyHandler, HandlePropertyName name,
const BaseProxyHandler *proxyHandler, HandlePropertyName name,
uint32_t pcOffset);
public:
static inline ICGetProp_DOMProxyShadowed *New(ICStubSpace *space, JitCode *code,
ICStub *firstMonitorStub, HandleShape shape,
BaseProxyHandler *proxyHandler,
const BaseProxyHandler *proxyHandler,
HandlePropertyName name, uint32_t pcOffset)
{
if (!code)
@ -6315,7 +6315,7 @@ IsCacheableDOMProxy(JSObject *obj)
if (!obj->is<ProxyObject>())
return false;
BaseProxyHandler *handler = obj->as<ProxyObject>().handler();
const BaseProxyHandler *handler = obj->as<ProxyObject>().handler();
if (handler->family() != GetDOMProxyHandlerFamily())
return false;

View File

@ -2114,7 +2114,7 @@ Proxy::getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id,
MutableHandle<PropertyDescriptor> desc)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
desc.object().set(nullptr); // default result if we refuse to perform this action
AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::GET, true);
if (!policy.allowed())
@ -2145,7 +2145,7 @@ Proxy::getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id,
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
desc.object().set(nullptr); // default result if we refuse to perform this action
AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::GET, true);
if (!policy.allowed())
@ -2170,7 +2170,7 @@ Proxy::defineProperty(JSContext *cx, HandleObject proxy, HandleId id,
MutableHandle<PropertyDescriptor> desc)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::SET, true);
if (!policy.allowed())
return policy.returnValue();
@ -2181,7 +2181,7 @@ bool
Proxy::getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
AutoEnterPolicy policy(cx, handler, proxy, JSID_VOIDHANDLE, BaseProxyHandler::ENUMERATE, true);
if (!policy.allowed())
return policy.returnValue();
@ -2192,7 +2192,7 @@ bool
Proxy::delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
*bp = true; // default result if we refuse to perform this action
AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::SET, true);
if (!policy.allowed())
@ -2224,7 +2224,7 @@ bool
Proxy::enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
AutoEnterPolicy policy(cx, handler, proxy, JSID_VOIDHANDLE, BaseProxyHandler::ENUMERATE, true);
if (!policy.allowed())
return policy.returnValue();
@ -2242,7 +2242,7 @@ bool
Proxy::has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
*bp = false; // default result if we refuse to perform this action
AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::GET, true);
if (!policy.allowed())
@ -2263,7 +2263,7 @@ bool
Proxy::hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
*bp = false; // default result if we refuse to perform this action
AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::GET, true);
if (!policy.allowed())
@ -2276,7 +2276,7 @@ Proxy::get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id
MutableHandleValue vp)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
vp.setUndefined(); // default result if we refuse to perform this action
AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::GET, true);
if (!policy.allowed())
@ -2317,7 +2317,7 @@ Proxy::set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id
MutableHandleValue vp)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::SET, true);
if (!policy.allowed())
return policy.returnValue();
@ -2354,7 +2354,7 @@ bool
Proxy::keys(JSContext *cx, HandleObject proxy, AutoIdVector &props)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
AutoEnterPolicy policy(cx, handler, proxy, JSID_VOIDHANDLE, BaseProxyHandler::ENUMERATE, true);
if (!policy.allowed())
return policy.returnValue();
@ -2365,7 +2365,7 @@ bool
Proxy::iterate(JSContext *cx, HandleObject proxy, unsigned flags, MutableHandleValue vp)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
vp.setUndefined(); // default result if we refuse to perform this action
if (!handler->hasPrototype()) {
AutoEnterPolicy policy(cx, handler, proxy, JSID_VOIDHANDLE,
@ -2400,7 +2400,7 @@ bool
Proxy::preventExtensions(JSContext *cx, HandleObject proxy)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
return handler->preventExtensions(cx, proxy);
}
@ -2408,7 +2408,7 @@ bool
Proxy::call(JSContext *cx, HandleObject proxy, const CallArgs &args)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
// Because vp[0] is JS_CALLEE on the way in and JS_RVAL on the way out, we
// can only set our default value once we're sure that we're not calling the
@ -2427,7 +2427,7 @@ bool
Proxy::construct(JSContext *cx, HandleObject proxy, const CallArgs &args)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
// Because vp[0] is JS_CALLEE on the way in and JS_RVAL on the way out, we
// can only set our default value once we're sure that we're not calling the
@ -2457,7 +2457,7 @@ bool
Proxy::hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
*bp = false; // default result if we refuse to perform this action
AutoEnterPolicy policy(cx, handler, proxy, JSID_VOIDHANDLE, BaseProxyHandler::GET, true);
if (!policy.allowed())
@ -2481,7 +2481,7 @@ Proxy::className(JSContext *cx, HandleObject proxy)
if (!JS_CHECK_STACK_SIZE(GetNativeStackLimit(cx), &stackDummy))
return "too much recursion";
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
AutoEnterPolicy policy(cx, handler, proxy, JSID_VOIDHANDLE,
BaseProxyHandler::GET, /* mayThrow = */ false);
// Do the safe thing if the policy rejects.
@ -2495,7 +2495,7 @@ JSString *
Proxy::fun_toString(JSContext *cx, HandleObject proxy, unsigned indent)
{
JS_CHECK_RECURSION(cx, return nullptr);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
AutoEnterPolicy policy(cx, handler, proxy, JSID_VOIDHANDLE,
BaseProxyHandler::GET, /* mayThrow = */ false);
// Do the safe thing if the policy rejects.
@ -2555,7 +2555,7 @@ Proxy::slice(JSContext *cx, HandleObject proxy, uint32_t begin, uint32_t end,
HandleObject result)
{
JS_CHECK_RECURSION(cx, return false);
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
AutoEnterPolicy policy(cx, handler, proxy, JSID_VOIDHANDLE, BaseProxyHandler::GET,
/* mayThrow = */ true);
if (!policy.allowed()) {

View File

@ -374,11 +374,11 @@ const uint32_t PROXY_HANDLER_SLOT = 1;
const uint32_t PROXY_EXTRA_SLOT = 2;
const uint32_t PROXY_MINIMUM_SLOTS = 4;
inline BaseProxyHandler *
inline const BaseProxyHandler *
GetProxyHandler(JSObject *obj)
{
JS_ASSERT(IsProxy(obj));
return (BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate();
return (const BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate();
}
inline const Value &
@ -471,7 +471,7 @@ class JS_FRIEND_API(AutoEnterPolicy)
{
public:
typedef BaseProxyHandler::Action Action;
AutoEnterPolicy(JSContext *cx, BaseProxyHandler *handler,
AutoEnterPolicy(JSContext *cx, const BaseProxyHandler *handler,
HandleObject wrapper, HandleId id, Action act, bool mayThrow)
#ifdef JS_DEBUG
: context(nullptr)

View File

@ -64,11 +64,11 @@ Wrapper::Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *
return existing;
}
Wrapper *
const Wrapper *
Wrapper::wrapperHandler(JSObject *wrapper)
{
JS_ASSERT(wrapper->is<WrapperObject>());
return static_cast<Wrapper*>(wrapper->as<ProxyObject>().handler());
return static_cast<const Wrapper*>(wrapper->as<ProxyObject>().handler());
}
JSObject *
@ -116,7 +116,7 @@ js::UnwrapOneChecked(JSObject *obj, bool stopAtOuter)
return obj;
}
Wrapper *handler = Wrapper::wrapperHandler(obj);
const Wrapper *handler = Wrapper::wrapperHandler(obj);
return handler->hasSecurityPolicy() ? nullptr : Wrapper::wrappedObject(obj);
}

View File

@ -73,7 +73,7 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler
static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *handler);
static Wrapper *wrapperHandler(JSObject *wrapper);
static const Wrapper *wrapperHandler(JSObject *wrapper);
static JSObject *wrappedObject(JSObject *wrapper);

View File

@ -41,8 +41,8 @@ class ProxyObject : public JSObject
return const_cast<ProxyObject*>(this)->private_().toObjectOrNull();
}
BaseProxyHandler *handler() {
return static_cast<BaseProxyHandler*>(GetReservedSlot(this, HANDLER_SLOT).toPrivate());
const BaseProxyHandler *handler() {
return static_cast<const BaseProxyHandler*>(GetReservedSlot(this, HANDLER_SLOT).toPrivate());
}
void initHandler(const BaseProxyHandler *handler);

View File

@ -363,7 +363,7 @@ XPCCallContext::UnwrapThisIfAllowed(HandleObject obj, HandleObject fun, unsigned
// XPC_WN_GetterSetter does.
bool set = argc && argc != NO_ARGS && member->IsWritableAttribute();
js::Wrapper::Action act = set ? js::Wrapper::SET : js::Wrapper::GET;
js::Wrapper *handler = js::Wrapper::wrapperHandler(obj);
const js::Wrapper *handler = js::Wrapper::wrapperHandler(obj);
bool ignored;
JS::Rooted<jsid> id(mJSContext, member->GetName());
if (!handler->enter(mJSContext, obj, id, act, &ignored))

View File

@ -32,8 +32,7 @@ AllowedByBase(JSContext *cx, HandleObject wrapper, HandleId id,
MOZ_ASSERT(js::Wrapper::wrapperHandler(wrapper) ==
&ChromeObjectWrapper::singleton);
bool bp;
ChromeObjectWrapper *handler =
const_cast<ChromeObjectWrapper*>(&ChromeObjectWrapper::singleton);
const ChromeObjectWrapper *handler = &ChromeObjectWrapper::singleton;
return handler->ChromeObjectWrapperBase::enter(cx, wrapper, id, act, &bp);
}
@ -57,8 +56,7 @@ PropIsFromStandardPrototype(JSContext *cx, HandleObject wrapper,
MOZ_ASSERT(js::Wrapper::wrapperHandler(wrapper) ==
&ChromeObjectWrapper::singleton);
Rooted<JSPropertyDescriptor> desc(cx);
ChromeObjectWrapper *handler =
const_cast<ChromeObjectWrapper*>(&ChromeObjectWrapper::singleton);
const ChromeObjectWrapper *handler = &ChromeObjectWrapper::singleton;
if (!handler->ChromeObjectWrapperBase::getPropertyDescriptor(cx, wrapper, id,
&desc) ||
!desc.object())

View File

@ -1598,7 +1598,7 @@ XrayTraits::set(JSContext *cx, HandleObject wrapper, HandleObject receiver, Hand
bool strict, MutableHandleValue vp)
{
// Skip our Base if it isn't already BaseProxyHandler.
js::BaseProxyHandler *handler = js::GetProxyHandler(wrapper);
const js::BaseProxyHandler *handler = js::GetProxyHandler(wrapper);
return handler->js::BaseProxyHandler::set(cx, wrapper, receiver, id, strict, vp);
}
@ -1891,7 +1891,7 @@ DOMXrayTraits::set(JSContext *cx, HandleObject wrapper, HandleObject receiver, H
MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(wrapper));
RootedObject obj(cx, getTargetObject(wrapper));
if (IsDOMProxy(obj)) {
DOMProxyHandler* handler = GetDOMProxyHandler(obj);
const DOMProxyHandler* handler = GetDOMProxyHandler(obj);
bool done;
if (!handler->setCustom(cx, obj, id, vp, &done))
@ -2031,7 +2031,7 @@ HasNativeProperty(JSContext *cx, HandleObject wrapper, HandleId id, bool *hasPro
NS_ENSURE_TRUE(holder, false);
*hasProp = false;
Rooted<JSPropertyDescriptor> desc(cx);
Wrapper *handler = Wrapper::wrapperHandler(wrapper);
const Wrapper *handler = Wrapper::wrapperHandler(wrapper);
// Try resolveOwnProperty.
Maybe<ResolvingId> resolvingId;