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#ifndef QV4RUNTIMEAPI_P_H
4#define QV4RUNTIMEAPI_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <private/qv4global_p.h>
18#include <private/qv4staticvalue_p.h>
19
20QT_BEGIN_NAMESPACE
21
22namespace QV4 {
23
24typedef uint Bool;
25
26struct Q_QML_PRIVATE_EXPORT Runtime {
27 typedef ReturnedValue (*UnaryOperation)(const Value &value);
28 typedef ReturnedValue (*BinaryOperation)(const Value &left, const Value &right);
29 typedef ReturnedValue (*BinaryOperationContext)(ExecutionEngine *, const Value &left, const Value &right);
30
31 enum class Throws { No, Yes };
32 enum class ChangesContext { No, Yes };
33 enum class Pure { No, Yes };
34 enum class LastArgumentIsOutputValue { No, Yes };
35
36 template<Throws t, ChangesContext c = ChangesContext::No, Pure p = Pure::No,
37 LastArgumentIsOutputValue out = LastArgumentIsOutputValue::No>
38 struct Method
39 {
40 static constexpr bool throws = t == Throws::Yes;
41 static constexpr bool changesContext = c == ChangesContext::Yes;
42 static constexpr bool pure = p == Pure::Yes;
43 static constexpr bool lastArgumentIsOutputValue = out == LastArgumentIsOutputValue::Yes;
44 };
45 using PureMethod = Method<Throws::No, ChangesContext::No, Pure::Yes>;
46 using IteratorMethod = Method<Throws::Yes, ChangesContext::No, Pure::No,
47 LastArgumentIsOutputValue::Yes>;
48
49 /* call */
50 struct Q_QML_PRIVATE_EXPORT CallGlobalLookup : Method<Throws::Yes>
51 {
52 static ReturnedValue call(ExecutionEngine *, uint, Value[], int);
53 };
54 struct Q_QML_PRIVATE_EXPORT CallQmlContextPropertyLookup : Method<Throws::Yes>
55 {
56 static ReturnedValue call(ExecutionEngine *, uint, Value[], int);
57 };
58 struct Q_QML_PRIVATE_EXPORT CallName : Method<Throws::Yes>
59 {
60 static ReturnedValue call(ExecutionEngine *, int, Value[], int);
61 };
62 struct Q_QML_PRIVATE_EXPORT CallProperty : Method<Throws::Yes>
63 {
64 static ReturnedValue call(ExecutionEngine *, const Value &, int, Value[], int);
65 };
66 struct Q_QML_PRIVATE_EXPORT CallPropertyLookup : Method<Throws::Yes>
67 {
68 static ReturnedValue call(ExecutionEngine *, const Value &, uint, Value[], int);
69 };
70 struct Q_QML_PRIVATE_EXPORT CallValue : Method<Throws::Yes>
71 {
72 static ReturnedValue call(ExecutionEngine *, const Value &, Value[], int);
73 };
74 struct Q_QML_PRIVATE_EXPORT CallWithReceiver : Method<Throws::Yes>
75 {
76 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &, Value[], int);
77 };
78 struct Q_QML_PRIVATE_EXPORT CallPossiblyDirectEval : Method<Throws::Yes>
79 {
80 static ReturnedValue call(ExecutionEngine *, Value[], int);
81 };
82 struct Q_QML_PRIVATE_EXPORT CallWithSpread : Method<Throws::Yes>
83 {
84 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &, Value[], int);
85 };
86 struct Q_QML_PRIVATE_EXPORT TailCall : Method<Throws::Yes>
87 {
88 static ReturnedValue call(JSTypesStackFrame *, ExecutionEngine *engine);
89 };
90
91 /* construct */
92 struct Q_QML_PRIVATE_EXPORT Construct : Method<Throws::Yes>
93 {
94 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &, Value[], int);
95 };
96 struct Q_QML_PRIVATE_EXPORT ConstructWithSpread : Method<Throws::Yes>
97 {
98 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &, Value[], int);
99 };
100
101 /* load & store */
102 struct Q_QML_PRIVATE_EXPORT StoreNameStrict : Method<Throws::Yes>
103 {
104 static void call(ExecutionEngine *, int, const Value &);
105 };
106 struct Q_QML_PRIVATE_EXPORT StoreNameSloppy : Method<Throws::Yes>
107 {
108 static void call(ExecutionEngine *, int, const Value &);
109 };
110 struct Q_QML_PRIVATE_EXPORT StoreProperty : Method<Throws::Yes>
111 {
112 static void call(ExecutionEngine *, const Value &, int, const Value &);
113 };
114 struct Q_QML_PRIVATE_EXPORT StoreElement : Method<Throws::Yes>
115 {
116 static void call(ExecutionEngine *, const Value &, const Value &, const Value &);
117 };
118 struct Q_QML_PRIVATE_EXPORT LoadProperty : Method<Throws::Yes>
119 {
120 static ReturnedValue call(ExecutionEngine *, const Value &, int);
121 };
122 struct Q_QML_PRIVATE_EXPORT LoadName : Method<Throws::Yes>
123 {
124 static ReturnedValue call(ExecutionEngine *, int);
125 };
126 struct Q_QML_PRIVATE_EXPORT LoadElement : Method<Throws::Yes>
127 {
128 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &);
129 };
130 struct Q_QML_PRIVATE_EXPORT LoadSuperProperty : Method<Throws::Yes>
131 {
132 static ReturnedValue call(ExecutionEngine *, const Value &);
133 };
134 struct Q_QML_PRIVATE_EXPORT StoreSuperProperty : Method<Throws::Yes>
135 {
136 static void call(ExecutionEngine *, const Value &, const Value &);
137 };
138 struct Q_QML_PRIVATE_EXPORT LoadSuperConstructor : Method<Throws::Yes>
139 {
140 static ReturnedValue call(ExecutionEngine *, const Value &);
141 };
142 struct Q_QML_PRIVATE_EXPORT LoadGlobalLookup : Method<Throws::Yes>
143 {
144 static ReturnedValue call(ExecutionEngine *, Function *, int);
145 };
146 struct Q_QML_PRIVATE_EXPORT LoadQmlContextPropertyLookup : Method<Throws::Yes>
147 {
148 static ReturnedValue call(ExecutionEngine *, uint);
149 };
150 struct Q_QML_PRIVATE_EXPORT GetLookup : Method<Throws::Yes>
151 {
152 static ReturnedValue call(ExecutionEngine *, Function *, const Value &, int);
153 };
154 struct Q_QML_PRIVATE_EXPORT SetLookupStrict : Method<Throws::Yes>
155 {
156 static void call(Function *, const Value &, int, const Value &);
157 };
158 struct Q_QML_PRIVATE_EXPORT SetLookupSloppy : Method<Throws::Yes>
159 {
160 static void call(Function *, const Value &, int, const Value &);
161 };
162
163 /* typeof */
164 struct Q_QML_PRIVATE_EXPORT TypeofValue : PureMethod
165 {
166 static ReturnedValue call(ExecutionEngine *, const Value &);
167 };
168 struct Q_QML_PRIVATE_EXPORT TypeofName : Method<Throws::No>
169 {
170 static ReturnedValue call(ExecutionEngine *, int);
171 };
172
173 /* delete */
174 struct Q_QML_PRIVATE_EXPORT DeleteProperty_NoThrow : Method<Throws::No>
175 {
176 static Bool call(ExecutionEngine *, const Value &, const Value &);
177 };
178 struct Q_QML_PRIVATE_EXPORT DeleteProperty : Method<Throws::Yes>
179 {
180 static ReturnedValue call(ExecutionEngine *, Function *, const Value &, const Value &);
181 };
182 struct Q_QML_PRIVATE_EXPORT DeleteName_NoThrow : Method<Throws::No>
183 {
184 static Bool call(ExecutionEngine *, int);
185 };
186 struct Q_QML_PRIVATE_EXPORT DeleteName : Method<Throws::Yes>
187 {
188 static ReturnedValue call(ExecutionEngine *, Function *, int);
189 };
190
191 /* exceptions & scopes */
192 struct Q_QML_PRIVATE_EXPORT ThrowException : Method<Throws::Yes>
193 {
194 static void call(ExecutionEngine *, const Value &);
195 };
196 struct Q_QML_PRIVATE_EXPORT PushCallContext : Method<Throws::No, ChangesContext::Yes>
197 {
198 static void call(JSTypesStackFrame *);
199 };
200 struct Q_QML_PRIVATE_EXPORT PushWithContext : Method<Throws::Yes, ChangesContext::Yes>
201 {
202 static ReturnedValue call(ExecutionEngine *, const Value &);
203 };
204 struct Q_QML_PRIVATE_EXPORT PushCatchContext : Method<Throws::No, ChangesContext::Yes>
205 {
206 static void call(ExecutionEngine *, int, int);
207 };
208 struct Q_QML_PRIVATE_EXPORT PushBlockContext : Method<Throws::No, ChangesContext::Yes>
209 {
210 static void call(ExecutionEngine *, int);
211 };
212 struct Q_QML_PRIVATE_EXPORT CloneBlockContext : Method<Throws::No, ChangesContext::Yes>
213 {
214 static void call(ExecutionEngine *);
215 };
216 struct Q_QML_PRIVATE_EXPORT PushScriptContext : Method<Throws::No, ChangesContext::Yes>
217 {
218 static void call(ExecutionEngine *, int);
219 };
220 struct Q_QML_PRIVATE_EXPORT PopScriptContext : Method<Throws::No, ChangesContext::Yes>
221 {
222 static void call(ExecutionEngine *);
223 };
224 struct Q_QML_PRIVATE_EXPORT ThrowReferenceError : Method<Throws::Yes>
225 {
226 static void call(ExecutionEngine *, int);
227 };
228 struct Q_QML_PRIVATE_EXPORT ThrowOnNullOrUndefined : Method<Throws::Yes>
229 {
230 static void call(ExecutionEngine *, const Value &);
231 };
232
233 /* closures */
234 struct Q_QML_PRIVATE_EXPORT Closure : Method<Throws::No>
235 {
236 static ReturnedValue call(ExecutionEngine *, int);
237 };
238
239 /* Function header */
240 struct Q_QML_PRIVATE_EXPORT ConvertThisToObject : Method<Throws::Yes>
241 {
242 static ReturnedValue call(ExecutionEngine *, const Value &);
243 };
244 struct Q_QML_PRIVATE_EXPORT DeclareVar : Method<Throws::Yes>
245 {
246 static void call(ExecutionEngine *, Bool, int);
247 };
248 struct Q_QML_PRIVATE_EXPORT CreateMappedArgumentsObject : Method<Throws::No>
249 {
250 static ReturnedValue call(ExecutionEngine *);
251 };
252 struct Q_QML_PRIVATE_EXPORT CreateUnmappedArgumentsObject : Method<Throws::No>
253 {
254 static ReturnedValue call(ExecutionEngine *);
255 };
256 struct Q_QML_PRIVATE_EXPORT CreateRestParameter : PureMethod
257 {
258 static ReturnedValue call(ExecutionEngine *, int);
259 };
260
261 /* literals */
262 struct Q_QML_PRIVATE_EXPORT ArrayLiteral : Method<Throws::Yes>
263 {
264 static ReturnedValue call(ExecutionEngine *, Value[], uint);
265 };
266 struct Q_QML_PRIVATE_EXPORT ObjectLiteral : Method<Throws::Yes>
267 {
268 static ReturnedValue call(ExecutionEngine *, int, Value[], int);
269 };
270 struct Q_QML_PRIVATE_EXPORT CreateClass : Method<Throws::Yes>
271 {
272 static ReturnedValue call(ExecutionEngine *, int, const Value &, Value[]);
273 };
274
275 /* for-in, for-of and array destructuring */
276 struct Q_QML_PRIVATE_EXPORT GetIterator : Method<Throws::Yes>
277 {
278 static ReturnedValue call(ExecutionEngine *, const Value &, int);
279 };
280 struct Q_QML_PRIVATE_EXPORT IteratorNext : IteratorMethod
281 {
282 static ReturnedValue call(ExecutionEngine *, const Value &, Value *);
283 };
284 struct Q_QML_PRIVATE_EXPORT IteratorNextForYieldStar : IteratorMethod
285 {
286 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &, Value *);
287 };
288 struct Q_QML_PRIVATE_EXPORT IteratorClose : Method<Throws::Yes>
289 {
290 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &);
291 };
292 struct Q_QML_PRIVATE_EXPORT DestructureRestElement : Method<Throws::Yes>
293 {
294 static ReturnedValue call(ExecutionEngine *, const Value &);
295 };
296
297 /* conversions */
298 struct Q_QML_PRIVATE_EXPORT ToObject : Method<Throws::Yes>
299 {
300 static ReturnedValue call(ExecutionEngine *, const Value &);
301 };
302 struct Q_QML_PRIVATE_EXPORT ToBoolean : PureMethod
303 {
304 static Bool call(const Value &);
305 };
306 struct Q_QML_PRIVATE_EXPORT ToNumber : Method<Throws::Yes>
307 {
308 static ReturnedValue call(ExecutionEngine *, const Value &);
309 };
310 /* unary operators */
311 struct Q_QML_PRIVATE_EXPORT UMinus : Method<Throws::Yes>
312 {
313 static ReturnedValue call(const Value &);
314 };
315
316 /* binary operators */
317 struct Q_QML_PRIVATE_EXPORT Instanceof : Method<Throws::Yes>
318 {
319 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &);
320 };
321 struct Q_QML_PRIVATE_EXPORT As : Method<Throws::No>
322 {
323 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &);
324 };
325 struct Q_QML_PRIVATE_EXPORT In : Method<Throws::Yes>
326 {
327 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &);
328 };
329 struct Q_QML_PRIVATE_EXPORT Add : Method<Throws::Yes>
330 {
331 static ReturnedValue call(ExecutionEngine *, const Value &, const Value &);
332 };
333 struct Q_QML_PRIVATE_EXPORT Sub : Method<Throws::Yes>
334 {
335 static ReturnedValue call(const Value &, const Value &);
336 };
337 struct Q_QML_PRIVATE_EXPORT Mul : Method<Throws::Yes>
338 {
339 static ReturnedValue call(const Value &, const Value &);
340 };
341 struct Q_QML_PRIVATE_EXPORT Div : Method<Throws::Yes>
342 {
343 static ReturnedValue call(const Value &, const Value &);
344 };
345 struct Q_QML_PRIVATE_EXPORT Mod : Method<Throws::Yes>
346 {
347 static ReturnedValue call(const Value &, const Value &);
348 };
349 struct Q_QML_PRIVATE_EXPORT Exp : Method<Throws::Yes>
350 {
351 static ReturnedValue call(const Value &, const Value &);
352 };
353 struct Q_QML_PRIVATE_EXPORT BitAnd : Method<Throws::Yes>
354 {
355 static ReturnedValue call(const Value &, const Value &);
356 };
357 struct Q_QML_PRIVATE_EXPORT BitOr : Method<Throws::Yes>
358 {
359 static ReturnedValue call(const Value &, const Value &);
360 };
361 struct Q_QML_PRIVATE_EXPORT BitXor : Method<Throws::Yes>
362 {
363 static ReturnedValue call(const Value &, const Value &);
364 };
365 struct Q_QML_PRIVATE_EXPORT Shl : Method<Throws::Yes>
366 {
367 static ReturnedValue call(const Value &, const Value &);
368 };
369 struct Q_QML_PRIVATE_EXPORT Shr : Method<Throws::Yes>
370 {
371 static ReturnedValue call(const Value &, const Value &);
372 };
373 struct Q_QML_PRIVATE_EXPORT UShr : Method<Throws::Yes>
374 {
375 static ReturnedValue call(const Value &, const Value &);
376 };
377 struct Q_QML_PRIVATE_EXPORT GreaterThan : Method<Throws::Yes>
378 {
379 static ReturnedValue call(const Value &, const Value &);
380 };
381 struct Q_QML_PRIVATE_EXPORT LessThan : Method<Throws::Yes>
382 {
383 static ReturnedValue call(const Value &, const Value &);
384 };
385 struct Q_QML_PRIVATE_EXPORT GreaterEqual : Method<Throws::Yes>
386 {
387 static ReturnedValue call(const Value &, const Value &);
388 };
389 struct Q_QML_PRIVATE_EXPORT LessEqual : Method<Throws::Yes>
390 {
391 static ReturnedValue call(const Value &, const Value &);
392 };
393 struct Q_QML_PRIVATE_EXPORT Equal : Method<Throws::Yes>
394 {
395 static ReturnedValue call(const Value &, const Value &);
396 };
397 struct Q_QML_PRIVATE_EXPORT NotEqual : Method<Throws::Yes>
398 {
399 static ReturnedValue call(const Value &, const Value &);
400 };
401 struct Q_QML_PRIVATE_EXPORT StrictEqual : Method<Throws::Yes>
402 {
403 static ReturnedValue call(const Value &, const Value &);
404 };
405 struct Q_QML_PRIVATE_EXPORT StrictNotEqual : Method<Throws::Yes>
406 {
407 static ReturnedValue call(const Value &, const Value &);
408 };
409
410 /* comparisons */
411 struct Q_QML_PRIVATE_EXPORT CompareGreaterThan : Method<Throws::Yes>
412 {
413 static Bool call(const Value &, const Value &);
414 };
415 struct Q_QML_PRIVATE_EXPORT CompareLessThan : Method<Throws::Yes>
416 {
417 static Bool call(const Value &, const Value &);
418 };
419 struct Q_QML_PRIVATE_EXPORT CompareGreaterEqual : Method<Throws::Yes>
420 {
421 static Bool call(const Value &, const Value &);
422 };
423 struct Q_QML_PRIVATE_EXPORT CompareLessEqual : Method<Throws::Yes>
424 {
425 static Bool call(const Value &, const Value &);
426 };
427 struct Q_QML_PRIVATE_EXPORT CompareEqual : Method<Throws::Yes>
428 {
429 static Bool call(const Value &, const Value &);
430 };
431 struct Q_QML_PRIVATE_EXPORT CompareNotEqual : Method<Throws::Yes>
432 {
433 static Bool call(const Value &, const Value &);
434 };
435 struct Q_QML_PRIVATE_EXPORT CompareStrictEqual : Method<Throws::Yes>
436 {
437 static Bool call(const Value &, const Value &);
438 };
439 struct Q_QML_PRIVATE_EXPORT CompareStrictNotEqual : Method<Throws::Yes>
440 {
441 static Bool call(const Value &, const Value &);
442 };
443
444 struct Q_QML_PRIVATE_EXPORT CompareInstanceof : Method<Throws::Yes>
445 {
446 static Bool call(ExecutionEngine *, const Value &, const Value &);
447 };
448 struct Q_QML_PRIVATE_EXPORT CompareIn : Method<Throws::Yes>
449 {
450 static Bool call(ExecutionEngine *, const Value &, const Value &);
451 };
452
453 struct Q_QML_PRIVATE_EXPORT RegexpLiteral : PureMethod
454 {
455 static ReturnedValue call(ExecutionEngine *, int);
456 };
457 struct Q_QML_PRIVATE_EXPORT GetTemplateObject : PureMethod
458 {
459 static ReturnedValue call(Function *, int);
460 };
461
462 struct StackOffsets {
463 static const int tailCall_function = -1;
464 static const int tailCall_thisObject = -2;
465 static const int tailCall_argv = -3;
466 static const int tailCall_argc = -4;
467 };
468
469 static QHash<const void *, const char *> symbolTable();
470};
471
472static_assert(std::is_standard_layout<Runtime>::value, "Runtime needs to be standard layout in order for us to be able to use offsetof");
473static_assert(sizeof(Runtime::BinaryOperation) == sizeof(void*), "JIT expects a function pointer to fit into a regular pointer, for cross-compilation offset translation");
474
475} // namespace QV4
476
477QT_END_NAMESPACE
478
479#endif // QV4RUNTIMEAPI_P_H
480

source code of qtdeclarative/src/qml/jsruntime/qv4runtimeapi_p.h