v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
source-positions.cc
Go to the documentation of this file.
1
// Copyright 2018 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
#include "
src/torque/source-positions.h
"
6
7
#include <fstream>
8
#include "
src/torque/utils.h
"
9
10
EXPORT_CONTEXTUAL_VARIABLE
(v8::internal::torque::CurrentSourceFile)
11
EXPORT_CONTEXTUAL_VARIABLE
(
v8::internal::torque::SourceFileMap
)
12
13
namespace
v8
{
14
namespace
internal
{
15
namespace
torque {
16
17
// static
18
const
std::string&
SourceFileMap::PathFromV8Root
(
SourceId
file) {
19
CHECK
(file.IsValid());
20
return
Get
().sources_[file.id_];
21
}
22
23
// static
24
std::string
SourceFileMap::AbsolutePath
(
SourceId
file) {
25
const
std::string& root_path =
PathFromV8Root
(file);
26
if
(
StringStartsWith
(root_path,
"file://"
))
return
root_path;
27
return
Get
().v8_root_ +
"/"
+
PathFromV8Root
(file);
28
}
29
30
// static
31
std::string
SourceFileMap::PathFromV8RootWithoutExtension
(
SourceId
file) {
32
std::string path_from_root =
PathFromV8Root
(file);
33
if
(!
StringEndsWith
(path_from_root,
".tq"
)) {
34
Error
(
"Not a .tq file: "
, path_from_root).
Throw
();
35
}
36
path_from_root.resize(path_from_root.size() - strlen(
".tq"
));
37
return
path_from_root;
38
}
39
40
// static
41
SourceId
SourceFileMap::AddSource
(std::string path) {
42
Get
().sources_.push_back(std::move(path));
43
return
SourceId
(
static_cast<
int
>
(
Get
().
sources_
.size()) - 1);
44
}
45
46
// static
47
SourceId
SourceFileMap::GetSourceId
(
const
std::string& path) {
48
for
(
size_t
i
= 0;
i
<
Get
().sources_.
size
(); ++
i
) {
49
if
(
Get
().
sources_
[
i
] == path) {
50
return
SourceId
(
static_cast<
int
>
(
i
));
51
}
52
}
53
return
SourceId::Invalid
();
54
}
55
56
// static
57
std::vector<SourceId>
SourceFileMap::AllSources
() {
58
SourceFileMap
& self =
Get
();
59
std::vector<SourceId>
result
;
60
result
.reserve(
static_cast<
int
>
(self.
sources_
.size()));
61
for
(
int
i
= 0; i < static_cast<int>(self.
sources_
.size()); ++
i
) {
62
result
.push_back(
SourceId
(
i
));
63
}
64
return
result
;
65
}
66
67
// static
68
bool
SourceFileMap::FileRelativeToV8RootExists
(
const
std::string& path) {
69
const
std::string file =
Get
().v8_root_ +
"/"
+ path;
70
std::ifstream stream(file);
71
return
stream.good();
72
}
73
74
}
// namespace torque
75
}
// namespace internal
76
}
// namespace v8
size
v8::base::ContextualVariable::Get
static VarType & Get()
Definition
contextual.h:64
v8::internal::torque::MessageBuilder::Throw
void Throw() const
Definition
utils.cc:160
v8::internal::torque::SourceFileMap
Definition
source-positions.h:90
v8::internal::torque::SourceFileMap::FileRelativeToV8RootExists
static bool FileRelativeToV8RootExists(const std::string &path)
Definition
source-positions.cc:68
v8::internal::torque::SourceFileMap::AllSources
static std::vector< SourceId > AllSources()
Definition
source-positions.cc:57
v8::internal::torque::SourceFileMap::PathFromV8Root
static const std::string & PathFromV8Root(SourceId file)
Definition
source-positions.cc:18
v8::internal::torque::SourceFileMap::AddSource
static SourceId AddSource(std::string path)
Definition
source-positions.cc:41
v8::internal::torque::SourceFileMap::sources_
std::vector< std::string > sources_
Definition
source-positions.h:102
v8::internal::torque::SourceFileMap::PathFromV8RootWithoutExtension
static std::string PathFromV8RootWithoutExtension(SourceId file)
Definition
source-positions.cc:31
v8::internal::torque::SourceFileMap::GetSourceId
static SourceId GetSourceId(const std::string &path)
Definition
source-positions.cc:47
v8::internal::torque::SourceFileMap::AbsolutePath
static std::string AbsolutePath(SourceId file)
Definition
source-positions.cc:24
v8::internal::torque::SourceId
Definition
source-positions.h:18
v8::internal::torque::SourceId::Invalid
static SourceId Invalid()
Definition
source-positions.h:20
EXPORT_CONTEXTUAL_VARIABLE
#define EXPORT_CONTEXTUAL_VARIABLE(VarName)
Definition
contextual.h:94
result
ZoneVector< RpoNumber > & result
Definition
jump-threading.cc:21
v8::internal::torque::StringEndsWith
bool StringEndsWith(const std::string &s, const std::string &suffix)
Definition
utils.h:361
v8::internal::torque::StringStartsWith
bool StringStartsWith(const std::string &s, const std::string &prefix)
Definition
utils.h:357
v8::internal::torque::Error
MessageBuilder Error(Args &&... args)
Definition
utils.h:81
v8::internal
Definition
api-arguments-inl.h:20
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
v8
Definition
api-arguments-inl.h:19
source-positions.h
CHECK
#define CHECK(condition)
Definition
logging.h:124
utils.h
src
torque
source-positions.cc
Generated on Sun Apr 6 2025 21:08:57 for v8 by
1.12.0