1998-03-28 05:44:41 +03:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
1999-09-29 03:12:09 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-03-28 05:44:41 +03:00
|
|
|
*
|
1999-09-29 03:12:09 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-03-28 05:44:41 +03:00
|
|
|
*
|
1999-09-29 03:12:09 +04:00
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-03-28 05:44:41 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-09-29 03:12:09 +04:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* terms of the GNU Public License (the "GPL"), in which case the
|
|
|
|
* provisions of the GPL are applicable instead of those above.
|
|
|
|
* If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of the GPL and not to allow others to use your
|
|
|
|
* version of this file under the NPL, indicate your decision by
|
|
|
|
* deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this
|
|
|
|
* file under either the NPL or the GPL.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef jsatom_h___
|
|
|
|
#define jsatom_h___
|
|
|
|
/*
|
|
|
|
* JS atom table.
|
|
|
|
*/
|
|
|
|
#include <stddef.h>
|
1998-10-14 14:22:38 +04:00
|
|
|
#include "jstypes.h"
|
|
|
|
#include "jshash.h" /* Added by JSIFY */
|
1998-03-28 05:44:41 +03:00
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jsprvtd.h"
|
|
|
|
#include "jspubtd.h"
|
|
|
|
|
1998-04-24 04:31:11 +04:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
#include "jslock.h"
|
|
|
|
#endif
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_BEGIN_EXTERN_C
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-04-24 04:31:11 +04:00
|
|
|
#define ATOM_NOCOPY 0x01 /* don't copy atom string bytes */
|
|
|
|
#define ATOM_TMPSTR 0x02 /* internal, to avoid extra string */
|
|
|
|
#define ATOM_MARK 0x04 /* atom is reachable via GC */
|
|
|
|
#define ATOM_PINNED 0x08 /* atom is pinned against GC */
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
struct JSAtom {
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashEntry entry; /* key is jsval, value keyword info */
|
1998-04-24 04:31:11 +04:00
|
|
|
uint8 flags; /* flags, PINNED and/or MARK for now */
|
1998-03-28 05:44:41 +03:00
|
|
|
int8 kwindex; /* keyword index, -1 if not keyword */
|
|
|
|
jsatomid number; /* atom serial number and hash code */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ATOM_KEY(atom) ((jsval)(atom)->entry.key)
|
|
|
|
#define ATOM_IS_OBJECT(atom) JSVAL_IS_OBJECT(ATOM_KEY(atom))
|
|
|
|
#define ATOM_TO_OBJECT(atom) JSVAL_TO_OBJECT(ATOM_KEY(atom))
|
|
|
|
#define ATOM_IS_INT(atom) JSVAL_IS_INT(ATOM_KEY(atom))
|
|
|
|
#define ATOM_TO_INT(atom) JSVAL_TO_INT(ATOM_KEY(atom))
|
|
|
|
#define ATOM_IS_DOUBLE(atom) JSVAL_IS_DOUBLE(ATOM_KEY(atom))
|
|
|
|
#define ATOM_TO_DOUBLE(atom) JSVAL_TO_DOUBLE(ATOM_KEY(atom))
|
|
|
|
#define ATOM_IS_STRING(atom) JSVAL_IS_STRING(ATOM_KEY(atom))
|
|
|
|
#define ATOM_TO_STRING(atom) JSVAL_TO_STRING(ATOM_KEY(atom))
|
|
|
|
#define ATOM_IS_BOOLEAN(atom) JSVAL_IS_BOOLEAN(ATOM_KEY(atom))
|
|
|
|
#define ATOM_TO_BOOLEAN(atom) JSVAL_TO_BOOLEAN(ATOM_KEY(atom))
|
|
|
|
#define ATOM_BYTES(atom) JS_GetStringBytes(ATOM_TO_STRING(atom))
|
1998-04-24 04:31:11 +04:00
|
|
|
|
|
|
|
struct JSAtomListElement {
|
2000-01-18 14:06:05 +03:00
|
|
|
JSHashEntry entry;
|
1998-04-24 04:31:11 +04:00
|
|
|
};
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2000-01-18 14:06:05 +03:00
|
|
|
#define ALE_ATOM(ale) ((JSAtom *) (ale)->entry.key)
|
|
|
|
#define ALE_INDEX(ale) ((jsatomid) (ale)->entry.value)
|
|
|
|
#define ALE_NODE(ale) ((JSParseNode *) (ale)->entry.value)
|
|
|
|
#define ALE_NEXT(ale) ((JSAtomListElement *) (ale)->entry.next)
|
|
|
|
|
|
|
|
#define ALE_SET_ATOM(ale,atom) ((ale)->entry.key = (const void *)(atom))
|
|
|
|
#define ALE_SET_INDEX(ale,index)((ale)->entry.value = (void *)(index))
|
|
|
|
#define ALE_SET_NODE(ale,pn) ((ale)->entry.value = (void *)(pn))
|
|
|
|
#define ALE_SET_NEXT(ale,link) ((ale)->entry.next = (JSHashEntry *)(link))
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
struct JSAtomList {
|
1998-04-24 04:31:11 +04:00
|
|
|
JSAtomListElement *list; /* literals indexed for mapping */
|
2000-01-18 14:06:05 +03:00
|
|
|
JSHashTable *table; /* hash table if list gets too long */
|
1998-03-28 05:44:41 +03:00
|
|
|
jsuint count; /* count of indexed literals */
|
|
|
|
};
|
|
|
|
|
2000-01-18 14:06:05 +03:00
|
|
|
#define ATOM_LIST_INIT(al) ((al)->list = NULL, (al)->table = NULL, \
|
|
|
|
(al)->count = 0)
|
1998-04-24 04:31:11 +04:00
|
|
|
|
|
|
|
#define ATOM_LIST_SEARCH(_ale,_al,_atom) \
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_BEGIN_MACRO \
|
2000-01-18 14:06:05 +03:00
|
|
|
JSHashEntry **_hep; \
|
|
|
|
ATOM_LIST_LOOKUP(_ale, _hep, _al, _atom); \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
|
|
|
#define ATOM_LIST_LOOKUP(_ale,_hep,_al,_atom) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
if ((_al)->table) { \
|
|
|
|
_hep = JS_HashTableRawLookup((_al)->table, _atom->number, _atom); \
|
|
|
|
_ale = *_hep ? (JSAtomListElement *) *_hep : NULL; \
|
|
|
|
} else { \
|
|
|
|
JSAtomListElement **_alep = &(_al)->list; \
|
|
|
|
_hep = NULL; \
|
|
|
|
while ((_ale = *_alep) != NULL) { \
|
|
|
|
if (ALE_ATOM(_ale) == (_atom)) { \
|
|
|
|
/* Hit, move atom's element to the front of the list. */ \
|
|
|
|
*_alep = ALE_NEXT(_ale); \
|
|
|
|
ALE_SET_NEXT(_ale, (_al)->list); \
|
|
|
|
(_al)->list = _ale; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
_alep = (JSAtomListElement **)&_ale->entry.next; \
|
|
|
|
} \
|
|
|
|
} \
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_END_MACRO
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
struct JSAtomMap {
|
|
|
|
JSAtom **vector; /* array of ptrs to indexed atoms */
|
|
|
|
jsatomid length; /* count of (to-be-)indexed atoms */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct JSAtomState {
|
1998-04-24 04:31:11 +04:00
|
|
|
JSRuntime *runtime; /* runtime that owns us */
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashTable *table; /* hash table containing all atoms */
|
1998-03-28 05:44:41 +03:00
|
|
|
jsatomid number; /* one beyond greatest atom number */
|
|
|
|
|
|
|
|
/* Type names and value literals. */
|
|
|
|
JSAtom *typeAtoms[JSTYPE_LIMIT];
|
|
|
|
JSAtom *booleanAtoms[2];
|
|
|
|
JSAtom *nullAtom;
|
|
|
|
|
|
|
|
/* Various built-in or commonly-used atoms. */
|
2000-08-19 12:37:07 +04:00
|
|
|
JSAtom *ArgumentsAtom;
|
1998-03-28 05:44:41 +03:00
|
|
|
JSAtom *ArrayAtom;
|
2000-08-19 12:37:07 +04:00
|
|
|
JSAtom *BooleanAtom;
|
|
|
|
JSAtom *CallAtom;
|
|
|
|
JSAtom *DateAtom;
|
|
|
|
JSAtom *ErrorAtom;
|
|
|
|
JSAtom *FunctionAtom;
|
1998-04-24 04:31:11 +04:00
|
|
|
JSAtom *MathAtom;
|
2000-08-19 12:37:07 +04:00
|
|
|
JSAtom *NumberAtom;
|
1998-03-28 05:44:41 +03:00
|
|
|
JSAtom *ObjectAtom;
|
2000-08-19 12:37:07 +04:00
|
|
|
JSAtom *RegExpAtom;
|
|
|
|
JSAtom *ScriptAtom;
|
|
|
|
JSAtom *StringAtom;
|
1998-03-28 05:44:41 +03:00
|
|
|
JSAtom *anonymousAtom;
|
1998-04-24 04:31:11 +04:00
|
|
|
JSAtom *argumentsAtom;
|
|
|
|
JSAtom *arityAtom;
|
|
|
|
JSAtom *calleeAtom;
|
|
|
|
JSAtom *callerAtom;
|
1998-03-28 05:44:41 +03:00
|
|
|
JSAtom *classPrototypeAtom;
|
|
|
|
JSAtom *constructorAtom;
|
|
|
|
JSAtom *countAtom;
|
2000-08-19 12:37:07 +04:00
|
|
|
JSAtom *evalAtom;
|
2000-02-12 01:19:33 +03:00
|
|
|
JSAtom *getAtom;
|
2000-08-19 12:37:07 +04:00
|
|
|
JSAtom *getterAtom;
|
1998-03-28 05:44:41 +03:00
|
|
|
JSAtom *indexAtom;
|
|
|
|
JSAtom *inputAtom;
|
|
|
|
JSAtom *lengthAtom;
|
1998-04-24 04:31:11 +04:00
|
|
|
JSAtom *nameAtom;
|
1998-03-28 05:44:41 +03:00
|
|
|
JSAtom *parentAtom;
|
|
|
|
JSAtom *protoAtom;
|
2000-02-12 01:19:33 +03:00
|
|
|
JSAtom *setAtom;
|
2000-08-19 12:37:07 +04:00
|
|
|
JSAtom *setterAtom;
|
|
|
|
JSAtom *toLocaleStringAtom;
|
1998-04-24 04:31:11 +04:00
|
|
|
JSAtom *toSourceAtom;
|
1998-03-28 05:44:41 +03:00
|
|
|
JSAtom *toStringAtom;
|
|
|
|
JSAtom *valueOfAtom;
|
1998-04-24 04:31:11 +04:00
|
|
|
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
JSThinLock lock;
|
|
|
|
volatile uint32 tablegen;
|
|
|
|
#endif
|
1998-03-28 05:44:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Well-known predefined strings and their atoms. */
|
2000-08-19 12:37:07 +04:00
|
|
|
extern const char *js_type_str[];
|
|
|
|
extern const char *js_boolean_str[];
|
|
|
|
|
|
|
|
extern const char js_Arguments_str[];
|
|
|
|
extern const char js_Array_str[];
|
|
|
|
extern const char js_Boolean_str[];
|
|
|
|
extern const char js_Call_str[];
|
|
|
|
extern const char js_Date_str[];
|
|
|
|
extern const char js_Function_str[];
|
|
|
|
extern const char js_Math_str[];
|
|
|
|
extern const char js_Number_str[];
|
|
|
|
extern const char js_Object_str[];
|
|
|
|
extern const char js_RegExp_str[];
|
|
|
|
extern const char js_Script_str[];
|
|
|
|
extern const char js_String_str[];
|
|
|
|
extern const char js_anonymous_str[];
|
|
|
|
extern const char js_arguments_str[];
|
|
|
|
extern const char js_arity_str[];
|
|
|
|
extern const char js_callee_str[];
|
|
|
|
extern const char js_caller_str[];
|
|
|
|
extern const char js_class_prototype_str[];
|
|
|
|
extern const char js_constructor_str[];
|
|
|
|
extern const char js_count_str[];
|
|
|
|
extern const char js_eval_str[];
|
|
|
|
extern const char js_getter_str[];
|
|
|
|
extern const char js_get_str[];
|
|
|
|
extern const char js_index_str[];
|
|
|
|
extern const char js_input_str[];
|
|
|
|
extern const char js_length_str[];
|
|
|
|
extern const char js_name_str[];
|
|
|
|
extern const char js_parent_str[];
|
|
|
|
extern const char js_proto_str[];
|
|
|
|
extern const char js_setter_str[];
|
|
|
|
extern const char js_set_str[];
|
|
|
|
extern const char js_toSource_str[];
|
|
|
|
extern const char js_toString_str[];
|
|
|
|
extern const char js_toLocaleString_str[];
|
|
|
|
extern const char js_valueOf_str[];
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Initialize atom state. Return true on success, false with an out of
|
1998-03-28 05:44:41 +03:00
|
|
|
* memory error report on failure.
|
|
|
|
*/
|
|
|
|
extern JSBool
|
|
|
|
js_InitAtomState(JSContext *cx, JSAtomState *state);
|
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Free and clear atom state.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
extern void
|
|
|
|
js_FreeAtomState(JSContext *cx, JSAtomState *state);
|
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Atom garbage collection hooks.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
typedef void
|
2000-08-26 06:30:22 +04:00
|
|
|
(*JSGCThingMarker)(void *thing, void *data);
|
1998-04-24 04:31:11 +04:00
|
|
|
|
|
|
|
extern void
|
2000-08-26 06:30:22 +04:00
|
|
|
js_MarkAtomState(JSAtomState *state, JSGCThingMarker mark, void *data);
|
1998-04-24 04:31:11 +04:00
|
|
|
|
|
|
|
extern void
|
2000-07-08 06:06:01 +04:00
|
|
|
js_SweepAtomState(JSAtomState *state, uintN gcflags);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
extern void
|
1998-04-24 04:31:11 +04:00
|
|
|
js_UnpinPinnedAtoms(JSAtomState *state);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find or create the atom for an object. If we create a new atom, give it the
|
|
|
|
* type indicated in flags. Return 0 on failure to allocate memory.
|
|
|
|
*/
|
|
|
|
extern JSAtom *
|
|
|
|
js_AtomizeObject(JSContext *cx, JSObject *obj, uintN flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find or create the atom for a Boolean value. If we create a new atom, give
|
|
|
|
* it the type indicated in flags. Return 0 on failure to allocate memory.
|
|
|
|
*/
|
|
|
|
extern JSAtom *
|
|
|
|
js_AtomizeBoolean(JSContext *cx, JSBool b, uintN flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find or create the atom for an integer value. If we create a new atom, give
|
|
|
|
* it the type indicated in flags. Return 0 on failure to allocate memory.
|
|
|
|
*/
|
|
|
|
extern JSAtom *
|
|
|
|
js_AtomizeInt(JSContext *cx, jsint i, uintN flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find or create the atom for a double value. If we create a new atom, give
|
|
|
|
* it the type indicated in flags. Return 0 on failure to allocate memory.
|
|
|
|
*/
|
|
|
|
extern JSAtom *
|
|
|
|
js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find or create the atom for a string. If we create a new atom, give it the
|
|
|
|
* type indicated in flags. Return 0 on failure to allocate memory.
|
|
|
|
*/
|
|
|
|
extern JSAtom *
|
|
|
|
js_AtomizeString(JSContext *cx, JSString *str, uintN flags);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSAtom *)
|
|
|
|
js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSAtom *)
|
|
|
|
js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This variant handles all value tag types.
|
|
|
|
*/
|
|
|
|
extern JSAtom *
|
|
|
|
js_AtomizeValue(JSContext *cx, jsval value, uintN flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert v to an atomized string.
|
|
|
|
*/
|
|
|
|
extern JSAtom *
|
|
|
|
js_ValueToStringAtom(JSContext *cx, jsval v);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assign atom an index and insert it on al.
|
|
|
|
*/
|
1998-04-24 04:31:11 +04:00
|
|
|
extern JSAtomListElement *
|
1998-03-28 05:44:41 +03:00
|
|
|
js_IndexAtom(JSContext *cx, JSAtom *atom, JSAtomList *al);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the atom with index i from map.
|
|
|
|
*/
|
1998-04-24 04:31:11 +04:00
|
|
|
extern JS_FRIEND_API(JSAtom *)
|
1998-03-28 05:44:41 +03:00
|
|
|
js_GetAtom(JSContext *cx, JSAtomMap *map, jsatomid i);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For all unmapped atoms recorded in al, add a mapping from the atom's index
|
1998-04-24 04:31:11 +04:00
|
|
|
* to its address. The GC must not run until all indexed atoms in atomLists
|
|
|
|
* have been mapped by scripts connected to live objects (Function and Script
|
|
|
|
* class objects have scripts as/in their private data -- the GC knows about
|
|
|
|
* these two classes).
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(JSBool)
|
|
|
|
js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al);
|
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Free map->vector and clear map.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
js_FreeAtomMap(JSContext *cx, JSAtomMap *map);
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_END_EXTERN_C
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
#endif /* jsatom_h___ */
|