877 |
free(lines); |
free(lines); |
878 |
lines = NULL; |
lines = NULL; |
879 |
|
|
880 |
|
/* conditionals */ |
881 |
|
bool has_conditionals = false; |
882 |
|
size_t line_number = 0; |
883 |
|
size_t i = 0; |
884 |
|
while (i < input_length) { |
885 |
|
line_number++; |
886 |
|
size_t line_start = i; |
887 |
|
while (i < input_length && base[i] != '\r' && base[i] != '\n') { |
888 |
|
i++; |
889 |
|
} |
890 |
|
size_t line_end = i; |
891 |
|
if (i < input_length) { |
892 |
|
if (base[i] == '\r') { |
893 |
|
line_end = i; |
894 |
|
i++; |
895 |
|
if (i < input_length && base[i] == '\n') { |
896 |
|
i++; |
897 |
|
} |
898 |
|
} |
899 |
|
else if (base[i] == '\n') { |
900 |
|
line_end = i; |
901 |
|
i++; |
902 |
|
} |
903 |
|
else { |
904 |
|
abort(); |
905 |
|
} |
906 |
|
} |
907 |
|
char * line = js_DeflateString(context, base + line_start, line_end - line_start); |
908 |
|
if (str_starts_with(line, "//#JSCOVERAGE_IF")) { |
909 |
|
if (! has_conditionals) { |
910 |
|
has_conditionals = true; |
911 |
|
Stream_printf(output, "_$jscoverage['%s'].conditionals = [];\n", file_id); |
912 |
|
} |
913 |
|
Stream_printf(output, "_$jscoverage['%s'].conditionals[%d] = {condition: function () {return %s;}, ", file_id, line_number, line + 16); |
914 |
|
} |
915 |
|
else if (str_starts_with(line, "//#JSCOVERAGE_ENDIF")) { |
916 |
|
Stream_printf(output, "end: %d};\n", line_number); |
917 |
|
} |
918 |
|
JS_free(context, line); |
919 |
|
} |
920 |
|
|
921 |
/* copy the instrumented source code to the output */ |
/* copy the instrumented source code to the output */ |
922 |
Stream_write(output, instrumented->data, instrumented->length); |
Stream_write(output, instrumented->data, instrumented->length); |
923 |
Stream_write_char(output, '\n'); |
Stream_write_char(output, '\n'); |
924 |
|
|
925 |
/* copy the original source to the output */ |
/* copy the original source to the output */ |
926 |
size_t i = 0; |
i = 0; |
927 |
while (i < input_length) { |
while (i < input_length) { |
928 |
Stream_write_string(output, "// "); |
Stream_write_string(output, "// "); |
929 |
size_t line_start = i; |
size_t line_start = i; |