Bug 880041 (part 14) - Use JSObject::{is,as} for DeclEnvObject. r=evilpies.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 16 Jun 2013 19:02:10 -0700
changeset 135243 90b688861270ea9b1462786122a6ac2546fff018
parent 135242 af5e07a1308bd2db5ad492c0194fe10b0fc50005
child 135244 ff486a6eb5c9644f0cfb73676e1c8658a5369531
push id29584
push usernnethercote@mozilla.com
push dateMon, 17 Jun 2013 05:34:23 +0000
treeherdermozilla-inbound@90b688861270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpies
bugs880041
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 880041 (part 14) - Use JSObject::{is,as} for DeclEnvObject. r=evilpies.
js/src/ion/BaselineFrame-inl.h
js/src/ion/VMFunctions.h
js/src/jsfriendapi.h
js/src/jsobj.h
js/src/shell/jsheaptools.cpp
js/src/vm/ScopeObject-inl.h
js/src/vm/ScopeObject.cpp
js/src/vm/ScopeObject.h
js/src/vm/Stack-inl.h
js/src/vm/Stack.cpp
--- a/js/src/ion/BaselineFrame-inl.h
+++ b/js/src/ion/BaselineFrame-inl.h
@@ -17,17 +17,17 @@
 
 namespace js {
 namespace ion {
 
 inline void
 BaselineFrame::pushOnScopeChain(ScopeObject &scope)
 {
     JS_ASSERT(*scopeChain() == scope.enclosingScope() ||
-              *scopeChain() == scope.as<CallObject>().enclosingScope().asDeclEnv().enclosingScope());
+              *scopeChain() == scope.as<CallObject>().enclosingScope().as<DeclEnvObject>().enclosingScope());
     scopeChain_ = &scope;
 }
 
 inline void
 BaselineFrame::popOffScopeChain()
 {
     scopeChain_ = &scopeChain_->asScope().enclosingScope();
 }
--- a/js/src/ion/VMFunctions.h
+++ b/js/src/ion/VMFunctions.h
@@ -6,16 +6,17 @@
 
 #ifndef jsion_vm_functions_h__
 #define jsion_vm_functions_h__
 
 #include "jspubtd.h"
 
 namespace js {
 
+class DeclEnvObject;
 class ForkJoinSlice;
 
 namespace ion {
 
 enum DataType {
     Type_Void,
     Type_Bool,
     Type_Int32,
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -371,17 +371,16 @@ struct Function {
 struct Atom {
     static const size_t LENGTH_SHIFT = 4;
     size_t lengthAndFlags;
     const jschar *chars;
 };
 
 } /* namespace shadow */
 
-extern JS_FRIEND_DATA(js::Class) DeclEnvClass;
 extern JS_FRIEND_DATA(js::Class) FunctionClass;
 extern JS_FRIEND_DATA(js::Class) FunctionProxyClass;
 extern JS_FRIEND_DATA(js::Class) OuterWindowProxyClass;
 extern JS_FRIEND_DATA(js::Class) ObjectProxyClass;
 extern JS_FRIEND_DATA(js::Class) ObjectClass;
 
 inline js::Class *
 GetObjectClass(JSObject *obj)
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -218,17 +218,16 @@ extern Class StopIterationClass;
 extern Class StringClass;
 extern Class WeakMapClass;
 extern Class WithClass;
 
 class ArrayBufferObject;
 class BooleanObject;
 class ClonedBlockObject;
 class DebugScopeObject;
-class DeclEnvObject;
 class GlobalObject;
 class MapObject;
 class NestedScopeObject;
 class NewObjectCache;
 class NormalArgumentsObject;
 class NumberObject;
 class ScopeObject;
 class SetObject;
@@ -483,17 +482,17 @@ class JSObject : public js::ObjectImpl
      * created functions for non-compileAndGo scripts.
      *
      * Except for the non-script-accessible builtins, the global with which an
      * object is associated can be reached by following parent links to that
      * global (see global()).
      *
      * The scope chain of an object is the link in the search path when a
      * script does a name lookup on a scope object. For JS internal scope
-     * objects --- Call, DeclEnv and block --- the chain is stored in
+     * objects --- Call, DeclEnv and Block --- the chain is stored in
      * the first fixed slot of the object, and the object's parent is the
      * associated global. For other scope objects, the chain is stored in the
      * object's parent.
      *
      * In compileAndGo code, scope chains can contain only internal scope
      * objects with a global object at the root as the scope of the outermost
      * non-function script. In non-compileAndGo code, the scope of the
      * outermost non-function script might not be a global object, and can have
@@ -971,17 +970,16 @@ class JSObject : public js::ObjectImpl
     using js::ObjectImpl::isProxy;
     inline bool isRegExpStatics()    const { return hasClass(&js::RegExpStaticsClass); }
     inline bool isScope()            const;
     inline bool isStopIteration()    const { return hasClass(&js::StopIterationClass); }
     inline bool isTypedArray()       const;
     inline bool isWeakMap()          const { return hasClass(&js::WeakMapClass); }
 
     /* Subtypes of ScopeObject. */
-    inline bool isDeclEnv()     const { return hasClass(&js::DeclEnvClass); }
     inline bool isNestedScope() const;
     inline bool isWith()        const { return hasClass(&js::WithClass); }
     inline bool isClonedBlock() const;
     inline bool isStaticBlock() const;
 
     /* Subtypes of PrimitiveObject. */
     inline bool isBoolean() const { return hasClass(&js::BooleanClass); }
     inline bool isNumber()  const { return hasClass(&js::NumberClass); }
@@ -990,17 +988,16 @@ class JSObject : public js::ObjectImpl
     /* Subtypes of Proxy. */
     inline bool isDebugScope()              const;
     inline bool isWrapper()                 const;
     inline bool isFunctionProxy()           const { return hasClass(&js::FunctionProxyClass); }
     inline bool isCrossCompartmentWrapper() const;
 
     inline js::BooleanObject &asBoolean();
     inline js::ClonedBlockObject &asClonedBlock();
-    inline js::DeclEnvObject &asDeclEnv();
     inline js::DebugScopeObject &asDebugScope();
     inline js::GlobalObject &asGlobal();
     inline js::MapObject &asMap();
     inline js::NestedScopeObject &asNestedScope();
     inline js::NumberObject &asNumber();
     inline js::ScopeObject &asScope();
     inline js::SetObject &asSet();
     inline js::StaticBlockObject &asStaticBlock();
--- a/js/src/shell/jsheaptools.cpp
+++ b/js/src/shell/jsheaptools.cpp
@@ -381,17 +381,17 @@ class ReferenceFinder {
     jsval representable(void *cell, int kind) {
         if (kind == JSTRACE_OBJECT) {
             JSObject *object = static_cast<JSObject *>(cell);
 
             /* Certain classes of object are for internal use only. */
             if (object->is<BlockObject>() ||
                 object->is<CallObject>() ||
                 object->isWith() ||
-                object->isDeclEnv()) {
+                object->is<DeclEnvObject>()) {
                 return JSVAL_VOID;
             }
 
             /* Internal function objects should also not be revealed. */
             if (JS_ObjectIsFunction(context, object) && IsInternalFunctionObject(object))
                 return JSVAL_VOID;
 
             return OBJECT_TO_JSVAL(object);
--- a/js/src/vm/ScopeObject-inl.h
+++ b/js/src/vm/ScopeObject-inl.h
@@ -26,17 +26,17 @@ inline JSObject &
 ScopeObject::enclosingScope() const
 {
     return getReservedSlot(SCOPE_CHAIN_SLOT).toObject();
 }
 
 inline void
 ScopeObject::setEnclosingScope(HandleObject obj)
 {
-    JS_ASSERT_IF(obj->is<CallObject>() || obj->isDeclEnv() || obj->is<BlockObject>(),
+    JS_ASSERT_IF(obj->is<CallObject>() || obj->is<DeclEnvObject>() || obj->is<BlockObject>(),
                  obj->isDelegate());
     setFixedSlot(SCOPE_CHAIN_SLOT, ObjectValue(*obj));
 }
 
 inline const Value &
 ScopeObject::aliasedVar(ScopeCoordinate sc)
 {
     JS_ASSERT(is<CallObject>() || isClonedBlock());
@@ -254,23 +254,16 @@ ClonedBlockObject::setVar(unsigned i, co
 
 inline js::ScopeObject &
 JSObject::asScope()
 {
     JS_ASSERT(isScope());
     return *static_cast<js::ScopeObject *>(this);
 }
 
-inline js::DeclEnvObject &
-JSObject::asDeclEnv()
-{
-    JS_ASSERT(isDeclEnv());
-    return *static_cast<js::DeclEnvObject *>(this);
-}
-
 inline js::NestedScopeObject &
 JSObject::asNestedScope()
 {
     JS_ASSERT(isWith() || is<js::BlockObject>());
     return *static_cast<js::NestedScopeObject *>(this);
 }
 
 inline js::WithObject &
--- a/js/src/vm/ScopeObject.cpp
+++ b/js/src/vm/ScopeObject.cpp
@@ -303,17 +303,17 @@ Class CallObject::class_ = {
     JS_DeletePropertyStub,   /* delProperty */
     JS_PropertyStub,         /* getProperty */
     JS_StrictPropertyStub,   /* setProperty */
     JS_EnumerateStub,
     JS_ResolveStub,
     NULL                     /* convert: Leave it NULL so we notice if calls ever escape */
 };
 
-Class js::DeclEnvClass = {
+Class DeclEnvObject::class_ = {
     js_Object_str,
     JSCLASS_HAS_RESERVED_SLOTS(DeclEnvObject::RESERVED_SLOTS) |
     JSCLASS_HAS_CACHED_PROTO(JSProto_Object),
     JS_PropertyStub,         /* addProperty */
     JS_DeletePropertyStub,   /* delProperty */
     JS_PropertyStub,         /* getProperty */
     JS_StrictPropertyStub,   /* setProperty */
     JS_EnumerateStub,
@@ -324,22 +324,22 @@ Class js::DeclEnvClass = {
 /*
  * Create a DeclEnvObject for a JSScript that is not initialized to any
  * particular callsite. This object can either be initialized (with an enclosing
  * scope and callee) or used as a template for jit compilation.
  */
 DeclEnvObject *
 DeclEnvObject::createTemplateObject(JSContext *cx, HandleFunction fun, gc::InitialHeap heap)
 {
-    RootedTypeObject type(cx, cx->compartment()->getNewType(cx, &DeclEnvClass, NULL));
+    RootedTypeObject type(cx, cx->compartment()->getNewType(cx, &class_, NULL));
     if (!type)
         return NULL;
 
     RootedShape emptyDeclEnvShape(cx);
-    emptyDeclEnvShape = EmptyShape::getInitialShape(cx, &DeclEnvClass, NULL,
+    emptyDeclEnvShape = EmptyShape::getInitialShape(cx, &class_, NULL,
                                                     cx->global(), NULL, FINALIZE_KIND,
                                                     BaseShape::DELEGATE);
     if (!emptyDeclEnvShape)
         return NULL;
 
     RootedObject obj(cx, JSObject::create(cx, FINALIZE_KIND, heap, emptyDeclEnvShape, type));
     if (!obj)
         return NULL;
@@ -350,29 +350,29 @@ DeclEnvObject::createTemplateObject(JSCo
     unsigned attrs = JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY;
     if (!JSObject::putProperty(cx, obj, id, clasp->getProperty, clasp->setProperty,
                                lambdaSlot(), attrs, 0, 0))
     {
         return NULL;
     }
 
     JS_ASSERT(!obj->hasDynamicSlots());
-    return &obj->asDeclEnv();
+    return &obj->as<DeclEnvObject>();
 }
 
 DeclEnvObject *
 DeclEnvObject::create(JSContext *cx, HandleObject enclosing, HandleFunction callee)
 {
     RootedObject obj(cx, createTemplateObject(cx, callee, gc::DefaultHeap));
     if (!obj)
         return NULL;
 
     obj->asScope().setEnclosingScope(enclosing);
     obj->setFixedSlot(lambdaSlot(), ObjectValue(*callee));
-    return &obj->asDeclEnv();
+    return &obj->as<DeclEnvObject>();
 }
 
 WithObject *
 WithObject::create(JSContext *cx, HandleObject proto, HandleObject enclosing, uint32_t depth)
 {
     RootedTypeObject type(cx, proto->getNewType(cx, &WithClass));
     if (!type)
         return NULL;
@@ -1017,17 +1017,17 @@ ScopeIter &
 ScopeIter::operator++()
 {
     JS_ASSERT(!done());
     switch (type_) {
       case Call:
         if (hasScopeObject_) {
             cur_ = &cur_->as<CallObject>().enclosingScope();
             if (CallObjectLambdaName(*frame_.fun()))
-                cur_ = &cur_->asDeclEnv().enclosingScope();
+                cur_ = &cur_->as<DeclEnvObject>().enclosingScope();
         }
         frame_ = NullFramePtr();
         break;
       case Block:
         block_ = block_->enclosingBlock();
         if (hasScopeObject_)
             cur_ = &cur_->asClonedBlock().enclosingScope();
         settle();
@@ -1282,17 +1282,18 @@ class DebugScopeProxy : public BaseProxy
                 else
                     block->setVar(i, vp, DONT_CHECK_ALIASING);
             }
 
             return true;
         }
 
         /* The rest of the internal scopes do not have unaliased vars. */
-        JS_ASSERT(scope->isDeclEnv() || scope->isWith() || scope->as<CallObject>().isForEval());
+        JS_ASSERT(scope->is<DeclEnvObject>() || scope->isWith() ||
+                  scope->as<CallObject>().isForEval());
         return false;
     }
 
     static bool isArguments(JSContext *cx, jsid id)
     {
         return id == NameToId(cx->names().arguments);
     }
 
@@ -1567,17 +1568,17 @@ DebugScopeObject::initSnapshot(JSObject 
     JS_ASSERT(maybeSnapshot() == NULL);
     SetProxyExtra(this, SNAPSHOT_EXTRA, ObjectValue(o));
 }
 
 bool
 DebugScopeObject::isForDeclarative() const
 {
     ScopeObject &s = scope();
-    return s.is<CallObject>() || s.is<BlockObject>() || s.isDeclEnv();
+    return s.is<CallObject>() || s.is<BlockObject>() || s.is<DeclEnvObject>();
 }
 
 bool
 js_IsDebugScopeSlow(JSObject *obj)
 {
     return obj->getClass() == &ObjectProxyClass &&
            GetProxyHandler(obj) == &DebugScopeProxy::singleton;
 }
@@ -2030,19 +2031,19 @@ GetDebugScopeForScope(JSContext *cx, Han
     if (DebugScopeObject *debugScope = DebugScopes::hasDebugScope(cx, *scope))
         return debugScope;
 
     RootedObject enclosingDebug(cx, GetDebugScope(cx, enclosing));
     if (!enclosingDebug)
         return NULL;
 
     JSObject &maybeDecl = scope->enclosingScope();
-    if (maybeDecl.isDeclEnv()) {
+    if (maybeDecl.is<DeclEnvObject>()) {
         JS_ASSERT(CallObjectLambdaName(scope->as<CallObject>().callee()));
-        enclosingDebug = DebugScopeObject::create(cx, maybeDecl.asDeclEnv(), enclosingDebug);
+        enclosingDebug = DebugScopeObject::create(cx, maybeDecl.as<DeclEnvObject>(), enclosingDebug);
         if (!enclosingDebug)
             return NULL;
     }
 
     DebugScopeObject *debugScope = DebugScopeObject::create(cx, *scope, enclosingDebug);
     if (!debugScope)
         return NULL;
 
@@ -2076,19 +2077,19 @@ GetDebugScopeForMissing(JSContext *cx, c
      */
     DebugScopeObject *debugScope = NULL;
     switch (si.type()) {
       case ScopeIter::Call: {
         Rooted<CallObject*> callobj(cx, CallObject::createForFunction(cx, si.frame()));
         if (!callobj)
             return NULL;
 
-        if (callobj->enclosingScope().isDeclEnv()) {
+        if (callobj->enclosingScope().is<DeclEnvObject>()) {
             JS_ASSERT(CallObjectLambdaName(callobj->callee()));
-            DeclEnvObject &declenv = callobj->enclosingScope().asDeclEnv();
+            DeclEnvObject &declenv = callobj->enclosingScope().as<DeclEnvObject>();
             enclosingDebug = DebugScopeObject::create(cx, declenv, enclosingDebug);
             if (!enclosingDebug)
                 return NULL;
         }
 
         debugScope = DebugScopeObject::create(cx, *callobj, enclosingDebug);
         break;
       }
--- a/js/src/vm/ScopeObject.h
+++ b/js/src/vm/ScopeObject.h
@@ -229,16 +229,18 @@ class DeclEnvObject : public ScopeObject
 {
     // Pre-allocated slot for the named lambda.
     static const uint32_t LAMBDA_SLOT = 1;
 
   public:
     static const uint32_t RESERVED_SLOTS = 2;
     static const gc::AllocKind FINALIZE_KIND = gc::FINALIZE_OBJECT2;
 
+    static Class class_;
+
     static DeclEnvObject *
     createTemplateObject(JSContext *cx, HandleFunction fun, gc::InitialHeap heap);
 
     static DeclEnvObject *create(JSContext *cx, HandleObject enclosing, HandleFunction callee);
 
     static inline size_t lambdaSlot() {
         return LAMBDA_SLOT;
     }
@@ -626,12 +628,12 @@ inline bool
 JSObject::isNestedScope() const
 {
     return is<js::BlockObject>() || isWith();
 }
 
 inline bool
 JSObject::isScope() const
 {
-    return is<js::CallObject>() || isDeclEnv() || isNestedScope();
+    return is<js::CallObject>() || is<js::DeclEnvObject>() || isNestedScope();
 }
 
 #endif /* ScopeObject_h___ */
--- a/js/src/vm/Stack-inl.h
+++ b/js/src/vm/Stack-inl.h
@@ -26,17 +26,17 @@ namespace js {
 /*
  * We cache name lookup results only for the global object or for native
  * non-global objects without prototype or with prototype that never mutates,
  * see bug 462734 and bug 487039.
  */
 static inline bool
 IsCacheableNonGlobalScope(JSObject *obj)
 {
-    bool cacheable = (obj->is<CallObject>() || obj->is<BlockObject>() || obj->isDeclEnv());
+    bool cacheable = (obj->is<CallObject>() || obj->is<BlockObject>() || obj->is<DeclEnvObject>());
 
     JS_ASSERT_IF(cacheable, !obj->getOps()->lookupProperty);
     return cacheable;
 }
 
 inline HandleObject
 StackFrame::scopeChain() const
 {
@@ -204,17 +204,17 @@ StackFrame::aliasedVarScope(ScopeCoordin
         scope = &scope->asScope().enclosingScope();
     return scope->asScope();
 }
 
 inline void
 StackFrame::pushOnScopeChain(ScopeObject &scope)
 {
     JS_ASSERT(*scopeChain() == scope.enclosingScope() ||
-              *scopeChain() == scope.as<CallObject>().enclosingScope().asDeclEnv().enclosingScope());
+              *scopeChain() == scope.as<CallObject>().enclosingScope().as<DeclEnvObject>().enclosingScope());
     scopeChain_ = &scope;
     flags_ |= HAS_SCOPECHAIN;
 }
 
 inline void
 StackFrame::popOffScopeChain()
 {
     JS_ASSERT(flags_ & HAS_SCOPECHAIN);
--- a/js/src/vm/Stack.cpp
+++ b/js/src/vm/Stack.cpp
@@ -260,17 +260,17 @@ AssertDynamicScopeMatchesStaticScope(JSC
                 JS_ASSERT(i.block() == scope->asClonedBlock().staticBlock());
                 scope = &scope->asClonedBlock().enclosingScope();
                 break;
               case StaticScopeIter::FUNCTION:
                 JS_ASSERT(scope->as<CallObject>().callee().nonLazyScript() == i.funScript());
                 scope = &scope->as<CallObject>().enclosingScope();
                 break;
               case StaticScopeIter::NAMED_LAMBDA:
-                scope = &scope->asDeclEnv().enclosingScope();
+                scope = &scope->as<DeclEnvObject>().enclosingScope();
                 break;
             }
         }
     }
 
     /*
      * Ideally, we'd JS_ASSERT(!scope->isScope()) but the enclosing lexical
      * scope chain stops at eval() boundaries. See StaticScopeIter comment.