77 |
|
|
78 |
char * end; |
char * end; |
79 |
js_version = (JSVersion) strtol(version, &end, 10); |
js_version = (JSVersion) strtol(version, &end, 10); |
80 |
if (end - version != strlen(version)) { |
if ((size_t) (end - version) != strlen(version)) { |
81 |
fatal("invalid version: %s", version); |
fatal("invalid version: %s", version); |
82 |
} |
} |
83 |
} |
} |
364 |
} |
} |
365 |
JSAtom * param = JS_LOCAL_NAME_TO_ATOM(local_names[i]); |
JSAtom * param = JS_LOCAL_NAME_TO_ATOM(local_names[i]); |
366 |
if (param == NULL) { |
if (param == NULL) { |
367 |
fatal("unsupported parameter type for function: %s", file_id); |
fatal_source(file_id, node->pn_pos.begin.lineno, "unsupported parameter type for function"); |
368 |
} |
} |
369 |
print_string_atom(param, f); |
print_string_atom(param, f); |
370 |
} |
} |
560 |
instrument_expression(node->pn_kid, f); |
instrument_expression(node->pn_kid, f); |
561 |
break; |
break; |
562 |
default: |
default: |
563 |
fatal("%s: unknown operator (%d) in file", file_id, node->pn_op); |
fatal_source(file_id, node->pn_pos.begin.lineno, "unknown operator (%d)", node->pn_op); |
564 |
break; |
break; |
565 |
} |
} |
566 |
break; |
break; |
670 |
Stream_write_char(f, '{'); |
Stream_write_char(f, '{'); |
671 |
for (struct JSParseNode * p = node->pn_head; p != NULL; p = p->pn_next) { |
for (struct JSParseNode * p = node->pn_head; p != NULL; p = p->pn_next) { |
672 |
if (p->pn_type != TOK_COLON) { |
if (p->pn_type != TOK_COLON) { |
673 |
fatal("unsupported node type in file %s: %d", file_id, p->pn_type); |
fatal_source(file_id, p->pn_pos.begin.lineno, "unsupported node type (%d)", p->pn_type); |
674 |
} |
} |
675 |
if (p != node->pn_head) { |
if (p != node->pn_head) { |
676 |
Stream_write_string(f, ", "); |
Stream_write_string(f, ", "); |
688 |
} |
} |
689 |
instrument_expression(p->pn_left, f); |
instrument_expression(p->pn_left, f); |
690 |
if (p->pn_right->pn_type != TOK_FUNCTION) { |
if (p->pn_right->pn_type != TOK_FUNCTION) { |
691 |
fatal("parse error: expected function"); |
fatal_source(file_id, p->pn_pos.begin.lineno, "expected function"); |
692 |
} |
} |
693 |
instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER); |
instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER); |
694 |
break; |
break; |
814 |
instrument_declarations(node, f); |
instrument_declarations(node, f); |
815 |
break; |
break; |
816 |
default: |
default: |
817 |
fatal("unsupported node type in file %s: %d", file_id, node->pn_type); |
fatal_source(file_id, node->pn_pos.begin.lineno, "unsupported node type (%d)", node->pn_type); |
818 |
} |
} |
819 |
} |
} |
820 |
|
|
843 |
uint16_t line = node->pn_pos.begin.lineno; |
uint16_t line = node->pn_pos.begin.lineno; |
844 |
if (! is_jscoverage_if) { |
if (! is_jscoverage_if) { |
845 |
if (line > num_lines) { |
if (line > num_lines) { |
846 |
fatal("%s: script contains more than 65,535 lines", file_id); |
fatal("file %s contains more than 65,535 lines", file_id); |
847 |
} |
} |
848 |
if (line >= 2 && exclusive_directives[line - 2]) { |
if (line >= 2 && exclusive_directives[line - 2]) { |
849 |
is_jscoverage_if = true; |
is_jscoverage_if = true; |
1139 |
Stream_write_string(f, "debugger;\n"); |
Stream_write_string(f, "debugger;\n"); |
1140 |
break; |
break; |
1141 |
default: |
default: |
1142 |
fatal("unsupported node type in file %s: %d", file_id, node->pn_type); |
fatal_source(file_id, node->pn_pos.begin.lineno, "unsupported node type (%d)", node->pn_type); |
1143 |
} |
} |
1144 |
} |
} |
1145 |
|
|
1152 |
if (node->pn_type != TOK_LC && node->pn_type != TOK_LEXICALSCOPE) { |
if (node->pn_type != TOK_LC && node->pn_type != TOK_LEXICALSCOPE) { |
1153 |
uint16_t line = node->pn_pos.begin.lineno; |
uint16_t line = node->pn_pos.begin.lineno; |
1154 |
if (line > num_lines) { |
if (line > num_lines) { |
1155 |
fatal("%s: script contains more than 65,535 lines", file_id); |
fatal("file %s contains more than 65,535 lines", file_id); |
1156 |
} |
} |
1157 |
|
|
1158 |
/* the root node has line number 0 */ |
/* the root node has line number 0 */ |
1200 |
} |
} |
1201 |
|
|
1202 |
static void error_reporter(JSContext * context, const char * message, JSErrorReport * report) { |
static void error_reporter(JSContext * context, const char * message, JSErrorReport * report) { |
1203 |
fprintf(stderr, "jscoverage: parse error: line %u: %s\n", report->lineno, message); |
fatal_source(file_id, report->lineno, message); |
1204 |
} |
} |
1205 |
|
|
1206 |
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) { |
1209 |
/* parse the javascript */ |
/* parse the javascript */ |
1210 |
JSParseContext parse_context; |
JSParseContext parse_context; |
1211 |
if (! js_InitParseContext(context, &parse_context, NULL, NULL, characters, num_characters, NULL, NULL, 1)) { |
if (! js_InitParseContext(context, &parse_context, NULL, NULL, characters, num_characters, NULL, NULL, 1)) { |
1212 |
fatal("cannot create token stream from file: %s", file_id); |
fatal("cannot create token stream from file %s", file_id); |
1213 |
} |
} |
1214 |
JSErrorReporter old_error_reporter = JS_SetErrorReporter(context, error_reporter); |
JSErrorReporter old_error_reporter = JS_SetErrorReporter(context, error_reporter); |
1215 |
JSParseNode * node = js_ParseScript(context, global, &parse_context); |
JSParseNode * node = js_ParseScript(context, global, &parse_context); |
1216 |
if (node == NULL) { |
if (node == NULL) { |
1217 |
js_ReportUncaughtException(context); |
js_ReportUncaughtException(context); |
1218 |
fatal("parse error in file: %s", file_id); |
fatal("parse error in file %s", file_id); |
1219 |
} |
} |
1220 |
JS_SetErrorReporter(context, old_error_reporter); |
JS_SetErrorReporter(context, old_error_reporter); |
1221 |
num_lines = node->pn_pos.end.lineno; |
num_lines = node->pn_pos.end.lineno; |
1236 |
size_t i = 0; |
size_t i = 0; |
1237 |
while (i < num_characters) { |
while (i < num_characters) { |
1238 |
if (line_number == UINT16_MAX) { |
if (line_number == UINT16_MAX) { |
1239 |
fatal("%s: script has more than 65,535 lines", file_id); |
fatal("file %s contains more than 65,535 lines", file_id); |
1240 |
} |
} |
1241 |
line_number++; |
line_number++; |
1242 |
size_t line_start = i; |
size_t line_start = i; |