Add -o <option> to shell; add JSOPTION_ANONFUNFIX and test it for ECMA conformance (376052, r=igor).

This commit is contained in:
brendan%mozilla.org 2007-04-07 01:20:28 +00:00
Родитель efd917b8cc
Коммит 9306c0f164
3 изменённых файлов: 34 добавлений и 13 удалений

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

@ -285,7 +285,7 @@ static int
usage(void)
{
fprintf(gErrFile, "%s\n", JS_GetImplementationVersion());
fprintf(gErrFile, "usage: js [-PswWxCi] [-b branchlimit] [-c stackchunksize] [-v version] [-f scriptfile] [-e script] [-S maxstacksize] [scriptfile] [scriptarg...]\n");
fprintf(gErrFile, "usage: js [-PswWxCi] [-b branchlimit] [-c stackchunksize] [-o option] [-v version] [-f scriptfile] [-e script] [-S maxstacksize] [scriptfile] [scriptarg...]\n");
return 2;
}
@ -313,6 +313,19 @@ my_BranchCallback(JSContext *cx, JSScript *script)
return JS_TRUE;
}
static struct {
const char *name;
uint32 flag;
} js_options[] = {
{"strict", JSOPTION_STRICT},
{"werror", JSOPTION_WERROR},
{"atline", JSOPTION_ATLINE},
{"xml", JSOPTION_XML},
{"relimit", JSOPTION_RELIMIT},
{"anonfunfix", JSOPTION_ANONFUNFIX},
{NULL, 0}
};
extern JSClass global_class;
static int
@ -406,6 +419,18 @@ ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc)
JS_ToggleOptions(cx, JSOPTION_XML);
break;
case 'o':
if (++i == argc)
return usage();
for (j = 0; js_options[j].name; ++j) {
if (strcmp(js_options[j].name, argv[i]) == 0) {
JS_ToggleOptions(cx, js_options[j].flag);
break;
}
}
break;
case 'P':
if (JS_GET_CLASS(cx, JS_GetPrototype(cx, obj)) != &global_class) {
JSObject *gobj;
@ -505,18 +530,6 @@ Version(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return JS_TRUE;
}
static struct {
const char *name;
uint32 flag;
} js_options[] = {
{"strict", JSOPTION_STRICT},
{"werror", JSOPTION_WERROR},
{"atline", JSOPTION_ATLINE},
{"xml", JSOPTION_XML},
{"relimit", JSOPTION_RELIMIT },
{0, 0}
};
static JSBool
Options(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{

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

@ -573,6 +573,9 @@ JS_StringToVersion(const char *string);
backtracks more than n^3
times, where n is length
of the input string */
#define JSOPTION_ANONFUNFIX JS_BIT(10) /* Disallow function () {} in
statement context per
ECMA-262 Edition 3. */
extern JS_PUBLIC_API(uint32)
JS_GetOptions(JSContext *cx);

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

@ -1074,6 +1074,11 @@ FunctionDef(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc,
if (tt == TOK_NAME) {
funAtom = CURRENT_TOKEN(ts).t_atom;
} else {
if (!lambda && (cx->options & JSOPTION_ANONFUNFIX)) {
js_ReportCompileErrorNumber(cx, ts, JSREPORT_TS | JSREPORT_ERROR,
JSMSG_SYNTAX_ERROR);
return NULL;
}
funAtom = NULL;
js_UngetToken(ts);
}