| 127 | } |
| 128 | |
| 129 | int main(int argc, char **argv) { |
| 130 | if (argc != 2) { |
| 131 | fprintf(stderr, "usage: jsc-runner file\n"); |
| 132 | exit(1); |
| 133 | } |
| 134 | |
| 135 | char *filename = argv[1]; |
| 136 | std::ifstream ifs(filename); |
| 137 | if (ifs.fail()) { |
| 138 | std::cerr << "Error opening \"" << filename << "\": " << strerror(errno) << "\n"; |
| 139 | exit(1); |
| 140 | } |
| 141 | std::string script( |
| 142 | (std::istreambuf_iterator<char>(ifs)), |
| 143 | (std::istreambuf_iterator<char>()) |
| 144 | ); |
| 145 | JSStringRef jsScript = JSStringCreateWithUTF8CString(script.c_str()); |
| 146 | JSStringRef jsURL = JSStringCreateWithUTF8CString(argv[1]); |
| 147 | |
| 148 | JSGlobalContextRef ctx = JSGlobalContextCreate(NULL); |
| 149 | add_native_hook( |
| 150 | ctx, |
| 151 | JSContextGetGlobalObject(ctx), |
| 152 | "print", |
| 153 | js_print |
| 154 | ); |
| 155 | |
| 156 | JSObjectRef jsPerfCounters = JSObjectMake(ctx, NULL, NULL); |
| 157 | add_native_hook( |
| 158 | ctx, |
| 159 | jsPerfCounters, |
| 160 | "init", |
| 161 | js_perf_counters_init |
| 162 | ); |
| 163 | add_native_hook( |
| 164 | ctx, |
| 165 | jsPerfCounters, |
| 166 | "getCounters", |
| 167 | js_perf_counters_get_counters |
| 168 | ); |
| 169 | JSObjectSetProperty( |
| 170 | ctx, |
| 171 | JSContextGetGlobalObject(ctx), |
| 172 | JSStringCreateWithUTF8CString("PerfCounters"), |
| 173 | jsPerfCounters, |
| 174 | kJSPropertyAttributeNone, |
| 175 | NULL |
| 176 | ); |
| 177 | |
| 178 | JSValueRef jsError = NULL; |
| 179 | JSValueRef result = JSEvaluateScript( |
| 180 | ctx, |
| 181 | jsScript, |
| 182 | NULL, |
| 183 | jsURL, |
| 184 | 0, |
| 185 | &jsError |
| 186 | ); |
nothing calls this directly
no test coverage detected