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 QV4ARGUMENTSOBJECTS_H |
4 | #define QV4ARGUMENTSOBJECTS_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 "qv4object_p.h" |
18 | |
19 | QT_BEGIN_NAMESPACE |
20 | |
21 | namespace QV4 { |
22 | |
23 | namespace Heap { |
24 | |
25 | #define ArgumentsObjectMembers(class, Member) \ |
26 | Member(class, Pointer, CallContext *, context) \ |
27 | Member(class, NoMark, bool, fullyCreated) \ |
28 | Member(class, NoMark, uint, argCount) \ |
29 | Member(class, NoMark, quint64, mapped) |
30 | |
31 | DECLARE_HEAP_OBJECT(ArgumentsObject, Object) { |
32 | DECLARE_MARKOBJECTS(ArgumentsObject) |
33 | enum { |
34 | LengthPropertyIndex = 0, |
35 | SymbolIteratorPropertyIndex = 1, |
36 | CalleePropertyIndex = 2 |
37 | }; |
38 | void init(CppStackFrame *frame); |
39 | }; |
40 | |
41 | #define StrictArgumentsObjectMembers(class, Member) |
42 | |
43 | DECLARE_HEAP_OBJECT(StrictArgumentsObject, Object) { |
44 | enum { |
45 | LengthPropertyIndex = 0, |
46 | SymbolIteratorPropertyIndex = 1, |
47 | CalleePropertyIndex = 2, |
48 | CalleeSetterPropertyIndex = 3 |
49 | }; |
50 | void init(JSTypesStackFrame *frame); |
51 | }; |
52 | |
53 | } |
54 | |
55 | struct ArgumentsObject: Object { |
56 | V4_OBJECT2(ArgumentsObject, Object) |
57 | Q_MANAGED_TYPE(ArgumentsObject) |
58 | |
59 | Heap::CallContext *context() const { return d()->context; } |
60 | bool fullyCreated() const { return d()->fullyCreated; } |
61 | |
62 | static bool isNonStrictArgumentsObject(Managed *m) { |
63 | return m->vtable() == staticVTable(); |
64 | } |
65 | |
66 | static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *desc, PropertyAttributes attrs); |
67 | static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); |
68 | static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver); |
69 | static bool virtualDeleteProperty(Managed *m, PropertyKey id); |
70 | static PropertyAttributes virtualGetOwnProperty(const Managed *m, PropertyKey id, Property *p); |
71 | static qint64 virtualGetLength(const Managed *m); |
72 | static OwnPropertyKeyIterator *virtualOwnPropertyKeys(const Object *m, Value *target); |
73 | |
74 | void fullyCreate(); |
75 | |
76 | // There's a slight hack here, as this limits the amount of mapped arguments to 64, but that should be |
77 | // more than enough for all practical uses of arguments |
78 | bool isMapped(uint arg) const { |
79 | return arg < 64 && (d()->mapped & (1ull << arg)); |
80 | } |
81 | |
82 | void removeMapping(uint arg) { |
83 | if (arg < 64) |
84 | (d()->mapped &= ~(1ull << arg)); |
85 | } |
86 | |
87 | }; |
88 | |
89 | struct StrictArgumentsObject : Object { |
90 | V4_OBJECT2(StrictArgumentsObject, Object) |
91 | Q_MANAGED_TYPE(ArgumentsObject) |
92 | }; |
93 | |
94 | } |
95 | |
96 | QT_END_NAMESPACE |
97 | |
98 | #endif |
99 | |
100 | |