/[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 101 by siliconforks, Sat May 24 18:11:30 2008 UTC revision 336 by siliconforks, Thu Oct 23 20:08:29 2008 UTC
# Line 17  Line 17 
17      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */  */
19    
20    #include <config.h>
21    
22  #include "instrument-js.h"  #include "instrument-js.h"
23    
24  #include <assert.h>  #include <assert.h>
# Line 24  Line 26 
26  #include <string.h>  #include <string.h>
27    
28  #include <jsapi.h>  #include <jsapi.h>
29    #include <jsarena.h>
30  #include <jsatom.h>  #include <jsatom.h>
31    #include <jsexn.h>
32  #include <jsfun.h>  #include <jsfun.h>
33  #include <jsinterp.h>  #include <jsinterp.h>
34  #include <jsparse.h>  #include <jsparse.h>
# Line 32  Line 36 
36  #include <jsscope.h>  #include <jsscope.h>
37  #include <jsstr.h>  #include <jsstr.h>
38    
39    #include "encoding.h"
40    #include "global.h"
41    #include "highlight.h"
42    #include "resource-manager.h"
43  #include "util.h"  #include "util.h"
44    
45    struct IfDirective {
46      const jschar * condition_start;
47      const jschar * condition_end;
48      uint16_t start_line;
49      uint16_t end_line;
50      struct IfDirective * next;
51    };
52    
53    static bool * exclusive_directives = NULL;
54    
55  static JSRuntime * runtime = NULL;  static JSRuntime * runtime = NULL;
56  static JSContext * context = NULL;  static JSContext * context = NULL;
57  static JSObject * global = NULL;  static JSObject * global = NULL;
# Line 44  Line 62 
62  */  */
63  static const char * file_id = NULL;  static const char * file_id = NULL;
64  static char * lines = NULL;  static char * lines = NULL;
65    static uint16_t num_lines = 0;
66    
67  void jscoverage_init(void) {  void jscoverage_init(void) {
68    runtime = JS_NewRuntime(8L * 1024L * 1024L);    runtime = JS_NewRuntime(8L * 1024L * 1024L);
# Line 71  Line 90 
90    JS_DestroyRuntime(runtime);    JS_DestroyRuntime(runtime);
91  }  }
92    
93    static void print_javascript(const jschar * characters, size_t num_characters, Stream * f) {
94      for (size_t i = 0; i < num_characters; i++) {
95        jschar c = characters[i];
96        /*
97        XXX does not handle no-break space, other unicode "space separator"
98        */
99        switch (c) {
100        case 0x9:
101        case 0xB:
102        case 0xC:
103          Stream_write_char(f, c);
104          break;
105        default:
106          if (32 <= c && c <= 126) {
107            Stream_write_char(f, c);
108          }
109          else {
110            Stream_printf(f, "\\u%04x", c);
111          }
112          break;
113        }
114      }
115    }
116    
117  static void print_string(JSString * s, Stream * f) {  static void print_string(JSString * s, Stream * f) {
118    for (size_t i = 0; i < s->length; i++) {    size_t length = JSSTRING_LENGTH(s);
119      char c = s->chars[i];    jschar * characters = JSSTRING_CHARS(s);
120      Stream_write_char(f, c);    for (size_t i = 0; i < length; i++) {
121        jschar c = characters[i];
122        if (32 <= c && c <= 126) {
123          switch (c) {
124          case '"':
125            Stream_write_string(f, "\\\"");
126            break;
127    /*
128          case '\'':
129            Stream_write_string(f, "\\'");
130            break;
131    */
132          case '\\':
133            Stream_write_string(f, "\\\\");
134            break;
135          default:
136            Stream_write_char(f, c);
137            break;
138          }
139        }
140        else {
141          switch (c) {
142          case 0x8:
143            Stream_write_string(f, "\\b");
144            break;
145          case 0x9:
146            Stream_write_string(f, "\\t");
147            break;
148          case 0xa:
149            Stream_write_string(f, "\\n");
150            break;
151          /* IE doesn't support this */
152          /*
153          case 0xb:
154            Stream_write_string(f, "\\v");
155            break;
156          */
157          case 0xc:
158            Stream_write_string(f, "\\f");
159            break;
160          case 0xd:
161            Stream_write_string(f, "\\r");
162            break;
163          default:
164            Stream_printf(f, "\\u%04x", c);
165            break;
166          }
167        }
168    }    }
169  }  }
170    
# Line 84  Line 174 
174    print_string(s, f);    print_string(s, f);
175  }  }
176    
177  static void print_string_jsval(jsval value, Stream * f) {  static void print_regex(jsval value, Stream * f) {
178    assert(JSVAL_IS_STRING(value));    assert(JSVAL_IS_STRING(value));
179    JSString * s = JSVAL_TO_STRING(value);    JSString * s = JSVAL_TO_STRING(value);
180    print_string(s, f);    size_t length = JSSTRING_LENGTH(s);
181      jschar * characters = JSSTRING_CHARS(s);
182      for (size_t i = 0; i < length; i++) {
183        jschar c = characters[i];
184        if (32 <= c && c <= 126) {
185          Stream_write_char(f, c);
186        }
187        else {
188          Stream_printf(f, "\\u%04x", c);
189        }
190      }
191  }  }
192    
193  static void print_quoted_string_atom(JSAtom * atom, Stream * f) {  static void print_quoted_string_atom(JSAtom * atom, Stream * f) {
194    assert(ATOM_IS_STRING(atom));    assert(ATOM_IS_STRING(atom));
195    JSString * s = ATOM_TO_STRING(atom);    JSString * s = ATOM_TO_STRING(atom);
196    JSString * quoted = js_QuoteString(context, s, '"');    Stream_write_char(f, '"');
197    print_string(quoted, f);    print_string(s, f);
198      Stream_write_char(f, '"');
199  }  }
200    
201  static const char * get_op(uint8 op) {  static const char * get_op(uint8 op) {
202    switch(op) {    switch(op) {
203      case JSOP_OR:
204        return "||";
205      case JSOP_AND:
206        return "&&";
207    case JSOP_BITOR:    case JSOP_BITOR:
208      return "|";      return "|";
209    case JSOP_BITXOR:    case JSOP_BITXOR:
# Line 109  Line 214 
214      return "==";      return "==";
215    case JSOP_NE:    case JSOP_NE:
216      return "!=";      return "!=";
217    case JSOP_NEW_EQ:    case JSOP_STRICTEQ:
218      return "===";      return "===";
219    case JSOP_NEW_NE:    case JSOP_STRICTNE:
220      return "!==";      return "!==";
221    case JSOP_LT:    case JSOP_LT:
222      return "<";      return "<";
# Line 143  Line 248 
248  }  }
249    
250  static void instrument_expression(JSParseNode * node, Stream * f);  static void instrument_expression(JSParseNode * node, Stream * f);
251  static void instrument_statement(JSParseNode * node, Stream * f, int indent);  static void instrument_statement(JSParseNode * node, Stream * f, int indent, bool is_jscoverage_if);
252    
253  static void instrument_function(JSParseNode * node, Stream * f, int indent) {  enum FunctionType {
254      assert(node->pn_arity == PN_FUNC);    FUNCTION_NORMAL,
255      assert(ATOM_IS_OBJECT(node->pn_funAtom));    FUNCTION_GETTER_OR_SETTER
256      JSObject * object = ATOM_TO_OBJECT(node->pn_funAtom);  };
257      assert(JS_ObjectIsFunction(context, object));  
258      JSFunction * function = (JSFunction *) JS_GetPrivate(context, object);  static void instrument_function(JSParseNode * node, Stream * f, int indent, enum FunctionType type) {
259      assert(function);    assert(node->pn_type == TOK_FUNCTION);
260      assert(object == function->object);    assert(node->pn_arity == PN_FUNC);
261      Stream_printf(f, "%*s", indent, "");    JSObject * object = node->pn_funpob->object;
262      assert(JS_ObjectIsFunction(context, object));
263      JSFunction * function = (JSFunction *) JS_GetPrivate(context, object);
264      assert(function);
265      assert(object == &function->object);
266      Stream_printf(f, "%*s", indent, "");
267      if (type == FUNCTION_NORMAL) {
268      Stream_write_string(f, "function");      Stream_write_string(f, "function");
269      }
270    
271      /* function name */    /* function name */
272      if (function->atom) {    if (function->atom) {
273        Stream_write_char(f, ' ');      Stream_write_char(f, ' ');
274        print_string_atom(function->atom, f);      print_string_atom(function->atom, f);
275      }    }
276    
277      /* function parameters */    /*
278      Stream_write_string(f, "(");    function parameters - see JS_DecompileFunction in jsapi.cpp, which calls
279      JSAtom ** params = xmalloc(function->nargs * sizeof(JSAtom *));    js_DecompileFunction in jsopcode.cpp
280      for (int i = 0; i < function->nargs; i++) {    */
281        /* initialize to NULL for sanity check */    Stream_write_string(f, "(");
282        params[i] = NULL;    JSArenaPool pool;
283      }    JS_INIT_ARENA_POOL(&pool, "instrument_function", 256, 1, &context->scriptStackQuota);
284      JSScope * scope = OBJ_SCOPE(object);    jsuword * local_names = NULL;
285      for (JSScopeProperty * scope_property = SCOPE_LAST_PROP(scope); scope_property != NULL; scope_property = scope_property->parent) {    if (JS_GET_LOCAL_NAME_COUNT(function)) {
286        if (scope_property->getter != js_GetArgument) {      local_names = js_GetLocalNameArray(context, function, &pool);
287          continue;      if (local_names == NULL) {
288        }        fatal("out of memory");
       assert(scope_property->flags & SPROP_HAS_SHORTID);  
       assert((uint16) scope_property->shortid < function->nargs);  
       assert(JSID_IS_ATOM(scope_property->id));  
       params[(uint16) scope_property->shortid] = JSID_TO_ATOM(scope_property->id);  
289      }      }
290      for (int i = 0; i < function->nargs; i++) {    }
291        assert(params[i] != NULL);    for (int i = 0; i < function->nargs; i++) {
292        if (i > 0) {      if (i > 0) {
293          Stream_write_string(f, ", ");        Stream_write_string(f, ", ");
       }  
       if (ATOM_IS_STRING(params[i])) {  
         print_string_atom(params[i], f);  
       }  
294      }      }
295      Stream_write_string(f, ") {\n");      JSAtom * param = JS_LOCAL_NAME_TO_ATOM(local_names[i]);
296      free(params);      print_string_atom(param, f);
297      }
298      JS_FinishArenaPool(&pool);
299      Stream_write_string(f, ") {\n");
300    
301      /* function body */    /* function body */
302      instrument_statement(node->pn_body, f, indent + 2);    instrument_statement(node->pn_body, f, indent + 2, false);
303    
304      Stream_write_string(f, "}\n");    Stream_write_string(f, "}\n");
305  }  }
306    
307  static void instrument_function_call(JSParseNode * node, Stream * f) {  static void instrument_function_call(JSParseNode * node, Stream * f) {
# Line 225  Line 332 
332  static void instrument_expression(JSParseNode * node, Stream * f) {  static void instrument_expression(JSParseNode * node, Stream * f) {
333    switch (node->pn_type) {    switch (node->pn_type) {
334    case TOK_FUNCTION:    case TOK_FUNCTION:
335      instrument_function(node, f, 0);      instrument_function(node, f, 0, FUNCTION_NORMAL);
336      break;      break;
337    case TOK_COMMA:    case TOK_COMMA:
338      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) {
# Line 267  Line 374 
374      instrument_expression(node->pn_kid3, f);      instrument_expression(node->pn_kid3, f);
375      break;      break;
376    case TOK_OR:    case TOK_OR:
     instrument_expression(node->pn_left, f);  
     Stream_write_string(f, " || ");  
     instrument_expression(node->pn_right, f);  
     break;  
377    case TOK_AND:    case TOK_AND:
     instrument_expression(node->pn_left, f);  
     Stream_write_string(f, " && ");  
     instrument_expression(node->pn_right, f);  
     break;  
378    case TOK_BITOR:    case TOK_BITOR:
379    case TOK_BITXOR:    case TOK_BITXOR:
380    case TOK_BITAND:    case TOK_BITAND:
# Line 388  Line 487 
487      assert(ATOM_IS_STRING(node->pn_atom));      assert(ATOM_IS_STRING(node->pn_atom));
488      {      {
489        JSString * s = ATOM_TO_STRING(node->pn_atom);        JSString * s = ATOM_TO_STRING(node->pn_atom);
490        /* XXX - semantics changed in 1.7 */        bool is_keyword = (js_CheckKeyword(JSSTRING_CHARS(s), JSSTRING_LENGTH(s)) != TOK_EOF);
491        if (! ATOM_KEYWORD(node->pn_atom) && js_IsIdentifier(s)) {        if (! is_keyword && js_IsIdentifier(s)) {
492          Stream_write_char(f, '.');          Stream_write_char(f, '.');
493          print_string_atom(node->pn_atom, f);          print_string_atom(node->pn_atom, f);
494        }        }
# Line 432  Line 531 
531        if (p != node->pn_head) {        if (p != node->pn_head) {
532          Stream_write_string(f, ", ");          Stream_write_string(f, ", ");
533        }        }
534        instrument_expression(p->pn_left, f);  
535        Stream_write_string(f, ": ");        /* check whether this is a getter or setter */
536        instrument_expression(p->pn_right, f);        switch (p->pn_op) {
537          case JSOP_GETTER:
538          case JSOP_SETTER:
539            if (p->pn_op == JSOP_GETTER) {
540              Stream_write_string(f, "get ");
541            }
542            else {
543              Stream_write_string(f, "set ");
544            }
545            instrument_expression(p->pn_left, f);
546            if (p->pn_right->pn_type != TOK_FUNCTION) {
547              fatal("parse error: expected function");
548            }
549            instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);
550            break;
551          default:
552            instrument_expression(p->pn_left, f);
553            Stream_write_string(f, ": ");
554            instrument_expression(p->pn_right, f);
555            break;
556          }
557      }      }
558      Stream_write_char(f, '}');      Stream_write_char(f, '}');
559      break;      break;
# Line 449  Line 568 
568    case TOK_STRING:    case TOK_STRING:
569      print_quoted_string_atom(node->pn_atom, f);      print_quoted_string_atom(node->pn_atom, f);
570      break;      break;
571    case TOK_OBJECT:    case TOK_REGEXP:
572      switch (node->pn_op) {      assert(node->pn_op == JSOP_REGEXP);
573      case JSOP_OBJECT:      {
574        /* I assume this is JSOP_REGEXP */        JSObject * object = node->pn_pob->object;
575        abort();        jsval result;
576        break;        js_regexp_toString(context, object, &result);
577      case JSOP_REGEXP:        print_regex(result, f);
       assert(ATOM_IS_OBJECT(node->pn_atom));  
       {  
         JSObject * object = ATOM_TO_OBJECT(node->pn_atom);  
         jsval result;  
         js_regexp_toString(context, object, 0, NULL, &result);  
         print_string_jsval(result, f);  
       }  
       break;  
     default:  
       abort();  
       break;  
578      }      }
579      break;      break;
580    case TOK_NUMBER:    case TOK_NUMBER:
# Line 535  Line 643 
643    }    }
644  }  }
645    
646  static void output_statement(JSParseNode * node, Stream * f, int indent) {  static void output_statement(JSParseNode * node, Stream * f, int indent, bool is_jscoverage_if) {
647    switch (node->pn_type) {    switch (node->pn_type) {
648    case TOK_FUNCTION:    case TOK_FUNCTION:
649      instrument_function(node, f, indent);      instrument_function(node, f, indent, FUNCTION_NORMAL);
650      break;      break;
651    case TOK_LC:    case TOK_LC:
652      assert(node->pn_arity == PN_LIST);      assert(node->pn_arity == PN_LIST);
# Line 546  Line 654 
654      Stream_write_string(f, "{\n");      Stream_write_string(f, "{\n");
655  */  */
656      for (struct JSParseNode * p = node->pn_u.list.head; p != NULL; p = p->pn_next) {      for (struct JSParseNode * p = node->pn_u.list.head; p != NULL; p = p->pn_next) {
657        instrument_statement(p, f, indent);        instrument_statement(p, f, indent, false);
658      }      }
659  /*  /*
660      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
# Line 554  Line 662 
662  */  */
663      break;      break;
664    case TOK_IF:    case TOK_IF:
665      {
666      assert(node->pn_arity == PN_TERNARY);      assert(node->pn_arity == PN_TERNARY);
667    
668        uint16_t line = node->pn_pos.begin.lineno;
669        if (! is_jscoverage_if) {
670          if (line > num_lines) {
671            fatal("%s: script contains more than 65,535 lines", file_id);
672          }
673          if (line >= 2 && exclusive_directives[line - 2]) {
674            is_jscoverage_if = true;
675          }
676        }
677    
678      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
679      Stream_write_string(f, "if (");      Stream_write_string(f, "if (");
680      instrument_expression(node->pn_kid1, f);      instrument_expression(node->pn_kid1, f);
681      Stream_write_string(f, ") {\n");      Stream_write_string(f, ") {\n");
682      instrument_statement(node->pn_kid2, f, indent + 2);      if (is_jscoverage_if && node->pn_kid3) {
683          uint16_t else_start = node->pn_kid3->pn_pos.begin.lineno;
684          uint16_t else_end = node->pn_kid3->pn_pos.end.lineno + 1;
685          Stream_printf(f, "%*s", indent + 2, "");
686          Stream_printf(f, "_$jscoverage['%s'].conditionals[%d] = %d;\n", file_id, else_start, else_end);
687        }
688        instrument_statement(node->pn_kid2, f, indent + 2, false);
689      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
690      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
691      if (node->pn_kid3) {  
692        if (node->pn_kid3 || is_jscoverage_if) {
693        Stream_printf(f, "%*s", indent, "");        Stream_printf(f, "%*s", indent, "");
694        Stream_write_string(f, "else {\n");        Stream_write_string(f, "else {\n");
695        instrument_statement(node->pn_kid3, f, indent + 2);  
696          if (is_jscoverage_if) {
697            uint16_t if_start = node->pn_kid2->pn_pos.begin.lineno + 1;
698            uint16_t if_end = node->pn_kid2->pn_pos.end.lineno + 1;
699            Stream_printf(f, "%*s", indent + 2, "");
700            Stream_printf(f, "_$jscoverage['%s'].conditionals[%d] = %d;\n", file_id, if_start, if_end);
701          }
702    
703          if (node->pn_kid3) {
704            instrument_statement(node->pn_kid3, f, indent + 2, is_jscoverage_if);
705          }
706    
707        Stream_printf(f, "%*s", indent, "");        Stream_printf(f, "%*s", indent, "");
708        Stream_write_string(f, "}\n");        Stream_write_string(f, "}\n");
709      }      }
710    
711      break;      break;
712      }
713    case TOK_SWITCH:    case TOK_SWITCH:
714      assert(node->pn_arity == PN_BINARY);      assert(node->pn_arity == PN_BINARY);
715      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
# Line 591  Line 731 
731          abort();          abort();
732          break;          break;
733        }        }
734        instrument_statement(p->pn_right, f, indent + 2);        instrument_statement(p->pn_right, f, indent + 2, false);
735      }      }
736      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
737      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
# Line 606  Line 746 
746      Stream_write_string(f, "while (");      Stream_write_string(f, "while (");
747      instrument_expression(node->pn_left, f);      instrument_expression(node->pn_left, f);
748      Stream_write_string(f, ") {\n");      Stream_write_string(f, ") {\n");
749      instrument_statement(node->pn_right, f, indent + 2);      instrument_statement(node->pn_right, f, indent + 2, false);
750      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
751      break;      break;
752    case TOK_DO:    case TOK_DO:
753      assert(node->pn_arity == PN_BINARY);      assert(node->pn_arity == PN_BINARY);
754      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
755      Stream_write_string(f, "do {\n");      Stream_write_string(f, "do {\n");
756      instrument_statement(node->pn_left, f, indent + 2);      instrument_statement(node->pn_left, f, indent + 2, false);
757      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
758      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
759      Stream_write_string(f, "while (");      Stream_write_string(f, "while (");
# Line 676  Line 816 
816        break;        break;
817      }      }
818      Stream_write_string(f, ") {\n");      Stream_write_string(f, ") {\n");
819      instrument_statement(node->pn_right, f, indent + 2);      instrument_statement(node->pn_right, f, indent + 2, false);
820      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
821      break;      break;
822    case TOK_THROW:    case TOK_THROW:
# Line 689  Line 829 
829    case TOK_TRY:    case TOK_TRY:
830      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
831      Stream_write_string(f, "try {\n");      Stream_write_string(f, "try {\n");
832      instrument_statement(node->pn_kid1, f, indent + 2);      instrument_statement(node->pn_kid1, f, indent + 2, false);
833      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
834      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
835      {      if (node->pn_kid2) {
836        for (JSParseNode * catch = node->pn_kid2; catch != NULL; catch = catch->pn_kid2) {        assert(node->pn_kid2->pn_type == TOK_RESERVED);
837          for (JSParseNode * scope = node->pn_kid2->pn_head; scope != NULL; scope = scope->pn_next) {
838            assert(scope->pn_type == TOK_LEXICALSCOPE);
839            JSParseNode * catch = scope->pn_expr;
840          assert(catch->pn_type == TOK_CATCH);          assert(catch->pn_type == TOK_CATCH);
841          Stream_printf(f, "%*s", indent, "");          Stream_printf(f, "%*s", indent, "");
842          Stream_write_string(f, "catch (");          Stream_write_string(f, "catch (");
843          assert(catch->pn_kid1->pn_arity == PN_NAME);          assert(catch->pn_kid1->pn_arity == PN_NAME);
844          print_string_atom(catch->pn_kid1->pn_atom, f);          print_string_atom(catch->pn_kid1->pn_atom, f);
845          if (catch->pn_kid1->pn_expr) {          if (catch->pn_kid2) {
846            Stream_write_string(f, " if ");            Stream_write_string(f, " if ");
847            instrument_expression(catch->pn_kid1->pn_expr, f);            instrument_expression(catch->pn_kid2, f);
848          }          }
849          Stream_write_string(f, ") {\n");          Stream_write_string(f, ") {\n");
850          instrument_statement(catch->pn_kid3, f, indent + 2);          instrument_statement(catch->pn_kid3, f, indent + 2, false);
851          Stream_printf(f, "%*s", indent, "");          Stream_printf(f, "%*s", indent, "");
852          Stream_write_string(f, "}\n");          Stream_write_string(f, "}\n");
853        }        }
# Line 712  Line 855 
855      if (node->pn_kid3) {      if (node->pn_kid3) {
856        Stream_printf(f, "%*s", indent, "");        Stream_printf(f, "%*s", indent, "");
857        Stream_write_string(f, "finally {\n");        Stream_write_string(f, "finally {\n");
858        instrument_statement(node->pn_kid3, f, indent + 2);        instrument_statement(node->pn_kid3, f, indent + 2, false);
859        Stream_printf(f, "%*s", indent, "");        Stream_printf(f, "%*s", indent, "");
860        Stream_write_string(f, "}\n");        Stream_write_string(f, "}\n");
861      }      }
# Line 738  Line 881 
881      Stream_write_string(f, "with (");      Stream_write_string(f, "with (");
882      instrument_expression(node->pn_left, f);      instrument_expression(node->pn_left, f);
883      Stream_write_string(f, ") {\n");      Stream_write_string(f, ") {\n");
884      instrument_statement(node->pn_right, f, indent + 2);      instrument_statement(node->pn_right, f, indent + 2, false);
885      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
886      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");
887      break;      break;
# Line 776  Line 919 
919      /*      /*
920      ... use output_statement instead of instrument_statement.      ... use output_statement instead of instrument_statement.
921      */      */
922      output_statement(node->pn_expr, f, indent);      output_statement(node->pn_expr, f, indent, false);
923      break;      break;
924    default:    default:
925      fatal("unsupported node type in file %s: %d", file_id, node->pn_type);      fatal("unsupported node type in file %s: %d", file_id, node->pn_type);
# Line 788  Line 931 
931  TOK_FUNCTION is handled as a statement and as an expression.  TOK_FUNCTION is handled as a statement and as an expression.
932  TOK_EXPORT, TOK_IMPORT are not handled.  TOK_EXPORT, TOK_IMPORT are not handled.
933  */  */
934  static void instrument_statement(JSParseNode * node, Stream * f, int indent) {  static void instrument_statement(JSParseNode * node, Stream * f, int indent, bool is_jscoverage_if) {
935    if (node->pn_type != TOK_LC) {    if (node->pn_type != TOK_LC) {
936      int line = node->pn_pos.begin.lineno;      uint16_t line = node->pn_pos.begin.lineno;
937        if (line > num_lines) {
938          fatal("%s: script contains more than 65,535 lines", file_id);
939        }
940    
941      /* the root node has line number 0 */      /* the root node has line number 0 */
942      if (line != 0) {      if (line != 0) {
943        Stream_printf(f, "%*s", indent, "");        Stream_printf(f, "%*s", indent, "");
# Line 798  Line 945 
945        lines[line - 1] = 1;        lines[line - 1] = 1;
946      }      }
947    }    }
948    output_statement(node, f, indent);    output_statement(node, f, indent, is_jscoverage_if);
949  }  }
950    
951  void jscoverage_instrument_js(const char * id, Stream * input, Stream * output) {  static bool characters_start_with(const jschar * characters, size_t line_start, size_t line_end, const char * prefix) {
952    file_id = id;    const jschar * characters_end = characters + line_end;
953      const jschar * cp = characters + line_start;
954    /* scan the javascript */    const char * bp = prefix;
955    size_t input_length = input->length;    for (;;) {
956    jschar * base = js_InflateString(context, input->data, &input_length);      if (*bp == '\0') {
957    if (base == NULL) {        return true;
958      fatal("out of memory");      }
959        else if (cp == characters_end) {
960          return false;
961        }
962        else if (*cp != *bp) {
963          return false;
964        }
965        bp++;
966        cp++;
967    }    }
968    JSTokenStream * token_stream = js_NewTokenStream(context, base, input_length, NULL, 1, NULL);  }
969    if (token_stream == NULL) {  
970      fatal("cannot create token stream from file: %s", file_id);  static bool characters_are_white_space(const jschar * characters, size_t line_start, size_t line_end) {
971      /* XXX - other Unicode space */
972      const jschar * end = characters + line_end;
973      for (const jschar * p = characters + line_start; p < end; p++) {
974        jschar c = *p;
975        if (c == 0x9 || c == 0xB || c == 0xC || c == 0x20 || c == 0xA0) {
976          continue;
977        }
978        else {
979          return false;
980        }
981    }    }
982      return true;
983    }
984    
985    static void error_reporter(JSContext * context, const char * message, JSErrorReport * report) {
986      fprintf(stderr, "jscoverage: parse error: line %u: %s\n", report->lineno, message);
987    }
988    
989    void jscoverage_instrument_js(const char * id, const uint16_t * characters, size_t num_characters, Stream * output) {
990      file_id = id;
991    
992    /* parse the javascript */    /* parse the javascript */
993    JSParseNode * node = js_ParseTokenStream(context, global, token_stream);    JSParseContext parse_context;
994      if (! js_InitParseContext(context, &parse_context, NULL, NULL, characters, num_characters, NULL, NULL, 1)) {
995        fatal("cannot create token stream from file: %s", file_id);
996      }
997      JSErrorReporter old_error_reporter = JS_SetErrorReporter(context, error_reporter);
998      JSParseNode * node = js_ParseScript(context, global, &parse_context);
999    if (node == NULL) {    if (node == NULL) {
1000        js_ReportUncaughtException(context);
1001      fatal("parse error in file: %s", file_id);      fatal("parse error in file: %s", file_id);
1002    }    }
1003    int num_lines = node->pn_pos.end.lineno;    JS_SetErrorReporter(context, old_error_reporter);
1004      num_lines = node->pn_pos.end.lineno;
1005    lines = xmalloc(num_lines);    lines = xmalloc(num_lines);
1006    for (int i = 0; i < num_lines; i++) {    for (unsigned int i = 0; i < num_lines; i++) {
1007      lines[i] = 0;      lines[i] = 0;
1008    }    }
1009    
1010      /* search code for conditionals */
1011      exclusive_directives = xnew(bool, num_lines);
1012      for (unsigned int i = 0; i < num_lines; i++) {
1013        exclusive_directives[i] = false;
1014      }
1015    
1016      bool has_conditionals = false;
1017      struct IfDirective * if_directives = NULL;
1018      size_t line_number = 0;
1019      size_t i = 0;
1020      while (i < num_characters) {
1021        if (line_number == UINT16_MAX) {
1022          fatal("%s: script has more than 65,535 lines", file_id);
1023        }
1024        line_number++;
1025        size_t line_start = i;
1026        jschar c;
1027        bool done = false;
1028        while (! done && i < num_characters) {
1029          c = characters[i];
1030          switch (c) {
1031          case '\r':
1032          case '\n':
1033          case 0x2028:
1034          case 0x2029:
1035            done = true;
1036            break;
1037          default:
1038            i++;
1039          }
1040        }
1041        size_t line_end = i;
1042        if (i < num_characters) {
1043          i++;
1044          if (c == '\r' && i < num_characters && characters[i] == '\n') {
1045            i++;
1046          }
1047        }
1048    
1049        if (characters_start_with(characters, line_start, line_end, "//#JSCOVERAGE_IF")) {
1050          has_conditionals = true;
1051    
1052          if (characters_are_white_space(characters, line_start + 16, line_end)) {
1053            exclusive_directives[line_number - 1] = true;
1054          }
1055          else {
1056            struct IfDirective * if_directive = xnew(struct IfDirective, 1);
1057            if_directive->condition_start = characters + line_start + 16;
1058            if_directive->condition_end = characters + line_end;
1059            if_directive->start_line = line_number;
1060            if_directive->end_line = 0;
1061            if_directive->next = if_directives;
1062            if_directives = if_directive;
1063          }
1064        }
1065        else if (characters_start_with(characters, line_start, line_end, "//#JSCOVERAGE_ENDIF")) {
1066          for (struct IfDirective * p = if_directives; p != NULL; p = p->next) {
1067            if (p->end_line == 0) {
1068              p->end_line = line_number;
1069              break;
1070            }
1071          }
1072        }
1073      }
1074    
1075    /*    /*
1076    An instrumented JavaScript file has 3 sections:    An instrumented JavaScript file has 4 sections:
1077    1. initialization    1. initialization
1078    2. instrumented source code    2. instrumented source code
1079    3. original source code (TODO)    3. conditionals
1080      4. original source code
1081    */    */
1082    
1083    Stream * instrumented = Stream_new(0);    Stream * instrumented = Stream_new(0);
1084    instrument_statement(node, instrumented, 0);    instrument_statement(node, instrumented, 0, false);
1085      js_FinishParseContext(context, &parse_context);
1086    
1087    /* write line number info to the output */    /* write line number info to the output */
1088    Stream_write_string(output, "/* automatically generated by JSCoverage - do not edit */\n");    Stream_write_string(output, "/* automatically generated by JSCoverage - do not edit */\n");
# Line 850  Line 1098 
1098    Stream_write_string(output, "}\n");    Stream_write_string(output, "}\n");
1099    free(lines);    free(lines);
1100    lines = NULL;    lines = NULL;
1101      free(exclusive_directives);
1102      exclusive_directives = NULL;
1103    
1104      /* conditionals */
1105      if (has_conditionals) {
1106        Stream_printf(output, "_$jscoverage['%s'].conditionals = [];\n", file_id);
1107      }
1108    
1109    /* copy the instrumented source code to the output */    /* copy the instrumented source code to the output */
1110    Stream_write(output, instrumented->data, instrumented->length);    Stream_write(output, instrumented->data, instrumented->length);
1111    Stream_write_char(output, '\n');  
1112      /* conditionals */
1113      for (struct IfDirective * if_directive = if_directives; if_directive != NULL; if_directive = if_directive->next) {
1114        Stream_write_string(output, "if (!(");
1115        print_javascript(if_directive->condition_start, if_directive->condition_end - if_directive->condition_start, output);
1116        Stream_write_string(output, ")) {\n");
1117        Stream_printf(output, "  _$jscoverage['%s'].conditionals[%d] = %d;\n", file_id, if_directive->start_line, if_directive->end_line);
1118        Stream_write_string(output, "}\n");
1119      }
1120    
1121      /* free */
1122      while (if_directives != NULL) {
1123        struct IfDirective * if_directive = if_directives;
1124        if_directives = if_directives->next;
1125        free(if_directive);
1126      }
1127    
1128    /* copy the original source to the output */    /* copy the original source to the output */
1129    size_t i = 0;    Stream_printf(output, "_$jscoverage['%s'].source = ", file_id);
1130    while (i < input_length) {    jscoverage_write_source(id, characters, num_characters, output);
1131      Stream_write_string(output, "// ");    Stream_printf(output, ";\n");
     size_t line_start = i;  
     while (i < input_length && base[i] != '\r' && base[i] != '\n') {  
       i++;  
     }  
1132    
1133      size_t line_end = i;    Stream_delete(instrumented);
1134      if (i < input_length) {  
1135        if (base[i] == '\r') {    file_id = NULL;
1136          line_end = i;  }
1137    
1138    void jscoverage_write_source(const char * id, const jschar * characters, size_t num_characters, Stream * output) {
1139      Stream_write_string(output, "[");
1140      if (jscoverage_highlight) {
1141        Stream * highlighted_stream = Stream_new(num_characters);
1142        jscoverage_highlight_js(context, id, characters, num_characters, highlighted_stream);
1143        size_t i = 0;
1144        while (i < highlighted_stream->length) {
1145          if (i > 0) {
1146            Stream_write_char(output, ',');
1147          }
1148    
1149          Stream_write_char(output, '"');
1150          bool done = false;
1151          while (! done) {
1152            char c = highlighted_stream->data[i];
1153            switch (c) {
1154            case 0x8:
1155              /* backspace */
1156              Stream_write_string(output, "\\b");
1157              break;
1158            case 0x9:
1159              /* horizontal tab */
1160              Stream_write_string(output, "\\t");
1161              break;
1162            case 0xa:
1163              /* line feed (new line) */
1164              done = true;
1165              break;
1166            /* IE doesn't support this */
1167            /*
1168            case 0xb:
1169              Stream_write_string(output, "\\v");
1170              break;
1171            */
1172            case 0xc:
1173              /* form feed */
1174              Stream_write_string(output, "\\f");
1175              break;
1176            case 0xd:
1177              /* carriage return */
1178              done = true;
1179              if (i + 1 < highlighted_stream->length && highlighted_stream->data[i + 1] == '\n') {
1180                i++;
1181              }
1182              break;
1183            case '"':
1184              Stream_write_string(output, "\\\"");
1185              break;
1186            case '\\':
1187              Stream_write_string(output, "\\\\");
1188              break;
1189            default:
1190              Stream_write_char(output, c);
1191              break;
1192            }
1193          i++;          i++;
1194          if (i < input_length && base[i] == '\n') {          if (i >= highlighted_stream->length) {
1195            i++;            done = true;
1196          }          }
1197        }        }
1198        else if (base[i] == '\n') {        Stream_write_char(output, '"');
1199          line_end = i;      }
1200        Stream_delete(highlighted_stream);
1201      }
1202      else {
1203        size_t i = 0;
1204        while (i < num_characters) {
1205          if (i > 0) {
1206            Stream_write_char(output, ',');
1207          }
1208    
1209          Stream_write_char(output, '"');
1210          bool done = false;
1211          while (! done) {
1212            jschar c = characters[i];
1213            switch (c) {
1214            case 0x8:
1215              /* backspace */
1216              Stream_write_string(output, "\\b");
1217              break;
1218            case 0x9:
1219              /* horizontal tab */
1220              Stream_write_string(output, "\\t");
1221              break;
1222            case 0xa:
1223              /* line feed (new line) */
1224              done = true;
1225              break;
1226            /* IE doesn't support this */
1227            /*
1228            case 0xb:
1229              Stream_write_string(output, "\\v");
1230              break;
1231            */
1232            case 0xc:
1233              /* form feed */
1234              Stream_write_string(output, "\\f");
1235              break;
1236            case 0xd:
1237              /* carriage return */
1238              done = true;
1239              if (i + 1 < num_characters && characters[i + 1] == '\n') {
1240                i++;
1241              }
1242              break;
1243            case '"':
1244              Stream_write_string(output, "\\\"");
1245              break;
1246            case '\\':
1247              Stream_write_string(output, "\\\\");
1248              break;
1249            case '&':
1250              Stream_write_string(output, "&amp;");
1251              break;
1252            case '<':
1253              Stream_write_string(output, "&lt;");
1254              break;
1255            case '>':
1256              Stream_write_string(output, "&gt;");
1257              break;
1258            case 0x2028:
1259            case 0x2029:
1260              done = true;
1261              break;
1262            default:
1263              if (32 <= c && c <= 126) {
1264                Stream_write_char(output, c);
1265              }
1266              else {
1267                Stream_printf(output, "&#%d;", c);
1268              }
1269              break;
1270            }
1271          i++;          i++;
1272            if (i >= num_characters) {
1273              done = true;
1274            }
1275        }        }
1276        else {        Stream_write_char(output, '"');
1277          abort();      }
1278      }
1279      Stream_write_string(output, "]");
1280    }
1281    
1282    void jscoverage_copy_resources(const char * destination_directory) {
1283      copy_resource("jscoverage.html", destination_directory);
1284      copy_resource("jscoverage.css", destination_directory);
1285      copy_resource("jscoverage.js", destination_directory);
1286      copy_resource("jscoverage-ie.css", destination_directory);
1287      copy_resource("jscoverage-throbber.gif", destination_directory);
1288      copy_resource("jscoverage-highlight.css", destination_directory);
1289    }
1290    
1291    /*
1292    coverage reports
1293    */
1294    
1295    struct FileCoverageList {
1296      FileCoverage * file_coverage;
1297      struct FileCoverageList * next;
1298    };
1299    
1300    struct Coverage {
1301      JSHashTable * coverage_table;
1302      struct FileCoverageList * coverage_list;
1303    };
1304    
1305    static int compare_strings(const void * p1, const void * p2) {
1306      return strcmp(p1, p2) == 0;
1307    }
1308    
1309    Coverage * Coverage_new(void) {
1310      Coverage * result = xmalloc(sizeof(Coverage));
1311      result->coverage_table = JS_NewHashTable(1024, JS_HashString, compare_strings, NULL, NULL, NULL);
1312      if (result->coverage_table == NULL) {
1313        fatal("cannot create hash table");
1314      }
1315      result->coverage_list = NULL;
1316      return result;
1317    }
1318    
1319    void Coverage_delete(Coverage * coverage) {
1320      JS_HashTableDestroy(coverage->coverage_table);
1321      struct FileCoverageList * p = coverage->coverage_list;
1322      while (p != NULL) {
1323        free(p->file_coverage->coverage_lines);
1324        if (p->file_coverage->source_lines != NULL) {
1325          for (uint32 i = 0; i < p->file_coverage->num_source_lines; i++) {
1326            free(p->file_coverage->source_lines[i]);
1327        }        }
1328          free(p->file_coverage->source_lines);
1329      }      }
1330        free(p->file_coverage->id);
1331        free(p->file_coverage);
1332        struct FileCoverageList * q = p;
1333        p = p->next;
1334        free(q);
1335      }
1336      free(coverage);
1337    }
1338    
1339      char * line = js_DeflateString(context, base + line_start, line_end - line_start);  struct EnumeratorArg {
1340      Stream_write_string(output, line);    CoverageForeachFunction f;
1341      Stream_write_char(output, '\n');    void * p;
1342      JS_free(context, line);  };
1343    
1344    static intN enumerator(JSHashEntry * entry, intN i, void * arg) {
1345      struct EnumeratorArg * enumerator_arg = arg;
1346      enumerator_arg->f(entry->value, i, enumerator_arg->p);
1347      return 0;
1348    }
1349    
1350    void Coverage_foreach_file(Coverage * coverage, CoverageForeachFunction f, void * p) {
1351      struct EnumeratorArg enumerator_arg;
1352      enumerator_arg.f = f;
1353      enumerator_arg.p = p;
1354      JS_HashTableEnumerateEntries(coverage->coverage_table, enumerator, &enumerator_arg);
1355    }
1356    
1357    int jscoverage_parse_json(Coverage * coverage, const uint8_t * json, size_t length) {
1358      int result = 0;
1359    
1360      jschar * base = js_InflateString(context, (char *) json, &length);
1361      if (base == NULL) {
1362        fatal("out of memory");
1363    }    }
1364    
1365    Stream_delete(instrumented);    jschar * parenthesized_json = xnew(jschar, addst(length, 2));
1366      parenthesized_json[0] = '(';
1367      memcpy(parenthesized_json + 1, base, mulst(length, sizeof(jschar)));
1368      parenthesized_json[length + 1] = ')';
1369    
1370    JS_free(context, base);    JS_free(context, base);
1371    
1372    file_id = NULL;    JSParseContext parse_context;
1373      if (! js_InitParseContext(context, &parse_context, NULL, NULL, parenthesized_json, length + 2, NULL, NULL, 1)) {
1374        free(parenthesized_json);
1375        return -1;
1376      }
1377      JSParseNode * root = js_ParseScript(context, global, &parse_context);
1378      free(parenthesized_json);
1379      if (root == NULL) {
1380        result = -1;
1381        goto done;
1382      }
1383    
1384      /* root node must be TOK_LC */
1385      if (root->pn_type != TOK_LC) {
1386        result = -1;
1387        goto done;
1388      }
1389      JSParseNode * semi = root->pn_u.list.head;
1390    
1391      /* the list must be TOK_SEMI and it must contain only one element */
1392      if (semi->pn_type != TOK_SEMI || semi->pn_next != NULL) {
1393        result = -1;
1394        goto done;
1395      }
1396      JSParseNode * parenthesized = semi->pn_kid;
1397    
1398      /* this must be a parenthesized expression */
1399      if (parenthesized->pn_type != TOK_RP) {
1400        result = -1;
1401        goto done;
1402      }
1403      JSParseNode * object = parenthesized->pn_kid;
1404    
1405      /* this must be an object literal */
1406      if (object->pn_type != TOK_RC) {
1407        result = -1;
1408        goto done;
1409      }
1410    
1411      for (JSParseNode * p = object->pn_head; p != NULL; p = p->pn_next) {
1412        /* every element of this list must be TOK_COLON */
1413        if (p->pn_type != TOK_COLON) {
1414          result = -1;
1415          goto done;
1416        }
1417    
1418        /* the key must be a string representing the file */
1419        JSParseNode * key = p->pn_left;
1420        if (key->pn_type != TOK_STRING || ! ATOM_IS_STRING(key->pn_atom)) {
1421          result = -1;
1422          goto done;
1423        }
1424        char * id_bytes = JS_GetStringBytes(ATOM_TO_STRING(key->pn_atom));
1425    
1426        /* the value must be an object literal OR an array */
1427        JSParseNode * value = p->pn_right;
1428        if (! (value->pn_type == TOK_RC || value->pn_type == TOK_RB)) {
1429          result = -1;
1430          goto done;
1431        }
1432    
1433        JSParseNode * array = NULL;
1434        JSParseNode * source = NULL;
1435        if (value->pn_type == TOK_RB) {
1436          /* an array */
1437          array = value;
1438        }
1439        else if (value->pn_type == TOK_RC) {
1440          /* an object literal */
1441          if (value->pn_count != 2) {
1442            result = -1;
1443            goto done;
1444          }
1445          for (JSParseNode * element = value->pn_head; element != NULL; element = element->pn_next) {
1446            if (element->pn_type != TOK_COLON) {
1447              result = -1;
1448              goto done;
1449            }
1450            JSParseNode * left = element->pn_left;
1451            if (left->pn_type != TOK_STRING || ! ATOM_IS_STRING(left->pn_atom)) {
1452              result = -1;
1453              goto done;
1454            }
1455            const char * s = JS_GetStringBytes(ATOM_TO_STRING(left->pn_atom));
1456            if (strcmp(s, "coverage") == 0) {
1457              array = element->pn_right;
1458              if (array->pn_type != TOK_RB) {
1459                result = -1;
1460                goto done;
1461              }
1462            }
1463            else if (strcmp(s, "source") == 0) {
1464              source = element->pn_right;
1465              if (source->pn_type != TOK_RB) {
1466                result = -1;
1467                goto done;
1468              }
1469            }
1470            else {
1471              result = -1;
1472              goto done;
1473            }
1474          }
1475        }
1476        else {
1477          result = -1;
1478          goto done;
1479        }
1480    
1481        if (array == NULL) {
1482          result = -1;
1483          goto done;
1484        }
1485    
1486        /* look up the file in the coverage table */
1487        FileCoverage * file_coverage = JS_HashTableLookup(coverage->coverage_table, id_bytes);
1488        if (file_coverage == NULL) {
1489          /* not there: create a new one */
1490          char * id = xstrdup(id_bytes);
1491          file_coverage = xmalloc(sizeof(FileCoverage));
1492          file_coverage->id = id;
1493          file_coverage->num_coverage_lines = array->pn_count;
1494          file_coverage->coverage_lines = xnew(int, array->pn_count);
1495          file_coverage->source_lines = NULL;
1496    
1497          /* set coverage for all lines */
1498          uint32 i = 0;
1499          for (JSParseNode * element = array->pn_head; element != NULL; element = element->pn_next, i++) {
1500            if (element->pn_type == TOK_NUMBER) {
1501              file_coverage->coverage_lines[i] = (int) element->pn_dval;
1502            }
1503            else if (element->pn_type == TOK_PRIMARY && element->pn_op == JSOP_NULL) {
1504              file_coverage->coverage_lines[i] = -1;
1505            }
1506            else {
1507              result = -1;
1508              goto done;
1509            }
1510          }
1511          assert(i == array->pn_count);
1512    
1513          /* add to the hash table */
1514          JS_HashTableAdd(coverage->coverage_table, id, file_coverage);
1515          struct FileCoverageList * coverage_list = xmalloc(sizeof(struct FileCoverageList));
1516          coverage_list->file_coverage = file_coverage;
1517          coverage_list->next = coverage->coverage_list;
1518          coverage->coverage_list = coverage_list;
1519        }
1520        else {
1521          /* sanity check */
1522          assert(strcmp(file_coverage->id, id_bytes) == 0);
1523          if (file_coverage->num_coverage_lines != array->pn_count) {
1524            result = -2;
1525            goto done;
1526          }
1527    
1528          /* merge the coverage */
1529          uint32 i = 0;
1530          for (JSParseNode * element = array->pn_head; element != NULL; element = element->pn_next, i++) {
1531            if (element->pn_type == TOK_NUMBER) {
1532              if (file_coverage->coverage_lines[i] == -1) {
1533                result = -2;
1534                goto done;
1535              }
1536              file_coverage->coverage_lines[i] += (int) element->pn_dval;
1537            }
1538            else if (element->pn_type == TOK_PRIMARY && element->pn_op == JSOP_NULL) {
1539              if (file_coverage->coverage_lines[i] != -1) {
1540                result = -2;
1541                goto done;
1542              }
1543            }
1544            else {
1545              result = -1;
1546              goto done;
1547            }
1548          }
1549          assert(i == array->pn_count);
1550        }
1551    
1552        /* if this JSON file has source, use it */
1553        if (file_coverage->source_lines == NULL && source != NULL) {
1554          file_coverage->num_source_lines = source->pn_count;
1555          file_coverage->source_lines = xnew(char *, source->pn_count);
1556          uint32 i = 0;
1557          for (JSParseNode * element = source->pn_head; element != NULL; element = element->pn_next, i++) {
1558            if (element->pn_type != TOK_STRING) {
1559              result = -1;
1560              goto done;
1561            }
1562            file_coverage->source_lines[i] = xstrdup(JS_GetStringBytes(ATOM_TO_STRING(element->pn_atom)));
1563          }
1564          assert(i == source->pn_count);
1565        }
1566      }
1567    
1568    done:
1569      js_FinishParseContext(context, &parse_context);
1570      return result;
1571  }  }

Legend:
Removed from v.101  
changed lines
  Added in v.336

  ViewVC Help
Powered by ViewVC 1.1.24