/[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 246 by siliconforks, Sun Oct 5 18:05:42 2008 UTC revision 293 by siliconforks, Sun Oct 12 16:41:57 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 539  Line 540 
540        /* check whether this is a getter or setter */        /* check whether this is a getter or setter */
541        switch (p->pn_op) {        switch (p->pn_op) {
542        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;  
543        case JSOP_SETTER:        case JSOP_SETTER:
544          Stream_write_string(f, "set ");          if (p->pn_op == JSOP_GETTER) {
545              Stream_write_string(f, "get ");
546            }
547            else {
548              Stream_write_string(f, "set ");
549            }
550          instrument_expression(p->pn_left, f);          instrument_expression(p->pn_left, f);
551            if (p->pn_right->pn_type != TOK_FUNCTION) {
552              fatal("parse error: expected function");
553            }
554          instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);          instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);
555          break;          break;
556        default:        default:
# Line 990  Line 995 
995    return true;    return true;
996  }  }
997    
998    static void error_reporter(JSContext * context, const char * message, JSErrorReport * report) {
999      fprintf(stderr, "jscoverage: parse error: line %u: %s\n", report->lineno, message);
1000    }
1001    
1002  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) {
1003    file_id = id;    file_id = id;
1004    
# Line 1000  Line 1009 
1009    }    }
1010    
1011    /* parse the javascript */    /* parse the javascript */
1012      JSErrorReporter old_error_reporter = JS_SetErrorReporter(context, error_reporter);
1013    JSParseNode * node = js_ParseTokenStream(context, global, token_stream);    JSParseNode * node = js_ParseTokenStream(context, global, token_stream);
1014    if (node == NULL) {    if (node == NULL) {
1015        js_ReportUncaughtException(context);
1016      fatal("parse error in file: %s", file_id);      fatal("parse error in file: %s", file_id);
1017    }    }
1018      JS_SetErrorReporter(context, old_error_reporter);
1019    num_lines = node->pn_pos.end.lineno;    num_lines = node->pn_pos.end.lineno;
1020    lines = xmalloc(num_lines);    lines = xmalloc(num_lines);
1021    for (unsigned int i = 0; i < num_lines; i++) {    for (unsigned int i = 0; i < num_lines; i++) {

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

  ViewVC Help
Powered by ViewVC 1.1.24