/[jscoverage]/trunk/instrument-js.c
ViewVC logotype

Diff of /trunk/instrument-js.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 155 by siliconforks, Mon Sep 1 20:30:28 2008 UTC revision 156 by siliconforks, Fri Sep 12 19:44:03 2008 UTC
# Line 154  Line 154 
154  };  };
155    
156  static void instrument_function(JSParseNode * node, Stream * f, int indent, enum FunctionType type) {  static void instrument_function(JSParseNode * node, Stream * f, int indent, enum FunctionType type) {
157      assert(node->pn_arity == PN_FUNC);    assert(node->pn_arity == PN_FUNC);
158      assert(ATOM_IS_OBJECT(node->pn_funAtom));    assert(ATOM_IS_OBJECT(node->pn_funAtom));
159      JSObject * object = ATOM_TO_OBJECT(node->pn_funAtom);    JSObject * object = ATOM_TO_OBJECT(node->pn_funAtom);
160      assert(JS_ObjectIsFunction(context, object));    assert(JS_ObjectIsFunction(context, object));
161      JSFunction * function = (JSFunction *) JS_GetPrivate(context, object);    JSFunction * function = (JSFunction *) JS_GetPrivate(context, object);
162      assert(function);    assert(function);
163      assert(object == function->object);    assert(object == function->object);
164      Stream_printf(f, "%*s", indent, "");    Stream_printf(f, "%*s", indent, "");
165      if (type == FUNCTION_NORMAL) {    if (type == FUNCTION_NORMAL) {
166        Stream_write_string(f, "function");      Stream_write_string(f, "function");
167      }
168    
169      /* function name */
170      if (function->atom) {
171        Stream_write_char(f, ' ');
172        print_string_atom(function->atom, f);
173      }
174    
175      /* function parameters */
176      Stream_write_string(f, "(");
177      JSAtom ** params = xnew(JSAtom *, function->nargs);
178      for (int i = 0; i < function->nargs; i++) {
179        /* initialize to NULL for sanity check */
180        params[i] = NULL;
181      }
182      JSScope * scope = OBJ_SCOPE(object);
183      for (JSScopeProperty * scope_property = SCOPE_LAST_PROP(scope); scope_property != NULL; scope_property = scope_property->parent) {
184        if (scope_property->getter != js_GetArgument) {
185          continue;
186      }      }
187        assert(scope_property->flags & SPROP_HAS_SHORTID);
188      /* function name */      assert((uint16) scope_property->shortid < function->nargs);
189      if (function->atom) {      assert(JSID_IS_ATOM(scope_property->id));
190        Stream_write_char(f, ' ');      params[(uint16) scope_property->shortid] = JSID_TO_ATOM(scope_property->id);
191        print_string_atom(function->atom, f);    }
192      }    for (int i = 0; i < function->nargs; i++) {
193        assert(params[i] != NULL);
194      /* function parameters */      if (i > 0) {
195      Stream_write_string(f, "(");        Stream_write_string(f, ", ");
     JSAtom ** params = xnew(JSAtom *, function->nargs);  
     for (int i = 0; i < function->nargs; i++) {  
       /* initialize to NULL for sanity check */  
       params[i] = NULL;  
     }  
     JSScope * scope = OBJ_SCOPE(object);  
     for (JSScopeProperty * scope_property = SCOPE_LAST_PROP(scope); scope_property != NULL; scope_property = scope_property->parent) {  
       if (scope_property->getter != js_GetArgument) {  
         continue;  
       }  
       assert(scope_property->flags & SPROP_HAS_SHORTID);  
       assert((uint16) scope_property->shortid < function->nargs);  
       assert(JSID_IS_ATOM(scope_property->id));  
       params[(uint16) scope_property->shortid] = JSID_TO_ATOM(scope_property->id);  
196      }      }
197      for (int i = 0; i < function->nargs; i++) {      if (ATOM_IS_STRING(params[i])) {
198        assert(params[i] != NULL);        print_string_atom(params[i], f);
       if (i > 0) {  
         Stream_write_string(f, ", ");  
       }  
       if (ATOM_IS_STRING(params[i])) {  
         print_string_atom(params[i], f);  
       }  
199      }      }
200      Stream_write_string(f, ") {\n");    }
201      free(params);    Stream_write_string(f, ") {\n");
202      free(params);
203    
204      /* function body */    /* function body */
205      instrument_statement(node->pn_body, f, indent + 2);    instrument_statement(node->pn_body, f, indent + 2);
206    
207      Stream_write_string(f, "}\n");    Stream_write_string(f, "}\n");
208  }  }
209    
210  static void instrument_function_call(JSParseNode * node, Stream * f) {  static void instrument_function_call(JSParseNode * node, Stream * f) {

Legend:
Removed from v.155  
changed lines
  Added in v.156

  ViewVC Help
Powered by ViewVC 1.1.24