History

rework ScriptValue to act like a stack variable rather than a pointer

Heather Anderson committed 5 years ago

Commit 85810221 parent f209c51170 files · +2837 −2594Browse files

Showing the changes to libraries/script-engine/src/qtscript/ScriptValueQtWrapper.cpp (1 of 170 files). Show all

Unified · Split

libraries/script-engine/src/qtscript/ScriptValueQtWrapper.cpp+45−47
@@ -13,73 +13,71 @@ · 12 unmodified lines
1313
1414 #include "ScriptValueIteratorQtWrapper.h"
1515
16−ScriptValueQtWrapper* ScriptValueQtWrapper::unwrap(ScriptValuePointer val) {
17− if (!val) {
18− return nullptr;
19− }
16+void ScriptValueQtWrapper::release() {
17+ delete this;
18+}
2019
21− return dynamic_cast<ScriptValueQtWrapper*>(val.data());
20+ScriptValueProxy* ScriptValueQtWrapper::copy() const {
21+ return new ScriptValueQtWrapper(_engine, _value);
2222 }
2323
24−QScriptValue ScriptValueQtWrapper::fullUnwrap(const ScriptValuePointer& value) const {
25− if (!value) {
26− return QScriptValue();
27− }
24+ScriptValueQtWrapper* ScriptValueQtWrapper::unwrap(const ScriptValue& val) {
25+ return dynamic_cast<ScriptValueQtWrapper*>(val.ptr());
26+}
27+
28+QScriptValue ScriptValueQtWrapper::fullUnwrap(const ScriptValue& value) const {
2829 ScriptValueQtWrapper* unwrapped = unwrap(value);
2930 if (unwrapped) {
3031 return unwrapped->toQtValue();
3132 }
32− QVariant varValue = value->toVariant();
33+ QVariant varValue = value.toVariant();
3334 return static_cast<QScriptEngine*>(_engine)->newVariant(varValue);
3435 }
3536
36−QScriptValue ScriptValueQtWrapper::fullUnwrap(ScriptEngineQtScript* engine, const ScriptValuePointer& value) {
37− if (!value) {
38− return QScriptValue();
39− }
37+QScriptValue ScriptValueQtWrapper::fullUnwrap(ScriptEngineQtScript* engine, const ScriptValue& value) {
4038 ScriptValueQtWrapper* unwrapped = unwrap(value);
4139 if (unwrapped) {
4240 return unwrapped->toQtValue();
4341 }
44− QVariant varValue = value->toVariant();
42+ QVariant varValue = value.toVariant();
4543 return static_cast<QScriptEngine*>(engine)->newVariant(varValue);
4644 }
4745
48−ScriptValuePointer ScriptValueQtWrapper::call(const ScriptValuePointer& thisObject, const ScriptValueList& args) {
46+ScriptValue ScriptValueQtWrapper::call(const ScriptValue& thisObject, const ScriptValueList& args) {
4947 QScriptValue qThis = fullUnwrap(thisObject);
5048 QScriptValueList qArgs;
5149 for (ScriptValueList::const_iterator iter = args.begin(); iter != args.end(); ++iter) {
5250 qArgs.push_back(fullUnwrap(*iter));
5351 }
5452 QScriptValue result = _value.call(qThis, qArgs);
55− return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));
53+ return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
5654 }
5755
58−ScriptValuePointer ScriptValueQtWrapper::call(const ScriptValuePointer& thisObject, const ScriptValuePointer& arguments) {
56+ScriptValue ScriptValueQtWrapper::call(const ScriptValue& thisObject, const ScriptValue& arguments) {
5957 QScriptValue qThis = fullUnwrap(thisObject);
6058 QScriptValue qArgs = fullUnwrap(arguments);
6159 QScriptValue result = _value.call(qThis, qArgs);
62− return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));
60+ return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
6361 }
6462
65−ScriptValuePointer ScriptValueQtWrapper::construct(const ScriptValueList& args) {
63+ScriptValue ScriptValueQtWrapper::construct(const ScriptValueList& args) {
6664 QScriptValueList qArgs;
6765 for (ScriptValueList::const_iterator iter = args.begin(); iter != args.end(); ++iter) {
6866 qArgs.push_back(fullUnwrap(*iter));
6967 }
7068 QScriptValue result = _value.construct(qArgs);
71− return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));
69+ return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
7270 }
7371
74−ScriptValuePointer ScriptValueQtWrapper::construct(const ScriptValuePointer& arguments) {
72+ScriptValue ScriptValueQtWrapper::construct(const ScriptValue& arguments) {
7573 QScriptValue unwrapped = fullUnwrap(arguments);
7674 QScriptValue result = _value.construct(unwrapped);
77− return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));
75+ return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
7876 }
7977
80−ScriptValuePointer ScriptValueQtWrapper::data() const {
78+ScriptValue ScriptValueQtWrapper::data() const {
8179 QScriptValue result = _value.data();
82− return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));
80+ return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
8381 }
8482
8583 ScriptEnginePointer ScriptValueQtWrapper::engine() const {
@@ -89,43 +87,43 @@ ScriptEnginePointer ScriptValueQtWrapper::engine() const { · 3 unmodified lines
8987 return _engine->sharedFromThis();
9088 }
9189
92−ScriptValueIteratorPointer ScriptValueQtWrapper::newIterator() {
90+ScriptValueIteratorPointer ScriptValueQtWrapper::newIterator() const {
9391 return ScriptValueIteratorPointer(new ScriptValueIteratorQtWrapper(_engine, _value));
9492 }
9593
96−ScriptValuePointer ScriptValueQtWrapper::property(const QString& name, const ResolveFlags& mode) const {
94+ScriptValue ScriptValueQtWrapper::property(const QString& name, const ScriptValue::ResolveFlags& mode) const {
9795 QScriptValue result = _value.property(name, (QScriptValue::ResolveFlags)(int)mode);
98− return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));
96+ return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
9997 }
10098
101−ScriptValuePointer ScriptValueQtWrapper::property(quint32 arrayIndex, const ResolveFlags& mode) const {
99+ScriptValue ScriptValueQtWrapper::property(quint32 arrayIndex, const ScriptValue::ResolveFlags& mode) const {
102100 QScriptValue result = _value.property(arrayIndex, (QScriptValue::ResolveFlags)(int)mode);
103− return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));
101+ return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
104102 }
105103
106−void ScriptValueQtWrapper::setData(const ScriptValuePointer& value) {
104+void ScriptValueQtWrapper::setData(const ScriptValue& value) {
107105 QScriptValue unwrapped = fullUnwrap(value);
108106 _value.setData(unwrapped);
109107 }
110108
111−void ScriptValueQtWrapper::setProperty(const QString& name, const ScriptValuePointer& value, const PropertyFlags& flags) {
109+void ScriptValueQtWrapper::setProperty(const QString& name, const ScriptValue& value, const ScriptValue::PropertyFlags& flags) {
112110 QScriptValue unwrapped = fullUnwrap(value);
113111 _value.setProperty(name, unwrapped, (QScriptValue::PropertyFlags)(int)flags);
114112 }
115113
116−void ScriptValueQtWrapper::setProperty(quint32 arrayIndex, const ScriptValuePointer& value, const PropertyFlags& flags) {
114+void ScriptValueQtWrapper::setProperty(quint32 arrayIndex, const ScriptValue& value, const ScriptValue::PropertyFlags& flags) {
117115 QScriptValue unwrapped = fullUnwrap(value);
118116 _value.setProperty(arrayIndex, unwrapped, (QScriptValue::PropertyFlags)(int)flags);
119117 }
120118
121−void ScriptValueQtWrapper::setPrototype(const ScriptValuePointer& prototype) {
119+void ScriptValueQtWrapper::setPrototype(const ScriptValue& prototype) {
122120 ScriptValueQtWrapper* unwrappedPrototype = unwrap(prototype);
123121 if (unwrappedPrototype) {
124122 _value.setPrototype(unwrappedPrototype->toQtValue());
125123 }
126124 }
127125
128−bool ScriptValueQtWrapper::strictlyEquals(const ScriptValuePointer& other) const {
126+bool ScriptValueQtWrapper::strictlyEquals(const ScriptValue& other) const {
129127 ScriptValueQtWrapper* unwrappedOther = unwrap(other);
130128 return unwrappedOther ? _value.strictlyEquals(unwrappedOther->toQtValue()) : false;
131129 }
@@ -166,51 +164,51 @@ QObject* ScriptValueQtWrapper::toQObject() const { · 34 unmodified lines
166164 return _value.toQObject();
167165 }
168166
169−bool ScriptValueQtWrapper::equalsInternal(const ScriptValuePointer& other) const {
167+bool ScriptValueQtWrapper::equals(const ScriptValue& other) const {
170168 ScriptValueQtWrapper* unwrappedOther = unwrap(other);
171169 return unwrappedOther ? _value.equals(unwrappedOther->toQtValue()) : false;
172170 }
173171
174−bool ScriptValueQtWrapper::isArrayInternal() const {
172+bool ScriptValueQtWrapper::isArray() const {
175173 return _value.isArray();
176174 }
177175
178−bool ScriptValueQtWrapper::isBoolInternal() const {
176+bool ScriptValueQtWrapper::isBool() const {
179177 return _value.isBool();
180178 }
181179
182−bool ScriptValueQtWrapper::isErrorInternal() const {
180+bool ScriptValueQtWrapper::isError() const {
183181 return _value.isError();
184182 }
185183
186−bool ScriptValueQtWrapper::isFunctionInternal() const {
184+bool ScriptValueQtWrapper::isFunction() const {
187185 return _value.isFunction();
188186 }
189187
190−bool ScriptValueQtWrapper::isNumberInternal() const {
188+bool ScriptValueQtWrapper::isNumber() const {
191189 return _value.isNumber();
192190 }
193191
194−bool ScriptValueQtWrapper::isNullInternal() const {
192+bool ScriptValueQtWrapper::isNull() const {
195193 return _value.isNull();
196194 }
197195
198−bool ScriptValueQtWrapper::isObjectInternal() const {
196+bool ScriptValueQtWrapper::isObject() const {
199197 return _value.isObject();
200198 }
201199
202−bool ScriptValueQtWrapper::isStringInternal() const {
200+bool ScriptValueQtWrapper::isString() const {
203201 return _value.isString();
204202 }
205203
206−bool ScriptValueQtWrapper::isUndefinedInternal() const {
204+bool ScriptValueQtWrapper::isUndefined() const {
207205 return _value.isUndefined();
208206 }
209207
210−bool ScriptValueQtWrapper::isValidInternal() const {
208+bool ScriptValueQtWrapper::isValid() const {
211209 return _value.isValid();
212210 }
213211
214−bool ScriptValueQtWrapper::isVariantInternal() const {
212+bool ScriptValueQtWrapper::isVariant() const {
215213 return _value.isVariant();
216214 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t