File indexing completed on 2026-09-20 09:15:51
0001
0002
0003
0004
0005 #ifndef INCLUDE_SOURCE_LOCATION_H_
0006 #define INCLUDE_SOURCE_LOCATION_H_
0007
0008 #include <cstddef>
0009 #include <source_location>
0010 #include <string>
0011
0012 #include "v8config.h" // NOLINT(build/include_directory)
0013
0014 #define V8_SUPPORTS_SOURCE_LOCATION 1
0015
0016 namespace v8 {
0017
0018
0019
0020
0021
0022 class V8_EXPORT SourceLocation final {
0023 public:
0024
0025
0026
0027
0028 static constexpr SourceLocation Current(
0029 const std::source_location& loc = std::source_location::current()) {
0030 return SourceLocation(loc);
0031 }
0032 #ifdef DEBUG
0033 static constexpr SourceLocation CurrentIfDebug(
0034 const std::source_location& loc = std::source_location::current()) {
0035 return SourceLocation(loc);
0036 }
0037 #else
0038 static constexpr SourceLocation CurrentIfDebug() { return {}; }
0039 #endif
0040
0041
0042
0043
0044 constexpr SourceLocation() = default;
0045
0046
0047
0048
0049
0050
0051
0052 constexpr const char* Function() const { return loc_.function_name(); }
0053
0054
0055
0056
0057
0058
0059 constexpr const char* FileName() const { return loc_.file_name(); }
0060
0061
0062
0063
0064
0065
0066 constexpr size_t Line() const { return loc_.line(); }
0067
0068
0069
0070
0071
0072
0073 std::string ToString() const;
0074
0075
0076
0077
0078
0079
0080 operator bool() const { return loc_.line() != 0; }
0081
0082 private:
0083 constexpr explicit SourceLocation(const std::source_location& loc)
0084 : loc_(loc) {}
0085
0086 std::source_location loc_;
0087 };
0088
0089 }
0090
0091 #endif