Bug 355736: no quotas arround name matching keywords in keywordless context. r=brendan,mrbkap

This commit is contained in:
igor@mir2.org 2007-03-24 00:34:47 -07:00
Родитель cb86161398
Коммит e354216aff
4 изменённых файлов: 29 добавлений и 28 удалений

Просмотреть файл

@ -1776,28 +1776,6 @@ static JSFunctionSpec function_methods[] = {
{0,0,0,0,0}
};
JSBool
js_IsIdentifier(JSString *str)
{
size_t length;
jschar c, *chars, *end, *s;
length = JSSTRING_LENGTH(str);
if (length == 0)
return JS_FALSE;
chars = JSSTRING_CHARS(str);
c = *chars;
if (!JS_ISIDSTART(c))
return JS_FALSE;
end = chars + length;
for (s = chars + 1; s != end; ++s) {
c = *s;
if (!JS_ISIDENT(c))
return JS_FALSE;
}
return !js_IsKeyword(chars, length);
}
static JSBool
Function(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{

Просмотреть файл

@ -90,9 +90,6 @@ extern JSBool
js_fun_toString(JSContext *cx, JSObject *obj, uint32 indent,
uintN argc, jsval *argv, jsval *rval);
extern JSBool
js_IsIdentifier(JSString *str);
extern JSObject *
js_InitFunctionClass(JSContext *cx, JSObject *obj);

Просмотреть файл

@ -151,6 +151,28 @@ js_MapKeywords(void (*mapfun)(const char *))
mapfun(keyword_defs[i].chars);
}
JSBool
js_IsIdentifier(JSString *str)
{
size_t length;
jschar c, *chars, *end;
length = JSSTRING_LENGTH(str);
if (length == 0)
return JS_FALSE;
chars = JSSTRING_CHARS(str);
c = *chars;
if (!JS_ISIDSTART(c))
return JS_FALSE;
end = chars + length;
while (++chars != end) {
c = *chars;
if (!JS_ISIDENT(c))
return JS_FALSE;
}
return JS_TRUE;
}
JSTokenStream *
js_NewTokenStream(JSContext *cx, const jschar *base, size_t length,
const char *filename, uintN lineno,

Просмотреть файл

@ -329,9 +329,6 @@ js_fgets(char *buf, int size, FILE *file);
extern JSTokenType
js_CheckKeyword(const jschar *chars, size_t length);
#define js_IsKeyword(chars, length) \
(js_CheckKeyword(chars, length) != TOK_EOF)
/*
* Friend-exported API entry point to call a mapping function on each reserved
* identifier in the scanner's keyword table.
@ -339,6 +336,13 @@ js_CheckKeyword(const jschar *chars, size_t length);
extern JS_FRIEND_API(void)
js_MapKeywords(void (*mapfun)(const char *));
/*
* Check that str forms a valid JS identifier name. The function does not
* check if str is a JS keyword.
*/
extern JSBool
js_IsIdentifier(JSString *str);
/*
* Report a compile-time error by its number, using ts or cg to show context.
* Return true for a warning, false for an error.