/[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 240 by siliconforks, Fri Oct 3 23:51:32 2008 UTC revision 246 by siliconforks, Sun Oct 5 18:05:42 2008 UTC
# Line 88  Line 88 
88    JS_DestroyRuntime(runtime);    JS_DestroyRuntime(runtime);
89  }  }
90    
91    static void print_javascript(const jschar * characters, size_t num_characters, Stream * f) {
92      for (size_t i = 0; i < num_characters; i++) {
93        jschar c = characters[i];
94        /*
95        XXX does not handle no-break space, other unicode "space separator"
96        */
97        switch (c) {
98        case 0x9:
99        case 0xB:
100        case 0xC:
101          Stream_write_char(f, c);
102          break;
103        default:
104          if (32 <= c && c <= 126) {
105            Stream_write_char(f, c);
106          }
107          else {
108            Stream_printf(f, "\\u%04x", c);
109          }
110          break;
111        }
112      }
113    }
114    
115  static void print_string(JSString * s, Stream * f) {  static void print_string(JSString * s, Stream * f) {
116    size_t length = JSSTRING_LENGTH(s);    size_t length = JSSTRING_LENGTH(s);
117    jschar * characters = JSSTRING_CHARS(s);    jschar * characters = JSSTRING_CHARS(s);
# Line 1090  Line 1114 
1114    /* conditionals */    /* conditionals */
1115    for (struct IfDirective * if_directive = if_directives; if_directive != NULL; if_directive = if_directive->next) {    for (struct IfDirective * if_directive = if_directives; if_directive != NULL; if_directive = if_directive->next) {
1116      Stream_write_string(output, "if (!(");      Stream_write_string(output, "if (!(");
1117      for (const jschar * p = if_directive->condition_start; p < if_directive->condition_end; p++) {      print_javascript(if_directive->condition_start, if_directive->condition_end - if_directive->condition_start, output);
       jschar c = *p;  
       if (c == '\t' || (32 <= c && c <= 126)) {  
         Stream_write_char(output, c);  
       }  
       else {  
         Stream_printf(output, "\\u%04x", c);  
       }  
     }  
1118      Stream_write_string(output, ")) {\n");      Stream_write_string(output, ")) {\n");
1119      Stream_printf(output, "  _$jscoverage['%s'].conditionals[%d] = %d;\n", file_id, if_directive->start_line, if_directive->end_line);      Stream_printf(output, "  _$jscoverage['%s'].conditionals[%d] = %d;\n", file_id, if_directive->start_line, if_directive->end_line);
1120      Stream_write_string(output, "}\n");      Stream_write_string(output, "}\n");
# Line 1456  Line 1472 
1472        file_coverage->id = id;        file_coverage->id = id;
1473        file_coverage->num_coverage_lines = array->pn_count;        file_coverage->num_coverage_lines = array->pn_count;
1474        file_coverage->coverage_lines = xnew(int, array->pn_count);        file_coverage->coverage_lines = xnew(int, array->pn_count);
1475        if (source == NULL) {        file_coverage->source_lines = NULL;
         file_coverage->source_lines = NULL;  
       }  
       else {  
         file_coverage->num_source_lines = source->pn_count;  
         file_coverage->source_lines = xnew(char *, source->pn_count);  
         uint32 i = 0;  
         for (JSParseNode * element = source->pn_head; element != NULL; element = element->pn_next, i++) {  
           if (element->pn_type != TOK_STRING) {  
             return -1;  
           }  
           file_coverage->source_lines[i] = xstrdup(JS_GetStringBytes(ATOM_TO_STRING(element->pn_atom)));  
         }  
         assert(i == source->pn_count);  
       }  
1476    
1477        /* set coverage for all lines */        /* set coverage for all lines */
1478        uint32 i = 0;        uint32 i = 0;
# Line 1520  Line 1522 
1522          }          }
1523        }        }
1524        assert(i == array->pn_count);        assert(i == array->pn_count);
1525        }
1526    
1527        /* if this JSON file has source, use it */      /* if this JSON file has source, use it */
1528        if (file_coverage->source_lines == NULL && source != NULL) {      if (file_coverage->source_lines == NULL && source != NULL) {
1529          file_coverage->num_source_lines = source->pn_count;        file_coverage->num_source_lines = source->pn_count;
1530          file_coverage->source_lines = xnew(char *, source->pn_count);        file_coverage->source_lines = xnew(char *, source->pn_count);
1531          uint32 i = 0;        uint32 i = 0;
1532          for (JSParseNode * element = source->pn_head; element != NULL; element = element->pn_next, i++) {        for (JSParseNode * element = source->pn_head; element != NULL; element = element->pn_next, i++) {
1533            if (element->pn_type != TOK_STRING) {          if (element->pn_type != TOK_STRING) {
1534              return -1;            return -1;
           }  
           file_coverage->source_lines[i] = xstrdup(JS_GetStringBytes(ATOM_TO_STRING(element->pn_atom)));  
1535          }          }
1536          assert(i == source->pn_count);          file_coverage->source_lines[i] = xstrdup(JS_GetStringBytes(ATOM_TO_STRING(element->pn_atom)));
1537        }        }
1538          assert(i == source->pn_count);
1539      }      }
1540    }    }
1541    

Legend:
Removed from v.240  
changed lines
  Added in v.246

  ViewVC Help
Powered by ViewVC 1.1.24