/[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 179 by siliconforks, Sun Sep 21 18:35:21 2008 UTC revision 293 by siliconforks, Sun Oct 12 16:41:57 2008 UTC
# Line 27  Line 27 
27    
28  #include <jsapi.h>  #include <jsapi.h>
29  #include <jsatom.h>  #include <jsatom.h>
30    #include <jsexn.h>
31  #include <jsfun.h>  #include <jsfun.h>
32  #include <jsinterp.h>  #include <jsinterp.h>
33  #include <jsparse.h>  #include <jsparse.h>
# Line 40  Line 41 
41  #include "resource-manager.h"  #include "resource-manager.h"
42  #include "util.h"  #include "util.h"
43    
44    struct IfDirective {
45      const jschar * condition_start;
46      const jschar * condition_end;
47      uint16_t start_line;
48      uint16_t end_line;
49      struct IfDirective * next;
50    };
51    
52    static bool * exclusive_directives = NULL;
53    
54  static JSRuntime * runtime = NULL;  static JSRuntime * runtime = NULL;
55  static JSContext * context = NULL;  static JSContext * context = NULL;
56  static JSObject * global = NULL;  static JSObject * global = NULL;
# Line 50  Line 61 
61  */  */
62  static const char * file_id = NULL;  static const char * file_id = NULL;
63  static char * lines = NULL;  static char * lines = NULL;
64    static uint16_t num_lines = 0;
65    
66  void jscoverage_init(void) {  void jscoverage_init(void) {
67    runtime = JS_NewRuntime(8L * 1024L * 1024L);    runtime = JS_NewRuntime(8L * 1024L * 1024L);
# Line 77  Line 89 
89    JS_DestroyRuntime(runtime);    JS_DestroyRuntime(runtime);
90  }  }
91    
92    static void print_javascript(const jschar * characters, size_t num_characters, Stream * f) {
93      for (size_t i = 0; i < num_characters; i++) {
94        jschar c = characters[i];
95        /*
96        XXX does not handle no-break space, other unicode "space separator"
97        */
98        switch (c) {
99        case 0x9:
100        case 0xB:
101        case 0xC:
102          Stream_write_char(f, c);
103          break;
104        default:
105          if (32 <= c && c <= 126) {
106            Stream_write_char(f, c);
107          }
108          else {
109            Stream_printf(f, "\\u%04x", c);
110          }
111          break;
112        }
113      }
114    }
115    
116  static void print_string(JSString * s, Stream * f) {  static void print_string(JSString * s, Stream * f) {
117    size_t length = JSSTRING_LENGTH(s);    size_t length = JSSTRING_LENGTH(s);
118    jschar * characters = JSSTRING_CHARS(s);    jschar * characters = JSSTRING_CHARS(s);
# Line 204  Line 240 
240  }  }
241    
242  static void instrument_expression(JSParseNode * node, Stream * f);  static void instrument_expression(JSParseNode * node, Stream * f);
243  static void instrument_statement(JSParseNode * node, Stream * f, int indent);  static void instrument_statement(JSParseNode * node, Stream * f, int indent, bool is_jscoverage_if);
244    
245  enum FunctionType {  enum FunctionType {
246    FUNCTION_NORMAL,    FUNCTION_NORMAL,
# Line 260  Line 296 
296    free(params);    free(params);
297    
298    /* function body */    /* function body */
299    instrument_statement(node->pn_body, f, indent + 2);    instrument_statement(node->pn_body, f, indent + 2, false);
300    
301    Stream_write_string(f, "}\n");    Stream_write_string(f, "}\n");
302  }  }
# Line 504  Line 540 
540        /* check whether this is a getter or setter */        /* check whether this is a getter or setter */
541        switch (p->pn_op) {        switch (p->pn_op) {
542        case JSOP_GETTER:        case JSOP_GETTER:
         Stream_write_string(f, "get ");  
         instrument_expression(p->pn_left, f);  
         instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);  
         break;  
543        case JSOP_SETTER:        case JSOP_SETTER:
544          Stream_write_string(f, "set ");          if (p->pn_op == JSOP_GETTER) {
545              Stream_write_string(f, "get ");
546            }
547            else {
548              Stream_write_string(f, "set ");
549            }
550          instrument_expression(p->pn_left, f);          instrument_expression(p->pn_left, f);
551            if (p->pn_right->pn_type != TOK_FUNCTION) {
552              fatal("parse error: expected function");
553            }
554          instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);          instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);
555          break;          break;
556        default:        default:
# Line 619  Line 659 
659    }    }
660  }  }
661    
662  static void output_statement(JSParseNode * node, Stream * f, int indent) {  static void output_statement(JSParseNode * node, Stream * f, int indent, bool is_jscoverage_if) {
663    switch (node->pn_type) {    switch (node->pn_type) {
664    case TOK_FUNCTION:    case TOK_FUNCTION:
665      instrument_function(node, f, indent, FUNCTION_NORMAL);      instrument_function(node, f, indent, FUNCTION_NORMAL);
# Line 630  Line 670 
670      Stream_write_string(f, "{\n");      Stream_write_string(f, "{\n");
671  */  */
672      for (struct JSParseNode * p = node->pn_u.list.head; p != NULL; p = p->pn_next) {      for (struct JSParseNode * p = node->pn_u.list.head; p != NULL; p = p->pn_next) {
673        instrument_statement(p, f, indent);        instrument_statement(p, f, indent, false);
674      }      }
675  /*  /*
676      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
# Line 638  Line 678 
678  */  */
679      break;      break;
680    case TOK_IF:    case TOK_IF:
681      {
682      assert(node->pn_arity == PN_TERNARY);      assert(node->pn_arity == PN_TERNARY);
683    
684        uint16_t line = node->pn_pos.begin.lineno;
685        if (! is_jscoverage_if) {
686          if (line > num_lines) {
687            fatal("%s: script contains more than 65,535 lines", file_id);
688          }
689          if (line >= 2 && exclusive_directives[line - 2]) {
690            is_jscoverage_if = true;
691          }
692        }
693    
694      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
695      Stream_write_string(f, "if (");      Stream_write_string(f, "if (");
696      instrument_expression(node->pn_kid1, f);      instrument_expression(node->pn_kid1, f);
697      Stream_write_string(f, ") {\n");      Stream_write_string(f, ") {\n");
698      instrument_statement(node->pn_kid2, f, indent + 2);      if (is_jscoverage_if && node->pn_kid3) {
699          uint16_t else_start = node->pn_kid3->pn_pos.begin.lineno;
700          uint16_t else_end = node->pn_kid3->pn_pos.end.lineno + 1;
701          Stream_printf(f, "%*s", indent + 2, "");
702          Stream_printf(f, "_$jscoverage['%s'].conditionals[%d] = %d;\n", file_id, else_start, else_end);
703        }
704        instrument_statement(node->pn_kid2, f, indent + 2, false);
705      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
706      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
707      if (node->pn_kid3) {  
708        if (node->pn_kid3 || is_jscoverage_if) {
709        Stream_printf(f, "%*s", indent, "");        Stream_printf(f, "%*s", indent, "");
710        Stream_write_string(f, "else {\n");        Stream_write_string(f, "else {\n");
711        instrument_statement(node->pn_kid3, f, indent + 2);  
712          if (is_jscoverage_if) {
713            uint16_t if_start = node->pn_kid2->pn_pos.begin.lineno + 1;
714            uint16_t if_end = node->pn_kid2->pn_pos.end.lineno + 1;
715            Stream_printf(f, "%*s", indent + 2, "");
716            Stream_printf(f, "_$jscoverage['%s'].conditionals[%d] = %d;\n", file_id, if_start, if_end);
717          }
718    
719          if (node->pn_kid3) {
720            instrument_statement(node->pn_kid3, f, indent + 2, is_jscoverage_if);
721          }
722    
723        Stream_printf(f, "%*s", indent, "");        Stream_printf(f, "%*s", indent, "");
724        Stream_write_string(f, "}\n");        Stream_write_string(f, "}\n");
725      }      }
726    
727      break;      break;
728      }
729    case TOK_SWITCH:    case TOK_SWITCH:
730      assert(node->pn_arity == PN_BINARY);      assert(node->pn_arity == PN_BINARY);
731      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
# Line 675  Line 747 
747          abort();          abort();
748          break;          break;
749        }        }
750        instrument_statement(p->pn_right, f, indent + 2);        instrument_statement(p->pn_right, f, indent + 2, false);
751      }      }
752      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
753      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
# Line 690  Line 762 
762      Stream_write_string(f, "while (");      Stream_write_string(f, "while (");
763      instrument_expression(node->pn_left, f);      instrument_expression(node->pn_left, f);
764      Stream_write_string(f, ") {\n");      Stream_write_string(f, ") {\n");
765      instrument_statement(node->pn_right, f, indent + 2);      instrument_statement(node->pn_right, f, indent + 2, false);
766      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
767      break;      break;
768    case TOK_DO:    case TOK_DO:
769      assert(node->pn_arity == PN_BINARY);      assert(node->pn_arity == PN_BINARY);
770      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
771      Stream_write_string(f, "do {\n");      Stream_write_string(f, "do {\n");
772      instrument_statement(node->pn_left, f, indent + 2);      instrument_statement(node->pn_left, f, indent + 2, false);
773      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
774      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
775      Stream_write_string(f, "while (");      Stream_write_string(f, "while (");
# Line 760  Line 832 
832        break;        break;
833      }      }
834      Stream_write_string(f, ") {\n");      Stream_write_string(f, ") {\n");
835      instrument_statement(node->pn_right, f, indent + 2);      instrument_statement(node->pn_right, f, indent + 2, false);
836      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
837      break;      break;
838    case TOK_THROW:    case TOK_THROW:
# Line 773  Line 845 
845    case TOK_TRY:    case TOK_TRY:
846      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
847      Stream_write_string(f, "try {\n");      Stream_write_string(f, "try {\n");
848      instrument_statement(node->pn_kid1, f, indent + 2);      instrument_statement(node->pn_kid1, f, indent + 2, false);
849      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
850      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
851      {      {
# Line 788  Line 860 
860            instrument_expression(catch->pn_kid1->pn_expr, f);            instrument_expression(catch->pn_kid1->pn_expr, f);
861          }          }
862          Stream_write_string(f, ") {\n");          Stream_write_string(f, ") {\n");
863          instrument_statement(catch->pn_kid3, f, indent + 2);          instrument_statement(catch->pn_kid3, f, indent + 2, false);
864          Stream_printf(f, "%*s", indent, "");          Stream_printf(f, "%*s", indent, "");
865          Stream_write_string(f, "}\n");          Stream_write_string(f, "}\n");
866        }        }
# Line 796  Line 868 
868      if (node->pn_kid3) {      if (node->pn_kid3) {
869        Stream_printf(f, "%*s", indent, "");        Stream_printf(f, "%*s", indent, "");
870        Stream_write_string(f, "finally {\n");        Stream_write_string(f, "finally {\n");
871        instrument_statement(node->pn_kid3, f, indent + 2);        instrument_statement(node->pn_kid3, f, indent + 2, false);
872        Stream_printf(f, "%*s", indent, "");        Stream_printf(f, "%*s", indent, "");
873        Stream_write_string(f, "}\n");        Stream_write_string(f, "}\n");
874      }      }
# Line 822  Line 894 
894      Stream_write_string(f, "with (");      Stream_write_string(f, "with (");
895      instrument_expression(node->pn_left, f);      instrument_expression(node->pn_left, f);
896      Stream_write_string(f, ") {\n");      Stream_write_string(f, ") {\n");
897      instrument_statement(node->pn_right, f, indent + 2);      instrument_statement(node->pn_right, f, indent + 2, false);
898      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
899      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
900      break;      break;
# Line 860  Line 932 
932      /*      /*
933      ... use output_statement instead of instrument_statement.      ... use output_statement instead of instrument_statement.
934      */      */
935      output_statement(node->pn_expr, f, indent);      output_statement(node->pn_expr, f, indent, false);
936      break;      break;
937    default:    default:
938      fatal("unsupported node type in file %s: %d", file_id, node->pn_type);      fatal("unsupported node type in file %s: %d", file_id, node->pn_type);
# Line 872  Line 944 
944  TOK_FUNCTION is handled as a statement and as an expression.  TOK_FUNCTION is handled as a statement and as an expression.
945  TOK_EXPORT, TOK_IMPORT are not handled.  TOK_EXPORT, TOK_IMPORT are not handled.
946  */  */
947  static void instrument_statement(JSParseNode * node, Stream * f, int indent) {  static void instrument_statement(JSParseNode * node, Stream * f, int indent, bool is_jscoverage_if) {
948    if (node->pn_type != TOK_LC) {    if (node->pn_type != TOK_LC) {
949      int line = node->pn_pos.begin.lineno;      uint16_t line = node->pn_pos.begin.lineno;
950        if (line > num_lines) {
951          fatal("%s: script contains more than 65,535 lines", file_id);
952        }
953    
954      /* the root node has line number 0 */      /* the root node has line number 0 */
955      if (line != 0) {      if (line != 0) {
956        Stream_printf(f, "%*s", indent, "");        Stream_printf(f, "%*s", indent, "");
# Line 882  Line 958 
958        lines[line - 1] = 1;        lines[line - 1] = 1;
959      }      }
960    }    }
961    output_statement(node, f, indent);    output_statement(node, f, indent, is_jscoverage_if);
962    }
963    
964    static bool characters_start_with(const jschar * characters, size_t line_start, size_t line_end, const char * prefix) {
965      const jschar * characters_end = characters + line_end;
966      const jschar * cp = characters + line_start;
967      const char * bp = prefix;
968      for (;;) {
969        if (*bp == '\0') {
970          return true;
971        }
972        else if (cp == characters_end) {
973          return false;
974        }
975        else if (*cp != *bp) {
976          return false;
977        }
978        bp++;
979        cp++;
980      }
981    }
982    
983    static bool characters_are_white_space(const jschar * characters, size_t line_start, size_t line_end) {
984      /* XXX - other Unicode space */
985      const jschar * end = characters + line_end;
986      for (const jschar * p = characters + line_start; p < end; p++) {
987        jschar c = *p;
988        if (c == 0x9 || c == 0xB || c == 0xC || c == 0x20 || c == 0xA0) {
989          continue;
990        }
991        else {
992          return false;
993        }
994      }
995      return true;
996    }
997    
998    static void error_reporter(JSContext * context, const char * message, JSErrorReport * report) {
999      fprintf(stderr, "jscoverage: parse error: line %u: %s\n", report->lineno, message);
1000  }  }
1001    
1002  void jscoverage_instrument_js(const char * id, const uint16_t * characters, size_t num_characters, Stream * output) {  void jscoverage_instrument_js(const char * id, const uint16_t * characters, size_t num_characters, Stream * output) {
# Line 895  Line 1009 
1009    }    }
1010    
1011    /* parse the javascript */    /* parse the javascript */
1012      JSErrorReporter old_error_reporter = JS_SetErrorReporter(context, error_reporter);
1013    JSParseNode * node = js_ParseTokenStream(context, global, token_stream);    JSParseNode * node = js_ParseTokenStream(context, global, token_stream);
1014    if (node == NULL) {    if (node == NULL) {
1015        js_ReportUncaughtException(context);
1016      fatal("parse error in file: %s", file_id);      fatal("parse error in file: %s", file_id);
1017    }    }
1018    int num_lines = node->pn_pos.end.lineno;    JS_SetErrorReporter(context, old_error_reporter);
1019      num_lines = node->pn_pos.end.lineno;
1020    lines = xmalloc(num_lines);    lines = xmalloc(num_lines);
1021    for (int i = 0; i < num_lines; i++) {    for (unsigned int i = 0; i < num_lines; i++) {
1022      lines[i] = 0;      lines[i] = 0;
1023    }    }
1024    
1025      /* search code for conditionals */
1026      exclusive_directives = xnew(bool, num_lines);
1027      for (unsigned int i = 0; i < num_lines; i++) {
1028        exclusive_directives[i] = false;
1029      }
1030    
1031      bool has_conditionals = false;
1032      struct IfDirective * if_directives = NULL;
1033      size_t line_number = 0;
1034      size_t i = 0;
1035      while (i < num_characters) {
1036        if (line_number == UINT16_MAX) {
1037          fatal("%s: script has more than 65,535 lines", file_id);
1038        }
1039        line_number++;
1040        size_t line_start = i;
1041        jschar c;
1042        bool done = false;
1043        while (! done && i < num_characters) {
1044          c = characters[i];
1045          switch (c) {
1046          case '\r':
1047          case '\n':
1048          case 0x2028:
1049          case 0x2029:
1050            done = true;
1051            break;
1052          default:
1053            i++;
1054          }
1055        }
1056        size_t line_end = i;
1057        if (i < num_characters) {
1058          i++;
1059          if (c == '\r' && i < num_characters && characters[i] == '\n') {
1060            i++;
1061          }
1062        }
1063    
1064        if (characters_start_with(characters, line_start, line_end, "//#JSCOVERAGE_IF")) {
1065          has_conditionals = true;
1066    
1067          if (characters_are_white_space(characters, line_start + 16, line_end)) {
1068            exclusive_directives[line_number - 1] = true;
1069          }
1070          else {
1071            struct IfDirective * if_directive = xnew(struct IfDirective, 1);
1072            if_directive->condition_start = characters + line_start + 16;
1073            if_directive->condition_end = characters + line_end;
1074            if_directive->start_line = line_number;
1075            if_directive->end_line = 0;
1076            if_directive->next = if_directives;
1077            if_directives = if_directive;
1078          }
1079        }
1080        else if (characters_start_with(characters, line_start, line_end, "//#JSCOVERAGE_ENDIF")) {
1081          for (struct IfDirective * p = if_directives; p != NULL; p = p->next) {
1082            if (p->end_line == 0) {
1083              p->end_line = line_number;
1084              break;
1085            }
1086          }
1087        }
1088      }
1089    
1090    /*    /*
1091    An instrumented JavaScript file has 3 sections:    An instrumented JavaScript file has 4 sections:
1092    1. initialization    1. initialization
1093    2. instrumented source code    2. instrumented source code
1094    3. original source code    3. conditionals
1095      4. original source code
1096    */    */
1097    
1098    Stream * instrumented = Stream_new(0);    Stream * instrumented = Stream_new(0);
1099    instrument_statement(node, instrumented, 0);    instrument_statement(node, instrumented, 0, false);
1100    
1101    /* write line number info to the output */    /* write line number info to the output */
1102    Stream_write_string(output, "/* automatically generated by JSCoverage - do not edit */\n");    Stream_write_string(output, "/* automatically generated by JSCoverage - do not edit */\n");
# Line 929  Line 1112 
1112    Stream_write_string(output, "}\n");    Stream_write_string(output, "}\n");
1113    free(lines);    free(lines);
1114    lines = NULL;    lines = NULL;
1115      free(exclusive_directives);
1116      exclusive_directives = NULL;
1117    
1118      /* conditionals */
1119      if (has_conditionals) {
1120        Stream_printf(output, "_$jscoverage['%s'].conditionals = [];\n", file_id);
1121      }
1122    
1123    /* copy the instrumented source code to the output */    /* copy the instrumented source code to the output */
1124    Stream_write(output, instrumented->data, instrumented->length);    Stream_write(output, instrumented->data, instrumented->length);
1125    
1126    /* conditionals */    /* conditionals */
1127    bool has_conditionals = false;    for (struct IfDirective * if_directive = if_directives; if_directive != NULL; if_directive = if_directive->next) {
1128    size_t line_number = 0;      Stream_write_string(output, "if (!(");
1129    size_t i = 0;      print_javascript(if_directive->condition_start, if_directive->condition_end - if_directive->condition_start, output);
1130    while (i < num_characters) {      Stream_write_string(output, ")) {\n");
1131      line_number++;      Stream_printf(output, "  _$jscoverage['%s'].conditionals[%d] = %d;\n", file_id, if_directive->start_line, if_directive->end_line);
1132      size_t line_start = i;      Stream_write_string(output, "}\n");
1133      /* FIXME */    }
1134      while (i < num_characters && characters[i] != '\r' && characters[i] != '\n') {  
1135        i++;    /* free */
1136      }    while (if_directives != NULL) {
1137      size_t line_end = i;      struct IfDirective * if_directive = if_directives;
1138      if (i < num_characters) {      if_directives = if_directives->next;
1139        if (characters[i] == '\r') {      free(if_directive);
         line_end = i;  
         i++;  
         if (i < num_characters && characters[i] == '\n') {  
           i++;  
         }  
       }  
       else if (characters[i] == '\n') {  
         line_end = i;  
         i++;  
       }  
       else {  
         abort();  
       }  
     }  
     char * line = js_DeflateString(context, characters + line_start, line_end - line_start);  
     if (str_starts_with(line, "//#JSCOVERAGE_IF")) {  
       if (! has_conditionals) {  
         has_conditionals = true;  
         Stream_printf(output, "_$jscoverage['%s'].conditionals = [];\n", file_id);  
       }  
       Stream_printf(output, "if (!%s) {\n", line + 16);  
       Stream_printf(output, "  _$jscoverage['%s'].conditionals[%d] = ", file_id, line_number);  
     }  
     else if (str_starts_with(line, "//#JSCOVERAGE_ENDIF")) {  
       Stream_printf(output, "%d;\n", line_number);  
       Stream_printf(output, "}\n");  
     }  
     JS_free(context, line);  
1140    }    }
1141    
1142    /* copy the original source to the output */    /* copy the original source to the output */
# Line 1322  Line 1484 
1484        file_coverage->id = id;        file_coverage->id = id;
1485        file_coverage->num_coverage_lines = array->pn_count;        file_coverage->num_coverage_lines = array->pn_count;
1486        file_coverage->coverage_lines = xnew(int, array->pn_count);        file_coverage->coverage_lines = xnew(int, array->pn_count);
1487        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);  
       }  
1488    
1489        /* set coverage for all lines */        /* set coverage for all lines */
1490        uint32 i = 0;        uint32 i = 0;
# Line 1386  Line 1534 
1534          }          }
1535        }        }
1536        assert(i == array->pn_count);        assert(i == array->pn_count);
1537        }
1538    
1539        /* if this JSON file has source, use it */      /* if this JSON file has source, use it */
1540        if (file_coverage->source_lines == NULL && source != NULL) {      if (file_coverage->source_lines == NULL && source != NULL) {
1541          file_coverage->num_source_lines = source->pn_count;        file_coverage->num_source_lines = source->pn_count;
1542          file_coverage->source_lines = xnew(char *, source->pn_count);        file_coverage->source_lines = xnew(char *, source->pn_count);
1543          uint32 i = 0;        uint32 i = 0;
1544          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++) {
1545            if (element->pn_type != TOK_STRING) {          if (element->pn_type != TOK_STRING) {
1546              return -1;            return -1;
           }  
           file_coverage->source_lines[i] = xstrdup(JS_GetStringBytes(ATOM_TO_STRING(element->pn_atom)));  
1547          }          }
1548          assert(i == source->pn_count);          file_coverage->source_lines[i] = xstrdup(JS_GetStringBytes(ATOM_TO_STRING(element->pn_atom)));
1549        }        }
1550          assert(i == source->pn_count);
1551      }      }
1552    }    }
1553    

Legend:
Removed from v.179  
changed lines
  Added in v.293

  ViewVC Help
Powered by ViewVC 1.1.24