Subj : Re: Compacting JS source via ParseTree or Decompile To : netscape.public.mozilla.jseng From : Dan Libby Date : Tue Jun 08 2004 10:44 pm Okay, I think I've got the loop for the getting the function arguments worked out using OBJ_SCOPE, etc. But I can't call it. I'm still clueless how to actually get the function objects in the first place. I feel I'm missing something obvious. :( Brendan Eich wrote: > > JS_Enumerate is for enumerable properties only. Also, until you execute > the script (or at least its prolog, see JS_ExecuteScriptPart), you won't > see any properties defined by it in the object you passed in as the obj > param when compiling it. > >> // Iterate through vars in function >> void shorten_function_vars(JSContext* cx, JSFunction* fun) { >> JSIdArray* ida = JS_Enumerate( cx, fun->object ); >> if( ida ) { >> jsval* val; >> int i; >> for(i = 0; i < ida->length; i++ ) { >> if( JS_TRUE == JS_GetElement(cx, fun->object, >> ida->vector[i], val) ) { >> JSType type = JS_TypeOfValue(cx, *val); > > > You don't really need the value -- you rather want to munge the id. > > And you will be using friend and (until we make more friend APIs) > private APIs to do this. So, you don't want JS_Enumerate, again. You > should instead loop from OBJ_SCOPE(fun->object)->lastProp following > parent links until null, testing for getter == js_GetLocalVariable || > getter == js_GetArgument. > >> Yes, arguments could/should be renamed (assuming JS only supports >> positional arguments). > > > Right, JS2 adds named parameter passing. Hmm. So how can I check if the script is JS2 or not? > > /be .