Path: blob/main/build/npm/gyp/custom-headers/v8-source-location.patch
4774 views
--- v8-source-location.h 2025-10-28 05:57:351+++ v8-source-location.h 2025-11-07 03:10:022@@ -6,12 +6,21 @@3#define INCLUDE_SOURCE_LOCATION_H_45#include <cstddef>6-#include <source_location>7#include <string>89#include "v8config.h" // NOLINT(build/include_directory)1011+#if defined(__has_builtin)12+#define V8_SUPPORTS_SOURCE_LOCATION \13+ (__has_builtin(__builtin_FUNCTION) && __has_builtin(__builtin_FILE) && \14+ __has_builtin(__builtin_LINE)) // NOLINT15+#elif defined(V8_CC_GNU) && __GNUC__ >= 716#define V8_SUPPORTS_SOURCE_LOCATION 117+#elif defined(V8_CC_INTEL) && __ICC >= 180018+#define V8_SUPPORTS_SOURCE_LOCATION 119+#else20+#define V8_SUPPORTS_SOURCE_LOCATION 021+#endif2223namespace v8 {2425@@ -25,10 +34,15 @@26* Construct source location information corresponding to the location of the27* call site.28*/29+#if V8_SUPPORTS_SOURCE_LOCATION30static constexpr SourceLocation Current(31- const std::source_location& loc = std::source_location::current()) {32- return SourceLocation(loc);33+ const char* function = __builtin_FUNCTION(),34+ const char* file = __builtin_FILE(), size_t line = __builtin_LINE()) {35+ return SourceLocation(function, file, line);36}37+#else38+ static constexpr SourceLocation Current() { return SourceLocation(); }39+#endif // V8_SUPPORTS_SOURCE_LOCATION40#ifdef DEBUG41static constexpr SourceLocation CurrentIfDebug(42const std::source_location& loc = std::source_location::current()) {43@@ -49,21 +63,21 @@44*45* \returns the function name as cstring.46*/47- constexpr const char* Function() const { return loc_.function_name(); }48+ constexpr const char* Function() const { return function_; }4950/**51* Returns the name of the current source file represented by this object.52*53* \returns the file name as cstring.54*/55- constexpr const char* FileName() const { return loc_.file_name(); }56+ constexpr const char* FileName() const { return file_; }5758/**59* Returns the line number represented by this object.60*61* \returns the line number.62*/63- constexpr size_t Line() const { return loc_.line(); }64+ constexpr size_t Line() const { return line_; }6566/**67* Returns a human-readable string representing this object.68@@ -71,18 +85,19 @@69* \returns a human-readable string representing source location information.70*/71std::string ToString() const {72- if (loc_.line() == 0) {73+ if (!file_) {74return {};75}76- return std::string(loc_.function_name()) + "@" + loc_.file_name() + ":" +77- std::to_string(loc_.line());78+ return std::string(function_) + "@" + file_ + ":" + std::to_string(line_);79}8081private:82- constexpr explicit SourceLocation(const std::source_location& loc)83- : loc_(loc) {}84+ constexpr SourceLocation(const char* function, const char* file, size_t line)85+ : function_(function), file_(file), line_(line) {}8687- std::source_location loc_;88+ const char* function_ = nullptr;89+ const char* file_ = nullptr;90+ size_t line_ = 0u;91};9293} // namespace v8949596