Annotation of sbbs/include/mozilla/js/jsatom.h, revision 1.1.1.2

1.1       root        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 jsatom_h___
                     41: #define jsatom_h___
                     42: /*
                     43:  * JS atom table.
                     44:  */
                     45: #include <stddef.h>
                     46: #include "jstypes.h"
                     47: #include "jshash.h" /* Added by JSIFY */
                     48: #include "jsapi.h"
                     49: #include "jsprvtd.h"
                     50: #include "jspubtd.h"
                     51: 
                     52: #ifdef JS_THREADSAFE
                     53: #include "jslock.h"
                     54: #endif
                     55: 
                     56: JS_BEGIN_EXTERN_C
                     57: 
                     58: #define ATOM_PINNED     0x01            /* atom is pinned against GC */
                     59: #define ATOM_INTERNED   0x02            /* pinned variant for JS_Intern* API */
                     60: #define ATOM_MARK       0x04            /* atom is reachable via GC */
1.1.1.2 ! root       61: #define ATOM_HIDDEN     0x08            /* atom is in special hidden subspace */
1.1       root       62: #define ATOM_NOCOPY     0x40            /* don't copy atom string bytes */
                     63: #define ATOM_TMPSTR     0x80            /* internal, to avoid extra string */
                     64: 
                     65: struct JSAtom {
1.1.1.2 ! root       66:     JSHashEntry         entry;          /* key is jsval or unhidden atom
        !            67:                                            if ATOM_HIDDEN */
1.1       root       68:     uint32              flags;          /* pinned, interned, and mark flags */
                     69:     jsatomid            number;         /* atom serial number and hash code */
                     70: };
                     71: 
                     72: #define ATOM_KEY(atom)            ((jsval)(atom)->entry.key)
                     73: #define ATOM_IS_OBJECT(atom)      JSVAL_IS_OBJECT(ATOM_KEY(atom))
                     74: #define ATOM_TO_OBJECT(atom)      JSVAL_TO_OBJECT(ATOM_KEY(atom))
                     75: #define ATOM_IS_INT(atom)         JSVAL_IS_INT(ATOM_KEY(atom))
                     76: #define ATOM_TO_INT(atom)         JSVAL_TO_INT(ATOM_KEY(atom))
                     77: #define ATOM_IS_DOUBLE(atom)      JSVAL_IS_DOUBLE(ATOM_KEY(atom))
                     78: #define ATOM_TO_DOUBLE(atom)      JSVAL_TO_DOUBLE(ATOM_KEY(atom))
                     79: #define ATOM_IS_STRING(atom)      JSVAL_IS_STRING(ATOM_KEY(atom))
                     80: #define ATOM_TO_STRING(atom)      JSVAL_TO_STRING(ATOM_KEY(atom))
                     81: #define ATOM_IS_BOOLEAN(atom)     JSVAL_IS_BOOLEAN(ATOM_KEY(atom))
                     82: #define ATOM_TO_BOOLEAN(atom)     JSVAL_TO_BOOLEAN(ATOM_KEY(atom))
                     83: 
                     84: /*
                     85:  * Return a printable, lossless char[] representation of a string-type atom.
                     86:  * The lifetime of the result extends at least until the next GC activation,
                     87:  * longer if cx's string newborn root is not overwritten.
                     88:  */
                     89: extern JS_FRIEND_API(const char *)
                     90: js_AtomToPrintableString(JSContext *cx, JSAtom *atom);
                     91: 
                     92: struct JSAtomListElement {
                     93:     JSHashEntry         entry;
                     94: };
                     95: 
                     96: #define ALE_ATOM(ale)   ((JSAtom *) (ale)->entry.key)
1.1.1.2 ! root       97: #define ALE_INDEX(ale)  ((jsatomid) JS_PTR_TO_UINT32((ale)->entry.value))
1.1       root       98: #define ALE_JSOP(ale)   ((JSOp) (ale)->entry.value)
                     99: #define ALE_VALUE(ale)  ((jsval) (ale)->entry.value)
                    100: #define ALE_NEXT(ale)   ((JSAtomListElement *) (ale)->entry.next)
                    101: 
                    102: #define ALE_SET_ATOM(ale,atom)  ((ale)->entry.key = (const void *)(atom))
1.1.1.2 ! root      103: #define ALE_SET_INDEX(ale,index)((ale)->entry.value = JS_UINT32_TO_PTR(index))
        !           104: #define ALE_SET_JSOP(ale,op)    ((ale)->entry.value = JS_UINT32_TO_PTR(op))
1.1       root      105: #define ALE_SET_VALUE(ale,val)  ((ale)->entry.value = (JSHashEntry *)(val))
                    106: #define ALE_SET_NEXT(ale,link)  ((ale)->entry.next = (JSHashEntry *)(link))
                    107: 
                    108: struct JSAtomList {
                    109:     JSAtomListElement   *list;          /* literals indexed for mapping */
                    110:     JSHashTable         *table;         /* hash table if list gets too long */
                    111:     jsuint              count;          /* count of indexed literals */
                    112: };
                    113: 
                    114: #define ATOM_LIST_INIT(al)  ((al)->list = NULL, (al)->table = NULL,           \
                    115:                              (al)->count = 0)
                    116: 
                    117: #define ATOM_LIST_SEARCH(_ale,_al,_atom)                                      \
                    118:     JS_BEGIN_MACRO                                                            \
                    119:         JSHashEntry **_hep;                                                   \
                    120:         ATOM_LIST_LOOKUP(_ale, _hep, _al, _atom);                             \
                    121:     JS_END_MACRO
                    122: 
                    123: #define ATOM_LIST_LOOKUP(_ale,_hep,_al,_atom)                                 \
                    124:     JS_BEGIN_MACRO                                                            \
                    125:         if ((_al)->table) {                                                   \
                    126:             _hep = JS_HashTableRawLookup((_al)->table, _atom->number, _atom); \
                    127:             _ale = *_hep ? (JSAtomListElement *) *_hep : NULL;                \
                    128:         } else {                                                              \
                    129:             JSAtomListElement **_alep = &(_al)->list;                         \
                    130:             _hep = NULL;                                                      \
                    131:             while ((_ale = *_alep) != NULL) {                                 \
                    132:                 if (ALE_ATOM(_ale) == (_atom)) {                              \
                    133:                     /* Hit, move atom's element to the front of the list. */  \
                    134:                     *_alep = ALE_NEXT(_ale);                                  \
                    135:                     ALE_SET_NEXT(_ale, (_al)->list);                          \
                    136:                     (_al)->list = _ale;                                       \
                    137:                     break;                                                    \
                    138:                 }                                                             \
                    139:                 _alep = (JSAtomListElement **)&_ale->entry.next;              \
                    140:             }                                                                 \
                    141:         }                                                                     \
                    142:     JS_END_MACRO
                    143: 
                    144: struct JSAtomMap {
                    145:     JSAtom              **vector;       /* array of ptrs to indexed atoms */
                    146:     jsatomid            length;         /* count of (to-be-)indexed atoms */
                    147: };
                    148: 
                    149: struct JSAtomState {
                    150:     JSRuntime           *runtime;       /* runtime that owns us */
                    151:     JSHashTable         *table;         /* hash table containing all atoms */
                    152:     jsatomid            number;         /* one beyond greatest atom number */
                    153:     jsatomid            liveAtoms;      /* number of live atoms after last GC */
                    154: 
1.1.1.2 ! root      155:     /* The rt->emptyString atom, see jsstr.c's js_InitRuntimeStringState. */
        !           156:     JSAtom              *emptyAtom;
        !           157: 
1.1       root      158:     /* Type names and value literals. */
                    159:     JSAtom              *typeAtoms[JSTYPE_LIMIT];
                    160:     JSAtom              *booleanAtoms[2];
                    161:     JSAtom              *nullAtom;
                    162: 
1.1.1.2 ! root      163:     /* Standard class constructor or prototype names. */
        !           164:     JSAtom              *classAtoms[JSProto_LIMIT];
        !           165: 
1.1       root      166:     /* Various built-in or commonly-used atoms, pinned on first context. */
                    167:     JSAtom              *anonymousAtom;
                    168:     JSAtom              *argumentsAtom;
                    169:     JSAtom              *arityAtom;
                    170:     JSAtom              *calleeAtom;
                    171:     JSAtom              *callerAtom;
                    172:     JSAtom              *classPrototypeAtom;
1.1.1.2 ! root      173:     JSAtom              *closeAtom;
1.1       root      174:     JSAtom              *constructorAtom;
                    175:     JSAtom              *countAtom;
1.1.1.2 ! root      176:     JSAtom              *eachAtom;
        !           177:     JSAtom              *etagoAtom;
1.1       root      178:     JSAtom              *evalAtom;
1.1.1.2 ! root      179:     JSAtom              *fileNameAtom;
1.1       root      180:     JSAtom              *getAtom;
                    181:     JSAtom              *getterAtom;
                    182:     JSAtom              *indexAtom;
                    183:     JSAtom              *inputAtom;
1.1.1.2 ! root      184:     JSAtom              *iteratorAtom;
1.1       root      185:     JSAtom              *lengthAtom;
1.1.1.2 ! root      186:     JSAtom              *lineNumberAtom;
        !           187:     JSAtom              *messageAtom;
1.1       root      188:     JSAtom              *nameAtom;
1.1.1.2 ! root      189:     JSAtom              *namespaceAtom;
        !           190:     JSAtom              *nextAtom;
1.1       root      191:     JSAtom              *noSuchMethodAtom;
                    192:     JSAtom              *parentAtom;
                    193:     JSAtom              *protoAtom;
1.1.1.2 ! root      194:     JSAtom              *ptagcAtom;
        !           195:     JSAtom              *qualifierAtom;
1.1       root      196:     JSAtom              *setAtom;
                    197:     JSAtom              *setterAtom;
1.1.1.2 ! root      198:     JSAtom              *spaceAtom;
        !           199:     JSAtom              *stackAtom;
        !           200:     JSAtom              *stagoAtom;
        !           201:     JSAtom              *starAtom;
        !           202:     JSAtom              *starQualifierAtom;
        !           203:     JSAtom              *tagcAtom;
1.1       root      204:     JSAtom              *toLocaleStringAtom;
                    205:     JSAtom              *toSourceAtom;
                    206:     JSAtom              *toStringAtom;
                    207:     JSAtom              *valueOfAtom;
1.1.1.2 ! root      208:     JSAtom              *xmlAtom;
1.1       root      209: 
                    210:     /* Less frequently used atoms, pinned lazily by JS_ResolveStandardClass. */
                    211:     struct {
                    212:         JSAtom          *InfinityAtom;
                    213:         JSAtom          *NaNAtom;
1.1.1.2 ! root      214:         JSAtom          *XMLListAtom;
1.1       root      215:         JSAtom          *decodeURIAtom;
                    216:         JSAtom          *decodeURIComponentAtom;
                    217:         JSAtom          *defineGetterAtom;
                    218:         JSAtom          *defineSetterAtom;
                    219:         JSAtom          *encodeURIAtom;
                    220:         JSAtom          *encodeURIComponentAtom;
                    221:         JSAtom          *escapeAtom;
1.1.1.2 ! root      222:         JSAtom          *functionNamespaceURIAtom;
1.1       root      223:         JSAtom          *hasOwnPropertyAtom;
                    224:         JSAtom          *isFiniteAtom;
                    225:         JSAtom          *isNaNAtom;
                    226:         JSAtom          *isPrototypeOfAtom;
1.1.1.2 ! root      227:         JSAtom          *isXMLNameAtom;
1.1       root      228:         JSAtom          *lookupGetterAtom;
                    229:         JSAtom          *lookupSetterAtom;
                    230:         JSAtom          *parseFloatAtom;
                    231:         JSAtom          *parseIntAtom;
                    232:         JSAtom          *propertyIsEnumerableAtom;
                    233:         JSAtom          *unescapeAtom;
                    234:         JSAtom          *unevalAtom;
                    235:         JSAtom          *unwatchAtom;
                    236:         JSAtom          *watchAtom;
                    237:     } lazy;
                    238: 
                    239: #ifdef JS_THREADSAFE
                    240:     JSThinLock          lock;
                    241:     volatile uint32     tablegen;
                    242: #endif
                    243: #ifdef NARCISSUS
                    244:     JSAtom              *callAtom;
                    245:     JSAtom              *constructAtom;
                    246:     JSAtom              *hasInstanceAtom;
                    247:     JSAtom              *ExecutionContextAtom;
                    248:     JSAtom              *currentAtom;
                    249: #endif
                    250: };
                    251: 
1.1.1.2 ! root      252: #define CLASS_ATOM(cx,name) \
        !           253:     ((cx)->runtime->atomState.classAtoms[JSProto_##name])
        !           254: 
1.1       root      255: /* Well-known predefined strings and their atoms. */
1.1.1.2 ! root      256: extern const char   *js_type_strs[];
        !           257: extern const char   *js_boolean_strs[];
        !           258: extern const char   *js_proto_strs[];
        !           259: 
        !           260: #define JS_PROTO(name,code,init) extern const char js_##name##_str[];
        !           261: #include "jsproto.tbl"
        !           262: #undef JS_PROTO
1.1       root      263: 
                    264: extern const char   js_anonymous_str[];
                    265: extern const char   js_arguments_str[];
                    266: extern const char   js_arity_str[];
                    267: extern const char   js_callee_str[];
                    268: extern const char   js_caller_str[];
                    269: extern const char   js_class_prototype_str[];
1.1.1.2 ! root      270: extern const char   js_close_str[];
1.1       root      271: extern const char   js_constructor_str[];
                    272: extern const char   js_count_str[];
1.1.1.2 ! root      273: extern const char   js_etago_str[];
        !           274: extern const char   js_each_str[];
1.1       root      275: extern const char   js_eval_str[];
1.1.1.2 ! root      276: extern const char   js_fileName_str[];
1.1       root      277: extern const char   js_get_str[];
1.1.1.2 ! root      278: extern const char   js_getter_str[];
1.1       root      279: extern const char   js_index_str[];
                    280: extern const char   js_input_str[];
1.1.1.2 ! root      281: extern const char   js_iterator_str[];
1.1       root      282: extern const char   js_length_str[];
1.1.1.2 ! root      283: extern const char   js_lineNumber_str[];
        !           284: extern const char   js_message_str[];
1.1       root      285: extern const char   js_name_str[];
1.1.1.2 ! root      286: extern const char   js_namespace_str[];
        !           287: extern const char   js_next_str[];
1.1       root      288: extern const char   js_noSuchMethod_str[];
1.1.1.2 ! root      289: extern const char   js_object_str[];
1.1       root      290: extern const char   js_parent_str[];
1.1.1.2 ! root      291: extern const char   js_private_str[];
1.1       root      292: extern const char   js_proto_str[];
1.1.1.2 ! root      293: extern const char   js_ptagc_str[];
        !           294: extern const char   js_qualifier_str[];
        !           295: extern const char   js_send_str[];
1.1       root      296: extern const char   js_setter_str[];
                    297: extern const char   js_set_str[];
1.1.1.2 ! root      298: extern const char   js_space_str[];
        !           299: extern const char   js_stack_str[];
        !           300: extern const char   js_stago_str[];
        !           301: extern const char   js_star_str[];
        !           302: extern const char   js_starQualifier_str[];
        !           303: extern const char   js_tagc_str[];
1.1       root      304: extern const char   js_toSource_str[];
                    305: extern const char   js_toString_str[];
                    306: extern const char   js_toLocaleString_str[];
                    307: extern const char   js_valueOf_str[];
1.1.1.2 ! root      308: extern const char   js_xml_str[];
1.1       root      309: 
                    310: #ifdef NARCISSUS
                    311: extern const char   js_call_str[];
                    312: extern const char   js_construct_str[];
                    313: extern const char   js_hasInstance_str[];
                    314: extern const char   js_ExecutionContext_str[];
                    315: extern const char   js_current_str[];
                    316: #endif
                    317: 
                    318: /*
                    319:  * Initialize atom state.  Return true on success, false with an out of
                    320:  * memory error report on failure.
                    321:  */
                    322: extern JSBool
                    323: js_InitAtomState(JSContext *cx, JSAtomState *state);
                    324: 
                    325: /*
                    326:  * Free and clear atom state (except for any interned string atoms).
                    327:  */
                    328: extern void
                    329: js_FreeAtomState(JSContext *cx, JSAtomState *state);
                    330: 
                    331: /*
                    332:  * Interned strings are atoms that live until state's runtime is destroyed.
                    333:  * This function frees all interned string atoms, and then frees and clears
                    334:  * state's members (just as js_FreeAtomState does), unless there aren't any
                    335:  * interned strings in state -- in which case state must be "free" already.
                    336:  *
                    337:  * NB: js_FreeAtomState is called for each "last" context being destroyed in
                    338:  * a runtime, where there may yet be another context created in the runtime;
                    339:  * whereas js_FinishAtomState is called from JS_DestroyRuntime, when we know
                    340:  * that no more contexts will be created.  Thus we minimize garbage during
                    341:  * context-free episodes on a runtime, while preserving atoms created by the
                    342:  * JS_Intern*String APIs for the life of the runtime.
                    343:  */
                    344: extern void
                    345: js_FinishAtomState(JSAtomState *state);
                    346: 
                    347: /*
                    348:  * Atom garbage collection hooks.
                    349:  */
                    350: typedef void
                    351: (*JSGCThingMarker)(void *thing, void *data);
                    352: 
                    353: extern void
1.1.1.2 ! root      354: js_MarkAtomState(JSAtomState *state, JSBool keepAtoms, JSGCThingMarker mark,
1.1       root      355:                  void *data);
                    356: 
                    357: extern void
                    358: js_SweepAtomState(JSAtomState *state);
                    359: 
                    360: extern JSBool
                    361: js_InitPinnedAtoms(JSContext *cx, JSAtomState *state);
                    362: 
                    363: extern void
                    364: js_UnpinPinnedAtoms(JSAtomState *state);
                    365: 
                    366: /*
                    367:  * Find or create the atom for an object.  If we create a new atom, give it the
                    368:  * type indicated in flags.  Return 0 on failure to allocate memory.
                    369:  */
                    370: extern JSAtom *
                    371: js_AtomizeObject(JSContext *cx, JSObject *obj, uintN flags);
                    372: 
                    373: /*
                    374:  * Find or create the atom for a Boolean value.  If we create a new atom, give
                    375:  * it the type indicated in flags.  Return 0 on failure to allocate memory.
                    376:  */
                    377: extern JSAtom *
                    378: js_AtomizeBoolean(JSContext *cx, JSBool b, uintN flags);
                    379: 
                    380: /*
                    381:  * Find or create the atom for an integer value.  If we create a new atom, give
                    382:  * it the type indicated in flags.  Return 0 on failure to allocate memory.
                    383:  */
                    384: extern JSAtom *
                    385: js_AtomizeInt(JSContext *cx, jsint i, uintN flags);
                    386: 
                    387: /*
                    388:  * Find or create the atom for a double value.  If we create a new atom, give
                    389:  * it the type indicated in flags.  Return 0 on failure to allocate memory.
                    390:  */
                    391: extern JSAtom *
                    392: js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags);
                    393: 
                    394: /*
                    395:  * Find or create the atom for a string.  If we create a new atom, give it the
                    396:  * type indicated in flags.  Return 0 on failure to allocate memory.
                    397:  */
                    398: extern JSAtom *
                    399: js_AtomizeString(JSContext *cx, JSString *str, uintN flags);
                    400: 
                    401: extern JS_FRIEND_API(JSAtom *)
                    402: js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags);
                    403: 
                    404: extern JS_FRIEND_API(JSAtom *)
                    405: js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags);
                    406: 
                    407: /*
1.1.1.2 ! root      408:  * Return an existing atom for the given char array or null if the char
        !           409:  * sequence is currently not atomized.
        !           410:  */
        !           411: extern JSAtom *
        !           412: js_GetExistingStringAtom(JSContext *cx, const jschar *chars, size_t length);
        !           413: 
        !           414: /*
1.1       root      415:  * This variant handles all value tag types.
                    416:  */
                    417: extern JSAtom *
                    418: js_AtomizeValue(JSContext *cx, jsval value, uintN flags);
                    419: 
                    420: /*
                    421:  * Convert v to an atomized string.
                    422:  */
                    423: extern JSAtom *
                    424: js_ValueToStringAtom(JSContext *cx, jsval v);
                    425: 
                    426: /*
                    427:  * Assign atom an index and insert it on al.
                    428:  */
                    429: extern JSAtomListElement *
                    430: js_IndexAtom(JSContext *cx, JSAtom *atom, JSAtomList *al);
                    431: 
                    432: /*
                    433:  * Get the atom with index i from map.
                    434:  */
                    435: extern JS_FRIEND_API(JSAtom *)
                    436: js_GetAtom(JSContext *cx, JSAtomMap *map, jsatomid i);
                    437: 
                    438: /*
                    439:  * For all unmapped atoms recorded in al, add a mapping from the atom's index
                    440:  * to its address.  The GC must not run until all indexed atoms in atomLists
                    441:  * have been mapped by scripts connected to live objects (Function and Script
                    442:  * class objects have scripts as/in their private data -- the GC knows about
                    443:  * these two classes).
                    444:  */
                    445: extern JS_FRIEND_API(JSBool)
                    446: js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al);
                    447: 
                    448: /*
                    449:  * Free map->vector and clear map.
                    450:  */
                    451: extern JS_FRIEND_API(void)
                    452: js_FreeAtomMap(JSContext *cx, JSAtomMap *map);
                    453: 
                    454: JS_END_EXTERN_C
                    455: 
                    456: #endif /* jsatom_h___ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.