Bug 880041 (part 16) - Use JSObject::{is,as} for WithObject. r=luke.

--HG--
extra : rebase_source : 02299e442ce3989551c8d3dc3b96019a3e6c47fc
This commit is contained in:
Nicholas Nethercote 2013-06-16 19:59:58 -07:00
parent ba4933250d
commit 3b243b4e32
14 changed files with 46 additions and 55 deletions

View File

@ -1716,7 +1716,7 @@ BytecodeEmitter::needsImplicitThis()
} else {
JSObject *scope = sc->asGlobalSharedContext()->scopeChain();
while (scope) {
if (scope->isWith())
if (scope->is<WithObject>())
return true;
scope = scope->enclosingScope();
}

View File

@ -503,7 +503,7 @@ FunctionBox::FunctionBox(JSContext *cx, ObjectBox* traceListHead, JSFunction *fu
//
JSObject *scope = outerpc->sc->asGlobalSharedContext()->scopeChain();
while (scope) {
if (scope->isWith())
if (scope->is<WithObject>())
inWith = true;
scope = scope->enclosingScope();
}

View File

@ -4833,7 +4833,7 @@ TryAttachScopeNameStub(JSContext *cx, HandleScript script, ICGetName_Fallback *s
return true;
}
if (!scopeChain->isScope() || scopeChain->isWith())
if (!scopeChain->isScope() || scopeChain->is<WithObject>())
return true;
// Check for an 'own' property on the scope. There is no need to

View File

@ -4729,7 +4729,7 @@ js::CheckAccess(JSContext *cx, JSObject *obj_, HandleId id, JSAccessMode mode,
JSBool writing;
RootedObject obj(cx, obj_), pobj(cx);
while (JS_UNLIKELY(obj->isWith()))
while (JS_UNLIKELY(obj->is<WithObject>()))
obj = obj->getProto();
writing = (mode & JSACC_WRITE) != 0;

View File

@ -217,7 +217,6 @@ extern Class RegExpStaticsClass;
extern Class StopIterationClass;
extern Class StringClass;
extern Class WeakMapClass;
extern Class WithClass;
class ArrayBufferObject;
class BooleanObject;
@ -233,7 +232,6 @@ class SetObject;
class StaticBlockObject;
class StrictArgumentsObject;
class StringObject;
class WithObject;
} /* namespace js */
@ -974,7 +972,6 @@ class JSObject : public js::ObjectImpl
inline bool isWeakMap() const { return hasClass(&js::WeakMapClass); }
/* Subtypes of ScopeObject. */
inline bool isWith() const { return hasClass(&js::WithClass); }
inline bool isClonedBlock() const;
inline bool isStaticBlock() const;
@ -999,7 +996,6 @@ class JSObject : public js::ObjectImpl
inline js::SetObject &asSet();
inline js::StaticBlockObject &asStaticBlock();
inline js::StringObject &asString();
inline js::WithObject &asWith();
static inline js::ThingRootKind rootKind() { return js::THING_ROOT_OBJECT; }

View File

@ -385,7 +385,7 @@ class ReferenceFinder {
/* Certain classes of object are for internal use only. */
if (object->is<BlockObject>() ||
object->is<CallObject>() ||
object->isWith() ||
object->is<WithObject>() ||
object->is<DeclEnvObject>()) {
return JSVAL_VOID;
}

View File

@ -5158,7 +5158,7 @@ IsDeclarative(Env *env)
static bool
IsWith(Env *env)
{
return env->isDebugScope() && env->asDebugScope().scope().isWith();
return env->isDebugScope() && env->asDebugScope().scope().is<WithObject>();
}
static JSBool
@ -5208,7 +5208,7 @@ DebuggerEnv_getObject(JSContext *cx, unsigned argc, Value *vp)
JSObject *obj;
if (IsWith(env)) {
obj = &env->asDebugScope().scope().asWith().object();
obj = &env->asDebugScope().scope().as<WithObject>().object();
} else {
obj = env;
JS_ASSERT(!obj->isDebugScope());

View File

@ -247,8 +247,8 @@ FetchName(JSContext *cx, HandleObject obj, HandleObject obj2, HandlePropertyName
return false;
} else {
Rooted<JSObject*> normalized(cx, obj);
if (normalized->getClass() == &WithClass && !shape->hasDefaultGetter())
normalized = &normalized->asWith().object();
if (normalized->getClass() == &WithObject::class_ && !shape->hasDefaultGetter())
normalized = &normalized->as<WithObject>().object();
if (!NativeGet(cx, normalized, obj2, shape, 0, vp))
return false;
}

View File

@ -835,7 +835,7 @@ js::UnwindScope(JSContext *cx, AbstractFramePtr frame, uint32_t stackDepth)
frame.popBlock(cx);
break;
case ScopeIter::With:
if (si.scope().asWith().stackDepth() < stackDepth)
if (si.scope().as<WithObject>().stackDepth() < stackDepth)
return;
frame.popWith(cx);
break;

View File

@ -259,13 +259,6 @@ JSObject::asScope()
return *static_cast<js::ScopeObject *>(this);
}
inline js::WithObject &
JSObject::asWith()
{
JS_ASSERT(isWith());
return *static_cast<js::WithObject *>(this);
}
inline js::StaticBlockObject &
JSObject::asStaticBlock()
{

View File

@ -373,11 +373,11 @@ DeclEnvObject::create(JSContext *cx, HandleObject enclosing, HandleFunction call
WithObject *
WithObject::create(JSContext *cx, HandleObject proto, HandleObject enclosing, uint32_t depth)
{
RootedTypeObject type(cx, proto->getNewType(cx, &WithClass));
RootedTypeObject type(cx, proto->getNewType(cx, &class_));
if (!type)
return NULL;
RootedShape shape(cx, EmptyShape::getInitialShape(cx, &WithClass, TaggedProto(proto),
RootedShape shape(cx, EmptyShape::getInitialShape(cx, &class_, TaggedProto(proto),
&enclosing->global(), NULL, FINALIZE_KIND));
if (!shape)
return NULL;
@ -395,14 +395,14 @@ WithObject::create(JSContext *cx, HandleObject proto, HandleObject enclosing, ui
obj->setFixedSlot(THIS_SLOT, ObjectValue(*thisp));
return &obj->asWith();
return &obj->as<WithObject>();
}
static JSBool
with_LookupGeneric(JSContext *cx, HandleObject obj, HandleId id,
MutableHandleObject objp, MutableHandleShape propp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::lookupGeneric(cx, actual, id, objp, propp);
}
@ -436,7 +436,7 @@ static JSBool
with_GetGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleId id,
MutableHandleValue vp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::getGeneric(cx, actual, actual, id, vp);
}
@ -470,7 +470,7 @@ static JSBool
with_SetGeneric(JSContext *cx, HandleObject obj, HandleId id,
MutableHandleValue vp, JSBool strict)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::setGeneric(cx, actual, actual, id, vp, strict);
}
@ -478,7 +478,7 @@ static JSBool
with_SetProperty(JSContext *cx, HandleObject obj, HandlePropertyName name,
MutableHandleValue vp, JSBool strict)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::setProperty(cx, actual, actual, name, vp, strict);
}
@ -486,7 +486,7 @@ static JSBool
with_SetElement(JSContext *cx, HandleObject obj, uint32_t index,
MutableHandleValue vp, JSBool strict)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::setElement(cx, actual, actual, index, vp, strict);
}
@ -494,63 +494,63 @@ static JSBool
with_SetSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid,
MutableHandleValue vp, JSBool strict)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::setSpecial(cx, actual, actual, sid, vp, strict);
}
static JSBool
with_GetGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigned *attrsp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::getGenericAttributes(cx, actual, id, attrsp);
}
static JSBool
with_GetPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::getPropertyAttributes(cx, actual, name, attrsp);
}
static JSBool
with_GetElementAttributes(JSContext *cx, HandleObject obj, uint32_t index, unsigned *attrsp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::getElementAttributes(cx, actual, index, attrsp);
}
static JSBool
with_GetSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::getSpecialAttributes(cx, actual, sid, attrsp);
}
static JSBool
with_SetGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigned *attrsp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::setGenericAttributes(cx, actual, id, attrsp);
}
static JSBool
with_SetPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::setPropertyAttributes(cx, actual, name, attrsp);
}
static JSBool
with_SetElementAttributes(JSContext *cx, HandleObject obj, uint32_t index, unsigned *attrsp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::setElementAttributes(cx, actual, index, attrsp);
}
static JSBool
with_SetSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::setSpecialAttributes(cx, actual, sid, attrsp);
}
@ -558,7 +558,7 @@ static JSBool
with_DeleteProperty(JSContext *cx, HandleObject obj, HandlePropertyName name,
JSBool *succeeded)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::deleteProperty(cx, actual, name, succeeded);
}
@ -566,7 +566,7 @@ static JSBool
with_DeleteElement(JSContext *cx, HandleObject obj, uint32_t index,
JSBool *succeeded)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::deleteElement(cx, actual, index, succeeded);
}
@ -574,7 +574,7 @@ static JSBool
with_DeleteSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid,
JSBool *succeeded)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::deleteSpecial(cx, actual, sid, succeeded);
}
@ -582,17 +582,17 @@ static JSBool
with_Enumerate(JSContext *cx, HandleObject obj, JSIterateOp enum_op,
MutableHandleValue statep, MutableHandleId idp)
{
RootedObject actual(cx, &obj->asWith().object());
RootedObject actual(cx, &obj->as<WithObject>().object());
return JSObject::enumerate(cx, actual, enum_op, statep, idp);
}
static JSObject *
with_ThisObject(JSContext *cx, HandleObject obj)
{
return &obj->asWith().withThis();
return &obj->as<WithObject>().withThis();
}
Class js::WithClass = {
Class WithObject::class_ = {
"With",
JSCLASS_HAS_RESERVED_SLOTS(WithObject::RESERVED_SLOTS) |
JSCLASS_IS_ANONYMOUS,
@ -1034,7 +1034,7 @@ ScopeIter::operator++()
break;
case With:
JS_ASSERT(hasScopeObject_);
cur_ = &cur_->asWith().enclosingScope();
cur_ = &cur_->as<WithObject>().enclosingScope();
settle();
break;
case StrictEvalScope:
@ -1094,10 +1094,10 @@ ScopeIter::settle()
} else if (frame_.isStrictEvalFrame() && !frame_.hasCallObj()) {
JS_ASSERT(cur_ == frame_.evalPrevScopeChain(cx));
frame_ = NullFramePtr();
} else if (cur_->isWith()) {
} else if (cur_->is<WithObject>()) {
JS_ASSERT_IF(frame_.isFunctionFrame(), frame_.fun()->isHeavyweight());
JS_ASSERT_IF(block_, block_->needsClone());
JS_ASSERT_IF(block_, block_->stackDepth() < cur_->asWith().stackDepth());
JS_ASSERT_IF(block_, block_->stackDepth() < cur_->as<WithObject>().stackDepth());
type_ = With;
hasScopeObject_ = true;
} else if (block_) {
@ -1287,7 +1287,7 @@ class DebugScopeProxy : public BaseProxyHandler
}
/* The rest of the internal scopes do not have unaliased vars. */
JS_ASSERT(scope->is<DeclEnvObject>() || scope->isWith() ||
JS_ASSERT(scope->is<DeclEnvObject>() || scope->is<WithObject>() ||
scope->as<CallObject>().isForEval());
return false;
}
@ -1876,7 +1876,7 @@ DebugScopes::onPopWith(AbstractFramePtr frame)
{
DebugScopes *scopes = frame.compartment()->debugScopes;
if (scopes)
scopes->liveScopes.remove(&frame.scopeChain()->asWith());
scopes->liveScopes.remove(&frame.scopeChain()->as<WithObject>());
}
void

View File

@ -265,6 +265,8 @@ class WithObject : public NestedScopeObject
static const unsigned RESERVED_SLOTS = 3;
static const gc::AllocKind FINALIZE_KIND = gc::FINALIZE_OBJECT4_BACKGROUND;
static Class class_;
static WithObject *
create(JSContext *cx, HandleObject proto, HandleObject enclosing, uint32_t depth);
@ -626,7 +628,7 @@ template<>
inline bool
JSObject::is<js::NestedScopeObject>() const
{
return is<js::BlockObject>() || isWith();
return is<js::BlockObject>() || is<js::WithObject>();
}
inline bool

View File

@ -338,8 +338,8 @@ Shape::set(JSContext* cx, HandleObject obj, HandleObject receiver, bool strict,
* |with (it) color='red';| ends up here.
* Avoid exposing the With object to native setters.
*/
if (obj->isWith()) {
RootedObject nobj(cx, &obj->asWith().object());
if (obj->is<WithObject>()) {
RootedObject nobj(cx, &obj->as<WithObject>().object());
return CallJSPropertyOpSetter(cx, self->setterOp(), nobj, id, strict, vp);
}

View File

@ -245,8 +245,8 @@ AssertDynamicScopeMatchesStaticScope(JSContext *cx, JSScript *script, JSObject *
* 'with' does not participate in the static scope of the script,
* but it does in the dynamic scope, so skip them here.
*/
while (scope->isWith())
scope = &scope->asWith().enclosingScope();
while (scope->is<WithObject>())
scope = &scope->as<WithObject>().enclosingScope();
switch (i.type()) {
case StaticScopeIter::BLOCK:
@ -422,7 +422,7 @@ StackFrame::popWith(JSContext *cx)
if (cx->compartment()->debugMode())
DebugScopes::onPopWith(this);
JS_ASSERT(scopeChain()->isWith());
JS_ASSERT(scopeChain()->is<WithObject>());
popOffScopeChain();
}