2007-03-22 10:30:00 -07:00
|
|
|
/* -*- 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___
|
2011-06-24 14:22:30 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <stddef.h>
|
2008-09-05 10:19:17 -07:00
|
|
|
#include "jsversion.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jsprvtd.h"
|
2010-07-28 09:54:14 -07:00
|
|
|
#include "jshashtable.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jspubtd.h"
|
2010-07-28 09:54:14 -07:00
|
|
|
#include "jsstr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jslock.h"
|
2010-07-14 23:19:36 -07:00
|
|
|
#include "jsvalue.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-20 11:44:20 -07:00
|
|
|
#include "vm/String.h"
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
/* Engine-internal extensions of jsid */
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsid
|
|
|
|
JSID_FROM_BITS(size_t bits)
|
|
|
|
{
|
|
|
|
jsid id;
|
|
|
|
JSID_BITS(id) = bits;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsid
|
|
|
|
ATOM_TO_JSID(JSAtom *atom)
|
|
|
|
{
|
|
|
|
JS_ASSERT(((size_t)atom & 0x7) == 0);
|
|
|
|
return JSID_FROM_BITS((size_t)atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All strings stored in jsids are atomized. */
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSID_IS_ATOM(jsid id)
|
|
|
|
{
|
|
|
|
return JSID_IS_STRING(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSID_IS_ATOM(jsid id, JSAtom *atom)
|
|
|
|
{
|
|
|
|
return JSID_BITS(id) == JSID_BITS(ATOM_TO_JSID(atom));
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSAtom *
|
|
|
|
JSID_TO_ATOM(jsid id)
|
|
|
|
{
|
|
|
|
return (JSAtom *)JSID_TO_STRING(id);
|
|
|
|
}
|
|
|
|
|
2011-07-27 15:44:29 -07:00
|
|
|
extern jsid
|
|
|
|
js_CheckForStringIndex(jsid id);
|
|
|
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSHashNumber) == 4);
|
|
|
|
JS_STATIC_ASSERT(sizeof(jsid) == JS_BYTES_PER_WORD);
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
namespace js {
|
|
|
|
|
2011-07-27 15:44:29 -07:00
|
|
|
static JS_ALWAYS_INLINE JSHashNumber
|
|
|
|
HashId(jsid id)
|
|
|
|
{
|
|
|
|
JS_ASSERT(js_CheckForStringIndex(id) == id);
|
|
|
|
JSHashNumber n =
|
|
|
|
#if JS_BYTES_PER_WORD == 4
|
|
|
|
JSHashNumber(JSID_BITS(id));
|
|
|
|
#elif JS_BYTES_PER_WORD == 8
|
|
|
|
JSHashNumber(JSID_BITS(id)) ^ JSHashNumber(JSID_BITS(id) >> 32);
|
|
|
|
#else
|
|
|
|
# error "Unsupported configuration"
|
|
|
|
#endif
|
|
|
|
return n * JS_GOLDEN_RATIO;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
IdToValue(jsid id)
|
|
|
|
{
|
|
|
|
if (JSID_IS_STRING(id))
|
|
|
|
return StringValue(JSID_TO_STRING(id));
|
|
|
|
if (JS_LIKELY(JSID_IS_INT(id)))
|
|
|
|
return Int32Value(JSID_TO_INT(id));
|
|
|
|
if (JS_LIKELY(JSID_IS_OBJECT(id)))
|
|
|
|
return ObjectValue(*JSID_TO_OBJECT(id));
|
|
|
|
JS_ASSERT(JSID_IS_DEFAULT_XML_NAMESPACE(id) || JSID_IS_VOID(id));
|
|
|
|
return UndefinedValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsval
|
|
|
|
IdToJsval(jsid id)
|
|
|
|
{
|
|
|
|
return Jsvalify(IdToValue(id));
|
|
|
|
}
|
|
|
|
|
2011-04-11 01:46:12 -07:00
|
|
|
template<>
|
|
|
|
struct DefaultHasher<jsid>
|
|
|
|
{
|
|
|
|
typedef jsid Lookup;
|
|
|
|
static HashNumber hash(const Lookup &l) {
|
|
|
|
JS_ASSERT(l == js_CheckForStringIndex(l));
|
2011-07-19 22:07:51 -07:00
|
|
|
return HashNumber(JSID_BITS(l));
|
2011-04-11 01:46:12 -07:00
|
|
|
}
|
|
|
|
static bool match(const jsid &id, const Lookup &l) {
|
|
|
|
JS_ASSERT(l == js_CheckForStringIndex(l));
|
|
|
|
return id == l;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-11 02:25:45 -07:00
|
|
|
#if JS_BYTES_PER_WORD == 4
|
|
|
|
# define ATOM_HASH(atom) ((JSHashNumber)(atom) >> 2)
|
|
|
|
#elif JS_BYTES_PER_WORD == 8
|
2007-11-16 20:20:37 -08:00
|
|
|
# define ATOM_HASH(atom) (((JSHashNumber)(jsuword)(atom) >> 3) ^ \
|
2007-07-11 02:25:45 -07:00
|
|
|
(JSHashNumber)((jsuword)(atom) >> 32))
|
|
|
|
#else
|
|
|
|
# error "Unsupported configuration"
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Return a printable, lossless char[] representation of a string-type atom.
|
2010-11-11 12:40:29 -08:00
|
|
|
* The lifetime of the result matches the lifetime of bytes.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-01-19 13:15:08 -08:00
|
|
|
extern const char *
|
2010-11-11 12:40:29 -08:00
|
|
|
js_AtomToPrintableString(JSContext *cx, JSAtom *atom, JSAutoByteString *bytes);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
struct JSAtomMap {
|
2011-06-24 14:22:30 -07:00
|
|
|
JSAtom **vector; /* array of ptrs to indexed atoms */
|
|
|
|
uint32 length; /* count of (to-be-)indexed atoms */
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-07-28 09:54:14 -07:00
|
|
|
namespace js {
|
|
|
|
|
2011-07-19 16:37:11 -07:00
|
|
|
typedef TaggedPointerEntry<JSAtom> AtomStateEntry;
|
2010-07-28 09:54:14 -07:00
|
|
|
|
|
|
|
struct AtomHasher
|
|
|
|
{
|
2011-03-14 13:59:53 -07:00
|
|
|
struct Lookup
|
|
|
|
{
|
2011-05-17 12:15:12 -07:00
|
|
|
const jschar *chars;
|
|
|
|
size_t length;
|
|
|
|
const JSAtom *atom; /* Optional. */
|
|
|
|
|
|
|
|
Lookup(const jschar *chars, size_t length) : chars(chars), length(length), atom(NULL) {}
|
|
|
|
Lookup(const JSAtom *atom) : chars(atom->chars()), length(atom->length()), atom(atom) {}
|
2011-03-14 13:59:53 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static HashNumber hash(const Lookup &l) {
|
|
|
|
return HashChars(l.chars, l.length);
|
2010-07-28 09:54:14 -07:00
|
|
|
}
|
|
|
|
|
2011-07-19 16:37:11 -07:00
|
|
|
static bool match(const AtomStateEntry &entry, const Lookup &lookup) {
|
|
|
|
JSAtom *key = entry.asPtr();
|
2011-05-17 12:15:12 -07:00
|
|
|
|
|
|
|
if (lookup.atom)
|
|
|
|
return lookup.atom == key;
|
2011-03-14 13:59:53 -07:00
|
|
|
if (key->length() != lookup.length)
|
|
|
|
return false;
|
|
|
|
return PodEqual(key->chars(), lookup.chars, lookup.length);
|
2010-07-28 09:54:14 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-05-17 12:15:12 -07:00
|
|
|
typedef HashSet<AtomStateEntry, AtomHasher, SystemAllocPolicy> AtomSet;
|
2010-07-28 09:54:14 -07:00
|
|
|
|
|
|
|
} /* namespace js */
|
|
|
|
|
|
|
|
struct JSAtomState
|
|
|
|
{
|
|
|
|
js::AtomSet atoms;
|
|
|
|
|
2007-08-07 00:29:32 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
JSThinLock lock;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* From this point until the end of struct definition the struct must
|
|
|
|
* contain only JSAtom fields. We use this to access the storage occupied
|
|
|
|
* by the common atoms in js_FinishCommonAtoms.
|
|
|
|
*
|
|
|
|
* js_common_atom_names defined in jsatom.c contains C strings for atoms
|
|
|
|
* in the order of atom fields here. Therefore you must update that array
|
|
|
|
* if you change member order here.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* The rt->emptyString atom, see jsstr.c's js_InitRuntimeStringState. */
|
|
|
|
JSAtom *emptyAtom;
|
|
|
|
|
2008-10-29 00:14:30 -07:00
|
|
|
/*
|
|
|
|
* Literal value and type names.
|
|
|
|
* NB: booleanAtoms must come right before typeAtoms!
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *booleanAtoms[2];
|
2008-10-29 00:14:30 -07:00
|
|
|
JSAtom *typeAtoms[JSTYPE_LIMIT];
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
2008-10-29 13:30:41 -07:00
|
|
|
JSAtom *applyAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *argumentsAtom;
|
|
|
|
JSAtom *arityAtom;
|
2011-05-04 13:54:23 -07:00
|
|
|
JSAtom *BYTES_PER_ELEMENTAtom;
|
2008-10-30 16:01:53 -07:00
|
|
|
JSAtom *callAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *calleeAtom;
|
|
|
|
JSAtom *callerAtom;
|
|
|
|
JSAtom *classPrototypeAtom;
|
|
|
|
JSAtom *constructorAtom;
|
|
|
|
JSAtom *eachAtom;
|
|
|
|
JSAtom *evalAtom;
|
|
|
|
JSAtom *fileNameAtom;
|
|
|
|
JSAtom *getAtom;
|
2010-06-05 18:16:03 -07:00
|
|
|
JSAtom *globalAtom;
|
|
|
|
JSAtom *ignoreCaseAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *indexAtom;
|
|
|
|
JSAtom *inputAtom;
|
2010-08-13 10:42:31 -07:00
|
|
|
JSAtom *toISOStringAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *iteratorAtom;
|
2010-07-15 10:33:33 -07:00
|
|
|
JSAtom *joinAtom;
|
2010-06-05 18:16:03 -07:00
|
|
|
JSAtom *lastIndexAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *lengthAtom;
|
|
|
|
JSAtom *lineNumberAtom;
|
|
|
|
JSAtom *messageAtom;
|
2010-06-05 18:16:03 -07:00
|
|
|
JSAtom *multilineAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *nameAtom;
|
|
|
|
JSAtom *nextAtom;
|
|
|
|
JSAtom *noSuchMethodAtom;
|
2010-10-12 11:50:03 -07:00
|
|
|
JSAtom *objectNullAtom;
|
|
|
|
JSAtom *objectUndefinedAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *protoAtom;
|
|
|
|
JSAtom *setAtom;
|
2010-06-05 18:16:03 -07:00
|
|
|
JSAtom *sourceAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *stackAtom;
|
2010-06-05 18:16:03 -07:00
|
|
|
JSAtom *stickyAtom;
|
2010-06-26 14:08:58 -07:00
|
|
|
JSAtom *toGMTStringAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *toLocaleStringAtom;
|
|
|
|
JSAtom *toSourceAtom;
|
|
|
|
JSAtom *toStringAtom;
|
2010-06-26 14:08:58 -07:00
|
|
|
JSAtom *toUTCStringAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *valueOfAtom;
|
2008-09-30 23:13:58 -07:00
|
|
|
JSAtom *toJSONAtom;
|
2007-06-12 12:33:40 -07:00
|
|
|
JSAtom *void0Atom;
|
2009-07-21 19:35:59 -07:00
|
|
|
JSAtom *enumerableAtom;
|
|
|
|
JSAtom *configurableAtom;
|
|
|
|
JSAtom *writableAtom;
|
|
|
|
JSAtom *valueAtom;
|
2010-09-07 18:09:26 -07:00
|
|
|
JSAtom *testAtom;
|
2009-11-18 13:33:53 -08:00
|
|
|
JSAtom *useStrictAtom;
|
2010-10-19 09:00:51 -07:00
|
|
|
JSAtom *locAtom;
|
|
|
|
JSAtom *lineAtom;
|
2010-11-01 13:47:45 -07:00
|
|
|
JSAtom *InfinityAtom;
|
|
|
|
JSAtom *NaNAtom;
|
2011-01-04 15:39:45 -08:00
|
|
|
JSAtom *builderAtom;
|
2007-08-07 00:29:32 -07:00
|
|
|
|
|
|
|
#if JS_HAS_XML_SUPPORT
|
|
|
|
JSAtom *etagoAtom;
|
|
|
|
JSAtom *namespaceAtom;
|
|
|
|
JSAtom *ptagcAtom;
|
|
|
|
JSAtom *qualifierAtom;
|
|
|
|
JSAtom *spaceAtom;
|
|
|
|
JSAtom *stagoAtom;
|
|
|
|
JSAtom *starAtom;
|
|
|
|
JSAtom *starQualifierAtom;
|
|
|
|
JSAtom *tagcAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAtom *xmlAtom;
|
2010-09-15 07:55:35 -07:00
|
|
|
|
|
|
|
/* Represents an invalid URI, for internal use only. */
|
|
|
|
JSAtom *functionNamespaceURIAtom;
|
2007-08-07 00:29:32 -07:00
|
|
|
#endif
|
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
JSAtom *ProxyAtom;
|
|
|
|
|
|
|
|
JSAtom *getOwnPropertyDescriptorAtom;
|
|
|
|
JSAtom *getPropertyDescriptorAtom;
|
|
|
|
JSAtom *definePropertyAtom;
|
|
|
|
JSAtom *deleteAtom;
|
|
|
|
JSAtom *getOwnPropertyNamesAtom;
|
|
|
|
JSAtom *enumerateAtom;
|
|
|
|
JSAtom *fixAtom;
|
|
|
|
|
|
|
|
JSAtom *hasAtom;
|
|
|
|
JSAtom *hasOwnAtom;
|
2011-01-10 11:42:11 -08:00
|
|
|
JSAtom *keysAtom;
|
2010-05-27 12:03:25 -07:00
|
|
|
JSAtom *iterateAtom;
|
2010-05-18 19:21:43 -07:00
|
|
|
|
2011-04-16 21:23:44 -07:00
|
|
|
JSAtom *WeakMapAtom;
|
|
|
|
|
2011-06-14 12:33:11 -07:00
|
|
|
JSAtom *byteLengthAtom;
|
|
|
|
|
2011-04-18 15:42:07 -07:00
|
|
|
JSAtom *returnAtom;
|
|
|
|
JSAtom *throwAtom;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Less frequently used atoms, pinned lazily by JS_ResolveStandardClass. */
|
|
|
|
struct {
|
|
|
|
JSAtom *XMLListAtom;
|
|
|
|
JSAtom *decodeURIAtom;
|
|
|
|
JSAtom *decodeURIComponentAtom;
|
|
|
|
JSAtom *defineGetterAtom;
|
|
|
|
JSAtom *defineSetterAtom;
|
|
|
|
JSAtom *encodeURIAtom;
|
|
|
|
JSAtom *encodeURIComponentAtom;
|
|
|
|
JSAtom *escapeAtom;
|
|
|
|
JSAtom *hasOwnPropertyAtom;
|
|
|
|
JSAtom *isFiniteAtom;
|
|
|
|
JSAtom *isNaNAtom;
|
|
|
|
JSAtom *isPrototypeOfAtom;
|
|
|
|
JSAtom *isXMLNameAtom;
|
|
|
|
JSAtom *lookupGetterAtom;
|
|
|
|
JSAtom *lookupSetterAtom;
|
|
|
|
JSAtom *parseFloatAtom;
|
|
|
|
JSAtom *parseIntAtom;
|
|
|
|
JSAtom *propertyIsEnumerableAtom;
|
|
|
|
JSAtom *unescapeAtom;
|
|
|
|
JSAtom *unevalAtom;
|
|
|
|
JSAtom *unwatchAtom;
|
|
|
|
JSAtom *watchAtom;
|
|
|
|
} lazy;
|
2011-05-17 12:15:12 -07:00
|
|
|
|
|
|
|
static const size_t commonAtomsOffset;
|
|
|
|
static const size_t lazyAtomsOffset;
|
|
|
|
|
|
|
|
void clearLazyAtoms() {
|
|
|
|
memset(&lazy, 0, sizeof(lazy));
|
|
|
|
}
|
|
|
|
|
|
|
|
void junkAtoms() {
|
|
|
|
#ifdef DEBUG
|
|
|
|
memset(commonAtomsStart(), JS_FREE_PATTERN, sizeof(*this) - commonAtomsOffset);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
JSAtom **commonAtomsStart() {
|
|
|
|
return &emptyAtom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkStaticInvariants();
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2011-05-17 12:15:12 -07:00
|
|
|
extern bool
|
|
|
|
AtomIsInterned(JSContext *cx, JSAtom *atom);
|
2010-05-18 19:21:43 -07:00
|
|
|
|
2011-05-17 12:15:12 -07:00
|
|
|
#define ATOM(name) cx->runtime->atomState.name##Atom
|
2007-08-07 00:29:32 -07:00
|
|
|
|
2008-11-13 00:30:20 -08:00
|
|
|
#define COMMON_ATOM_INDEX(name) \
|
2011-05-17 12:15:12 -07:00
|
|
|
((offsetof(JSAtomState, name##Atom) - JSAtomState::commonAtomsOffset) \
|
2008-11-13 00:30:20 -08:00
|
|
|
/ sizeof(JSAtom*))
|
|
|
|
#define COMMON_TYPE_ATOM_INDEX(type) \
|
2011-05-17 12:15:12 -07:00
|
|
|
((offsetof(JSAtomState, typeAtoms[type]) - JSAtomState::commonAtomsOffset)\
|
2008-11-13 00:30:20 -08:00
|
|
|
/ sizeof(JSAtom*))
|
2007-08-11 13:25:16 -07:00
|
|
|
|
2007-06-26 11:19:54 -07:00
|
|
|
#define ATOM_OFFSET(name) offsetof(JSAtomState, name##Atom)
|
|
|
|
#define OFFSET_TO_ATOM(rt,off) (*(JSAtom **)((char*)&(rt)->atomState + (off)))
|
2011-05-17 12:15:12 -07:00
|
|
|
#define CLASS_ATOM_OFFSET(name) offsetof(JSAtomState, classAtoms[JSProto_##name])
|
|
|
|
#define CLASS_ATOM(cx,name) ((cx)->runtime->atomState.classAtoms[JSProto_##name])
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-07 00:29:32 -07:00
|
|
|
extern const char *const js_common_atom_names[];
|
2008-11-13 00:30:20 -08:00
|
|
|
extern const size_t js_common_atom_count;
|
2007-08-07 00:29:32 -07:00
|
|
|
|
|
|
|
/*
|
2009-03-05 03:12:50 -08:00
|
|
|
* Macros to access C strings for JSType and boolean literals.
|
2007-08-07 00:29:32 -07:00
|
|
|
*/
|
2008-10-29 00:14:30 -07:00
|
|
|
#define JS_BOOLEAN_STR(type) (js_common_atom_names[1 + (type)])
|
|
|
|
#define JS_TYPE_STR(type) (js_common_atom_names[1 + 2 + (type)])
|
2007-08-07 00:29:32 -07:00
|
|
|
|
|
|
|
/* Well-known predefined C strings. */
|
2007-03-22 10:30:00 -07:00
|
|
|
#define JS_PROTO(name,code,init) extern const char js_##name##_str[];
|
|
|
|
#include "jsproto.tbl"
|
|
|
|
#undef JS_PROTO
|
|
|
|
|
|
|
|
extern const char js_anonymous_str[];
|
2008-10-29 13:30:41 -07:00
|
|
|
extern const char js_apply_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_arguments_str[];
|
|
|
|
extern const char js_arity_str[];
|
2011-05-04 13:54:23 -07:00
|
|
|
extern const char js_BYTES_PER_ELEMENT_str[];
|
2008-10-30 16:01:53 -07:00
|
|
|
extern const char js_call_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_callee_str[];
|
|
|
|
extern const char js_caller_str[];
|
|
|
|
extern const char js_class_prototype_str[];
|
|
|
|
extern const char js_close_str[];
|
|
|
|
extern const char js_constructor_str[];
|
|
|
|
extern const char js_count_str[];
|
|
|
|
extern const char js_etago_str[];
|
|
|
|
extern const char js_each_str[];
|
|
|
|
extern const char js_eval_str[];
|
|
|
|
extern const char js_fileName_str[];
|
|
|
|
extern const char js_get_str[];
|
|
|
|
extern const char js_getter_str[];
|
2010-06-05 18:16:03 -07:00
|
|
|
extern const char js_global_str[];
|
|
|
|
extern const char js_ignoreCase_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_index_str[];
|
|
|
|
extern const char js_input_str[];
|
|
|
|
extern const char js_iterator_str[];
|
2010-07-15 10:33:33 -07:00
|
|
|
extern const char js_join_str[];
|
2010-06-05 18:16:03 -07:00
|
|
|
extern const char js_lastIndex_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_length_str[];
|
|
|
|
extern const char js_lineNumber_str[];
|
|
|
|
extern const char js_message_str[];
|
2010-06-05 18:16:03 -07:00
|
|
|
extern const char js_multiline_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_name_str[];
|
|
|
|
extern const char js_namespace_str[];
|
|
|
|
extern const char js_next_str[];
|
|
|
|
extern const char js_noSuchMethod_str[];
|
|
|
|
extern const char js_object_str[];
|
|
|
|
extern const char js_proto_str[];
|
|
|
|
extern const char js_ptagc_str[];
|
|
|
|
extern const char js_qualifier_str[];
|
|
|
|
extern const char js_send_str[];
|
|
|
|
extern const char js_setter_str[];
|
|
|
|
extern const char js_set_str[];
|
2010-06-05 18:16:03 -07:00
|
|
|
extern const char js_source_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_space_str[];
|
|
|
|
extern const char js_stack_str[];
|
2010-06-05 18:16:03 -07:00
|
|
|
extern const char js_sticky_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_stago_str[];
|
|
|
|
extern const char js_star_str[];
|
|
|
|
extern const char js_starQualifier_str[];
|
|
|
|
extern const char js_tagc_str[];
|
2010-06-26 14:08:58 -07:00
|
|
|
extern const char js_toGMTString_str[];
|
|
|
|
extern const char js_toLocaleString_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_toSource_str[];
|
|
|
|
extern const char js_toString_str[];
|
2010-06-26 14:08:58 -07:00
|
|
|
extern const char js_toUTCString_str[];
|
2007-08-07 00:29:32 -07:00
|
|
|
extern const char js_undefined_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_valueOf_str[];
|
2008-09-30 23:13:58 -07:00
|
|
|
extern const char js_toJSON_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_xml_str[];
|
2009-07-21 19:35:59 -07:00
|
|
|
extern const char js_enumerable_str[];
|
|
|
|
extern const char js_configurable_str[];
|
|
|
|
extern const char js_writable_str[];
|
|
|
|
extern const char js_value_str[];
|
2010-09-07 18:09:26 -07:00
|
|
|
extern const char js_test_str[];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
2007-08-07 00:29:32 -07:00
|
|
|
* Initialize atom state. Return true on success, false on failure to allocate
|
|
|
|
* memory. The caller must zero rt->atomState before calling this function and
|
|
|
|
* only call it after js_InitGC successfully returns.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
extern JSBool
|
2007-08-07 00:29:32 -07:00
|
|
|
js_InitAtomState(JSRuntime *rt);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
2007-08-07 00:29:32 -07:00
|
|
|
* Free and clear atom state including any interned string atoms. This
|
|
|
|
* function must be called before js_FinishGC.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
extern void
|
2007-08-07 00:29:32 -07:00
|
|
|
js_FinishAtomState(JSRuntime *rt);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
2007-04-16 23:53:37 -07:00
|
|
|
* Atom tracing and garbage collection hooks.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
extern void
|
2010-04-23 15:15:42 -07:00
|
|
|
js_TraceAtomState(JSTracer *trc);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern void
|
2007-08-07 00:29:32 -07:00
|
|
|
js_SweepAtomState(JSContext *cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-17 12:15:12 -07:00
|
|
|
extern bool
|
2007-08-07 00:29:32 -07:00
|
|
|
js_InitCommonAtoms(JSContext *cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern void
|
2007-08-07 00:29:32 -07:00
|
|
|
js_FinishCommonAtoms(JSContext *cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-19 13:15:08 -08:00
|
|
|
extern JSAtom *
|
2011-05-17 12:15:12 -07:00
|
|
|
js_Atomize(JSContext *cx, const char *bytes, size_t length,
|
2011-05-26 15:50:05 -07:00
|
|
|
js::InternBehavior ib = js::DoNotInternAtom,
|
|
|
|
js::FlationCoding fc = js::NormalEncoding);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-19 13:15:08 -08:00
|
|
|
extern JSAtom *
|
2011-05-17 12:15:12 -07:00
|
|
|
js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length,
|
|
|
|
js::InternBehavior ib = js::DoNotInternAtom);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return an existing atom for the given char array or null if the char
|
|
|
|
* sequence is currently not atomized.
|
|
|
|
*/
|
|
|
|
extern JSAtom *
|
|
|
|
js_GetExistingStringAtom(JSContext *cx, const jschar *chars, size_t length);
|
|
|
|
|
2007-08-07 00:29:32 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
js_DumpAtoms(JSContext *cx, FILE *fp);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline bool
|
|
|
|
js_ValueToAtom(JSContext *cx, const js::Value &v, JSAtom **atomp);
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
js_ValueToStringId(JSContext *cx, const js::Value &v, jsid *idp);
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
js_InternNonIntElementId(JSContext *cx, JSObject *obj, const js::Value &idval,
|
|
|
|
jsid *idp);
|
|
|
|
inline bool
|
|
|
|
js_InternNonIntElementId(JSContext *cx, JSObject *obj, const js::Value &idval,
|
|
|
|
jsid *idp, js::Value *vp);
|
2011-06-24 14:22:30 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* For all unmapped atoms recorded in al, add a mapping from the atom's index
|
2007-07-08 02:03:34 -07:00
|
|
|
* to its address. map->length must already be set to the number of atoms in
|
|
|
|
* the list and map->vector must point to pre-allocated memory.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-01-19 13:15:08 -08:00
|
|
|
extern void
|
2011-06-24 14:22:30 -07:00
|
|
|
js_InitAtomMap(JSContext *cx, JSAtomMap *map, js::AtomIndexMap *indices);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#endif /* jsatom_h___ */
|