LCOV - code coverage report
Current view: directory - js/src - jsprvtd.h (source / functions) Found Hit Coverage
Test: app.info Lines: 9 9 100.0 %
Date: 2012-06-02 Functions: 17 17 100.0 %

       1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  *
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Mozilla Communicator client code, released
      17                 :  * March 31, 1998.
      18                 :  *
      19                 :  * The Initial Developer of the Original Code is
      20                 :  * Netscape Communications Corporation.
      21                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      22                 :  * the Initial Developer. All Rights Reserved.
      23                 :  *
      24                 :  * Contributor(s):
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      28                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef jsprvtd_h___
      41                 : #define jsprvtd_h___
      42                 : /*
      43                 :  * JS private typename definitions.
      44                 :  *
      45                 :  * This header is included only in other .h files, for convenience and for
      46                 :  * simplicity of type naming.  The alternative for structures is to use tags,
      47                 :  * which are named the same as their typedef names (legal in C/C++, and less
      48                 :  * noisy than suffixing the typedef name with "Struct" or "Str").  Instead,
      49                 :  * all .h files that include this file may use the same typedef name, whether
      50                 :  * declaring a pointer to struct type, or defining a member of struct type.
      51                 :  *
      52                 :  * A few fundamental scalar types are defined here too.  Neither the scalar
      53                 :  * nor the struct typedefs should change much, therefore the nearly-global
      54                 :  * make dependency induced by this file should not prove painful.
      55                 :  */
      56                 : 
      57                 : #include "jsapi.h"
      58                 : #include "jsutil.h"
      59                 : 
      60                 : #ifdef __cplusplus
      61                 : #include "js/HashTable.h"
      62                 : #include "js/Vector.h"
      63                 : #endif
      64                 : 
      65                 : JS_BEGIN_EXTERN_C
      66                 : 
      67                 : /*
      68                 :  * Convenience constants.
      69                 :  */
      70                 : #define JS_BITS_PER_UINT32_LOG2 5
      71                 : #define JS_BITS_PER_UINT32      32
      72                 : 
      73                 : /* The alignment required of objects stored in GC arenas. */
      74                 : static const unsigned JS_GCTHING_ALIGN = 8;
      75                 : static const unsigned JS_GCTHING_ZEROBITS = 3;
      76                 : 
      77                 : /* Scalar typedefs. */
      78                 : typedef uint8_t     jsbytecode;
      79                 : typedef uint8_t     jssrcnote;
      80                 : typedef uintptr_t   jsatomid;
      81                 : 
      82                 : /* Struct typedefs. */
      83                 : typedef struct JSArgumentFormatMap  JSArgumentFormatMap;
      84                 : typedef struct JSGCThing            JSGCThing;
      85                 : typedef struct JSGenerator          JSGenerator;
      86                 : typedef struct JSNativeEnumerator   JSNativeEnumerator;
      87                 : typedef struct JSProperty           JSProperty;
      88                 : typedef struct JSSharpObjectMap     JSSharpObjectMap;
      89                 : typedef struct JSTryNote            JSTryNote;
      90                 : 
      91                 : /* Friend "Advanced API" typedefs. */
      92                 : typedef struct JSAtomState          JSAtomState;
      93                 : typedef struct JSCodeSpec           JSCodeSpec;
      94                 : typedef struct JSPrinter            JSPrinter;
      95                 : typedef struct JSStackHeader        JSStackHeader;
      96                 : typedef struct JSSubString          JSSubString;
      97                 : typedef struct JSSpecializedNative  JSSpecializedNative;
      98                 : typedef struct JSXML                JSXML;
      99                 : 
     100                 : /*
     101                 :  * Template declarations.
     102                 :  *
     103                 :  * jsprvtd.h can be included in both C and C++ translation units. For C++, it
     104                 :  * may possibly be wrapped in an extern "C" block which does not agree with
     105                 :  * templates.
     106                 :  */
     107                 : #ifdef __cplusplus
     108                 : 
     109                 : extern "C++" {
     110                 : 
     111                 : class JSDependentString;
     112                 : class JSExtensibleString;
     113                 : class JSExternalString;
     114                 : class JSLinearString;
     115                 : class JSFixedString;
     116                 : class JSStaticAtom;
     117                 : class JSRope;
     118                 : class JSAtom;
     119                 : class JSWrapper;
     120                 : 
     121                 : namespace js {
     122                 : 
     123                 : struct ArgumentsData;
     124                 : struct Class;
     125                 : 
     126                 : class RegExpGuard;
     127                 : class RegExpObject;
     128                 : class RegExpObjectBuilder;
     129                 : class RegExpShared;
     130                 : class RegExpStatics;
     131                 : class MatchPairs;
     132                 : 
     133                 : namespace detail { class RegExpCode; }
     134                 : 
     135                 : enum RegExpFlag
     136                 : {
     137                 :     IgnoreCaseFlag  = 0x01,
     138                 :     GlobalFlag      = 0x02,
     139                 :     MultilineFlag   = 0x04,
     140                 :     StickyFlag      = 0x08,
     141                 : 
     142                 :     NoFlags         = 0x00,
     143                 :     AllFlags        = 0x0f
     144                 : };
     145                 : 
     146                 : enum RegExpExecType
     147                 : {
     148                 :     RegExpExec,
     149                 :     RegExpTest
     150                 : };
     151                 : 
     152                 : class ExecuteArgsGuard;
     153                 : class InvokeFrameGuard;
     154                 : class InvokeArgsGuard;
     155                 : class StringBuffer;
     156                 : 
     157                 : class FrameRegs;
     158                 : class StackFrame;
     159                 : class StackSegment;
     160                 : class StackSpace;
     161                 : class ContextStack;
     162                 : class FrameRegsIter;
     163                 : class CallReceiver;
     164                 : class CallArgs;
     165                 : 
     166                 : struct BytecodeEmitter;
     167                 : struct Definition;
     168                 : struct FunctionBox;
     169                 : struct ObjectBox;
     170                 : struct ParseNode;
     171                 : struct Parser;
     172                 : class TokenStream;
     173                 : struct Token;
     174                 : struct TokenPos;
     175                 : struct TokenPtr;
     176                 : struct TreeContext;
     177                 : class UpvarCookie;
     178                 : 
     179                 : class Proxy;
     180                 : class ProxyHandler;
     181                 : class Wrapper;
     182                 : class CrossCompartmentWrapper;
     183                 : 
     184                 : class TempAllocPolicy;
     185                 : class RuntimeAllocPolicy;
     186                 : 
     187                 : class GlobalObject;
     188                 : 
     189                 : template <typename K,
     190                 :           typename V,
     191                 :           size_t InlineElems>
     192          571145 : class InlineMap;
     193                 : 
     194                 : class LifoAlloc;
     195                 : 
     196                 : class BaseShape;
     197                 : class UnownedBaseShape;
     198                 : struct Shape;
     199                 : struct EmptyShape;
     200                 : class ShapeKindArray;
     201                 : class Bindings;
     202                 : 
     203                 : struct StackBaseShape;
     204                 : struct StackShape;
     205                 : 
     206                 : class MultiDeclRange;
     207                 : class ParseMapPool;
     208                 : class DefnOrHeader;
     209                 : typedef InlineMap<JSAtom *, Definition *, 24> AtomDefnMap;
     210                 : typedef InlineMap<JSAtom *, jsatomid, 24> AtomIndexMap;
     211                 : typedef InlineMap<JSAtom *, DefnOrHeader, 24> AtomDOHMap;
     212                 : typedef Vector<UpvarCookie, 8> UpvarCookies;
     213                 : 
     214                 : class Breakpoint;
     215                 : class BreakpointSite;
     216                 : class Debugger;
     217                 : class WatchpointMap;
     218                 : 
     219                 : /*
     220                 :  * Env is the type of what ES5 calls "lexical environments" (runtime
     221                 :  * activations of lexical scopes). This is currently just JSObject, and is
     222                 :  * implemented by Call, Block, With, and DeclEnv objects, among others--but
     223                 :  * environments and objects are really two different concepts.
     224                 :  */
     225                 : typedef JSObject Env;
     226                 : 
     227                 : typedef JSNative             Native;
     228                 : typedef JSPropertyOp         PropertyOp;
     229                 : typedef JSStrictPropertyOp   StrictPropertyOp;
     230                 : typedef JSPropertyDescriptor PropertyDescriptor;
     231                 : 
     232                 : namespace analyze {
     233                 : 
     234                 : struct LifetimeVariable;
     235                 : class LoopAnalysis;
     236                 : class ScriptAnalysis;
     237                 : class SlotValue;
     238                 : class SSAValue;
     239                 : class SSAUseChain;
     240                 : 
     241                 : } /* namespace analyze */
     242                 : 
     243                 : namespace types {
     244                 : 
     245                 : class TypeSet;
     246                 : struct TypeCallsite;
     247                 : struct TypeObject;
     248                 : struct TypeCompartment;
     249                 : 
     250                 : } /* namespace types */
     251                 : 
     252                 : enum ThingRootKind
     253                 : {
     254                 :     THING_ROOT_OBJECT,
     255                 :     THING_ROOT_SHAPE,
     256                 :     THING_ROOT_BASE_SHAPE,
     257                 :     THING_ROOT_TYPE_OBJECT,
     258                 :     THING_ROOT_STRING,
     259                 :     THING_ROOT_SCRIPT,
     260                 :     THING_ROOT_ID,
     261                 :     THING_ROOT_VALUE,
     262                 :     THING_ROOT_LIMIT
     263                 : };
     264                 : 
     265                 : template <typename T> class Root;
     266                 : template <typename T> class RootedVar;
     267                 : 
     268                 : template <typename T>
     269                 : struct RootMethods { };
     270                 : 
     271                 : /*
     272                 :  * Reference to a stack location rooted for GC. See "Moving GC Stack Rooting"
     273                 :  * comment in jscntxt.h.
     274                 :  */
     275                 : template <typename T>
     276                 : class Handle
     277                 : {
     278                 :   public:
     279                 :     /* Copy handles of different types, with implicit coercion. */
     280                 :     template <typename S> Handle(Handle<S> handle) {
     281                 :         testAssign<S>();
     282                 :         ptr = reinterpret_cast<const T *>(handle.address());
     283                 :     }
     284                 : 
     285                 :     /* Get a handle from a rooted stack location, with implicit coercion. */
     286                 :     template <typename S> inline Handle(const Root<S> &root);
     287                 :     template <typename S> inline Handle(const RootedVar<S> &root);
     288                 : 
     289                 :     const T *address() { return ptr; }
     290                 : 
     291       111349646 :     operator T () { return value(); }
     292        95463198 :     T operator ->() { return value(); }
     293                 : 
     294                 :   private:
     295                 :     const T *ptr;
     296       206812844 :     T value() { return *ptr; }
     297                 : 
     298                 :     template <typename S>
     299        45688419 :     void testAssign() {
     300                 : #ifdef DEBUG
     301        45688419 :         T a = RootMethods<T>::initial();
     302        45688419 :         S b = RootMethods<S>::initial();
     303        45688419 :         a = b;
     304                 :         (void)a;
     305                 : #endif
     306        45688419 :     }
     307                 : };
     308                 : 
     309                 : typedef Handle<JSObject*>          HandleObject;
     310                 : typedef Handle<JSFunction*>        HandleFunction;
     311                 : typedef Handle<Shape*>             HandleShape;
     312                 : typedef Handle<BaseShape*>         HandleBaseShape;
     313                 : typedef Handle<types::TypeObject*> HandleTypeObject;
     314                 : typedef Handle<JSString*>          HandleString;
     315                 : typedef Handle<JSAtom*>            HandleAtom;
     316                 : typedef Handle<jsid>               HandleId;
     317                 : typedef Handle<Value>              HandleValue;
     318                 : 
     319                 : } /* namespace js */
     320                 : 
     321                 : namespace JSC {
     322                 : 
     323                 : class ExecutableAllocator;
     324                 : 
     325                 : } /* namespace JSC */
     326                 : 
     327                 : namespace WTF {
     328                 : 
     329                 : class BumpPointerAllocator;
     330                 : 
     331                 : } /* namespace WTF */
     332                 : 
     333                 : } /* export "C++" */
     334                 : 
     335                 : #else
     336                 : 
     337                 : typedef struct JSAtom JSAtom;
     338                 : 
     339                 : #endif  /* __cplusplus */
     340                 : 
     341                 : /* "Friend" types used by jscntxt.h and jsdbgapi.h. */
     342                 : typedef enum JSTrapStatus {
     343                 :     JSTRAP_ERROR,
     344                 :     JSTRAP_CONTINUE,
     345                 :     JSTRAP_RETURN,
     346                 :     JSTRAP_THROW,
     347                 :     JSTRAP_LIMIT
     348                 : } JSTrapStatus;
     349                 : 
     350                 : typedef JSTrapStatus
     351                 : (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
     352                 :                   jsval closure);
     353                 : 
     354                 : typedef JSTrapStatus
     355                 : (* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
     356                 :                     void *closure);
     357                 : 
     358                 : typedef JSTrapStatus
     359                 : (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
     360                 :                       void *closure);
     361                 : 
     362                 : typedef JSTrapStatus
     363                 : (* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
     364                 :                 void *closure);
     365                 : 
     366                 : typedef JSBool
     367                 : (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, jsval old,
     368                 :                         jsval *newp, void *closure);
     369                 : 
     370                 : /* called just after script creation */
     371                 : typedef void
     372                 : (* JSNewScriptHook)(JSContext  *cx,
     373                 :                     const char *filename,  /* URL of script */
     374                 :                     unsigned      lineno,     /* first line */
     375                 :                     JSScript   *script,
     376                 :                     JSFunction *fun,
     377                 :                     void       *callerdata);
     378                 : 
     379                 : /* called just before script destruction */
     380                 : typedef void
     381                 : (* JSDestroyScriptHook)(JSContext *cx,
     382                 :                         JSScript  *script,
     383                 :                         void      *callerdata);
     384                 : 
     385                 : typedef void
     386                 : (* JSSourceHandler)(const char *filename, unsigned lineno, const jschar *str,
     387                 :                     size_t length, void **listenerTSData, void *closure);
     388                 : 
     389                 : /*
     390                 :  * This hook captures high level script execution and function calls (JS or
     391                 :  * native).  It is used by JS_SetExecuteHook to hook top level scripts and by
     392                 :  * JS_SetCallHook to hook function calls.  It will get called twice per script
     393                 :  * or function call: just before execution begins and just after it finishes.
     394                 :  * In both cases the 'current' frame is that of the executing code.
     395                 :  *
     396                 :  * The 'before' param is JS_TRUE for the hook invocation before the execution
     397                 :  * and JS_FALSE for the invocation after the code has run.
     398                 :  *
     399                 :  * The 'ok' param is significant only on the post execution invocation to
     400                 :  * signify whether or not the code completed 'normally'.
     401                 :  *
     402                 :  * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook
     403                 :  * for the 'before'invocation, but is whatever value is returned from that
     404                 :  * invocation for the 'after' invocation. Thus, the hook implementor *could*
     405                 :  * allocate a structure in the 'before' invocation and return a pointer to that
     406                 :  * structure. The pointer would then be handed to the hook for the 'after'
     407                 :  * invocation. Alternately, the 'before' could just return the same value as
     408                 :  * in 'closure' to cause the 'after' invocation to be called with the same
     409                 :  * 'closure' value as the 'before'.
     410                 :  *
     411                 :  * Returning NULL in the 'before' hook will cause the 'after' hook *not* to
     412                 :  * be called.
     413                 :  */
     414                 : typedef void *
     415                 : (* JSInterpreterHook)(JSContext *cx, JSStackFrame *fp, JSBool before,
     416                 :                       JSBool *ok, void *closure);
     417                 : 
     418                 : typedef JSBool
     419                 : (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report,
     420                 :                      void *closure);
     421                 : 
     422                 : typedef struct JSDebugHooks {
     423                 :     JSInterruptHook     interruptHook;
     424                 :     void                *interruptHookData;
     425                 :     JSNewScriptHook     newScriptHook;
     426                 :     void                *newScriptHookData;
     427                 :     JSDestroyScriptHook destroyScriptHook;
     428                 :     void                *destroyScriptHookData;
     429                 :     JSDebuggerHandler   debuggerHandler;
     430                 :     void                *debuggerHandlerData;
     431                 :     JSSourceHandler     sourceHandler;
     432                 :     void                *sourceHandlerData;
     433                 :     JSInterpreterHook   executeHook;
     434                 :     void                *executeHookData;
     435                 :     JSInterpreterHook   callHook;
     436                 :     void                *callHookData;
     437                 :     JSThrowHook         throwHook;
     438                 :     void                *throwHookData;
     439                 :     JSDebugErrorHook    debugErrorHook;
     440                 :     void                *debugErrorHookData;
     441                 : } JSDebugHooks;
     442                 : 
     443                 : /* js::ObjectOps function pointer typedefs. */
     444                 : 
     445                 : /*
     446                 :  * Look for id in obj and its prototype chain, returning false on error or
     447                 :  * exception, true on success.  On success, return null in *propp if id was
     448                 :  * not found.  If id was found, return the first object searching from obj
     449                 :  * along its prototype chain in which id names a direct property in *objp, and
     450                 :  * return a non-null, opaque property pointer in *propp.
     451                 :  *
     452                 :  * If JSLookupPropOp succeeds and returns with *propp non-null, that pointer
     453                 :  * may be passed as the prop parameter to a JSAttributesOp, as a short-cut
     454                 :  * that bypasses id re-lookup.
     455                 :  */
     456                 : typedef JSBool
     457                 : (* JSLookupPropOp)(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
     458                 :                    JSProperty **propp);
     459                 : 
     460                 : /*
     461                 :  * Get or set attributes of the property obj[id]. Return false on error or
     462                 :  * exception, true with current attributes in *attrsp.
     463                 :  */
     464                 : typedef JSBool
     465                 : (* JSAttributesOp)(JSContext *cx, JSObject *obj, jsid id, unsigned *attrsp);
     466                 : 
     467                 : /*
     468                 :  * A generic type for functions mapping an object to another object, or null
     469                 :  * if an error or exception was thrown on cx.
     470                 :  */
     471                 : typedef JSObject *
     472                 : (* JSObjectOp)(JSContext *cx, JSObject *obj);
     473                 : 
     474                 : /*
     475                 :  * Hook that creates an iterator object for a given object. Returns the
     476                 :  * iterator object or null if an error or exception was thrown on cx.
     477                 :  */
     478                 : typedef JSObject *
     479                 : (* JSIteratorOp)(JSContext *cx, JSObject *obj, JSBool keysonly);
     480                 : 
     481                 : /*
     482                 :  * The following determines whether JS_EncodeCharacters and JS_DecodeBytes
     483                 :  * treat char[] as utf-8 or simply as bytes that need to be inflated/deflated.
     484                 :  */
     485                 : #ifdef JS_C_STRINGS_ARE_UTF8
     486                 : # define js_CStringsAreUTF8 JS_TRUE
     487                 : #else
     488                 : extern JSBool js_CStringsAreUTF8;
     489                 : #endif
     490                 : 
     491                 : JS_END_EXTERN_C
     492                 : 
     493                 : #endif /* jsprvtd_h___ */

Generated by: LCOV version 1.7