Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qv4argumentsobject.cpp
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
5
6#include <private/qv4alloca_p.h>
7#include <private/qv4arrayobject_p.h>
8#include <private/qv4function_p.h>
9#include <private/qv4jscall_p.h>
10#include <private/qv4scopedvalue_p.h>
11#include <private/qv4stackframe_p.h>
12#include <private/qv4string_p.h>
13#include <private/qv4symbol_p.h>
14
15using namespace QV4;
16
19
20void Heap::StrictArgumentsObject::init(QV4::JSTypesStackFrame *frame)
21
22{
23 Q_ASSERT(vtable() == QV4::StrictArgumentsObject::staticVTable());
24 ExecutionEngine *v4 = internalClass->engine;
25
26 Object::init();
27
28 Q_ASSERT(internalClass->verifyIndex(v4->id_callee()->propertyKey(), CalleePropertyIndex));
29 Q_ASSERT(internalClass->findValueOrSetter(v4->id_callee()->propertyKey()).index == CalleeSetterPropertyIndex);
30 Q_ASSERT(internalClass->verifyIndex(v4->symbol_iterator()->propertyKey(), SymbolIteratorPropertyIndex));
31 setProperty(v4, SymbolIteratorPropertyIndex, *v4->arrayProtoValues());
32 setProperty(v4, CalleePropertyIndex, *v4->thrower());
33 setProperty(v4, CalleeSetterPropertyIndex, *v4->thrower());
34
35 Scope scope(v4);
36 Scoped<QV4::StrictArgumentsObject> args(scope, this);
37 args->arrayReserve(frame->argc());
38 args->arrayPut(0, frame->argv(), frame->argc());
39
40 Q_ASSERT(args->internalClass()->verifyIndex(v4->id_length()->propertyKey(), LengthPropertyIndex));
41 setProperty(v4, LengthPropertyIndex, Value::fromInt32(frame->argc()));
42}
43
44void Heap::ArgumentsObject::init(QV4::CppStackFrame *frame)
45{
46 ExecutionEngine *v4 = internalClass->engine;
47
48 QV4::CallContext *context = static_cast<QV4::CallContext *>(frame->context());
49
50 Object::init();
51 this->context.set(v4, context->d());
52 Q_ASSERT(vtable() == QV4::ArgumentsObject::staticVTable());
53
54 Q_ASSERT(internalClass->verifyIndex(v4->id_callee()->propertyKey(), CalleePropertyIndex));
55 setProperty(v4, CalleePropertyIndex, context->d()->function);
56 Q_ASSERT(internalClass->verifyIndex(v4->id_length()->propertyKey(), LengthPropertyIndex));
57 setProperty(v4, LengthPropertyIndex, Value::fromInt32(context->argc()));
58 Q_ASSERT(internalClass->verifyIndex(v4->symbol_iterator()->propertyKey(), SymbolIteratorPropertyIndex));
59 setProperty(v4, SymbolIteratorPropertyIndex, *v4->arrayProtoValues());
60
61 fullyCreated = false;
62 argCount = frame->argc();
63 uint nFormals = frame->v4Function->nFormals;
64 mapped = nFormals > 63 ? std::numeric_limits<quint64>::max() : (1ull << nFormals) - 1;
65}
66
68{
69 if (d()->fullyCreated)
70 return;
71
72 Scope scope(engine());
73
74 arrayReserve(d()->argCount);
75 arrayPut(0, context()->args(), d()->argCount);
76 // Use a sparse array, so that method_getElement() doesn't shortcut
78
79 d()->fullyCreated = true;
80}
81
83{
84 ArgumentsObject *args = static_cast<ArgumentsObject *>(m);
85 args->fullyCreate();
86 if (!id.isArrayIndex())
87 return Object::virtualDefineOwnProperty(m, id, desc, attrs);
88
89 uint index = id.asArrayIndex();
90
91 if (!args->isMapped(index))
92 return Object::virtualDefineOwnProperty(m, id, desc, attrs);
93
94 Scope scope(args);
96 ScopedProperty cDesc(scope);
97 cDesc->copy(desc, attrs);
98
99 if (attrs.isData() && desc->value.isEmpty() && attrs.hasWritable() && !attrs.isWritable()) {
100 cDesc->value = args->context()->args()[index];
101 cAttrs.setType(PropertyAttributes::Data);
102 }
103
104 bool allowed = Object::virtualDefineOwnProperty(m, id, cDesc, cAttrs);
105 if (!allowed)
106 return false;
107
108 if (attrs.isAccessor()) {
109 args->removeMapping(index);
110 } else {
111 if (!desc->value.isEmpty())
112 args->context()->setArg(index, desc->value);
113 if (attrs.hasWritable() && !attrs.isWritable())
114 args->removeMapping(index);
115 }
116 return true;
117}
118
119ReturnedValue ArgumentsObject::virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty)
120{
121 if (id.isArrayIndex()) {
122 const ArgumentsObject *args = static_cast<const ArgumentsObject *>(m);
123 uint index = id.asArrayIndex();
124 if (index < args->d()->argCount && !args->d()->fullyCreated) {
125 if (hasProperty)
126 *hasProperty = true;
127 return args->context()->args()[index].asReturnedValue();
128 }
129
130 if (args->isMapped(index)) {
131 Q_ASSERT(index < static_cast<uint>(args->context()->function->formalParameterCount()));
132 if (hasProperty)
133 *hasProperty = true;
134 return args->context()->args()[index].asReturnedValue();
135 }
136 }
137
138 return Object::virtualGet(m, id, receiver, hasProperty);
139}
140
142{
143 if (id.isArrayIndex()) {
144 ArgumentsObject *args = static_cast<ArgumentsObject *>(m);
145 uint index = id.asArrayIndex();
146
147 if (args == receiver && index < args->d()->argCount && !args->d()->fullyCreated) {
148 args->context()->setArg(index, value);
149 return true;
150 }
151
152 bool isMapped = (args == receiver && args->isMapped(index));
153 if (isMapped)
154 args->context()->setArg(index, value);
155 }
156
157 return Object::virtualPut(m, id, value, receiver);
158}
159
161{
162 ArgumentsObject *args = static_cast<ArgumentsObject *>(m);
163 args->fullyCreate();
165 if (result && id.isArrayIndex())
166 args->removeMapping(id.asArrayIndex());
167 return result;
168}
169
171{
172 if (!id.isArrayIndex())
173 return Object::virtualGetOwnProperty(m, id, p);
174
175 const ArgumentsObject *args = static_cast<const ArgumentsObject *>(m);
176 uint index = id.asArrayIndex();
177 if (index < args->d()->argCount && !args->d()->fullyCreated) {
178 p->value = args->context()->args()[index];
179 return Attr_Data;
180 }
181
183 if (attrs.isEmpty() || !args->isMapped(index))
184 return attrs;
185
186 Q_ASSERT(index < static_cast<uint>(args->context()->function->formalParameterCount()));
187 if (p)
188 p->value = args->context()->args()[index];
189 return attrs;
190}
191
193{
194 const ArgumentsObject *a = static_cast<const ArgumentsObject *>(m);
195 return a->propertyData(Heap::ArgumentsObject::LengthPropertyIndex)->toLength();
196}
197
quint64 ReturnedValue
@ Attr_Data
QFuture< QtPrivate::MapResultType< Sequence, MapFunctor > > mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
static void * context
static struct AttrInfo attrs[]
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
const GLfloat * m
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLenum target
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
unsigned int uint
Definition qtypes.h:34
long long qint64
Definition qtypes.h:60
#define DEFINE_OBJECT_VTABLE(classname)
QFrame frame
[0]
args<< 1<< 2;QJSValue threeAgain=fun.call(args);QString fileName="helloworld.qs";QFile scriptFile(fileName);if(!scriptFile.open(QIODevice::ReadOnly)) QTextStream stream(&scriptFile);QString contents=stream.readAll();scriptFile.close();myEngine.evaluate(contents, fileName);myEngine.globalObject().setProperty("myNumber", 123);...QJSValue myNumberPlusOne=myEngine.evaluate("myNumber + 1");QJSValue result=myEngine.evaluate(...);if(result.isError()) qDebug()<< "Uncaught exception at line"<< result.property("lineNumber").toInt()<< ":"<< result.toString();QPushButton *button=new QPushButton;QJSValue scriptButton=myEngine.newQObject(button);myEngine.globalObject().setProperty("button", scriptButton);myEngine.evaluate("button.checkable = true");qDebug()<< scriptButton.property("checkable").toBool();scriptButton.property("show").call();QJSEngine engine;QObject *myQObject=new QObject();myQObject- setProperty)("dynamicProperty", 3)
QJSValueList args
Heap::CallContext * context() const
bool isMapped(uint arg) const
Symbol * symbol_iterator() const
String * id_callee() const
String * id_length() const
Object * arrayProtoValues() const
FunctionObject * thrower() const
ExecutionEngine * engine() const
const Value * propertyData(uint index) const
bool hasProperty(PropertyKey id) const
bool arrayPut(uint index, const Value &value)
void initSparseArray()
void arrayReserve(uint n)
QV4_NEARLY_ALWAYS_INLINE constexpr quint32 value() const
PropertyKey propertyKey() const
static constexpr VTable::DefineOwnProperty virtualDefineOwnProperty
static constexpr VTable::OwnPropertyKeys virtualOwnPropertyKeys
static constexpr VTable::GetOwnProperty virtualGetOwnProperty
static constexpr VTable::DeleteProperty virtualDeleteProperty
static constexpr VTable::Get virtualGet
static constexpr VTable::GetLength virtualGetLength
static constexpr VTable::Put virtualPut
qint64 toLength() const
Definition qv4value_p.h:369
static constexpr Value fromInt32(int i)
Definition qv4value_p.h:187