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
qv4engine_p.h
Go to the documentation of this file.
1
// Copyright (C) 2016 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
#
ifndef
QV4ENGINE_H
5
#
define
QV4ENGINE_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
private
/
qintrusivelist_p
.
h
>
19
#
include
<
private
/
qqmldelayedcallqueue_p
.
h
>
20
#
include
<
private
/
qqmlrefcount_p
.
h
>
21
#
include
<
private
/
qv4compileddata_p
.
h
>
22
#
include
<
private
/
qv4context_p
.
h
>
23
#
include
<
private
/
qv4enginebase_p
.
h
>
24
#
include
<
private
/
qv4executablecompilationunit_p
.
h
>
25
#
include
<
private
/
qv4global_p
.
h
>
26
#
include
<
private
/
qv4stacklimits_p
.
h
>
27
28
#
include
<
QtCore
/
qelapsedtimer
.
h
>
29
#
include
<
QtCore
/
qmutex
.
h
>
30
#
include
<
QtCore
/
qprocessordetection
.
h
>
31
#
include
<
QtCore
/
qset
.
h
>
32
33
namespace
WTF
{
34
class
BumpPointerAllocator;
35
class
PageAllocation;
36
}
37
38
#
define
V4_DEFINE_EXTENSION
(
dataclass
,
datafunction
)
39
static
inline
dataclass
*
datafunction
(
QV4
::
ExecutionEngine
*
engine
)
40
{
41
static
int
extensionId
=
-
1
;
42
if
(
extensionId
==
-
1
)
{
43
QV4
::
ExecutionEngine
::
registrationMutex
(
)
->
lock
(
)
;
44
if
(
extensionId
==
-
1
)
45
extensionId
=
QV4
::
ExecutionEngine
::
registerExtension
(
)
;
46
QV4
::
ExecutionEngine
::
registrationMutex
(
)
->
unlock
(
)
;
47
}
48
dataclass
*
rv
=
(
dataclass
*
)
engine
->
extensionData
(
extensionId
)
;
49
if
(
!
rv
)
{
50
rv
=
new
dataclass
(
engine
)
;
51
engine
->
setExtensionData
(
extensionId
,
rv
)
;
52
}
53
return
rv
;
54
}
55
56
57
QT_BEGIN_NAMESPACE
58
59
#
if
QT_CONFIG
(
qml_network
)
60
class
QNetworkAccessManager;
61
#
endif
// qml_network
62
namespace
QV4
{
struct
QObjectMethod; }
63
64
// Used to allow a QObject method take and return raw V4 handles without having to expose
65
// 48 in the public API.
66
// Use like this:
67
// class MyClass : public QObject {
68
// Q_OBJECT
69
// ...
70
// Q_INVOKABLE void myMethod(QQmlV4FunctionPtr);
71
// };
72
// The QQmlV8Function - and consequently the arguments and return value - only remains
73
// valid during the call. If the return value isn't set within myMethod(), the will return
74
// undefined.
75
76
class
QQmlV4Function
77
{
78
public
:
79
int
length
()
const
{
return
callData->argc(); }
80
QV4
::
ReturnedValue
operator
[](
int
idx)
const
{
return
(idx < callData->argc() ? callData->args[idx].asReturnedValue() : QV4::Encode::undefined()); }
81
void
setReturnValue
(QV4::ReturnedValue rv) { *retVal = rv; }
82
QV4
::
ExecutionEngine
*
v4engine
()
const
{
return
e; }
83
private
:
84
friend
struct
QV4
::QObjectMethod;
85
QQmlV4Function();
86
QQmlV4Function(
const
QQmlV4Function
&);
87
QQmlV4Function
&operator=(
const
QQmlV4Function
&);
88
89
QQmlV4Function(QV4::CallData *callData, QV4::Value *retVal, QV4::ExecutionEngine *e)
90
: callData(callData), retVal(retVal), e(e)
91
{
92
callData->thisObject = QV4::Encode::undefined();
93
}
94
95
QV4::CallData *callData;
96
QV4::Value *retVal;
97
QV4::ExecutionEngine *e;
98
};
99
100
class
QQmlError;
101
class
QJSEngine
;
102
class
QQmlEngine;
103
class
QQmlContextData;
104
class
QQmlTypeLoader;
105
106
namespace
QV4
{
107
namespace
Debugging
{
108
class
Debugger;
109
}
// namespace Debugging
110
namespace
Profiling
{
111
class
Profiler;
112
}
// namespace Profiling
113
namespace
CompiledData
{
114
struct
CompilationUnit
;
115
}
116
117
namespace
Heap
{
118
struct
Module;
119
};
120
121
struct
Function;
122
123
namespace
Promise
{
124
class
ReactionHandler
;
125
};
126
127
struct
Q_QML_EXPORT
ExecutionEngine
:
public
EngineBase
128
{
129
private
:
130
friend
struct
ExecutionContextSaver
;
131
friend
struct
ExecutionContext
;
132
friend
struct
Heap
::
ExecutionContext
;
133
public
:
134
enum
class
DiskCache
:
quint8
{
135
Disabled
= 0,
136
AotByteCode
= 1 << 0,
137
AotNative
= 1 << 1,
138
QmlcRead
= 1 << 2,
139
QmlcWrite
= 1 << 3,
140
Aot
=
AotByteCode
|
AotNative
,
141
Qmlc
=
QmlcRead
|
QmlcWrite
,
142
Enabled
=
Aot
|
Qmlc
,
143
144
};
145
146
Q_DECLARE_FLAGS
(
DiskCacheOptions
,
DiskCache
);
147
148
ExecutableAllocator
*
executableAllocator
=
nullptr
;
149
ExecutableAllocator
*
regExpAllocator
=
nullptr
;
150
151
WTF
::
BumpPointerAllocator
*
bumperPointerAllocator
=
nullptr
;
// Used by Yarr Regex engine.
152
153
WTF
::
PageAllocation
*
jsStack
=
nullptr
;
154
155
WTF
::
PageAllocation
*
gcStack
=
nullptr
;
156
157
// Using jsAlloca directly can be dangerous as it temporarily, until
158
// some initialization is performed, leaves an element on the
159
// stack that is garbage memory.
160
// That element could be accessed by other parts of the system
161
// before an initialization step is performed, involuntary
162
// interacting with that memory.
163
//
164
// For example, any allocation performed by the MemoryManager
165
// might run the garbage collector, which in turn has a chance of
166
// accessing all current elements on the stack, including the
167
// garbage memory that can be left on the stack by a call to this
168
// method.
169
//
170
// Thus care needs to be taken when using jsAlloca, such that all
171
// allocated stack slots are initialized as soon as possible and
172
// without any heap allocation or other accesses to the new stack
173
// elements in the middle.
174
QML_NEARLY_ALWAYS_INLINE
Value
*
jsAlloca
(
int
nValues
) {
175
Value
*
ptr
=
jsStackTop
;
176
jsStackTop
=
ptr
+
nValues
;
177
return
ptr
;
178
}
179
180
Function
*
globalCode
=
nullptr
;
181
182
QJSEngine
*
jsEngine
()
const
{
return
publicEngine
; }
183
QQmlEngine
*
qmlEngine
()
const
{
return
m_qmlEngine
; }
184
QJSEngine
*
publicEngine
=
nullptr
;
185
186
template
<
typename
TypeLoader
=
QQmlTypeLoader
>
187
TypeLoader
*
typeLoader
()
188
{
189
if
(!
m_typeLoader
)
190
m_typeLoader
=
std
::
make_unique
<
TypeLoader
>(
this
);
191
return
m_typeLoader
.
get
();
192
}
193
194
enum
JSObjects
{
195
RootContext
,
196
ScriptContext
,
197
IntegerNull
,
// Has to come after the RootContext to make the context stack safe
198
ObjectProto
,
199
SymbolProto
,
200
ArrayProto
,
201
ArrayProtoValues
,
202
PropertyListProto
,
203
StringProto
,
204
NumberProto
,
205
BooleanProto
,
206
DateProto
,
207
FunctionProto
,
208
GeneratorProto
,
209
RegExpProto
,
210
ErrorProto
,
211
EvalErrorProto
,
212
RangeErrorProto
,
213
ReferenceErrorProto
,
214
SyntaxErrorProto
,
215
TypeErrorProto
,
216
URIErrorProto
,
217
PromiseProto
,
218
VariantProto
,
219
VariantAssociationProto
,
220
SequenceProto
,
221
SharedArrayBufferProto
,
222
ArrayBufferProto
,
223
DataViewProto
,
224
WeakSetProto
,
225
SetProto
,
226
WeakMapProto
,
227
MapProto
,
228
IntrinsicTypedArrayProto
,
229
ValueTypeProto
,
230
TypeWrapperProto
,
231
SignalHandlerProto
,
232
IteratorProto
,
233
ForInIteratorProto
,
234
SetIteratorProto
,
235
MapIteratorProto
,
236
ArrayIteratorProto
,
237
StringIteratorProto
,
238
UrlProto
,
239
UrlSearchParamsProto
,
240
241
Object_Ctor
,
242
String_Ctor
,
243
Symbol_Ctor
,
244
Number_Ctor
,
245
Boolean_Ctor
,
246
Array_Ctor
,
247
Function_Ctor
,
248
GeneratorFunction_Ctor
,
249
Date_Ctor
,
250
RegExp_Ctor
,
251
Error_Ctor
,
252
EvalError_Ctor
,
253
RangeError_Ctor
,
254
ReferenceError_Ctor
,
255
SyntaxError_Ctor
,
256
TypeError_Ctor
,
257
URIError_Ctor
,
258
SharedArrayBuffer_Ctor
,
259
Promise_Ctor
,
260
ArrayBuffer_Ctor
,
261
DataView_Ctor
,
262
WeakSet_Ctor
,
263
Set_Ctor
,
264
WeakMap_Ctor
,
265
Map_Ctor
,
266
IntrinsicTypedArray_Ctor
,
267
Url_Ctor
,
268
UrlSearchParams_Ctor
,
269
270
GetSymbolSpecies
,
271
272
Eval_Function
,
273
GetStack_Function
,
274
ThrowerObject
,
275
NJSObjects
276
};
277
Value
*
jsObjects
=
nullptr
;
278
enum
{
NTypedArrayTypes
= 9 };
// == TypedArray::NValues, avoid header dependency
279
280
ExecutionContext
*
rootContext
()
const
{
return
reinterpret_cast
<
ExecutionContext
*>(
jsObjects
+
RootContext
); }
281
ExecutionContext
*
scriptContext
()
const
{
return
reinterpret_cast
<
ExecutionContext
*>(
jsObjects
+
ScriptContext
); }
282
void
setScriptContext
(
ReturnedValue
c
) {
jsObjects
[
ScriptContext
] =
c
; }
283
FunctionObject
*
objectCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Object_Ctor
); }
284
FunctionObject
*
stringCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
String_Ctor
); }
285
FunctionObject
*
symbolCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Symbol_Ctor
); }
286
FunctionObject
*
numberCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Number_Ctor
); }
287
FunctionObject
*
booleanCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Boolean_Ctor
); }
288
FunctionObject
*
arrayCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Array_Ctor
); }
289
FunctionObject
*
functionCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Function_Ctor
); }
290
FunctionObject
*
generatorFunctionCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
GeneratorFunction_Ctor
); }
291
FunctionObject
*
dateCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Date_Ctor
); }
292
FunctionObject
*
regExpCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
RegExp_Ctor
); }
293
FunctionObject
*
errorCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Error_Ctor
); }
294
FunctionObject
*
evalErrorCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
EvalError_Ctor
); }
295
FunctionObject
*
rangeErrorCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
RangeError_Ctor
); }
296
FunctionObject
*
referenceErrorCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
ReferenceError_Ctor
); }
297
FunctionObject
*
syntaxErrorCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
SyntaxError_Ctor
); }
298
FunctionObject
*
typeErrorCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
TypeError_Ctor
); }
299
FunctionObject
*
uRIErrorCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
URIError_Ctor
); }
300
FunctionObject
*
sharedArrayBufferCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
SharedArrayBuffer_Ctor
); }
301
FunctionObject
*
promiseCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Promise_Ctor
); }
302
FunctionObject
*
arrayBufferCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
ArrayBuffer_Ctor
); }
303
FunctionObject
*
dataViewCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
DataView_Ctor
); }
304
FunctionObject
*
weakSetCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
WeakSet_Ctor
); }
305
FunctionObject
*
setCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Set_Ctor
); }
306
FunctionObject
*
weakMapCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
WeakMap_Ctor
); }
307
FunctionObject
*
mapCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Map_Ctor
); }
308
FunctionObject
*
intrinsicTypedArrayCtor
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
IntrinsicTypedArray_Ctor
); }
309
FunctionObject
*
urlCtor
()
const
310
{
311
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
Url_Ctor
);
312
}
313
FunctionObject
*
urlSearchParamsCtor
()
const
314
{
315
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
UrlSearchParams_Ctor
);
316
}
317
FunctionObject
*
typedArrayCtors
=
nullptr
;
318
319
FunctionObject
*
getSymbolSpecies
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
GetSymbolSpecies
); }
320
321
Object
*
objectPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
ObjectProto
); }
322
Object
*
symbolPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
SymbolProto
); }
323
Object
*
arrayPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
ArrayProto
); }
324
Object
*
arrayProtoValues
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
ArrayProtoValues
); }
325
Object
*
propertyListPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
PropertyListProto
); }
326
Object
*
stringPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
StringProto
); }
327
Object
*
numberPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
NumberProto
); }
328
Object
*
booleanPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
BooleanProto
); }
329
Object
*
datePrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
DateProto
); }
330
Object
*
functionPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
FunctionProto
); }
331
Object
*
generatorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
GeneratorProto
); }
332
Object
*
regExpPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
RegExpProto
); }
333
Object
*
errorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
ErrorProto
); }
334
Object
*
evalErrorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
EvalErrorProto
); }
335
Object
*
rangeErrorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
RangeErrorProto
); }
336
Object
*
referenceErrorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
ReferenceErrorProto
); }
337
Object
*
syntaxErrorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
SyntaxErrorProto
); }
338
Object
*
typeErrorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
TypeErrorProto
); }
339
Object
*
uRIErrorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
URIErrorProto
); }
340
Object
*
promisePrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
PromiseProto
); }
341
Object
*
variantPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
VariantProto
); }
342
Object
*
variantAssociationPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
VariantAssociationProto
); }
343
Object
*
sequencePrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
SequenceProto
); }
344
345
Object
*
sharedArrayBufferPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
SharedArrayBufferProto
); }
346
Object
*
arrayBufferPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
ArrayBufferProto
); }
347
Object
*
dataViewPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
DataViewProto
); }
348
Object
*
weakSetPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
WeakSetProto
); }
349
Object
*
setPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
SetProto
); }
350
Object
*
weakMapPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
WeakMapProto
); }
351
Object
*
mapPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
MapProto
); }
352
Object
*
intrinsicTypedArrayPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
IntrinsicTypedArrayProto
); }
353
Object
*
typedArrayPrototype
=
nullptr
;
354
355
Object
*
valueTypeWrapperPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
ValueTypeProto
); }
356
Object
*
signalHandlerPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
SignalHandlerProto
); }
357
Object
*
typeWrapperPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
TypeWrapperProto
); }
358
Object
*
iteratorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
IteratorProto
); }
359
Object
*
forInIteratorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
ForInIteratorProto
); }
360
Object
*
setIteratorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
SetIteratorProto
); }
361
Object
*
mapIteratorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
MapIteratorProto
); }
362
Object
*
arrayIteratorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
ArrayIteratorProto
); }
363
Object
*
stringIteratorPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
StringIteratorProto
); }
364
Object
*
urlPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
UrlProto
); }
365
Object
*
urlSearchParamsPrototype
()
const
{
return
reinterpret_cast
<
Object
*>(
jsObjects
+
UrlSearchParamsProto
); }
366
367
EvalFunction
*
evalFunction
()
const
{
return
reinterpret_cast
<
EvalFunction
*>(
jsObjects
+
Eval_Function
); }
368
FunctionObject
*
getStackFunction
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
GetStack_Function
); }
369
FunctionObject
*
thrower
()
const
{
return
reinterpret_cast
<
FunctionObject
*>(
jsObjects
+
ThrowerObject
); }
370
371
#
if
QT_CONFIG
(
qml_network
)
372
QNetworkAccessManager
*
getNetworkAccessManager
();
373
QNetworkAccessManager
*
networkAccessManager
=
nullptr
;
374
#
endif
375
376
enum
JSStrings
{
377
String_Empty
,
378
String_undefined
,
379
String_null
,
380
String_true
,
381
String_false
,
382
String_boolean
,
383
String_number
,
384
String_string
,
385
String_default
,
386
String_symbol
,
387
String_object
,
388
String_function
,
389
String_length
,
390
String_prototype
,
391
String_constructor
,
392
String_arguments
,
393
String_caller
,
394
String_callee
,
395
String_this
,
396
String___proto__
,
397
String_enumerable
,
398
String_configurable
,
399
String_writable
,
400
String_value
,
401
String_get
,
402
String_set
,
403
String_eval
,
404
String_uintMax
,
405
String_name
,
406
String_index
,
407
String_input
,
408
String_toString
,
409
String_toLocaleString
,
410
String_destroy
,
411
String_valueOf
,
412
String_byteLength
,
413
String_byteOffset
,
414
String_buffer
,
415
String_lastIndex
,
416
String_next
,
417
String_done
,
418
String_return
,
419
String_throw
,
420
String_global
,
421
String_ignoreCase
,
422
String_multiline
,
423
String_unicode
,
424
String_sticky
,
425
String_source
,
426
String_flags
,
427
428
NJSStrings
429
};
430
Value
*
jsStrings
=
nullptr
;
431
432
enum
JSSymbols
{
433
Symbol_hasInstance
,
434
Symbol_isConcatSpreadable
,
435
Symbol_iterator
,
436
Symbol_match
,
437
Symbol_replace
,
438
Symbol_search
,
439
Symbol_species
,
440
Symbol_split
,
441
Symbol_toPrimitive
,
442
Symbol_toStringTag
,
443
Symbol_unscopables
,
444
Symbol_revokableProxy
,
445
NJSSymbols
446
};
447
Value
*
jsSymbols
=
nullptr
;
448
449
String
*
id_empty
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_Empty
); }
450
String
*
id_undefined
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_undefined
); }
451
String
*
id_null
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_null
); }
452
String
*
id_true
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_true
); }
453
String
*
id_false
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_false
); }
454
String
*
id_boolean
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_boolean
); }
455
String
*
id_number
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_number
); }
456
String
*
id_string
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_string
); }
457
String
*
id_default
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_default
); }
458
String
*
id_symbol
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_symbol
); }
459
String
*
id_object
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_object
); }
460
String
*
id_function
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_function
); }
461
String
*
id_length
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_length
); }
462
String
*
id_prototype
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_prototype
); }
463
String
*
id_constructor
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_constructor
); }
464
String
*
id_arguments
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_arguments
); }
465
String
*
id_caller
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_caller
); }
466
String
*
id_callee
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_callee
); }
467
String
*
id_this
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_this
); }
468
String
*
id___proto__
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String___proto__
); }
469
String
*
id_enumerable
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_enumerable
); }
470
String
*
id_configurable
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_configurable
); }
471
String
*
id_writable
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_writable
); }
472
String
*
id_value
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_value
); }
473
String
*
id_get
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_get
); }
474
String
*
id_set
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_set
); }
475
String
*
id_eval
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_eval
); }
476
String
*
id_uintMax
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_uintMax
); }
477
String
*
id_name
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_name
); }
478
String
*
id_index
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_index
); }
479
String
*
id_input
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_input
); }
480
String
*
id_toString
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_toString
); }
481
String
*
id_toLocaleString
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_toLocaleString
); }
482
String
*
id_destroy
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_destroy
); }
483
String
*
id_valueOf
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_valueOf
); }
484
String
*
id_byteLength
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_byteLength
); }
485
String
*
id_byteOffset
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_byteOffset
); }
486
String
*
id_buffer
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_buffer
); }
487
String
*
id_lastIndex
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_lastIndex
); }
488
String
*
id_next
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_next
); }
489
String
*
id_done
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_done
); }
490
String
*
id_return
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_return
); }
491
String
*
id_throw
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_throw
); }
492
String
*
id_global
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_global
); }
493
String
*
id_ignoreCase
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_ignoreCase
); }
494
String
*
id_multiline
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_multiline
); }
495
String
*
id_unicode
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_unicode
); }
496
String
*
id_sticky
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_sticky
); }
497
String
*
id_source
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_source
); }
498
String
*
id_flags
()
const
{
return
reinterpret_cast
<
String
*>(
jsStrings
+
String_flags
); }
499
500
Symbol
*
symbol_hasInstance
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_hasInstance
); }
501
Symbol
*
symbol_isConcatSpreadable
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_isConcatSpreadable
); }
502
Symbol
*
symbol_iterator
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_iterator
); }
503
Symbol
*
symbol_match
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_match
); }
504
Symbol
*
symbol_replace
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_replace
); }
505
Symbol
*
symbol_search
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_search
); }
506
Symbol
*
symbol_species
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_species
); }
507
Symbol
*
symbol_split
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_split
); }
508
Symbol
*
symbol_toPrimitive
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_toPrimitive
); }
509
Symbol
*
symbol_toStringTag
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_toStringTag
); }
510
Symbol
*
symbol_unscopables
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_unscopables
); }
511
Symbol
*
symbol_revokableProxy
()
const
{
return
reinterpret_cast
<
Symbol
*>(
jsSymbols
+
Symbol_revokableProxy
); }
512
513
quint32
m_engineId
= 0;
514
515
RegExpCache
*
regExpCache
=
nullptr
;
516
517
// Scarce resources are "exceptionally high cost" QVariant types where allowing the
518
// normal JavaScript GC to clean them up is likely to lead to out-of-memory or other
519
// out-of-resource situations. When such a resource is passed into JavaScript we
520
// add it to the scarceResources list and it is destroyed when we return from the
521
// JavaScript execution that created it. The user can prevent this behavior by
522
// calling preserve() on the object which removes it from this scarceResource list.
523
class
ScarceResourceData
{
524
public
:
525
ScarceResourceData
() =
default
;
526
ScarceResourceData
(
const
QMetaType
type
,
const
void
*
data
) :
data
(
type
,
data
) {}
527
QVariant
data
;
528
QIntrusiveListNode
node
;
529
};
530
QIntrusiveList
<
ScarceResourceData
, &
ScarceResourceData
::
node
>
scarceResources
;
531
532
// Normally the JS wrappers for QObjects are stored in the QQmlData/QObjectPrivate,
533
// but any time a QObject is wrapped a second time in another engine, we have to do
534
// bookkeeping.
535
MultiplyWrappedQObjectMap
*
m_multiplyWrappedQObjects
=
nullptr
;
536
#
if
QT_CONFIG
(
qml_jit
)
537
const
bool
m_canAllocateExecutableMemory
=
false
;
538
#
endif
539
540
quintptr
protoIdCount
= 1;
541
542
ExecutionEngine
(
QJSEngine
*
jsEngine
=
nullptr
);
543
~
ExecutionEngine
();
544
545
#
if
!
QT_CONFIG
(
qml_debug
)
546
QV4
::
Debugging
::
Debugger
*
debugger
()
const
{
return
nullptr
; }
547
QV4
::
Profiling
::
Profiler
*
profiler
()
const
{
return
nullptr
; }
548
549
void
setDebugger
(
Debugging
::
Debugger
*) {}
550
void
setProfiler
(
Profiling
::
Profiler
*) {}
551
static
void
setPreviewing
(
bool
) {}
552
static
bool
isPreviewing
() {
return
false
; }
553
#
else
554
QV4
::
Debugging
::
Debugger
*
debugger
()
const
{
return
m_debugger
.
data
(); }
555
QV4
::
Profiling
::
Profiler
*
profiler
()
const
{
return
m_profiler
.
data
(); }
556
557
void
setDebugger
(
Debugging
::
Debugger
*
debugger
);
558
void
setProfiler
(
Profiling
::
Profiler
*
profiler
);
559
static
void
setPreviewing
(
bool
enabled
);
560
static
bool
isPreviewing
();
561
#
endif
// QT_CONFIG(qml_debug)
562
563
// We don't want to #include <private/qv4stackframe_p.h> here, but we still want
564
// currentContext() to be inline. Therefore we shift the requirement to provide the
565
// complete type of CppStackFrame to the caller by making this a template.
566
template
<
typename
StackFrame
=
CppStackFrame
>
567
ExecutionContext
*
currentContext
()
const
568
{
569
return
static_cast
<
const
StackFrame
*>(
currentStackFrame
)->
context
();
570
}
571
572
// ensure we always get odd prototype IDs. This helps make marking in QV4::Lookup fast
573
quintptr
newProtoId
() {
return
(
protoIdCount
+= 2); }
574
575
Heap
::
InternalClass
*
newInternalClass
(
const
VTable
*
vtable
,
Object
*
prototype
);
576
577
Heap
::
Object
*
newObject
();
578
Heap
::
Object
*
newObject
(
Heap
::
InternalClass
*
internalClass
);
579
580
Heap
::
String
*
newString
(
char16_t
c
) {
return
newString
(
QChar
(
c
)); }
581
Heap
::
String
*
newString
(
const
QString
&
s
=
QString
());
582
Heap
::
String
*
newIdentifier
(
const
QString
&
text
);
583
584
Heap
::
Object
*
newStringObject
(
const
String
*
string
);
585
Heap
::
Object
*
newSymbolObject
(
const
Symbol
*
symbol
);
586
Heap
::
Object
*
newNumberObject
(
double
value
);
587
Heap
::
Object
*
newBooleanObject
(
bool
b
);
588
589
Heap
::
ArrayObject
*
newArrayObject
(
int
count
= 0);
590
Heap
::
ArrayObject
*
newArrayObject
(
const
Value
*
values
,
int
length
);
591
Heap
::
ArrayObject
*
newArrayObject
(
const
QStringList
&
list
);
592
Heap
::
ArrayObject
*
newArrayObject
(
Heap
::
InternalClass
*
ic
);
593
594
Heap
::
ArrayBuffer
*
newArrayBuffer
(
const
QByteArray
&
array
);
595
Heap
::
ArrayBuffer
*
newArrayBuffer
(
size_t
length
);
596
597
Heap
::
DateObject
*
newDateObject
(
double
dateTime
);
598
Heap
::
DateObject
*
newDateObject
(
const
QDateTime
&
dateTime
);
599
Heap
::
DateObject
*
newDateObject
(
QDate
date
,
Heap
::
Object
*
parent
,
int
index
,
uint
flags
);
600
Heap
::
DateObject
*
newDateObject
(
QTime
time
,
Heap
::
Object
*
parent
,
int
index
,
uint
flags
);
601
Heap
::
DateObject
*
newDateObject
(
QDateTime
dateTime
,
Heap
::
Object
*
parent
,
int
index
,
uint
flags
);
602
603
Heap
::
RegExpObject
*
newRegExpObject
(
const
QString
&
pattern
,
int
flags
);
604
Heap
::
RegExpObject
*
newRegExpObject
(
RegExp
*
re
);
605
#
if
QT_CONFIG
(
regularexpression
)
606
Heap
::
RegExpObject
*
newRegExpObject
(
const
QRegularExpression
&
re
);
607
#
endif
608
609
Heap
::
UrlObject
*
newUrlObject
();
610
Heap
::
UrlObject
*
newUrlObject
(
const
QUrl
&
url
);
611
Heap
::
UrlSearchParamsObject
*
newUrlSearchParamsObject
();
612
613
Heap
::
Object
*
newErrorObject
(
const
Value
&
value
);
614
Heap
::
Object
*
newErrorObject
(
const
QString
&
message
);
615
Heap
::
Object
*
newSyntaxErrorObject
(
const
QString
&
message
,
const
QString
&
fileName
,
int
line
,
int
column
);
616
Heap
::
Object
*
newSyntaxErrorObject
(
const
QString
&
message
);
617
Heap
::
Object
*
newReferenceErrorObject
(
const
QString
&
message
);
618
Heap
::
Object
*
newReferenceErrorObject
(
const
QString
&
message
,
const
QString
&
fileName
,
int
line
,
int
column
);
619
Heap
::
Object
*
newTypeErrorObject
(
const
QString
&
message
);
620
Heap
::
Object
*
newRangeErrorObject
(
const
QString
&
message
);
621
Heap
::
Object
*
newURIErrorObject
(
const
QString
&
message
);
622
Heap
::
Object
*
newURIErrorObject
(
const
Value
&
message
);
623
Heap
::
Object
*
newEvalErrorObject
(
const
QString
&
message
);
624
625
Heap
::
PromiseObject
*
newPromiseObject
();
626
Heap
::
Object
*
newPromiseObject
(
const
QV4
::
FunctionObject
*
thisObject
,
const
QV4
::
PromiseCapability
*
capability
);
627
Promise
::
ReactionHandler
*
getPromiseReactionHandler
();
628
629
Heap
::
Object
*
newVariantObject
(
const
QMetaType
type
,
const
void
*
data
);
630
631
Heap
::
Object
*
newForInIteratorObject
(
Object
*
o
);
632
Heap
::
Object
*
newSetIteratorObject
(
Object
*
o
);
633
Heap
::
Object
*
newMapIteratorObject
(
Object
*
o
);
634
Heap
::
Object
*
newArrayIteratorObject
(
Object
*
o
);
635
636
static
Heap
::
ExecutionContext
*
qmlContext
(
Heap
::
ExecutionContext
*
ctx
)
637
{
638
Heap
::
ExecutionContext
*
outer
=
ctx
->
outer
;
639
640
if
(
ctx
->
type
!=
Heap
::
ExecutionContext
::
Type_QmlContext
&& !
outer
)
641
return
nullptr
;
642
643
while
(
outer
&&
outer
->
type
!=
Heap
::
ExecutionContext
::
Type_GlobalContext
) {
644
ctx
=
outer
;
645
outer
=
ctx
->
outer
;
646
}
647
648
Q_ASSERT
(
ctx
);
649
if
(
ctx
->
type
!=
Heap
::
ExecutionContext
::
Type_QmlContext
)
650
return
nullptr
;
651
652
return
ctx
;
653
}
654
655
Heap
::
QmlContext
*
qmlContext
()
const
;
656
QObject
*
qmlScopeObject
()
const
;
657
QQmlRefPointer
<
QQmlContextData
>
callingQmlContext
()
const
;
658
659
660
StackTrace
stackTrace
(
int
frameLimit
= -1)
const
;
661
QUrl
resolvedUrl
(
const
QString
&
file
);
662
663
void
markObjects
(
MarkStack
*
markStack
);
664
665
void
initRootContext
();
666
667
Heap
::
InternalClass
*
newClass
(
Heap
::
InternalClass
*
other
);
668
669
StackTrace
exceptionStackTrace
;
670
671
ReturnedValue
throwError
(
const
Value
&
value
);
672
ReturnedValue
catchException
(
StackTrace
*
trace
=
nullptr
);
673
674
ReturnedValue
throwError
(
const
QString
&
message
);
675
ReturnedValue
throwSyntaxError
(
const
QString
&
message
);
676
ReturnedValue
throwSyntaxError
(
const
QString
&
message
,
const
QString
&
fileName
,
int
lineNumber
,
int
column
);
677
ReturnedValue
throwTypeError
();
678
ReturnedValue
throwTypeError
(
const
QString
&
message
);
679
ReturnedValue
throwReferenceError
(
const
Value
&
value
);
680
ReturnedValue
throwReferenceError
(
const
QString
&
name
);
681
ReturnedValue
throwReferenceError
(
const
QString
&
value
,
const
QString
&
fileName
,
int
lineNumber
,
int
column
);
682
ReturnedValue
throwRangeError
(
const
Value
&
value
);
683
ReturnedValue
throwRangeError
(
const
QString
&
message
);
684
ReturnedValue
throwURIError
(
const
Value
&
msg
);
685
ReturnedValue
throwUnimplemented
(
const
QString
&
message
);
686
687
// Use only inside catch(...) -- will re-throw if no JS exception
688
QQmlError
catchExceptionAsQmlError
();
689
690
void
amendException
();
691
692
// variant conversions
693
static
QVariant
toVariant
(
694
const
QV4
::
Value
&
value
,
QMetaType
typeHint
,
bool
createJSValueForObjectsAndSymbols
=
true
);
695
static
QVariant
toVariantLossy
(
const
QV4
::
Value
&
value
);
696
QV4
::
ReturnedValue
fromVariant
(
const
QVariant
&);
697
QV4
::
ReturnedValue
fromVariant
(
698
const
QVariant
&
variant
,
Heap
::
Object
*
parent
,
int
property
,
uint
flags
);
699
static
bool
isUndefinedVariant
(
const
QVariant
&
variant
);
700
static
bool
isEquivalentToUndefinedData
(
QMetaType
metaType
,
const
void
*
data
);
701
702
static
QVariantMap
variantMapFromJS
(
const
QV4
::
Object
*
o
);
703
static
QVariantHash
variantHashFromJS
(
const
QV4
::
Object
*
o
);
704
705
static
bool
metaTypeFromJS
(
const
Value
&
value
,
QMetaType
type
,
void
*
data
);
706
QV4
::
ReturnedValue
metaTypeToJS
(
QMetaType
type
,
const
void
*
data
);
707
708
int
maxJSStackSize
()
const
;
709
int
maxGCStackSize
()
const
;
710
711
bool
checkStackLimits
();
712
int
safeForAllocLength
(
qint64
len64
);
713
714
template
<
typename
Jittable
>
715
bool
canJIT
(
Jittable
*
jittable
)
const
716
{
717
#
if
QT_CONFIG
(
qml_jit
)
718
return
m_canAllocateExecutableMemory
719
&&
jittable
->
isJittable
()
720
&&
jittable
->
interpreterCallCount
>=
s_jitCallCountThreshold
;
721
#
else
722
Q_UNUSED
(
jittable
);
723
return
false
;
724
#
endif
725
}
726
727
QV4
::
ReturnedValue
global
();
728
void
initQmlGlobalObject
();
729
void
initializeGlobal
();
730
void
createQtObject
();
731
732
void
freezeObject
(
const
QV4
::
Value
&
value
);
733
void
lockObject
(
const
QV4
::
Value
&
value
);
734
735
#
if
QT_CONFIG
(
qml_xml_http_request
)
736
void
setupXmlHttpRequestExtension
();
737
void
*
xmlHttpRequestData
()
const
{
return
m_xmlHttpRequestData
; }
738
#
endif
739
740
void
setQmlEngine
(
QQmlEngine
*
engine
);
741
void
resetQmlEngine
() {
m_qmlEngine
=
nullptr
; }
742
743
QQmlDelayedCallQueue
*
delayedCallQueue
() {
return
&
m_delayedCallQueue
; }
744
745
// used for console.time(), console.timeEnd()
746
void
startTimer
(
const
QString
&
timerName
);
747
qint64
stopTimer
(
const
QString
&
timerName
,
bool
*
wasRunning
);
748
749
// used for console.count()
750
int
consoleCountHelper
(
const
QString
&
file
,
quint16
line
,
quint16
column
);
751
752
struct
Deletable
{
753
virtual
~
Deletable
() {}
754
};
755
756
static
QMutex
*
registrationMutex
();
757
static
int
registerExtension
();
758
759
void
setExtensionData
(
int
,
Deletable
*);
760
Deletable
*
extensionData
(
int
index
)
const
761
{
762
if
(
index
<
m_extensionData
.
size
())
763
return
m_extensionData
[
index
];
764
else
765
return
nullptr
;
766
}
767
768
double
localTZA
= 0.0;
// local timezone, initialized at startup
769
770
QQmlRefPointer
<
ExecutableCompilationUnit
>
compilationUnitForUrl
(
const
QUrl
&
url
)
const
;
771
772
QQmlRefPointer
<
ExecutableCompilationUnit
>
executableCompilationUnit
(
773
QQmlRefPointer
<
QV4
::
CompiledData
::
CompilationUnit
> &&
unit
);
774
775
QQmlRefPointer
<
ExecutableCompilationUnit
>
insertCompilationUnit
(
776
QQmlRefPointer
<
QV4
::
CompiledData
::
CompilationUnit
> &&
unit
);
777
778
QMultiHash
<
QUrl
,
QQmlRefPointer
<
ExecutableCompilationUnit
>>
compilationUnits
()
const
779
{
780
return
m_compilationUnits
;
781
}
782
783
void
trimCompilationUnits
();
784
void
trimCompilationUnitsForUrl
(
const
QUrl
&
url
);
785
786
using
Module
=
QQmlRefPointer
<
ExecutableCompilationUnit
>;
787
788
Module
registerNativeModule
(
const
QUrl
&
url
,
const
QV4
::
Value
&
value
);
789
Module
moduleForUrl
(
const
QUrl
&
_url
,
const
ExecutableCompilationUnit
*
referrer
=
nullptr
);
790
791
DiskCacheOptions
diskCacheOptions
()
const
;
792
793
void
callInContext
(
QV4
::
Function
*
function
,
QObject
*
self
,
QV4
::
ExecutionContext
*
ctxt
,
794
int
argc
,
void
**
args
,
QMetaType
*
types
);
795
QV4
::
ReturnedValue
callInContext
(
QV4
::
Function
*
function
,
QObject
*
self
,
796
QV4
::
ExecutionContext
*
ctxt
,
int
argc
,
const
QV4
::
Value
*
argv
);
797
798
QV4
::
ReturnedValue
fromData
(
799
QMetaType
type
,
const
void
*
ptr
,
800
Heap
::
Object
*
parent
=
nullptr
,
int
property
= -1,
uint
flags
= 0);
801
802
803
static
void
setMaxCallDepth
(
int
maxCallDepth
) {
s_maxCallDepth
=
maxCallDepth
; }
804
static
int
maxCallDepth
() {
return
s_maxCallDepth
; }
805
806
template
<
typename
Value
>
807
static
QJSPrimitiveValue
createPrimitive
(
const
Value
&
v
)
808
{
809
if
(
v
->
isUndefined
())
810
return
QJSPrimitiveValue
(
QJSPrimitiveUndefined
());
811
if
(
v
->
isNull
())
812
return
QJSPrimitiveValue
(
QJSPrimitiveNull
());
813
if
(
v
->
isBoolean
())
814
return
QJSPrimitiveValue
(
v
->
toBoolean
());
815
if
(
v
->
isInteger
())
816
return
QJSPrimitiveValue
(
v
->
integerValue
());
817
if
(
v
->
isDouble
())
818
return
QJSPrimitiveValue
(
v
->
doubleValue
());
819
bool
ok
;
820
const
QString
result
=
v
->
toQString
(&
ok
);
821
return
ok
?
QJSPrimitiveValue
(
result
) :
QJSPrimitiveValue
(
QJSPrimitiveUndefined
());
822
}
823
824
private
:
825
template
<
int
Frames
>
826
friend
struct
ExecutionEngineCallDepthRecorder
;
827
828
static
void
initializeStaticMembers
();
829
830
bool
inStack
(
const
void
*
current
)
const
831
{
832
#
if
Q_STACK_GROWTH_DIRECTION
>
0
833
return
current
<
cppStackLimit
&&
current
>=
cppStackBase
;
834
#
else
835
return
current
>
cppStackLimit
&&
current
<=
cppStackBase
;
836
#
endif
837
}
838
839
void
setCppStackProperties
()
840
{
841
const
StackProperties
stack
=
stackProperties
();
842
cppStackBase
=
stack
.
base
;
843
if
(
s_stackSizeSoftLimit
== -1)
844
cppStackLimit
=
stack
.
softLimit
;
845
else
846
cppStackLimit
=
incrementStackPointer
(
stack
.
base
,
s_stackSizeSoftLimit
);
847
}
848
849
bool
hasCppStackOverflow
()
850
{
851
if
(
s_maxCallDepth
>= 0)
852
return
callDepth
>=
s_maxCallDepth
;
853
854
if
(
inStack
(
currentStackPointer
()))
855
return
false
;
856
857
// Double check the stack limits on failure.
858
// We may have moved to a different thread.
859
setCppStackProperties
();
860
861
return
!
inStack
(
currentStackPointer
());
862
}
863
864
bool
hasJsStackOverflow
()
const
865
{
866
return
jsStackTop
>
jsStackLimit
;
867
}
868
869
bool
hasStackOverflow
()
870
{
871
return
hasJsStackOverflow
() ||
hasCppStackOverflow
();
872
}
873
874
static
int
s_maxCallDepth
;
875
static
int
s_jitCallCountThreshold
;
876
static
int
s_maxJSStackSize
;
877
static
int
s_maxGCStackSize
;
878
static
int
s_stackSizeSoftLimit
;
879
880
#
if
QT_CONFIG
(
qml_debug
)
881
QScopedPointer
<
QV4
::
Debugging
::
Debugger
>
m_debugger
;
882
QScopedPointer
<
QV4
::
Profiling
::
Profiler
>
m_profiler
;
883
#
endif
884
885
// used by generated Promise objects to handle 'then' events
886
QScopedPointer
<
QV4
::
Promise
::
ReactionHandler
>
m_reactionHandler
;
887
888
#
if
QT_CONFIG
(
qml_xml_http_request
)
889
void
*
m_xmlHttpRequestData
=
nullptr
;
890
#
endif
891
892
std
::
unique_ptr
<
QQmlTypeLoader
>
m_typeLoader
;
893
QQmlEngine
*
m_qmlEngine
=
nullptr
;
894
895
QQmlDelayedCallQueue
m_delayedCallQueue
;
896
897
QElapsedTimer
m_time
;
898
QHash
<
QString
,
qint64
>
m_startedTimers
;
899
900
QHash
<
QString
,
quint32
>
m_consoleCount
;
901
902
QList
<
Deletable
*>
m_extensionData
;
903
904
QMultiHash
<
QUrl
,
QQmlRefPointer
<
ExecutableCompilationUnit
>>
m_compilationUnits
;
905
};
906
907
#
define
CHECK_STACK_LIMITS
(
v4
)
908
if
(
v4
->
checkStackLimits
(
)
)
909
return
Encode
::
undefined
(
)
;
910
ExecutionEngineCallDepthRecorder
_executionEngineCallDepthRecorder
(
v4
)
;
911
912
template
<
int
Frames = 1>
913
struct
ExecutionEngineCallDepthRecorder
914
{
915
ExecutionEngine
*
ee
;
916
917
ExecutionEngineCallDepthRecorder
(ExecutionEngine *e):
ee
(
e
)
918
{
919
if
(ExecutionEngine::s_maxCallDepth >= 0)
920
ee->callDepth += Frames;
921
}
922
923
~
ExecutionEngineCallDepthRecorder
()
924
{
925
if
(ExecutionEngine::s_maxCallDepth >= 0)
926
ee->callDepth -= Frames;
927
}
928
929
bool
hasOverflow
()
const
930
{
931
return
ee->hasCppStackOverflow();
932
}
933
};
934
935
inline
bool
ExecutionEngine
::
checkStackLimits
()
936
{
937
if
(
Q_UNLIKELY
(
hasStackOverflow
())) {
938
throwRangeError
(
QStringLiteral
(
"Maximum call stack size exceeded."
));
939
return
true
;
940
}
941
942
return
false
;
943
}
944
945
Q_DECLARE_OPERATORS_FOR_FLAGS
(
ExecutionEngine
::
DiskCacheOptions
);
946
947
}
// namespace QV4
948
949
QT_END_NAMESPACE
950
951
#
endif
// QV4ENGINE_H
QJSManagedValue::QJSEngine
friend class QJSEngine
Definition
qjsmanagedvalue.h:123
QQmlV4Function
Definition
qv4engine_p.h:77
QQmlV4Function::v4engine
QV4::ExecutionEngine * v4engine() const
Definition
qv4engine_p.h:82
QQmlV4Function::operator[]
QV4::ReturnedValue operator[](int idx) const
Definition
qv4engine_p.h:80
QQmlV4Function::length
int length() const
Definition
qv4engine_p.h:79
QQmlV4Function::setReturnValue
void setReturnValue(QV4::ReturnedValue rv)
Definition
qv4engine_p.h:81
QV4::Promise::ReactionHandler
Definition
qv4promiseobject_p.h:33
QV4::CompiledData
Definition
qv4compileddata.cpp:22
QV4::Debugging
Definition
qv4engine_p.h:107
QV4::Heap
Definition
qv4compileddata_p.h:76
QV4::Profiling
Definition
qv4engine_p.h:110
QV4::Promise
Definition
qv4engine_p.h:123
QV4
Definition
qjsvalue.h:24
WTF
Definition
qv4engine_p.h:33
QV4::CompiledData::CompilationUnit::IdToObjectMap
QMap< int, int > IdToObjectMap
Definition
qv4compileddata_p.h:1531
QV4::ExecutionEngineCallDepthRecorder
Definition
qv4engine_p.h:914
QV4::ExecutionEngineCallDepthRecorder::hasOverflow
bool hasOverflow() const
Definition
qv4engine_p.h:929
QV4::ExecutionEngineCallDepthRecorder::~ExecutionEngineCallDepthRecorder
~ExecutionEngineCallDepthRecorder()
Definition
qv4engine_p.h:923
QV4::ExecutionEngineCallDepthRecorder::ExecutionEngineCallDepthRecorder
ExecutionEngineCallDepthRecorder(ExecutionEngine *e)
Definition
qv4engine_p.h:917
QV4::ExecutionEngineCallDepthRecorder::ee
ExecutionEngine * ee
Definition
qv4engine_p.h:915
QV4::ExecutionEngine
\inmodule QtQml
Definition
qv4engine_p.h:128
qtdeclarative
src
qml
jsruntime
qv4engine_p.h
Generated on
for Qt by
1.18.0