| 278 | } |
| 279 | |
| 280 | GJS_JSAPI_RETURN_CONVENTION |
| 281 | static bool gjs_console_interact(JSContext* cx, unsigned argc, JS::Value* vp) { |
| 282 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
| 283 | volatile bool eof, exit_warning; // accessed after setjmp() |
| 284 | JS::RootedObject global{cx, JS::CurrentGlobalOrNull(cx)}; |
| 285 | volatile int lineno; // accessed after setjmp() |
| 286 | volatile int startline; // accessed after setjmp() |
| 287 | GjsContextPrivate* gjs = GjsContextPrivate::from_cx(cx); |
| 288 | |
| 289 | #ifndef HAVE_READLINE_READLINE_H |
| 290 | int rl_end = 0; // nonzero if using readline and any text is typed in |
| 291 | #endif |
| 292 | |
| 293 | JS::SetWarningReporter(cx, gjs_console_warning_reporter); |
| 294 | |
| 295 | AutoCatchCtrlC ctrl_c; |
| 296 | |
| 297 | // Separate initialization from declaration because of possible overwriting |
| 298 | // when siglongjmp() jumps into this function |
| 299 | eof = exit_warning = false; |
| 300 | lineno = 1; |
| 301 | do { |
| 302 | /* |
| 303 | * Accumulate lines until we get a 'compilable unit' - one that either |
| 304 | * generates an error (before running out of source) or that compiles |
| 305 | * cleanly. This should be whenever we get a complete statement that |
| 306 | * coincides with the end of a line. |
| 307 | */ |
| 308 | startline = lineno; |
| 309 | std::string buffer; |
| 310 | do { |
| 311 | #ifdef HAVE_SIGNAL_H |
| 312 | // sigsetjmp() returns 0 if control flow encounters it normally, and |
| 313 | // nonzero if it's been jumped to. In the latter case, use a while |
| 314 | // loop so that we call sigsetjmp() a second time to reinit the jump |
| 315 | // buffer. |
| 316 | while (sigsetjmp(AutoCatchCtrlC::jump_buffer, 1) != 0) { |
| 317 | g_fprintf(stdout, "\n"); |
| 318 | if (buffer.empty() && rl_end == 0) { |
| 319 | if (!exit_warning) { |
| 320 | g_fprintf(stdout, |
| 321 | "(To exit, press Ctrl+C again or Ctrl+D)\n"); |
| 322 | exit_warning = true; |
| 323 | } else { |
| 324 | ctrl_c.raise_default(); |
| 325 | } |
| 326 | } else { |
| 327 | exit_warning = false; |
| 328 | } |
| 329 | buffer.clear(); |
| 330 | startline = lineno = 1; |
| 331 | } |
| 332 | #endif // HAVE_SIGNAL_H |
| 333 | |
| 334 | std::string temp_buf; |
| 335 | if (!gjs_console_readline(&temp_buf, |
| 336 | startline == lineno ? "gjs> " : ".... ", |
| 337 | gjs->repl_history_path())) { |
nothing calls this directly
no test coverage detected