/[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 156 by siliconforks, Fri Sep 12 19:44:03 2008 UTC revision 167 by siliconforks, Mon Sep 15 15:54:26 2008 UTC
# Line 881  Line 881 
881    Stream_write(output, instrumented->data, instrumented->length);    Stream_write(output, instrumented->data, instrumented->length);
882    Stream_write_char(output, '\n');    Stream_write_char(output, '\n');
883    
884    /* copy the original source to the output */    /* conditionals */
885      bool has_conditionals = false;
886      size_t line_number = 0;
887    size_t i = 0;    size_t i = 0;
888    while (i < input_length) {    while (i < input_length) {
889        line_number++;
890        size_t line_start = i;
891        while (i < input_length && base[i] != '\r' && base[i] != '\n') {
892          i++;
893        }
894        size_t line_end = i;
895        if (i < input_length) {
896          if (base[i] == '\r') {
897            line_end = i;
898            i++;
899            if (i < input_length && base[i] == '\n') {
900              i++;
901            }
902          }
903          else if (base[i] == '\n') {
904            line_end = i;
905            i++;
906          }
907          else {
908            abort();
909          }
910        }
911        char * line = js_DeflateString(context, base + line_start, line_end - line_start);
912        if (str_starts_with(line, "//#JSCOVERAGE_IF")) {
913          if (! has_conditionals) {
914            has_conditionals = true;
915            Stream_printf(output, "_$jscoverage['%s'].conditionals = [];\n", file_id);
916          }
917          Stream_printf(output, "if (!%s) {\n", line + 16);
918          Stream_printf(output, "  _$jscoverage['%s'].conditionals[%d] = ", file_id, line_number);
919        }
920        else if (str_starts_with(line, "//#JSCOVERAGE_ENDIF")) {
921          Stream_printf(output, "%d;\n", line_number);
922          Stream_printf(output, "}\n");
923        }
924        JS_free(context, line);
925      }
926    
927      /* copy the original source to the output */
928      i = 0;
929      while (i < input_length) {
930      Stream_write_string(output, "// ");      Stream_write_string(output, "// ");
931      size_t line_start = i;      size_t line_start = i;
932      while (i < input_length && base[i] != '\r' && base[i] != '\n') {      while (i < input_length && base[i] != '\r' && base[i] != '\n') {
# Line 925  Line 968 
968    copy_resource("jscoverage.html", destination_directory);    copy_resource("jscoverage.html", destination_directory);
969    copy_resource("jscoverage.css", destination_directory);    copy_resource("jscoverage.css", destination_directory);
970    copy_resource("jscoverage.js", destination_directory);    copy_resource("jscoverage.js", destination_directory);
971      copy_resource("jscoverage-ie.js", destination_directory);
972    copy_resource("jscoverage-throbber.gif", destination_directory);    copy_resource("jscoverage-throbber.gif", destination_directory);
973    copy_resource("jscoverage-sh_main.js", destination_directory);    copy_resource("jscoverage-sh_main.js", destination_directory);
974    copy_resource("jscoverage-sh_javascript.js", destination_directory);    copy_resource("jscoverage-sh_javascript.js", destination_directory);

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

  ViewVC Help
Powered by ViewVC 1.1.24