📄 jsatom.h
字号:
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla 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/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Mozilla Communicator client code, released * March 31, 1998. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */#ifndef jsatom_h___#define jsatom_h___/* * JS atom table. */#include <stddef.h>#include "jstypes.h"#include "jshash.h" /* Added by JSIFY */#include "jsapi.h"#include "jsprvtd.h"#include "jspubtd.h"#ifdef JS_THREADSAFE#include "jslock.h"#endifJS_BEGIN_EXTERN_C#define ATOM_PINNED 0x01 /* atom is pinned against GC */#define ATOM_INTERNED 0x02 /* pinned variant for JS_Intern* API */#define ATOM_MARK 0x04 /* atom is reachable via GC */#define ATOM_HIDDEN 0x08 /* atom is in special hidden subspace */#define ATOM_NOCOPY 0x40 /* don't copy atom string bytes */#define ATOM_TMPSTR 0x80 /* internal, to avoid extra string */struct JSAtom { JSHashEntry entry; /* key is jsval or unhidden atom if ATOM_HIDDEN */ uint32 flags; /* pinned, interned, and mark flags */ 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))/* * Return a printable, lossless char[] representation of a string-type atom. * The lifetime of the result extends at least until the next GC activation, * longer if cx's string newborn root is not overwritten. */extern JS_FRIEND_API(const char *)js_AtomToPrintableString(JSContext *cx, JSAtom *atom);struct JSAtomListElement { JSHashEntry entry;};#define ALE_ATOM(ale) ((JSAtom *) (ale)->entry.key)#define ALE_INDEX(ale) ((jsatomid) JS_PTR_TO_UINT32((ale)->entry.value))#define ALE_JSOP(ale) ((JSOp) (ale)->entry.value)#define ALE_VALUE(ale) ((jsval) (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 = JS_UINT32_TO_PTR(index))#define ALE_SET_JSOP(ale,op) ((ale)->entry.value = JS_UINT32_TO_PTR(op))#define ALE_SET_VALUE(ale,val) ((ale)->entry.value = (JSHashEntry *)(val))#define ALE_SET_NEXT(ale,link) ((ale)->entry.next = (JSHashEntry *)(link))struct JSAtomList { JSAtomListElement *list; /* literals indexed for mapping */ JSHashTable *table; /* hash table if list gets too long */ jsuint count; /* count of indexed literals */};#define ATOM_LIST_INIT(al) ((al)->list = NULL, (al)->table = NULL, \ (al)->count = 0)#define ATOM_LIST_SEARCH(_ale,_al,_atom) \ JS_BEGIN_MACRO \ 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; \ } \ } \ JS_END_MACROstruct JSAtomMap { JSAtom **vector; /* array of ptrs to indexed atoms */ jsatomid length; /* count of (to-be-)indexed atoms */};struct JSAtomState { JSRuntime *runtime; /* runtime that owns us */ JSHashTable *table; /* hash table containing all atoms */ jsatomid number; /* one beyond greatest atom number */ jsatomid liveAtoms; /* number of live atoms after last GC */ /* The rt->emptyString atom, see jsstr.c's js_InitRuntimeStringState. */ JSAtom *emptyAtom; /* Type names and value literals. */ JSAtom *typeAtoms[JSTYPE_LIMIT]; JSAtom *booleanAtoms[2]; JSAtom *nullAtom; /* Standard class constructor or prototype names. */ JSAtom *classAtoms[JSProto_LIMIT]; /* Various built-in or commonly-used atoms, pinned on first context. */ JSAtom *anonymousAtom; JSAtom *argumentsAtom; JSAtom *arityAtom; JSAtom *calleeAtom; JSAtom *callerAtom; JSAtom *classPrototypeAtom; JSAtom *closeAtom; JSAtom *constructorAtom; JSAtom *countAtom; JSAtom *eachAtom; JSAtom *etagoAtom; JSAtom *evalAtom; JSAtom *fileNameAtom; JSAtom *getAtom; JSAtom *getterAtom; JSAtom *indexAtom; JSAtom *inputAtom; JSAtom *iteratorAtom; JSAtom *lengthAtom; JSAtom *lineNumberAtom; JSAtom *messageAtom; JSAtom *nameAtom; JSAtom *namespaceAtom; JSAtom *nextAtom; JSAtom *noSuchMethodAtom; JSAtom *parentAtom; JSAtom *protoAtom; JSAtom *ptagcAtom; JSAtom *qualifierAtom; JSAtom *setAtom; JSAtom *setterAtom; JSAtom *spaceAtom; JSAtom *stackAtom; JSAtom *stagoAtom; JSAtom *starAtom; JSAtom *starQualifierAtom; JSAtom *tagcAtom; JSAtom *toLocaleStringAtom; JSAtom *toSourceAtom; JSAtom *toStringAtom; JSAtom *valueOfAtom; JSAtom *xmlAtom; /* Less frequently used atoms, pinned lazily by JS_ResolveStandardClass. */ struct { JSAtom *InfinityAtom; JSAtom *NaNAtom; JSAtom *XMLListAtom; JSAtom *decodeURIAtom; JSAtom *decodeURIComponentAtom; JSAtom *defineGetterAtom; JSAtom *defineSetterAtom; JSAtom *encodeURIAtom; JSAtom *encodeURIComponentAtom; JSAtom *escapeAtom; JSAtom *functionNamespaceURIAtom; JSAtom *hasOwnPropertyAtom; JSAtom *isFiniteAtom; JSAtom *isNaNAtom; JSAtom *isPrototypeOfAtom; JSAtom *isXMLNameAtom; JSAtom *lookupGetterAtom; JSAtom *lookupSetterAtom;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -