MCPcopy Create free account
hub / github.com/GNOME/gjs / format_syntax_error_location

Function format_syntax_error_location

gjs/jsapi-util.cpp:424–460  ·  view source on GitHub ↗

Helper function: format the file name, line number, and column number where a SyntaxError occurred.

Source from the content-addressed store, hash-verified

422// Helper function: format the file name, line number, and column number where a
423// SyntaxError occurred.
424static 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
462using CauseSet = JS::GCHashSet<JSObject*, js::DefaultHasher<JSObject*>,
463 js::SystemAllocPolicy>;

Callers 1

Calls 3

log_exception_briefFunction · 0.85
toStringMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected