Subj : Re: BUG :( Re: Compacting JS source via ParseTree or Decompile To : Dan Libby From : Brendan Eich Date : Thu Jun 10 2004 04:26 pm Dan Libby wrote: > Thus, it appears to me that internally these two local variables are > really the same object. When I change the id atom for the var in the > latter func, it also gets updated in the former. That says you are changing the atom itself, which is a bug. > QUESTION: > I think that to fix this correctly, I need a way to determine if a given > local variable is referencing a global variable. No, you shouldn't need to do any such thing. We're concerned only with identifier usage in static source, not with expression evaluation, or specifically assignments to lvalues at runtime. > void shorten_function_vars(work_plan* wp, JSContext* cx, JSFunction* fun) { > JSScopeProperty* sp = OBJ_SCOPE(fun->object)->lastProp; > #define NAME_LEN 6 > char var_name[NAME_LEN] = {0}; > > while( sp ) { > if( ( !wp->localvarsoff && sp->getter == js_GetLocalVariable) || > ( !wp->argvarsoff && sp->getter == js_GetArgument) ) { > jsid idval = ID_TO_VALUE(sp->id); > JSString* idstr = js_ValueToString(cx, idval); You don't use idstr -- are you showing all the code? Really need to see all your code to help.... /be > > // increment variable name, eg: 'a', 'b', .. 'z', 'aa' > inc_name(var_name, NAME_LEN); > JSAtom* atom = js_Atomize(cx, var_name, strlen(var_name), 0); > sp->id = (jsid)atom; > } > sp = sp->parent; > } > } .