Fix Function.prototype.to{Source,String} to parenthesize function objects that were expressed rather than declared (73760, r=rogerl, sr=shaver).

This commit is contained in:
brendan%mozilla.org 2001-04-10 01:10:28 +00:00
Родитель d66f23edc0
Коммит 1b196ec47f
5 изменённых файлов: 11 добавлений и 4 удалений

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

@ -998,6 +998,7 @@ Disassemble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
#define SHOW_FLAG(flag) if (flags & JSFUN_##flag) fputs(" " #flag, stdout);
SHOW_FLAG(LAMBDA);
SHOW_FLAG(SETTER);
SHOW_FLAG(GETTER);
SHOW_FLAG(BOUND_METHOD);

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

@ -121,11 +121,12 @@ JS_BEGIN_EXTERN_C
#define JSPROP_INDEX 0x80 /* name is actually (jsint) index */
/* Function flags, set in JSFunctionSpec and passed to JS_NewFunction etc. */
#define JSFUN_LAMBDA 0x08 /* expressed, not declared, function */
#define JSFUN_GETTER JSPROP_GETTER
#define JSFUN_SETTER JSPROP_SETTER
#define JSFUN_BOUND_METHOD 0x40 /* bind this to fun->object's parent */
#define JSFUN_HEAVYWEIGHT 0x80 /* activation requires a Call object */
#define JSFUN_FLAGS_MASK 0xf0 /* overlay JSFUN_* attributes */
#define JSFUN_FLAGS_MASK 0xf8 /* overlay JSFUN_* attributes */
/*
* Well-known JS values. The extern'd variables are initialized when the

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

@ -1419,7 +1419,7 @@ Function(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
parent = NULL;
#endif
fun = js_NewFunction(cx, obj, NULL, 0, 0, parent,
fun = js_NewFunction(cx, obj, NULL, 0, JSFUN_LAMBDA, parent,
(JSVERSION_IS_ECMA(cx->version))
? cx->runtime->atomState.anonymousAtom
: NULL);

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

@ -2268,6 +2268,8 @@ js_DecompileFunction(JSPrinter *jp, JSFunction *fun)
js_puts(jp, "\n");
js_printf(jp, "\t");
}
if (fun->flags & JSFUN_LAMBDA)
js_puts(jp, "(");
if (fun->flags & JSFUN_GETTER)
js_printf(jp, "%s ", js_getter_str);
else if (fun->flags & JSFUN_SETTER)
@ -2326,6 +2328,8 @@ js_DecompileFunction(JSPrinter *jp, JSFunction *fun)
}
jp->indent -= 4;
js_printf(jp, "\t}");
if (fun->flags & JSFUN_LAMBDA)
js_puts(jp, ")");
if (jp->pretty)
js_puts(jp, "\n");
return JS_TRUE;

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

@ -637,7 +637,8 @@ FunctionDef(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc,
/* Find the nearest variable-declaring scope and use it as our parent. */
parent = cx->fp->varobj;
fun = js_NewFunction(cx, NULL, NULL, 0, 0, parent, funAtom);
fun = js_NewFunction(cx, NULL, NULL, 0, lambda ? JSFUN_LAMBDA : 0, parent,
funAtom);
if (!fun)
return NULL;
@ -2792,7 +2793,7 @@ PrimaryExpr(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc)
/* We have to fake a 'function' token here. */
CURRENT_TOKEN(ts).t_op = JSOP_NOP;
CURRENT_TOKEN(ts).type = TOK_FUNCTION;
pn2 = FunctionDef(cx, ts, tc, JS_TRUE);
pn2 = FunctionExpr(cx, ts, tc);
pn2 = NewBinary(cx, TOK_COLON, op, pn3, pn2, tc);
goto skip;
}