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
13 13
14#include "ScriptValueIteratorQtWrapper.h"14#include "ScriptValueIteratorQtWrapper.h"
15 15
16ScriptValueQtWrapper* ScriptValueQtWrapper::unwrap(ScriptValuePointer val) {16void ScriptValueQtWrapper::release() {
17 if (!val) {17 delete this;
18 return nullptr;18}
19 }
20 19
21 return dynamic_cast<ScriptValueQtWrapper*>(val.data());20ScriptValueProxy* ScriptValueQtWrapper::copy() const {
21 return new ScriptValueQtWrapper(_engine, _value);
22}22}
23 23
24QScriptValue ScriptValueQtWrapper::fullUnwrap(const ScriptValuePointer& value) const {24ScriptValueQtWrapper* ScriptValueQtWrapper::unwrap(const ScriptValue& val) {
25 if (!value) {25 return dynamic_cast<ScriptValueQtWrapper*>(val.ptr());
26 return QScriptValue();26}
27 }27
28QScriptValue ScriptValueQtWrapper::fullUnwrap(const ScriptValue& value) const {
28 ScriptValueQtWrapper* unwrapped = unwrap(value);29 ScriptValueQtWrapper* unwrapped = unwrap(value);
29 if (unwrapped) {30 if (unwrapped) {
30 return unwrapped->toQtValue();31 return unwrapped->toQtValue();
31 }32 }
32 QVariant varValue = value->toVariant();33 QVariant varValue = value.toVariant();
33 return static_cast<QScriptEngine*>(_engine)->newVariant(varValue);34 return static_cast<QScriptEngine*>(_engine)->newVariant(varValue);
34}35}
35 36
36QScriptValue ScriptValueQtWrapper::fullUnwrap(ScriptEngineQtScript* engine, const ScriptValuePointer& value) {37QScriptValue ScriptValueQtWrapper::fullUnwrap(ScriptEngineQtScript* engine, const ScriptValue& value) {
37 if (!value) {
38 return QScriptValue();
39 }
40 ScriptValueQtWrapper* unwrapped = unwrap(value);38 ScriptValueQtWrapper* unwrapped = unwrap(value);
41 if (unwrapped) {39 if (unwrapped) {
42 return unwrapped->toQtValue();40 return unwrapped->toQtValue();
43 }41 }
44 QVariant varValue = value->toVariant();42 QVariant varValue = value.toVariant();
45 return static_cast<QScriptEngine*>(engine)->newVariant(varValue);43 return static_cast<QScriptEngine*>(engine)->newVariant(varValue);
46}44}
47 45
48ScriptValuePointer ScriptValueQtWrapper::call(const ScriptValuePointer& thisObject, const ScriptValueList& args) {46ScriptValue ScriptValueQtWrapper::call(const ScriptValue& thisObject, const ScriptValueList& args) {
49 QScriptValue qThis = fullUnwrap(thisObject);47 QScriptValue qThis = fullUnwrap(thisObject);
50 QScriptValueList qArgs;48 QScriptValueList qArgs;
51 for (ScriptValueList::const_iterator iter = args.begin(); iter != args.end(); ++iter) {49 for (ScriptValueList::const_iterator iter = args.begin(); iter != args.end(); ++iter) {
52 qArgs.push_back(fullUnwrap(*iter));50 qArgs.push_back(fullUnwrap(*iter));
53 }51 }
54 QScriptValue result = _value.call(qThis, qArgs);52 QScriptValue result = _value.call(qThis, qArgs);
55 return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));53 return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
56}54}
57 55
58ScriptValuePointer ScriptValueQtWrapper::call(const ScriptValuePointer& thisObject, const ScriptValuePointer& arguments) {56ScriptValue ScriptValueQtWrapper::call(const ScriptValue& thisObject, const ScriptValue& arguments) {
59 QScriptValue qThis = fullUnwrap(thisObject);57 QScriptValue qThis = fullUnwrap(thisObject);
60 QScriptValue qArgs = fullUnwrap(arguments);58 QScriptValue qArgs = fullUnwrap(arguments);
61 QScriptValue result = _value.call(qThis, qArgs);59 QScriptValue result = _value.call(qThis, qArgs);
62 return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));60 return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
63}61}
64 62
65ScriptValuePointer ScriptValueQtWrapper::construct(const ScriptValueList& args) {63ScriptValue ScriptValueQtWrapper::construct(const ScriptValueList& args) {
66 QScriptValueList qArgs;64 QScriptValueList qArgs;
67 for (ScriptValueList::const_iterator iter = args.begin(); iter != args.end(); ++iter) {65 for (ScriptValueList::const_iterator iter = args.begin(); iter != args.end(); ++iter) {
68 qArgs.push_back(fullUnwrap(*iter));66 qArgs.push_back(fullUnwrap(*iter));
69 }67 }
70 QScriptValue result = _value.construct(qArgs);68 QScriptValue result = _value.construct(qArgs);
71 return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));69 return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
72}70}
73 71
74ScriptValuePointer ScriptValueQtWrapper::construct(const ScriptValuePointer& arguments) {72ScriptValue ScriptValueQtWrapper::construct(const ScriptValue& arguments) {
75 QScriptValue unwrapped = fullUnwrap(arguments);73 QScriptValue unwrapped = fullUnwrap(arguments);
76 QScriptValue result = _value.construct(unwrapped);74 QScriptValue result = _value.construct(unwrapped);
77 return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));75 return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
78}76}
79 77
80ScriptValuePointer ScriptValueQtWrapper::data() const {78ScriptValue ScriptValueQtWrapper::data() const {
81 QScriptValue result = _value.data();79 QScriptValue result = _value.data();
82 return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result)));80 return ScriptValue(new ScriptValueQtWrapper(_engine, std::move(result)));
83}81}
84 82
85ScriptEnginePointer ScriptValueQtWrapper::engine() const {83ScriptEnginePointer ScriptValueQtWrapper::engine() const {
@@ -89,43 +87,43 @@ ScriptEnginePointer ScriptValueQtWrapper::engine() const { · 3 unmodified lines
89 return _engine->sharedFromThis();87 return _engine->sharedFromThis();
90}88}
91 89
92ScriptValueIteratorPointer ScriptValueQtWrapper::newIterator() {90ScriptValueIteratorPointer ScriptValueQtWrapper::newIterator() const {
93 return ScriptValueIteratorPointer(new ScriptValueIteratorQtWrapper(_engine, _value));91 return ScriptValueIteratorPointer(new ScriptValueIteratorQtWrapper(_engine, _value));
94}92}
95 93
96ScriptValuePointer ScriptValueQtWrapper::property(const QString& name, const ResolveFlags& mode) const {94ScriptValue ScriptValueQtWrapper::property(const QString& name, const ScriptValue::ResolveFlags& mode) const {
97 QScriptValue result = _value.property(name, (QScriptValue::ResolveFlags)(int)mode);95 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)));
99}97}
100 98
101ScriptValuePointer ScriptValueQtWrapper::property(quint32 arrayIndex, const ResolveFlags& mode) const {99ScriptValue ScriptValueQtWrapper::property(quint32 arrayIndex, const ScriptValue::ResolveFlags& mode) const {
102 QScriptValue result = _value.property(arrayIndex, (QScriptValue::ResolveFlags)(int)mode);100 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)));
104}102}
105 103
106void ScriptValueQtWrapper::setData(const ScriptValuePointer& value) {104void ScriptValueQtWrapper::setData(const ScriptValue& value) {
107 QScriptValue unwrapped = fullUnwrap(value);105 QScriptValue unwrapped = fullUnwrap(value);
108 _value.setData(unwrapped);106 _value.setData(unwrapped);
109}107}
110 108
111void ScriptValueQtWrapper::setProperty(const QString& name, const ScriptValuePointer& value, const PropertyFlags& flags) {109void ScriptValueQtWrapper::setProperty(const QString& name, const ScriptValue& value, const ScriptValue::PropertyFlags& flags) {
112 QScriptValue unwrapped = fullUnwrap(value);110 QScriptValue unwrapped = fullUnwrap(value);
113 _value.setProperty(name, unwrapped, (QScriptValue::PropertyFlags)(int)flags);111 _value.setProperty(name, unwrapped, (QScriptValue::PropertyFlags)(int)flags);
114}112}
115 113
116void ScriptValueQtWrapper::setProperty(quint32 arrayIndex, const ScriptValuePointer& value, const PropertyFlags& flags) {114void ScriptValueQtWrapper::setProperty(quint32 arrayIndex, const ScriptValue& value, const ScriptValue::PropertyFlags& flags) {
117 QScriptValue unwrapped = fullUnwrap(value);115 QScriptValue unwrapped = fullUnwrap(value);
118 _value.setProperty(arrayIndex, unwrapped, (QScriptValue::PropertyFlags)(int)flags);116 _value.setProperty(arrayIndex, unwrapped, (QScriptValue::PropertyFlags)(int)flags);
119}117}
120 118
121void ScriptValueQtWrapper::setPrototype(const ScriptValuePointer& prototype) {119void ScriptValueQtWrapper::setPrototype(const ScriptValue& prototype) {
122 ScriptValueQtWrapper* unwrappedPrototype = unwrap(prototype);120 ScriptValueQtWrapper* unwrappedPrototype = unwrap(prototype);
123 if (unwrappedPrototype) {121 if (unwrappedPrototype) {
124 _value.setPrototype(unwrappedPrototype->toQtValue());122 _value.setPrototype(unwrappedPrototype->toQtValue());
125 }123 }
126}124}
127 125
128bool ScriptValueQtWrapper::strictlyEquals(const ScriptValuePointer& other) const {126bool ScriptValueQtWrapper::strictlyEquals(const ScriptValue& other) const {
129 ScriptValueQtWrapper* unwrappedOther = unwrap(other);127 ScriptValueQtWrapper* unwrappedOther = unwrap(other);
130 return unwrappedOther ? _value.strictlyEquals(unwrappedOther->toQtValue()) : false;128 return unwrappedOther ? _value.strictlyEquals(unwrappedOther->toQtValue()) : false;
131}129}
@@ -166,51 +164,51 @@ QObject* ScriptValueQtWrapper::toQObject() const { · 34 unmodified lines
166 return _value.toQObject();164 return _value.toQObject();
167}165}
168 166
169bool ScriptValueQtWrapper::equalsInternal(const ScriptValuePointer& other) const {167bool ScriptValueQtWrapper::equals(const ScriptValue& other) const {
170 ScriptValueQtWrapper* unwrappedOther = unwrap(other);168 ScriptValueQtWrapper* unwrappedOther = unwrap(other);
171 return unwrappedOther ? _value.equals(unwrappedOther->toQtValue()) : false;169 return unwrappedOther ? _value.equals(unwrappedOther->toQtValue()) : false;
172}170}
173 171
174bool ScriptValueQtWrapper::isArrayInternal() const {172bool ScriptValueQtWrapper::isArray() const {
175 return _value.isArray();173 return _value.isArray();
176}174}
177 175
178bool ScriptValueQtWrapper::isBoolInternal() const {176bool ScriptValueQtWrapper::isBool() const {
179 return _value.isBool();177 return _value.isBool();
180}178}
181 179
182bool ScriptValueQtWrapper::isErrorInternal() const {180bool ScriptValueQtWrapper::isError() const {
183 return _value.isError();181 return _value.isError();
184}182}
185 183
186bool ScriptValueQtWrapper::isFunctionInternal() const {184bool ScriptValueQtWrapper::isFunction() const {
187 return _value.isFunction();185 return _value.isFunction();
188}186}
189 187
190bool ScriptValueQtWrapper::isNumberInternal() const {188bool ScriptValueQtWrapper::isNumber() const {
191 return _value.isNumber();189 return _value.isNumber();
192}190}
193 191
194bool ScriptValueQtWrapper::isNullInternal() const {192bool ScriptValueQtWrapper::isNull() const {
195 return _value.isNull();193 return _value.isNull();
196}194}
197 195
198bool ScriptValueQtWrapper::isObjectInternal() const {196bool ScriptValueQtWrapper::isObject() const {
199 return _value.isObject();197 return _value.isObject();
200}198}
201 199
202bool ScriptValueQtWrapper::isStringInternal() const {200bool ScriptValueQtWrapper::isString() const {
203 return _value.isString();201 return _value.isString();
204}202}
205 203
206bool ScriptValueQtWrapper::isUndefinedInternal() const {204bool ScriptValueQtWrapper::isUndefined() const {
207 return _value.isUndefined();205 return _value.isUndefined();
208}206}
209 207
210bool ScriptValueQtWrapper::isValidInternal() const {208bool ScriptValueQtWrapper::isValid() const {
211 return _value.isValid();209 return _value.isValid();
212}210}
213 211
214bool ScriptValueQtWrapper::isVariantInternal() const {212bool ScriptValueQtWrapper::isVariant() const {
215 return _value.isVariant();213 return _value.isVariant();
216}214}

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