v8 12.4.254 (node 22.4.1)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-source-location.h
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_SOURCE_LOCATION_H_
6#define INCLUDE_SOURCE_LOCATION_H_
7
8#include <cstddef>
9#include <string>
10
11#include "v8config.h" // NOLINT(build/include_directory)
12
13#if defined(__has_builtin)
14#define V8_SUPPORTS_SOURCE_LOCATION \
15 (__has_builtin(__builtin_FUNCTION) && __has_builtin(__builtin_FILE) && \
16 __has_builtin(__builtin_LINE)) // NOLINT
17#elif defined(V8_CC_GNU) && __GNUC__ >= 7
18#define V8_SUPPORTS_SOURCE_LOCATION 1
19#elif defined(V8_CC_INTEL) && __ICC >= 1800
20#define V8_SUPPORTS_SOURCE_LOCATION 1
21#else
22#define V8_SUPPORTS_SOURCE_LOCATION 0
23#endif
24
25namespace v8 {
26
32 public:
37#if V8_SUPPORTS_SOURCE_LOCATION
38 static constexpr SourceLocation Current(
39 const char* function = __builtin_FUNCTION(),
40 const char* file = __builtin_FILE(), size_t line = __builtin_LINE()) {
41 return SourceLocation(function, file, line);
42 }
43#else
44 static constexpr SourceLocation Current() { return SourceLocation(); }
45#endif // V8_SUPPORTS_SOURCE_LOCATION
46
50 constexpr SourceLocation() = default;
51
58 constexpr const char* Function() const { return function_; }
59
65 constexpr const char* FileName() const { return file_; }
66
72 constexpr size_t Line() const { return line_; }
73
79 std::string ToString() const;
80
81 private:
82 constexpr SourceLocation(const char* function, const char* file, size_t line)
83 : function_(function), file_(file), line_(line) {}
84
85 const char* function_ = nullptr;
86 const char* file_ = nullptr;
87 size_t line_ = 0u;
88};
89
90} // namespace v8
91
92#endif // INCLUDE_SOURCE_LOCATION_H_
constexpr size_t Line() const
std::string ToString() const
constexpr SourceLocation()=default
constexpr const char * FileName() const
constexpr const char * Function() const
static constexpr SourceLocation Current()
#define V8_EXPORT
Definition v8config.h:753