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> |
991 |
return true; |
return true; |
992 |
} |
} |
993 |
|
|
994 |
|
static void error_reporter(JSContext * context, const char * message, JSErrorReport * report) { |
995 |
|
fprintf(stderr, "jscoverage: parse error: line %u: %s\n", report->lineno, message); |
996 |
|
} |
997 |
|
|
998 |
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) { |
999 |
file_id = id; |
file_id = id; |
1000 |
|
|
1005 |
} |
} |
1006 |
|
|
1007 |
/* parse the javascript */ |
/* parse the javascript */ |
1008 |
|
JSErrorReporter old_error_reporter = JS_SetErrorReporter(context, error_reporter); |
1009 |
JSParseNode * node = js_ParseTokenStream(context, global, token_stream); |
JSParseNode * node = js_ParseTokenStream(context, global, token_stream); |
1010 |
if (node == NULL) { |
if (node == NULL) { |
1011 |
|
js_ReportUncaughtException(context); |
1012 |
fatal("parse error in file: %s", file_id); |
fatal("parse error in file: %s", file_id); |
1013 |
} |
} |
1014 |
|
JS_SetErrorReporter(context, old_error_reporter); |
1015 |
num_lines = node->pn_pos.end.lineno; |
num_lines = node->pn_pos.end.lineno; |
1016 |
lines = xmalloc(num_lines); |
lines = xmalloc(num_lines); |
1017 |
for (unsigned int i = 0; i < num_lines; i++) { |
for (unsigned int i = 0; i < num_lines; i++) { |