LCOV - code coverage report
Current view: directory - js/src - jsscriptinlines.h (source / functions) Found Hit Coverage
Test: app.info Lines: 93 83 89.2 %
Date: 2012-06-02 Functions: 20 19 95.0 %

       1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * vim: set ts=8 sw=4 et tw=79 ft=cpp:
       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 JavaScript engine.
      18                 :  *
      19                 :  * The Initial Developer of the Original Code is
      20                 :  * Mozilla Corporation.
      21                 :  * Portions created by the Initial Developer are Copyright (C) 2009
      22                 :  * the Initial Developer. All Rights Reserved.
      23                 :  *
      24                 :  * Contributor(s):
      25                 :  *   Jason Orendorff <jorendorff@mozilla.com>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      29                 :  * 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 jsscriptinlines_h___
      42                 : #define jsscriptinlines_h___
      43                 : 
      44                 : #include "jsautooplen.h"
      45                 : #include "jscntxt.h"
      46                 : #include "jsfun.h"
      47                 : #include "jsopcode.h"
      48                 : #include "jsscript.h"
      49                 : #include "jsscope.h"
      50                 : 
      51                 : #include "vm/ScopeObject.h"
      52                 : #include "vm/GlobalObject.h"
      53                 : #include "vm/RegExpObject.h"
      54                 : 
      55                 : #include "jsscopeinlines.h"
      56                 : 
      57                 : namespace js {
      58                 : 
      59                 : inline
      60         5045884 : Bindings::Bindings(JSContext *cx)
      61         5045884 :     : lastBinding(NULL), nargs(0), nvars(0), nupvars(0), hasDup_(false)
      62         5045884 : {}
      63                 : 
      64                 : inline void
      65         3255844 : Bindings::transfer(JSContext *cx, Bindings *bindings)
      66                 : {
      67         3255844 :     JS_ASSERT(!lastBinding);
      68         3255844 :     JS_ASSERT(!bindings->lastBinding || !bindings->lastBinding->inDictionary());
      69                 : 
      70         3255844 :     *this = *bindings;
      71                 : #ifdef DEBUG
      72         3255844 :     bindings->lastBinding = NULL;
      73                 : #endif
      74         3255844 : }
      75                 : 
      76                 : inline void
      77                 : Bindings::clone(JSContext *cx, Bindings *bindings)
      78                 : {
      79                 :     JS_ASSERT(!lastBinding);
      80                 :     JS_ASSERT(!bindings->lastBinding || !bindings->lastBinding->inDictionary());
      81                 : 
      82                 :     *this = *bindings;
      83                 : }
      84                 : 
      85                 : Shape *
      86          703452 : Bindings::lastShape() const
      87                 : {
      88          703452 :     JS_ASSERT(lastBinding);
      89          703452 :     JS_ASSERT(!lastBinding->inDictionary());
      90          703452 :     return lastBinding;
      91                 : }
      92                 : 
      93                 : Shape *
      94         1288501 : Bindings::initialShape(JSContext *cx) const
      95                 : {
      96                 :     /* Get an allocation kind to match an empty call object. */
      97         1288501 :     gc::AllocKind kind = gc::FINALIZE_OBJECT4;
      98         1288501 :     JS_ASSERT(gc::GetGCKindSlots(kind) == CallObject::RESERVED_SLOTS + 1);
      99                 : 
     100                 :     return EmptyShape::getInitialShape(cx, &CallClass, NULL, NULL, kind,
     101         1288501 :                                        BaseShape::VAROBJ);
     102                 : }
     103                 : 
     104                 : bool
     105         4023333 : Bindings::ensureShape(JSContext *cx)
     106                 : {
     107         4023333 :     if (!lastBinding) {
     108         1288492 :         lastBinding = initialShape(cx);
     109         1288492 :         if (!lastBinding)
     110               0 :             return false;
     111                 :     }
     112         4023333 :     return true;
     113                 : }
     114                 : 
     115                 : bool
     116         1419304 : Bindings::extensibleParents()
     117                 : {
     118         1419304 :     return lastBinding && lastBinding->extensibleParents();
     119                 : }
     120                 : 
     121                 : extern void
     122                 : CurrentScriptFileLineOriginSlow(JSContext *cx, const char **file, unsigned *linenop, JSPrincipals **origin);
     123                 : 
     124                 : inline void
     125           44727 : CurrentScriptFileLineOrigin(JSContext *cx, const char **file, unsigned *linenop, JSPrincipals **origin,
     126                 :                             LineOption opt = NOT_CALLED_FROM_JSOP_EVAL)
     127                 : {
     128           44727 :     if (opt == CALLED_FROM_JSOP_EVAL) {
     129           20484 :         JS_ASSERT(JSOp(*cx->regs().pc) == JSOP_EVAL);
     130           20484 :         JS_ASSERT(*(cx->regs().pc + JSOP_EVAL_LENGTH) == JSOP_LINENO);
     131           20484 :         JSScript *script = cx->fp()->script();
     132           20484 :         *file = script->filename;
     133           20484 :         *linenop = GET_UINT16(cx->regs().pc + JSOP_EVAL_LENGTH);
     134           20484 :         *origin = script->originPrincipals;
     135           20484 :         return;
     136                 :     }
     137                 : 
     138           24243 :     CurrentScriptFileLineOriginSlow(cx, file, linenop, origin);
     139                 : }
     140                 : 
     141                 : inline void
     142               0 : ScriptOpcodeCounts::destroy(JSContext *cx)
     143                 : {
     144               0 :     if (counts)
     145               0 :         cx->free_(counts);
     146               0 : }
     147                 : 
     148                 : } // namespace js
     149                 : 
     150                 : inline void
     151           38637 : JSScript::setFunction(JSFunction *fun)
     152                 : {
     153           38637 :     function_ = fun;
     154           38637 : }
     155                 : 
     156                 : inline JSFunction *
     157         1974838 : JSScript::getFunction(size_t index)
     158                 : {
     159         1974838 :     JSObject *funobj = getObject(index);
     160         1974838 :     JS_ASSERT(funobj->isFunction() && funobj->toFunction()->isInterpreted());
     161         1974838 :     return funobj->toFunction();
     162                 : }
     163                 : 
     164                 : inline JSFunction *
     165           99017 : JSScript::getCallerFunction()
     166                 : {
     167           99017 :     JS_ASSERT(savedCallerFun);
     168           99017 :     return getFunction(0);
     169                 : }
     170                 : 
     171                 : inline JSObject *
     172          221488 : JSScript::getRegExp(size_t index)
     173                 : {
     174          221488 :     JSObjectArray *arr = regexps();
     175          221488 :     JS_ASSERT(uint32_t(index) < arr->length);
     176          221488 :     JSObject *obj = arr->vector[index];
     177          221488 :     JS_ASSERT(obj->isRegExp());
     178          221488 :     return obj;
     179                 : }
     180                 : 
     181                 : inline bool
     182          180093 : JSScript::isEmpty() const
     183                 : {
     184          180093 :     if (length > 3)
     185          177927 :         return false;
     186                 : 
     187            2166 :     jsbytecode *pc = code;
     188            2166 :     if (noScriptRval && JSOp(*pc) == JSOP_FALSE)
     189               0 :         ++pc;
     190            2166 :     return JSOp(*pc) == JSOP_STOP;
     191                 : }
     192                 : 
     193                 : inline bool
     194         3530377 : JSScript::hasGlobal() const
     195                 : {
     196                 :     /*
     197                 :      * Make sure that we don't try to query information about global objects
     198                 :      * which have had their scopes cleared. compileAndGo code should not run
     199                 :      * anymore against such globals.
     200                 :      */
     201         3530377 :     JS_ASSERT(types && types->hasScope());
     202         3530377 :     js::GlobalObject *obj = types->global;
     203         3530377 :     return obj && !obj->isCleared();
     204                 : }
     205                 : 
     206                 : inline js::GlobalObject *
     207          604497 : JSScript::global() const
     208                 : {
     209          604497 :     JS_ASSERT(hasGlobal());
     210          604497 :     return types->global;
     211                 : }
     212                 : 
     213                 : inline bool
     214         9382030 : JSScript::hasClearedGlobal() const
     215                 : {
     216         9382030 :     JS_ASSERT(types && types->hasScope());
     217         9382030 :     js::GlobalObject *obj = types->global;
     218         9382030 :     return obj && obj->isCleared();
     219                 : }
     220                 : 
     221                 : inline js::types::TypeScriptNesting *
     222        56316626 : JSScript::nesting() const
     223                 : {
     224        56316626 :     JS_ASSERT(function() && types && types->hasScope());
     225        56316626 :     return types->nesting;
     226                 : }
     227                 : 
     228                 : inline void
     229             178 : JSScript::clearNesting()
     230                 : {
     231             178 :     js::types::TypeScriptNesting *nesting = this->nesting();
     232             178 :     if (nesting) {
     233             178 :         js::Foreground::delete_(nesting);
     234             178 :         types->nesting = NULL;
     235                 :     }
     236             178 : }
     237                 : 
     238                 : inline void
     239         1311624 : JSScript::writeBarrierPre(JSScript *script)
     240                 : {
     241                 : #ifdef JSGC_INCREMENTAL
     242         1311624 :     if (!script)
     243         1303764 :         return;
     244                 : 
     245            7860 :     JSCompartment *comp = script->compartment();
     246            7860 :     if (comp->needsBarrier()) {
     247               0 :         JS_ASSERT(!comp->rt->gcRunning);
     248               0 :         JSScript *tmp = script;
     249               0 :         MarkScriptUnbarriered(comp->barrierTracer(), &tmp, "write barrier");
     250               0 :         JS_ASSERT(tmp == script);
     251                 :     }
     252                 : #endif
     253                 : }
     254                 : 
     255                 : inline void
     256         4798245 : JSScript::writeBarrierPost(JSScript *script, void *addr)
     257                 : {
     258         4798245 : }
     259                 : 
     260                 : #endif /* jsscriptinlines_h___ */

Generated by: LCOV version 1.7