/[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 402 by siliconforks, Tue Dec 9 09:47:43 2008 UTC revision 444 by siliconforks, Sun Jul 26 17:09:09 2009 UTC
# Line 1  Line 1 
1  /*  /*
2      instrument-js.cpp - JavaScript instrumentation routines      instrument-js.cpp - JavaScript instrumentation routines
3      Copyright (C) 2007, 2008 siliconforks.com      Copyright (C) 2007, 2008, 2009 siliconforks.com
4    
5      This program is free software; you can redistribute it and/or modify      This program is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published by      it under the terms of the GNU General Public License as published by
# Line 53  Line 53 
53    struct IfDirective * next;    struct IfDirective * next;
54  };  };
55    
56  bool jscoverage_mozilla = false;  enum JSCoverageMode jscoverage_mode = JSCOVERAGE_NORMAL;
57    
58  static bool * exclusive_directives = NULL;  static bool * exclusive_directives = NULL;
59    
# Line 1391  Line 1391 
1391    js_FinishParseContext(context, &parse_context);    js_FinishParseContext(context, &parse_context);
1392    
1393    /* write line number info to the output */    /* write line number info to the output */
1394    Stream_write_string(output, "/* automatically generated by JSCoverage - do not edit */\n");    Stream_write_string(output, JSCOVERAGE_INSTRUMENTED_HEADER);
1395    if (jscoverage_mozilla) {    switch (jscoverage_mode) {
1396      case JSCOVERAGE_MOZILLA:
1397      Stream_write_string(output, "try {\n");      Stream_write_string(output, "try {\n");
1398      Stream_write_string(output, "  Components.utils.import('resource://gre/modules/jscoverage.jsm');\n");      Stream_write_string(output, "  Components.utils.import('resource://gre/modules/jscoverage.jsm');\n");
1399      Stream_printf(output, "  dump('%s: successfully imported jscoverage module\\n');\n", id);      Stream_printf(output, "  dump('%s: successfully imported jscoverage module\\n');\n", id);
# Line 1401  Line 1402 
1402      Stream_write_string(output, "  _$jscoverage = {};\n");      Stream_write_string(output, "  _$jscoverage = {};\n");
1403      Stream_printf(output, "  dump('%s: failed to import jscoverage module - coverage not available for this file\\n');\n", id);      Stream_printf(output, "  dump('%s: failed to import jscoverage module - coverage not available for this file\\n');\n", id);
1404      Stream_write_string(output, "}\n");      Stream_write_string(output, "}\n");
1405    }      break;
1406    else {    case JSCOVERAGE_NORMAL:
1407      Stream_write_string(output, "if (! top._$jscoverage) {\n  top._$jscoverage = {};\n}\n");      Stream_write_string(output, "if (! top._$jscoverage) {\n  top._$jscoverage = {};\n}\n");
1408      Stream_write_string(output, "var _$jscoverage = top._$jscoverage;\n");      Stream_write_string(output, "var _$jscoverage = top._$jscoverage;\n");
1409        break;
1410      case JSCOVERAGE_NO_BROWSER:
1411        Stream_write_string(output, "if (typeof _$jscoverage === 'undefined') {\n  var _$jscoverage = {};\n}\n");
1412        break;
1413    }    }
1414    Stream_printf(output, "if (! _$jscoverage['%s']) {\n", file_id);    Stream_printf(output, "if (! _$jscoverage['%s']) {\n", file_id);
1415    Stream_printf(output, "  _$jscoverage['%s'] = [];\n", file_id);    Stream_printf(output, "  _$jscoverage['%s'] = [];\n", file_id);
# Line 1419  Line 1424 
1424    free(exclusive_directives);    free(exclusive_directives);
1425    exclusive_directives = NULL;    exclusive_directives = NULL;
1426    
1427      /* copy the original source to the output */
1428      Stream_printf(output, "_$jscoverage['%s'].source = ", file_id);
1429      jscoverage_write_source(id, characters, num_characters, output);
1430      Stream_printf(output, ";\n");
1431    
1432    /* conditionals */    /* conditionals */
1433    if (has_conditionals) {    if (has_conditionals) {
1434      Stream_printf(output, "_$jscoverage['%s'].conditionals = [];\n", file_id);      Stream_printf(output, "_$jscoverage['%s'].conditionals = [];\n", file_id);
# Line 1443  Line 1453 
1453      free(if_directive);      free(if_directive);
1454    }    }
1455    
   /* copy the original source to the output */  
   Stream_printf(output, "_$jscoverage['%s'].source = ", file_id);  
   jscoverage_write_source(id, characters, num_characters, output);  
   Stream_printf(output, ";\n");  
   
1456    Stream_delete(instrumented);    Stream_delete(instrumented);
1457    
1458    file_id = NULL;    file_id = NULL;

Legend:
Removed from v.402  
changed lines
  Added in v.444

  ViewVC Help
Powered by ViewVC 1.1.24