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-04-07 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         2804624 : ScopeObject::enclosingScope() const
      50                 : {
      51         2804624 :     return getReservedSlot(SCOPE_CHAIN_SLOT).toObject();
      52                 : }
      53                 : 
      54                 : inline bool
      55          756950 : ScopeObject::setEnclosingScope(JSContext *cx, JSObject &obj)
      56                 : {
      57          756950 :     if (!obj.setDelegate(cx))
      58               0 :         return false;
      59          756950 :     setFixedSlot(SCOPE_CHAIN_SLOT, ObjectValue(obj));
      60          756950 :     return true;
      61                 : }
      62                 : 
      63                 : inline StackFrame *
      64         2358525 : ScopeObject::maybeStackFrame() const
      65                 : {
      66         2358525 :     JS_ASSERT(!isStaticBlock());
      67         2358525 :     return reinterpret_cast<StackFrame *>(JSObject::getPrivate());
      68                 : }
      69                 : 
      70                 : inline void
      71         1493061 : ScopeObject::setStackFrame(StackFrame *frame)
      72                 : {
      73         1493061 :     return setPrivate(frame);
      74                 : }
      75                 : 
      76                 : /*static*/ inline size_t
      77           25079 : ScopeObject::offsetOfEnclosingScope()
      78                 : {
      79           25079 :     return getFixedSlotOffset(SCOPE_CHAIN_SLOT);
      80                 : }
      81                 : 
      82                 : inline bool
      83         1559954 : CallObject::isForEval() const
      84                 : {
      85         1559954 :     JS_ASSERT(getReservedSlot(CALLEE_SLOT).isObjectOrNull());
      86         3116065 :     JS_ASSERT_IF(getReservedSlot(CALLEE_SLOT).isObject(),
      87         3116065 :                  getReservedSlot(CALLEE_SLOT).toObject().isFunction());
      88         1559954 :     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          486514 : CallObject::getCallee() const
     100                 : {
     101          486514 :     return getReservedSlot(CALLEE_SLOT).toObjectOrNull();
     102                 : }
     103                 : 
     104                 : inline JSFunction *
     105         2480735 : CallObject::getCalleeFunction() const
     106                 : {
     107         2480735 :     return getReservedSlot(CALLEE_SLOT).toObject().toFunction();
     108                 : }
     109                 : 
     110                 : inline const Value &
     111             999 : CallObject::arguments() const
     112                 : {
     113             999 :     JS_ASSERT(!isForEval());
     114             999 :     return getReservedSlot(ARGUMENTS_SLOT);
     115                 : }
     116                 : 
     117                 : inline void
     118           31307 : CallObject::setArguments(const Value &v)
     119                 : {
     120           31307 :     JS_ASSERT(!isForEval());
     121           31307 :     setFixedSlot(ARGUMENTS_SLOT, v);
     122           31307 : }
     123                 : 
     124                 : inline const Value &
     125            3585 : CallObject::arg(unsigned i) const
     126                 : {
     127            3585 :     JS_ASSERT(i < getCalleeFunction()->nargs);
     128            3585 :     return getSlot(RESERVED_SLOTS + i);
     129                 : }
     130                 : 
     131                 : inline void
     132          170224 : CallObject::setArg(unsigned i, const Value &v)
     133                 : {
     134          170224 :     JS_ASSERT(i < getCalleeFunction()->nargs);
     135          170224 :     setSlot(RESERVED_SLOTS + i, v);
     136          170224 : }
     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           94315 : CallObject::var(unsigned i) const
     147                 : {
     148           94315 :     JSFunction *fun = getCalleeFunction();
     149           94315 :     JS_ASSERT(fun->nargs == fun->script()->bindings.countArgs());
     150           94315 :     JS_ASSERT(i < fun->script()->bindings.countVars());
     151           94315 :     return getSlot(RESERVED_SLOTS + fun->nargs + i);
     152                 : }
     153                 : 
     154                 : inline void
     155          326570 : CallObject::setVar(unsigned i, const Value &v)
     156                 : {
     157          326570 :     JSFunction *fun = getCalleeFunction();
     158          326570 :     JS_ASSERT(fun->nargs == fun->script()->bindings.countArgs());
     159          326570 :     JS_ASSERT(i < fun->script()->bindings.countVars());
     160          326570 :     setSlot(RESERVED_SLOTS + fun->nargs + i, v);
     161          326570 : }
     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          187279 : CallObject::copyValues(unsigned nargs, Value *argv, unsigned nvars, Value *slots)
     174                 : {
     175          187279 :     JS_ASSERT(slotInRange(RESERVED_SLOTS + nargs + nvars, SENTINEL_ALLOWED));
     176          187279 :     copySlotRange(RESERVED_SLOTS, argv, nargs);
     177          187279 :     copySlotRange(RESERVED_SLOTS + nargs, slots, nvars);
     178          187279 : }
     179                 : 
     180                 : inline HeapSlotArray
     181          276879 : CallObject::argArray()
     182                 : {
     183          553758 :     DebugOnly<JSFunction*> fun = getCalleeFunction();
     184          276879 :     JS_ASSERT(hasContiguousSlots(RESERVED_SLOTS, fun->nargs));
     185          276879 :     return HeapSlotArray(getSlotAddress(RESERVED_SLOTS));
     186                 : }
     187                 : 
     188                 : inline HeapSlotArray
     189          276879 : CallObject::varArray()
     190                 : {
     191          276879 :     JSFunction *fun = getCalleeFunction();
     192          276879 :     JS_ASSERT(hasContiguousSlots(RESERVED_SLOTS + fun->nargs,
     193          276879 :                                  fun->script()->bindings.countVars()));
     194          276879 :     return HeapSlotArray(getSlotAddress(RESERVED_SLOTS + fun->nargs));
     195                 : }
     196                 : 
     197                 : inline uint32_t
     198          175553 : NestedScopeObject::stackDepth() const
     199                 : {
     200          175553 :     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            3438 : WithObject::object() const
     211                 : {
     212            3438 :     return *JSObject::getProto();
     213                 : }
     214                 : 
     215                 : inline uint32_t
     216         1590457 : BlockObject::slotCount() const
     217                 : {
     218         1590457 :     return propertyCount();
     219                 : }
     220                 : 
     221                 : inline HeapSlot &
     222         1295487 : BlockObject::slotValue(unsigned i)
     223                 : {
     224         1295487 :     return getSlotRef(RESERVED_SLOTS + i);
     225                 : }
     226                 : 
     227                 : inline StaticBlockObject *
     228          345905 : StaticBlockObject::enclosingBlock() const
     229                 : {
     230          345905 :     JSObject *obj = getReservedSlot(SCOPE_CHAIN_SLOT).toObjectOrNull();
     231          345905 :     return obj ? &obj->asStaticBlock() : NULL;
     232                 : }
     233                 : 
     234                 : inline void
     235          201441 : StaticBlockObject::setEnclosingBlock(StaticBlockObject *blockObj)
     236                 : {
     237          201441 :     setFixedSlot(SCOPE_CHAIN_SLOT, ObjectOrNullValue(blockObj));
     238          201441 : }
     239                 : 
     240                 : inline void
     241          100595 : StaticBlockObject::setStackDepth(uint32_t depth)
     242                 : {
     243          100595 :     JS_ASSERT(getReservedSlot(DEPTH_SLOT).isUndefined());
     244          100595 :     initReservedSlot(DEPTH_SLOT, PrivateUint32Value(depth));
     245          100595 : }
     246                 : 
     247                 : inline void
     248          323318 : StaticBlockObject::setDefinitionParseNode(unsigned i, Definition *def)
     249                 : {
     250          323318 :     JS_ASSERT(slotValue(i).isUndefined());
     251          323318 :     slotValue(i).init(this, i, PrivateValue(def));
     252          323318 : }
     253                 : 
     254                 : inline Definition *
     255          324254 : StaticBlockObject::maybeDefinitionParseNode(unsigned i)
     256                 : {
     257          324254 :     Value v = slotValue(i);
     258          324254 :     return v.isUndefined() ? NULL : reinterpret_cast<Definition *>(v.toPrivate());
     259                 : }
     260                 : 
     261                 : inline void
     262          324254 : StaticBlockObject::poisonDefinitionParseNode(unsigned i)
     263                 : {
     264          324254 :     slotValue(i).init(this, i, PrivateValue(NULL));
     265          324254 : }
     266                 : 
     267                 : inline StaticBlockObject &
     268             270 : ClonedBlockObject::staticBlock() const
     269                 : {
     270             270 :     return getProto()->asStaticBlock();
     271                 : }
     272                 : 
     273                 : inline const Value &
     274             343 : ClonedBlockObject::closedSlot(unsigned i)
     275                 : {
     276             343 :     JS_ASSERT(!maybeStackFrame());
     277             343 :     return slotValue(i);
     278                 : }
     279                 : 
     280                 : }  /* namespace js */
     281                 : 
     282                 : inline js::ScopeObject &
     283         3547522 : JSObject::asScope()
     284                 : {
     285         3547522 :     JS_ASSERT(isScope());
     286         3547522 :     return *static_cast<js::ScopeObject *>(this);
     287                 : }
     288                 : 
     289                 : inline js::CallObject &
     290         4588304 : JSObject::asCall()
     291                 : {
     292         4588304 :     JS_ASSERT(isCall());
     293         4588304 :     return *static_cast<js::CallObject *>(this);
     294                 : }
     295                 : 
     296                 : inline js::DeclEnvObject &
     297           16274 : JSObject::asDeclEnv()
     298                 : {
     299           16274 :     JS_ASSERT(isDeclEnv());
     300           16274 :     return *static_cast<js::DeclEnvObject *>(this);
     301                 : }
     302                 : 
     303                 : inline js::NestedScopeObject &
     304             153 : JSObject::asNestedScope()
     305                 : {
     306             153 :     JS_ASSERT(isWith() || isBlock());
     307             153 :     return *static_cast<js::NestedScopeObject *>(this);
     308                 : }
     309                 : 
     310                 : inline js::WithObject &
     311            7344 : JSObject::asWith()
     312                 : {
     313            7344 :     JS_ASSERT(isWith());
     314            7344 :     return *static_cast<js::WithObject *>(this);
     315                 : }
     316                 : 
     317                 : inline js::BlockObject &
     318           18486 : JSObject::asBlock()
     319                 : {
     320           18486 :     JS_ASSERT(isBlock());
     321           18486 :     return *static_cast<js::BlockObject *>(this);
     322                 : }
     323                 : 
     324                 : inline js::StaticBlockObject &
     325          716250 : JSObject::asStaticBlock()
     326                 : {
     327          716250 :     JS_ASSERT(isStaticBlock());
     328          716250 :     return *static_cast<js::StaticBlockObject *>(this);
     329                 : }
     330                 : 
     331                 : inline js::ClonedBlockObject &
     332            6951 : JSObject::asClonedBlock()
     333                 : {
     334            6951 :     JS_ASSERT(isClonedBlock());
     335            6951 :     return *static_cast<js::ClonedBlockObject *>(this);
     336                 : }
     337                 : 
     338                 : #endif /* CallObject_inl_h___ */

Generated by: LCOV version 1.7