/[jscoverage]/trunk/instrument-js.cpp
ViewVC logotype

Diff of /trunk/instrument-js.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 246 by siliconforks, Sun Oct 5 18:05:42 2008 UTC revision 317 by siliconforks, Tue Oct 14 01:28:46 2008 UTC
# Line 27  Line 27 
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>
# Line 146  Line 147 
147        case 0xa:        case 0xa:
148          Stream_write_string(f, "\\n");          Stream_write_string(f, "\\n");
149          break;          break;
150          /* IE doesn't support this */
151          /*
152        case 0xb:        case 0xb:
153          Stream_write_string(f, "\\v");          Stream_write_string(f, "\\v");
154          break;          break;
155          */
156        case 0xc:        case 0xc:
157          Stream_write_string(f, "\\f");          Stream_write_string(f, "\\f");
158          break;          break;
# Line 539  Line 543 
543        /* check whether this is a getter or setter */        /* check whether this is a getter or setter */
544        switch (p->pn_op) {        switch (p->pn_op) {
545        case JSOP_GETTER:        case JSOP_GETTER:
         Stream_write_string(f, "get ");  
         instrument_expression(p->pn_left, f);  
         instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);  
         break;  
546        case JSOP_SETTER:        case JSOP_SETTER:
547          Stream_write_string(f, "set ");          if (p->pn_op == JSOP_GETTER) {
548              Stream_write_string(f, "get ");
549            }
550            else {
551              Stream_write_string(f, "set ");
552            }
553          instrument_expression(p->pn_left, f);          instrument_expression(p->pn_left, f);
554            if (p->pn_right->pn_type != TOK_FUNCTION) {
555              fatal("parse error: expected function");
556            }
557          instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);          instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);
558          break;          break;
559        default:        default:
# Line 990  Line 998 
998    return true;    return true;
999  }  }
1000    
1001    static void error_reporter(JSContext * context, const char * message, JSErrorReport * report) {
1002      fprintf(stderr, "jscoverage: parse error: line %u: %s\n", report->lineno, message);
1003    }
1004    
1005  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) {
1006    file_id = id;    file_id = id;
1007    
# Line 1000  Line 1012 
1012    }    }
1013    
1014    /* parse the javascript */    /* parse the javascript */
1015      JSErrorReporter old_error_reporter = JS_SetErrorReporter(context, error_reporter);
1016    JSParseNode * node = js_ParseTokenStream(context, global, token_stream);    JSParseNode * node = js_ParseTokenStream(context, global, token_stream);
1017    if (node == NULL) {    if (node == NULL) {
1018        js_ReportUncaughtException(context);
1019      fatal("parse error in file: %s", file_id);      fatal("parse error in file: %s", file_id);
1020    }    }
1021      JS_SetErrorReporter(context, old_error_reporter);
1022    num_lines = node->pn_pos.end.lineno;    num_lines = node->pn_pos.end.lineno;
1023    lines = xmalloc(num_lines);    lines = xmalloc(num_lines);
1024    for (unsigned int i = 0; i < num_lines; i++) {    for (unsigned int i = 0; i < num_lines; i++) {
# Line 1165  Line 1180 
1180            /* line feed (new line) */            /* line feed (new line) */
1181            done = true;            done = true;
1182            break;            break;
1183            /* IE doesn't support this */
1184            /*
1185          case 0xb:          case 0xb:
           /* vertical tab */  
1186            Stream_write_string(output, "\\v");            Stream_write_string(output, "\\v");
1187            break;            break;
1188            */
1189          case 0xc:          case 0xc:
1190            /* form feed */            /* form feed */
1191            Stream_write_string(output, "\\f");            Stream_write_string(output, "\\f");
# Line 1223  Line 1240 
1240            /* line feed (new line) */            /* line feed (new line) */
1241            done = true;            done = true;
1242            break;            break;
1243            /* IE doesn't support this */
1244            /*
1245          case 0xb:          case 0xb:
           /* vertical tab */  
1246            Stream_write_string(output, "\\v");            Stream_write_string(output, "\\v");
1247            break;            break;
1248            */
1249          case 0xc:          case 0xc:
1250            /* form feed */            /* form feed */
1251            Stream_write_string(output, "\\f");            Stream_write_string(output, "\\f");

Legend:
Removed from v.246  
changed lines
  Added in v.317

  ViewVC Help
Powered by ViewVC 1.1.24