From 1b196ec47feeada2e92a661a2f2659e0df3ecef0 Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Tue, 10 Apr 2001 01:10:28 +0000 Subject: [PATCH] Fix Function.prototype.to{Source,String} to parenthesize function objects that were expressed rather than declared (73760, r=rogerl, sr=shaver). --- js/src/js.c | 1 + js/src/jsapi.h | 3 ++- js/src/jsfun.c | 2 +- js/src/jsopcode.c | 4 ++++ js/src/jsparse.c | 5 +++-- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/js/src/js.c b/js/src/js.c index b6986396a3f..7a1360f2d39 100644 --- a/js/src/js.c +++ b/js/src/js.c @@ -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); diff --git a/js/src/jsapi.h b/js/src/jsapi.h index e4d6c21692f..6a72309e6e1 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -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 diff --git a/js/src/jsfun.c b/js/src/jsfun.c index 2cfba3fd740..18140b29b53 100644 --- a/js/src/jsfun.c +++ b/js/src/jsfun.c @@ -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); diff --git a/js/src/jsopcode.c b/js/src/jsopcode.c index 9853c57bd84..c1d17a34380 100644 --- a/js/src/jsopcode.c +++ b/js/src/jsopcode.c @@ -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; diff --git a/js/src/jsparse.c b/js/src/jsparse.c index 67056b6d921..96fa159c2ab 100644 --- a/js/src/jsparse.c +++ b/js/src/jsparse.c @@ -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; }