Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/npm/gyp/custom-headers/v8-source-location.patch
4774 views
1
--- v8-source-location.h 2025-10-28 05:57:35
2
+++ v8-source-location.h 2025-11-07 03:10:02
3
@@ -6,12 +6,21 @@
4
#define INCLUDE_SOURCE_LOCATION_H_
5
6
#include <cstddef>
7
-#include <source_location>
8
#include <string>
9
10
#include "v8config.h" // NOLINT(build/include_directory)
11
12
+#if defined(__has_builtin)
13
+#define V8_SUPPORTS_SOURCE_LOCATION \
14
+ (__has_builtin(__builtin_FUNCTION) && __has_builtin(__builtin_FILE) && \
15
+ __has_builtin(__builtin_LINE)) // NOLINT
16
+#elif defined(V8_CC_GNU) && __GNUC__ >= 7
17
#define V8_SUPPORTS_SOURCE_LOCATION 1
18
+#elif defined(V8_CC_INTEL) && __ICC >= 1800
19
+#define V8_SUPPORTS_SOURCE_LOCATION 1
20
+#else
21
+#define V8_SUPPORTS_SOURCE_LOCATION 0
22
+#endif
23
24
namespace v8 {
25
26
@@ -25,10 +34,15 @@
27
* Construct source location information corresponding to the location of the
28
* call site.
29
*/
30
+#if V8_SUPPORTS_SOURCE_LOCATION
31
static constexpr SourceLocation Current(
32
- const std::source_location& loc = std::source_location::current()) {
33
- return SourceLocation(loc);
34
+ const char* function = __builtin_FUNCTION(),
35
+ const char* file = __builtin_FILE(), size_t line = __builtin_LINE()) {
36
+ return SourceLocation(function, file, line);
37
}
38
+#else
39
+ static constexpr SourceLocation Current() { return SourceLocation(); }
40
+#endif // V8_SUPPORTS_SOURCE_LOCATION
41
#ifdef DEBUG
42
static constexpr SourceLocation CurrentIfDebug(
43
const std::source_location& loc = std::source_location::current()) {
44
@@ -49,21 +63,21 @@
45
*
46
* \returns the function name as cstring.
47
*/
48
- constexpr const char* Function() const { return loc_.function_name(); }
49
+ constexpr const char* Function() const { return function_; }
50
51
/**
52
* Returns the name of the current source file represented by this object.
53
*
54
* \returns the file name as cstring.
55
*/
56
- constexpr const char* FileName() const { return loc_.file_name(); }
57
+ constexpr const char* FileName() const { return file_; }
58
59
/**
60
* Returns the line number represented by this object.
61
*
62
* \returns the line number.
63
*/
64
- constexpr size_t Line() const { return loc_.line(); }
65
+ constexpr size_t Line() const { return line_; }
66
67
/**
68
* Returns a human-readable string representing this object.
69
@@ -71,18 +85,19 @@
70
* \returns a human-readable string representing source location information.
71
*/
72
std::string ToString() const {
73
- if (loc_.line() == 0) {
74
+ if (!file_) {
75
return {};
76
}
77
- return std::string(loc_.function_name()) + "@" + loc_.file_name() + ":" +
78
- std::to_string(loc_.line());
79
+ return std::string(function_) + "@" + file_ + ":" + std::to_string(line_);
80
}
81
82
private:
83
- constexpr explicit SourceLocation(const std::source_location& loc)
84
- : loc_(loc) {}
85
+ constexpr SourceLocation(const char* function, const char* file, size_t line)
86
+ : function_(function), file_(file), line_(line) {}
87
88
- std::source_location loc_;
89
+ const char* function_ = nullptr;
90
+ const char* file_ = nullptr;
91
+ size_t line_ = 0u;
92
};
93
94
} // namespace v8
95
96