Check keyword version when scanning, not by installing different keywords on version selection (when starting to compile; bug 96562, r=rogerl, sr=shaver&jband, a=dbaron).

This commit is contained in:
brendan%mozilla.org 2001-08-24 03:32:31 +00:00
parent 57589cceed
commit f319c1d822
5 changed files with 24 additions and 34 deletions

View File

@ -191,7 +191,6 @@ js_alloc_atom(void *priv, const void *key)
atom->entry.key = key;
atom->entry.value = NULL;
atom->flags = 0;
atom->kwindex = -1;
atom->number = state->number++;
return &atom->entry;
}

View File

@ -58,23 +58,25 @@ JS_BEGIN_EXTERN_C
struct JSAtom {
JSHashEntry entry; /* key is jsval, value keyword info */
uint8 flags; /* pinned, interned, and mark flags */
int8 kwindex; /* keyword index, -1 if not keyword */
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))
#define ATOM_BYTES(atom) JS_GetStringBytes(ATOM_TO_STRING(atom))
#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))
#define ATOM_KEYWORD(atom) ((struct keyword *)(atom)->entry.value)
#define ATOM_SET_KEYWORD(atom,kw) ((atom)->entry.value = (kw))
struct JSAtomListElement {
JSHashEntry entry;

View File

@ -336,9 +336,6 @@ struct JSContext {
/* Per-context options. */
uint32 options; /* see jsapi.h for JSOPTION_* */
/* Delay JS_SetVersion scanner effects until they're needed. */
JSVersion scannerVersion;
/* Locale specific callbacks for string conversion. */
JSLocaleCallbacks *localeCallbacks;

View File

@ -729,7 +729,7 @@ js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
* If id is a string that's a reserved identifier, or else id is not
* an identifier at all, then it needs to be quoted.
*/
if (atom && (atom->kwindex >= 0 || !js_IsIdentifier(idstr))) {
if (atom && (ATOM_KEYWORD(atom) || !js_IsIdentifier(idstr))) {
idstr = js_QuoteString(cx, idstr, (jschar)'\'');
if (!idstr) {
ok = JS_FALSE;

View File

@ -176,10 +176,7 @@ js_InitScanner(JSContext *cx)
atom = js_Atomize(cx, kw->name, strlen(kw->name), ATOM_PINNED);
if (!atom)
return JS_FALSE;
atom->kwindex = (JSVERSION_IS_ECMA(cx->version) ||
kw->version <= cx->version)
? kw - keywords
: -1;
ATOM_SET_KEYWORD(atom, kw);
}
return JS_TRUE;
}
@ -217,12 +214,6 @@ js_NewBufferTokenStream(JSContext *cx, const jschar *base, size_t length)
size_t nb;
JSTokenStream *ts;
if (cx->scannerVersion != cx->version) {
if (!js_InitScanner(cx))
return NULL;
cx->scannerVersion = cx->version;
}
nb = sizeof(JSTokenStream) + JS_LINE_LIMIT * sizeof(jschar);
JS_ARENA_ALLOCATE_CAST(ts, JSTokenStream *, &cx->tempPool, nb);
if (!ts) {
@ -782,12 +773,13 @@ retry:
0);
if (!atom)
RETURN(TOK_ERROR);
if (!hadUnicodeEscape && atom->kwindex >= 0) {
struct keyword *kw;
if (!hadUnicodeEscape && ATOM_KEYWORD(atom)) {
struct keyword *kw = ATOM_KEYWORD(atom);
kw = &keywords[atom->kwindex];
tp->t_op = (JSOp) kw->op;
RETURN(kw->tokentype);
if (JSVERSION_IS_ECMA(cx->version) || kw->version <= cx->version) {
tp->t_op = (JSOp) kw->op;
RETURN(kw->tokentype);
}
}
tp->t_op = JSOP_NAME;
tp->t_atom = atom;