LCOV - app.info - js/src/jsscriptinlines.h

LCOV - code coverage report
| Current view: | directory - js/src - jsscriptinlines.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 92 | 83 | 90.2 %
| Date: | 2012-04-07 | 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          877647 : Bindings::Bindings(JSContext *cx)
          61          877647 :     : lastBinding(NULL), nargs(0), nvars(0), hasDup_(false)
          62          877647 : {}
          63                 :
          64                 : inline void
          65          583036 : Bindings::transfer(JSContext *cx, Bindings *bindings)
          66                 : {
          67          583036 :     JS_ASSERT(!lastBinding);
          68          583036 :     JS_ASSERT(!bindings->lastBinding || !bindings->lastBinding->inDictionary());
          69                 :
          70          583036 :     *this = *bindings;
          71                 : #ifdef DEBUG
          72          583036 :     bindings->lastBinding = NULL;
          73                 : #endif
          74          583036 : }
          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          745077 : Bindings::lastShape() const
          87                 : {
          88          745077 :     JS_ASSERT(lastBinding);
          89          745077 :     JS_ASSERT(!lastBinding->inDictionary());
          90          745077 :     return lastBinding;
          91                 : }
          92                 :
          93                 : Shape *
          94          263893 : Bindings::initialShape(JSContext *cx) const
          95                 : {
          96                 :     /* Get an allocation kind to match an empty call object. */
          97          263893 :     gc::AllocKind kind = gc::FINALIZE_OBJECT4;
          98          263893 :     JS_ASSERT(gc::GetGCKindSlots(kind) == CallObject::RESERVED_SLOTS + 1);
          99                 :
         100                 :     return EmptyShape::getInitialShape(cx, &CallClass, NULL, NULL, kind,
         101          263893 :                                        BaseShape::VAROBJ);
         102                 : }
         103                 :
         104                 : bool
         105          763436 : Bindings::ensureShape(JSContext *cx)
         106                 : {
         107          763436 :     if (!lastBinding) {
         108          263884 :         lastBinding = initialShape(cx);
         109          263884 :         if (!lastBinding)
         110               0 :             return false;
         111                 :     }
         112          763436 :     return true;
         113                 : }
         114                 :
         115                 : bool
         116          251422 : Bindings::extensibleParents()
         117                 : {
         118          251422 :     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           44828 : CurrentScriptFileLineOrigin(JSContext *cx, const char **file, unsigned *linenop, JSPrincipals **origin,
         126                 :                             LineOption opt = NOT_CALLED_FROM_JSOP_EVAL)
         127                 : {
         128           44828 :     if (opt == CALLED_FROM_JSOP_EVAL) {
         129           20186 :         JS_ASSERT(JSOp(*cx->regs().pc) == JSOP_EVAL);
         130           20186 :         JS_ASSERT(*(cx->regs().pc + JSOP_EVAL_LENGTH) == JSOP_LINENO);
         131           20186 :         JSScript *script = cx->fp()->script();
         132           20186 :         *file = script->filename;
         133           20186 :         *linenop = GET_UINT16(cx->regs().pc + JSOP_EVAL_LENGTH);
         134           20186 :         *origin = script->originPrincipals;
         135           20186 :         return;
         136                 :     }
         137                 :
         138           24642 :     CurrentScriptFileLineOriginSlow(cx, file, linenop, origin);
         139                 : }
         140                 :
         141                 : inline void
         142               0 : ScriptCounts::destroy(JSContext *cx)
         143                 : {
         144               0 :     cx->free_(pcCountsVector);
         145               0 : }
         146                 :
         147                 : } // namespace js
         148                 :
         149                 : inline void
         150           23629 : JSScript::setFunction(JSFunction *fun)
         151                 : {
         152           23629 :     function_ = fun;
         153           23629 : }
         154                 :
         155                 : inline JSFunction *
         156          426355 : JSScript::getFunction(size_t index)
         157                 : {
         158          426355 :     JSObject *funobj = getObject(index);
         159          426355 :     JS_ASSERT(funobj->isFunction() && funobj->toFunction()->isInterpreted());
         160          426355 :     return funobj->toFunction();
         161                 : }
         162                 :
         163                 : inline JSFunction *
         164           98566 : JSScript::getCallerFunction()
         165                 : {
         166           98566 :     JS_ASSERT(savedCallerFun);
         167           98566 :     return getFunction(0);
         168                 : }
         169                 :
         170                 : inline JSObject *
         171           95566 : JSScript::getRegExp(size_t index)
         172                 : {
         173           95566 :     JSObjectArray *arr = regexps();
         174           95566 :     JS_ASSERT(uint32_t(index) < arr->length);
         175           95566 :     JSObject *obj = arr->vector[index];
         176           95566 :     JS_ASSERT(obj->isRegExp());
         177           95566 :     return obj;
         178                 : }
         179                 :
         180                 : inline bool
         181          153147 : JSScript::isEmpty() const
         182                 : {
         183          153147 :     if (length > 3)
         184          151246 :         return false;
         185                 :
         186            1901 :     jsbytecode *pc = code;
         187            1901 :     if (noScriptRval && JSOp(*pc) == JSOP_FALSE)
         188               0 :         ++pc;
         189            1901 :     return JSOp(*pc) == JSOP_STOP;
         190                 : }
         191                 :
         192                 : inline bool
         193         2117163 : JSScript::hasGlobal() const
         194                 : {
         195                 :     /*
         196                 :      * Make sure that we don't try to query information about global objects
         197                 :      * which have had their scopes cleared. compileAndGo code should not run
         198                 :      * anymore against such globals.
         199                 :      */
         200         2117163 :     JS_ASSERT(types && types->hasScope());
         201         2117163 :     js::GlobalObject *obj = types->global;
         202         2117163 :     return obj && !obj->isCleared();
         203                 : }
         204                 :
         205                 : inline js::GlobalObject *
         206          613235 : JSScript::global() const
         207                 : {
         208          613235 :     JS_ASSERT(hasGlobal());
         209          613235 :     return types->global;
         210                 : }
         211                 :
         212                 : inline bool
         213         9347125 : JSScript::hasClearedGlobal() const
         214                 : {
         215         9347125 :     JS_ASSERT(types && types->hasScope());
         216         9347125 :     js::GlobalObject *obj = types->global;
         217         9347125 :     return obj && obj->isCleared();
         218                 : }
         219                 :
         220                 : inline js::types::TypeScriptNesting *
         221        41993758 : JSScript::nesting() const
         222                 : {
         223        41993758 :     JS_ASSERT(function() && types && types->hasScope());
         224        41993758 :     return types->nesting;
         225                 : }
         226                 :
         227                 : inline void
         228             160 : JSScript::clearNesting()
         229                 : {
         230             160 :     js::types::TypeScriptNesting *nesting = this->nesting();
         231             160 :     if (nesting) {
         232             160 :         js::Foreground::delete_(nesting);
         233             160 :         types->nesting = NULL;
         234                 :     }
         235             160 : }
         236                 :
         237                 : inline void
         238          315372 : JSScript::writeBarrierPre(JSScript *script)
         239                 : {
         240                 : #ifdef JSGC_INCREMENTAL
         241          315372 :     if (!script)
         242          307142 :         return;
         243                 :
         244            8230 :     JSCompartment *comp = script->compartment();
         245            8230 :     if (comp->needsBarrier()) {
         246               0 :         JS_ASSERT(!comp->rt->gcRunning);
         247               0 :         JSScript *tmp = script;
         248               0 :         MarkScriptUnbarriered(comp->barrierTracer(), &tmp, "write barrier");
         249               0 :         JS_ASSERT(tmp == script);
         250                 :     }
         251                 : #endif
         252                 : }
         253                 :
         254                 : inline void
         255         1363722 : JSScript::writeBarrierPost(JSScript *script, void *addr)
         256                 : {
         257         1363722 : }
         258                 :
         259                 : #endif /* jsscriptinlines_h___ */

Generated by: LCOV version 1.7