From 25c1c4801f94e6a52c3340c9882fcccbbfb28fc9 Mon Sep 17 00:00:00 2001 From: norris Date: Fri, 12 Jun 1998 17:22:04 +0000 Subject: [PATCH] (Not part of Communicator build.) Fix 111199 ECMA: don't enumerate parseInt.length --- js/ref/jsfun.c | 35 ++++++++++++++++++++++++++++++++++- js/ref/jsobj.c | 23 ++++++++++++++--------- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/js/ref/jsfun.c b/js/ref/jsfun.c index acf3b8328618..92dbaf745d1f 100644 --- a/js/ref/jsfun.c +++ b/js/ref/jsfun.c @@ -809,6 +809,39 @@ fun_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) return JS_TRUE; } + +static JSBool +fun_enumProperty(JSContext *cx, JSObject *obj) +{ + JSScope *scope; + JSScopeProperty *sprop; + + /* Because properties of function objects such as "length" are + * not defined in function_props to avoid interfering with + * unqualified lookups in local scopes (which pass through the + * function object as a stand-in for the call object), we + * must twiddle any of the special properties not to be enumer- + * ated in this callback, rather than simply predefining the + * properties without JSPROP_ENUMERATE. + */ + + JS_LOCK_OBJ(cx, obj); + scope = (JSScope *) obj->map; + for (sprop = scope->props; sprop; sprop = sprop->next) { + jsval id = sprop->id; + if (!JSVAL_IS_INT(id)) { + if (id == ATOM_KEY(cx->runtime->atomState.arityAtom) || + id == ATOM_KEY(cx->runtime->atomState.lengthAtom) || + id == ATOM_KEY(cx->runtime->atomState.callerAtom) || + id == ATOM_KEY(cx->runtime->atomState.nameAtom)) + { + sprop->attrs &= ~JSPROP_ENUMERATE; + } + } + } + return JS_TRUE; +} + static JSBool fun_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { @@ -1121,7 +1154,7 @@ JSClass js_FunctionClass = { JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE, JS_PropertyStub, fun_delProperty, fun_getProperty, fun_setProperty, - JS_EnumerateStub, (JSResolveOp)fun_resolve, + fun_enumProperty, (JSResolveOp)fun_resolve, fun_convert, fun_finalize, NULL, NULL, NULL, NULL, diff --git a/js/ref/jsobj.c b/js/ref/jsobj.c index 11568b094982..8462881272f3 100644 --- a/js/ref/jsobj.c +++ b/js/ref/jsobj.c @@ -2453,18 +2453,18 @@ out: #ifdef DEBUG -void printId(jsid id) { +/* Routines to print out values during debugging. */ + +void printVal(jsval val) { jsuint i; - JSAtom *atom; JSString *str; - fprintf(stderr, "id %d (0x%x) = ", id, id); - if (JSVAL_IS_INT(id)) { - fprintf(stderr, "%d\n", JSVAL_TO_INT(id)); - } else { - atom = (JSAtom *)id; - str = ATOM_TO_STRING(atom); - fputc('"', stderr); + fprintf(stderr, "val %d (0x%x) = ", val, val); + if (JSVAL_IS_INT(val)) { + fprintf(stderr, "(int) %d\n", JSVAL_TO_INT(val)); + } else if (JSVAL_IS_STRING(val)) { + fprintf(stderr, "(string) \""); + str = JSVAL_TO_STRING(val); for (i=0; i < str->length; i++) fputc(str->chars[i], stderr); fputc('"', stderr); @@ -2473,5 +2473,10 @@ void printId(jsid id) { fflush(stderr); } +void printId(jsid id) { + fprintf(stderr, "id %d (0x%x) is ", id, id); + printVal(js_IdToValue(id)); +} + #endif