/[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 369 by siliconforks, Mon Oct 27 20:33:57 2008 UTC revision 370 by siliconforks, Mon Oct 27 20:34:27 2008 UTC
# Line 77  Line 77 
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  }  }
# Line 364  Line 364 
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    }    }
# Line 560  Line 560 
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;
# Line 670  Line 670 
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, ", ");
# Line 688  Line 688 
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;
# Line 814  Line 814 
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    
# Line 843  Line 843 
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;
# Line 1139  Line 1139 
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    
# Line 1152  Line 1152 
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 */
# Line 1200  Line 1200 
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) {
# Line 1209  Line 1209 
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;
# Line 1236  Line 1236 
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;

Legend:
Removed from v.369  
changed lines
  Added in v.370

  ViewVC Help
Powered by ViewVC 1.1.24