1 |
/* |
/* |
2 |
instrument-js.c - JavaScript instrumentation routines |
instrument-js.c - JavaScript instrumentation routines |
3 |
Copyright (C) 2007 siliconforks.com |
Copyright (C) 2007, 2008 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 |
385 |
the dot syntax. |
the dot syntax. |
386 |
*/ |
*/ |
387 |
instrument_expression(node->pn_expr, f); |
instrument_expression(node->pn_expr, f); |
388 |
/* |
assert(ATOM_IS_STRING(node->pn_atom)); |
389 |
fputc('.', f); |
{ |
390 |
print_string_atom(node->pn_atom, f); |
JSString * s = ATOM_TO_STRING(node->pn_atom); |
391 |
*/ |
/* XXX - semantics changed in 1.7 */ |
392 |
fputc('[', f); |
if (! ATOM_KEYWORD(node->pn_atom) && js_IsIdentifier(s)) { |
393 |
print_quoted_string_atom(node->pn_atom, f); |
fputc('.', f); |
394 |
fputc(']', f); |
print_string_atom(node->pn_atom, f); |
395 |
|
} |
396 |
|
else { |
397 |
|
fputc('[', f); |
398 |
|
print_quoted_string_atom(node->pn_atom, f); |
399 |
|
fputc(']', f); |
400 |
|
} |
401 |
|
} |
402 |
break; |
break; |
403 |
case TOK_LB: |
case TOK_LB: |
404 |
instrument_expression(node->pn_left, f); |
instrument_expression(node->pn_left, f); |
801 |
output_statement(node, f, indent); |
output_statement(node, f, indent); |
802 |
} |
} |
803 |
|
|
804 |
static void instrument_js_stream(const char * id, int line, FILE * input, FILE * output) { |
static void instrument_js_stream(const char * id, int line, FILE * input, FILE * output, const char * temporary_file_name) { |
805 |
file_id = id; |
file_id = id; |
806 |
|
|
807 |
/* scan the javascript */ |
/* scan the javascript */ |
825 |
Create a temporary file - we can't write directly to the output because we |
Create a temporary file - we can't write directly to the output because we |
826 |
need to know the line number info first. |
need to know the line number info first. |
827 |
*/ |
*/ |
828 |
FILE * temporary = tmpfile(); |
FILE * temporary = fopen(temporary_file_name, "w+"); |
829 |
if (temporary == NULL) { |
if (temporary == NULL) { |
830 |
fatal("cannot create temporary file for script: %s", file_id); |
fatal("cannot create temporary file for script: %s", file_id); |
831 |
} |
} |
856 |
file_id = NULL; |
file_id = NULL; |
857 |
} |
} |
858 |
|
|
859 |
void jscoverage_instrument_js(const char * id, FILE * input, FILE * output) { |
void jscoverage_instrument_js(const char * id, FILE * input, FILE * output, const char * temporary_file_name) { |
860 |
instrument_js_stream(id, 0, input, output); |
instrument_js_stream(id, 0, input, output, temporary_file_name); |
861 |
} |
} |