LCOV - code coverage report
Current view: directory - js/src/vm - ScopeObject-inl.h (source / functions) Found Hit Coverage
Test: app.info Lines: 121 120 99.2 %
Date: 2012-06-02 Functions: 38 38 100.0 %

       1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * vim: set ts=8 sw=4 et tw=78:
       3                 :  *
       4                 :  * ***** BEGIN LICENSE BLOCK *****
       5                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       6                 :  *
       7                 :  * The contents of this file are subject to the Mozilla Public License Version
       8                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       9                 :  * the License. You may obtain a copy of the License at
      10                 :  * http://www.mozilla.org/MPL/
      11                 :  *
      12                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      13                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      14                 :  * for the specific language governing rights and limitations under the
      15                 :  * License.
      16                 :  *
      17                 :  * The Original Code is SpiderMonkey call object code.
      18                 :  *
      19                 :  * The Initial Developer of the Original Code is
      20                 :  * the Mozilla Foundation.
      21                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      22                 :  * the Initial Developer. All Rights Reserved.
      23                 :  *
      24                 :  * Contributor(s):
      25                 :  *   Paul Biggar <pbiggar@mozilla.com> (original author)
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      29                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #ifndef ScopeObject_inl_h___
      42                 : #define ScopeObject_inl_h___
      43                 : 
      44                 : #include "ScopeObject.h"
      45                 : 
      46                 : namespace js {
      47                 : 
      48                 : inline JSObject &
      49         6690585 : ScopeObject::enclosingScope() const
      50                 : {
      51         6690585 :     return getReservedSlot(SCOPE_CHAIN_SLOT).toObject();
      52                 : }
      53                 : 
      54                 : inline bool
      55          765408 : ScopeObject::setEnclosingScope(JSContext *cx, JSObject &obj)
      56                 : {
      57          765408 :     if (!obj.setDelegate(cx))
      58               0 :         return false;
      59          765408 :     setFixedSlot(SCOPE_CHAIN_SLOT, ObjectValue(obj));
      60          765408 :     return true;
      61                 : }
      62                 : 
      63                 : inline StackFrame *
      64         3534981 : ScopeObject::maybeStackFrame() const
      65                 : {
      66         3534981 :     JS_ASSERT(!isStaticBlock());
      67         3534981 :     return reinterpret_cast<StackFrame *>(JSObject::getPrivate());
      68                 : }
      69                 : 
      70                 : inline void
      71         1411821 : ScopeObject::setStackFrame(StackFrame *frame)
      72                 : {
      73         1411821 :     return setPrivate(frame);
      74                 : }
      75                 : 
      76                 : /*static*/ inline size_t
      77           31964 : ScopeObject::offsetOfEnclosingScope()
      78                 : {
      79           31964 :     return getFixedSlotOffset(SCOPE_CHAIN_SLOT);
      80                 : }
      81                 : 
      82                 : inline bool
      83         1505683 : CallObject::isForEval() const
      84                 : {
      85         1505683 :     JS_ASSERT(getReservedSlot(CALLEE_SLOT).isObjectOrNull());
      86         3007523 :     JS_ASSERT_IF(getReservedSlot(CALLEE_SLOT).isObject(),
      87         3007523 :                  getReservedSlot(CALLEE_SLOT).toObject().isFunction());
      88         1505683 :     return getReservedSlot(CALLEE_SLOT).isNull();
      89                 : }
      90                 : 
      91                 : inline void
      92                 : CallObject::setCallee(JSObject *callee)
      93                 : {
      94                 :     JS_ASSERT_IF(callee, callee->isFunction());
      95                 :     setFixedSlot(CALLEE_SLOT, ObjectOrNullValue(callee));
      96                 : }
      97                 : 
      98                 : inline JSObject *
      99         1583634 : CallObject::getCallee() const
     100                 : {
     101         1583634 :     return getReservedSlot(CALLEE_SLOT).toObjectOrNull();
     102                 : }
     103                 : 
     104                 : inline JSFunction *
     105         2246837 : CallObject::getCalleeFunction() const
     106                 : {
     107         2246837 :     return getReservedSlot(CALLEE_SLOT).toObject().toFunction();
     108                 : }
     109                 : 
     110                 : inline const Value &
     111           11236 : CallObject::arguments() const
     112                 : {
     113           11236 :     JS_ASSERT(!isForEval());
     114           11236 :     return getReservedSlot(ARGUMENTS_SLOT);
     115                 : }
     116                 : 
     117                 : inline void
     118            9774 : CallObject::setArguments(const Value &v)
     119                 : {
     120            9774 :     JS_ASSERT(!isForEval());
     121            9774 :     setFixedSlot(ARGUMENTS_SLOT, v);
     122            9774 : }
     123                 : 
     124                 : inline const Value &
     125          123045 : CallObject::arg(unsigned i) const
     126                 : {
     127          123045 :     JS_ASSERT(i < getCalleeFunction()->nargs);
     128          123045 :     return getSlot(RESERVED_SLOTS + i);
     129                 : }
     130                 : 
     131                 : inline void
     132          436019 : CallObject::setArg(unsigned i, const Value &v)
     133                 : {
     134          436019 :     JS_ASSERT(i < getCalleeFunction()->nargs);
     135          436019 :     setSlot(RESERVED_SLOTS + i, v);
     136          436019 : }
     137                 : 
     138                 : inline void
     139                 : CallObject::initArgUnchecked(unsigned i, const Value &v)
     140                 : {
     141                 :     JS_ASSERT(i < getCalleeFunction()->nargs);
     142                 :     initSlotUnchecked(RESERVED_SLOTS + i, v);
     143                 : }
     144                 : 
     145                 : inline const Value &
     146           99750 : CallObject::var(unsigned i) const
     147                 : {
     148           99750 :     JSFunction *fun = getCalleeFunction();
     149           99750 :     JS_ASSERT(fun->nargs == fun->script()->bindings.countArgs());
     150           99750 :     JS_ASSERT(i < fun->script()->bindings.countVars());
     151           99750 :     return getSlot(RESERVED_SLOTS + fun->nargs + i);
     152                 : }
     153                 : 
     154                 : inline void
     155          235371 : CallObject::setVar(unsigned i, const Value &v)
     156                 : {
     157          235371 :     JSFunction *fun = getCalleeFunction();
     158          235371 :     JS_ASSERT(fun->nargs == fun->script()->bindings.countArgs());
     159          235371 :     JS_ASSERT(i < fun->script()->bindings.countVars());
     160          235371 :     setSlot(RESERVED_SLOTS + fun->nargs + i, v);
     161          235371 : }
     162                 : 
     163                 : inline void
     164                 : CallObject::initVarUnchecked(unsigned i, const Value &v)
     165                 : {
     166                 :     JSFunction *fun = getCalleeFunction();
     167                 :     JS_ASSERT(fun->nargs == fun->script()->bindings.countArgs());
     168                 :     JS_ASSERT(i < fun->script()->bindings.countVars());
     169                 :     initSlotUnchecked(RESERVED_SLOTS + fun->nargs + i, v);
     170                 : }
     171                 : 
     172                 : inline void
     173           88592 : CallObject::copyValues(unsigned nargs, Value *argv, unsigned nvars, Value *slots)
     174                 : {
     175           88592 :     JS_ASSERT(slotInRange(RESERVED_SLOTS + nargs + nvars, SENTINEL_ALLOWED));
     176           88592 :     copySlotRange(RESERVED_SLOTS, argv, nargs);
     177           88592 :     copySlotRange(RESERVED_SLOTS + nargs, slots, nvars);
     178           88592 : }
     179                 : 
     180                 : inline HeapSlotArray
     181          100667 : CallObject::argArray()
     182                 : {
     183          201334 :     DebugOnly<JSFunction*> fun = getCalleeFunction();
     184          100667 :     JS_ASSERT(hasContiguousSlots(RESERVED_SLOTS, fun->nargs));
     185          100667 :     return HeapSlotArray(getSlotAddress(RESERVED_SLOTS));
     186                 : }
     187                 : 
     188                 : inline HeapSlotArray
     189          100667 : CallObject::varArray()
     190                 : {
     191          100667 :     JSFunction *fun = getCalleeFunction();
     192          100667 :     JS_ASSERT(hasContiguousSlots(RESERVED_SLOTS + fun->nargs,
     193          100667 :                                  fun->script()->bindings.countVars()));
     194          100667 :     return HeapSlotArray(getSlotAddress(RESERVED_SLOTS + fun->nargs));
     195                 : }
     196                 : 
     197                 : inline uint32_t
     198         2821817 : NestedScopeObject::stackDepth() const
     199                 : {
     200         2821817 :     return getReservedSlot(DEPTH_SLOT).toPrivateUint32();
     201                 : }
     202                 : 
     203                 : inline JSObject &
     204              18 : WithObject::withThis() const
     205                 : {
     206              18 :     return getReservedSlot(THIS_SLOT).toObject();
     207                 : }
     208                 : 
     209                 : inline JSObject &
     210            3384 : WithObject::object() const
     211                 : {
     212            3384 :     return *JSObject::getProto();
     213                 : }
     214                 : 
     215                 : inline uint32_t
     216         6327455 : BlockObject::slotCount() const
     217                 : {
     218         6327455 :     return propertyCount();
     219                 : }
     220                 : 
     221                 : inline HeapSlot &
     222         3026698 : BlockObject::slotValue(unsigned i)
     223                 : {
     224         3026698 :     return getSlotRef(RESERVED_SLOTS + i);
     225                 : }
     226                 : 
     227                 : inline StaticBlockObject *
     228         3307954 : StaticBlockObject::enclosingBlock() const
     229                 : {
     230         3307954 :     JSObject *obj = getReservedSlot(SCOPE_CHAIN_SLOT).toObjectOrNull();
     231         3307954 :     return obj ? &obj->asStaticBlock() : NULL;
     232                 : }
     233                 : 
     234                 : inline void
     235         1009287 : StaticBlockObject::setEnclosingBlock(StaticBlockObject *blockObj)
     236                 : {
     237         1009287 :     setFixedSlot(SCOPE_CHAIN_SLOT, ObjectOrNullValue(blockObj));
     238         1009287 : }
     239                 : 
     240                 : inline void
     241          560193 : StaticBlockObject::setStackDepth(uint32_t depth)
     242                 : {
     243          560193 :     JS_ASSERT(getReservedSlot(DEPTH_SLOT).isUndefined());
     244          560193 :     initReservedSlot(DEPTH_SLOT, PrivateUint32Value(depth));
     245          560193 : }
     246                 : 
     247                 : inline void
     248          751337 : StaticBlockObject::setDefinitionParseNode(unsigned i, Definition *def)
     249                 : {
     250          751337 :     JS_ASSERT(slotValue(i).isUndefined());
     251          751337 :     slotValue(i).init(this, i, PrivateValue(def));
     252          751337 : }
     253                 : 
     254                 : inline Definition *
     255          752343 : StaticBlockObject::maybeDefinitionParseNode(unsigned i)
     256                 : {
     257          752343 :     Value v = slotValue(i);
     258          752343 :     return v.isUndefined() ? NULL : reinterpret_cast<Definition *>(v.toPrivate());
     259                 : }
     260                 : 
     261                 : inline void
     262          752343 : StaticBlockObject::poisonDefinitionParseNode(unsigned i)
     263                 : {
     264          752343 :     slotValue(i).init(this, i, PrivateValue(NULL));
     265          752343 : }
     266                 : 
     267                 : inline StaticBlockObject &
     268            8944 : ClonedBlockObject::staticBlock() const
     269                 : {
     270            8944 :     return getProto()->asStaticBlock();
     271                 : }
     272                 : 
     273                 : inline const Value &
     274           19338 : ClonedBlockObject::closedSlot(unsigned i)
     275                 : {
     276           19338 :     JS_ASSERT(!maybeStackFrame());
     277           19338 :     return slotValue(i);
     278                 : }
     279                 : 
     280                 : }  /* namespace js */
     281                 : 
     282                 : inline js::ScopeObject &
     283         7375147 : JSObject::asScope()
     284                 : {
     285         7375147 :     JS_ASSERT(isScope());
     286         7375147 :     return *static_cast<js::ScopeObject *>(this);
     287                 : }
     288                 : 
     289                 : inline js::CallObject &
     290         5888383 : JSObject::asCall()
     291                 : {
     292         5888383 :     JS_ASSERT(isCall());
     293         5888383 :     return *static_cast<js::CallObject *>(this);
     294                 : }
     295                 : 
     296                 : inline js::DeclEnvObject &
     297           83090 : JSObject::asDeclEnv()
     298                 : {
     299           83090 :     JS_ASSERT(isDeclEnv());
     300           83090 :     return *static_cast<js::DeclEnvObject *>(this);
     301                 : }
     302                 : 
     303                 : inline js::NestedScopeObject &
     304             175 : JSObject::asNestedScope()
     305                 : {
     306             175 :     JS_ASSERT(isWith() || isBlock());
     307             175 :     return *static_cast<js::NestedScopeObject *>(this);
     308                 : }
     309                 : 
     310                 : inline js::WithObject &
     311            7218 : JSObject::asWith()
     312                 : {
     313            7218 :     JS_ASSERT(isWith());
     314            7218 :     return *static_cast<js::WithObject *>(this);
     315                 : }
     316                 : 
     317                 : inline js::BlockObject &
     318           18833 : JSObject::asBlock()
     319                 : {
     320           18833 :     JS_ASSERT(isBlock());
     321           18833 :     return *static_cast<js::BlockObject *>(this);
     322                 : }
     323                 : 
     324                 : inline js::StaticBlockObject &
     325         4228189 : JSObject::asStaticBlock()
     326                 : {
     327         4228189 :     JS_ASSERT(isStaticBlock());
     328         4228189 :     return *static_cast<js::StaticBlockObject *>(this);
     329                 : }
     330                 : 
     331                 : inline js::ClonedBlockObject &
     332          616641 : JSObject::asClonedBlock()
     333                 : {
     334          616641 :     JS_ASSERT(isClonedBlock());
     335          616641 :     return *static_cast<js::ClonedBlockObject *>(this);
     336                 : }
     337                 : 
     338                 : #endif /* CallObject_inl_h___ */

Generated by: LCOV version 1.7