Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qv4stackframe.cpp
Go to the documentation of this file.
1
// Copyright (C) 2018 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant
4
5
#
include
"qv4stackframe_p.h"
6
#
include
<
private
/
qv4qobjectwrapper_p
.
h
>
7
#
include
<
QtCore
/
qstring
.
h
>
8
9
using
namespace
QV4;
10
11
QString CppStackFrame::source()
const
12
{
13
return
v4Function ? v4Function->sourceFile() : QString();
14
}
15
16
QString CppStackFrame::function()
const
17
{
18
return
v4Function ? v4Function->name()->toQString() : QString();
19
}
20
21
static
const
CompiledData
::
CodeOffsetToLineAndStatement
*
lineAndStatement
(
const
CppStackFrame *frame)
22
{
23
if
(!frame->v4Function || frame->instructionPointer <= 0)
24
return
nullptr
;
25
26
auto
findLine = [](
const
CompiledData::CodeOffsetToLineAndStatement &entry, uint offset) {
27
return
entry.codeOffset < offset;
28
};
29
30
const
QV4::CompiledData::Function *cf = frame->v4Function->compiledFunction;
31
const
uint offset = frame->instructionPointer;
32
const
CompiledData::CodeOffsetToLineAndStatement *lineAndStatementNumbers
33
= cf->lineAndStatementNumberTable();
34
const
uint nLineAndStatementNumbers = cf->nLineAndStatementNumbers;
35
return
std::lower_bound(
36
lineAndStatementNumbers, lineAndStatementNumbers + nLineAndStatementNumbers,
37
offset, findLine) - 1;
38
}
39
40
int
CppStackFrame::lineNumber()
const
41
{
42
if
(
auto
*line = lineAndStatement(
this
))
43
return
line->line;
44
return
missingLineNumber();
45
}
46
47
int
CppStackFrame::statementNumber()
const
48
{
49
if
(
auto
*statement = lineAndStatement(
this
))
50
return
statement->statement;
51
return
-1;
52
}
53
54
int
CppStackFrame::missingLineNumber()
const
55
{
56
// Remove the first bit so that we can cast to positive int and negate.
57
// Remove the last bit so that it can't be -1.
58
const
int
result = -
int
(quintptr(
this
) & 0x7ffffffe);
59
Q_ASSERT(result < -1);
60
return
result;
61
}
62
63
ReturnedValue QV4::CppStackFrame::thisObject()
const
64
{
65
if
(isJSTypesFrame())
66
return
static_cast
<
const
JSTypesStackFrame *>(
this
)->thisObject();
67
68
Q_ASSERT(isMetaTypesFrame());
69
const
auto
metaTypesFrame =
static_cast
<
const
MetaTypesStackFrame *>(
this
);
70
return
QObjectWrapper::wrap(metaTypesFrame->context()->engine(), metaTypesFrame->thisObject());
71
}
lineAndStatement
static const CompiledData::CodeOffsetToLineAndStatement * lineAndStatement(const CppStackFrame *frame)
Definition
qv4stackframe.cpp:21
qtdeclarative
src
qml
jsruntime
qv4stackframe.cpp
Generated on
for Qt by
1.18.0