/[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 454 by siliconforks, Sun Jul 26 17:09:09 2009 UTC revision 455 by siliconforks, Mon Sep 7 21:18:00 2009 UTC
# Line 438  Line 438 
438    Stream_write_char(f, '}');    Stream_write_char(f, '}');
439  }  }
440    
441    static void output_function_arguments(JSParseNode * node, Stream * f) {
442      JSParseNode * function_node = node->pn_head;
443      Stream_write_char(f, '(');
444      for (struct JSParseNode * p = function_node->pn_next; p != NULL; p = p->pn_next) {
445        if (p != function_node->pn_next) {
446          Stream_write_string(f, ", ");
447        }
448        output_expression(p, f, false);
449      }
450      Stream_write_char(f, ')');
451    }
452    
453  static void instrument_function_call(JSParseNode * node, Stream * f) {  static void instrument_function_call(JSParseNode * node, Stream * f) {
454    JSParseNode * function_node = node->pn_head;    JSParseNode * function_node = node->pn_head;
455    if (function_node->pn_type == TOK_FUNCTION) {    if (function_node->pn_type == TOK_FUNCTION) {
# Line 456  Line 468 
468      }      }
469    }    }
470    output_expression(function_node, f, false);    output_expression(function_node, f, false);
471    Stream_write_char(f, '(');    output_function_arguments(node, f);
   for (struct JSParseNode * p = function_node->pn_next; p != NULL; p = p->pn_next) {  
     if (p != node->pn_head->pn_next) {  
       Stream_write_string(f, ", ");  
     }  
     output_expression(p, f, false);  
   }  
   Stream_write_char(f, ')');  
472  }  }
473    
474  static void instrument_declarations(JSParseNode * list, Stream * f) {  static void instrument_declarations(JSParseNode * list, Stream * f) {
# Line 635  Line 640 
640      }      }
641      break;      break;
642    case TOK_NEW:    case TOK_NEW:
643        /*
644        For an expression like
645          new (f())();
646        SpiderMonkey creates a node with pn_head NOT in parentheses.  If we just
647        output pn_head, we end up with
648          new f()();
649        This is not correct, because it is parsed as
650          (new f())();
651        We can fix this by surrounding pn_head in parentheses.
652        */
653      Stream_write_string(f, "new ");      Stream_write_string(f, "new ");
654      instrument_function_call(node, f);      if (node->pn_head->pn_type != TOK_NAME) {
655          Stream_write_char(f, '(');
656        }
657        output_expression(node->pn_head, f, false);
658        if (node->pn_head->pn_type != TOK_NAME) {
659          Stream_write_char(f, ')');
660        }
661        output_function_arguments(node, f);
662      break;      break;
663    case TOK_DELETE:    case TOK_DELETE:
664      Stream_write_string(f, "delete ");      Stream_write_string(f, "delete ");

Legend:
Removed from v.454  
changed lines
  Added in v.455

  ViewVC Help
Powered by ViewVC 1.1.24