Helper function: format the file name, line number, and column number where a SyntaxError occurred.
| 422 | // Helper function: format the file name, line number, and column number where a |
| 423 | // SyntaxError occurred. |
| 424 | static std::string format_syntax_error_location(JSContext* cx, |
| 425 | JS::HandleObject exc) { |
| 426 | const GjsAtoms& atoms = GjsContextPrivate::atoms(cx); |
| 427 | |
| 428 | JS::RootedValue property(cx); |
| 429 | int32_t line = 0; |
| 430 | if (JS_GetPropertyById(cx, exc, atoms.line_number(), &property)) { |
| 431 | if (property.isInt32()) |
| 432 | line = property.toInt32(); |
| 433 | } |
| 434 | log_exception_brief(cx); |
| 435 | |
| 436 | int32_t column = 0; |
| 437 | if (JS_GetPropertyById(cx, exc, atoms.column_number(), &property)) { |
| 438 | if (property.isInt32()) |
| 439 | column = property.toInt32(); |
| 440 | } |
| 441 | log_exception_brief(cx); |
| 442 | |
| 443 | JS::UniqueChars utf8_filename; |
| 444 | if (JS_GetPropertyById(cx, exc, atoms.file_name(), &property)) { |
| 445 | if (property.isString()) { |
| 446 | JS::RootedString str(cx, property.toString()); |
| 447 | utf8_filename = JS_EncodeStringToUTF8(cx, str); |
| 448 | } |
| 449 | } |
| 450 | log_exception_brief(cx); |
| 451 | |
| 452 | std::ostringstream out; |
| 453 | out << " @ "; |
| 454 | if (utf8_filename) |
| 455 | out << utf8_filename.get(); |
| 456 | else |
| 457 | out << "<unknown>"; |
| 458 | out << ":" << line << ":" << column; |
| 459 | return out.str(); |
| 460 | } |
| 461 | |
| 462 | using CauseSet = JS::GCHashSet<JSObject*, js::DefaultHasher<JSObject*>, |
| 463 | js::SystemAllocPolicy>; |
no test coverage detected