Showing the changes to libraries/script-engine/src/qtscript/ScriptValueQtWrapper.cpp (1 of 170 files). Show all
Unified · Split
| @@ -13,73 +13,71 @@ · 12 unmodified lines | |||
| 13 | 13 | ||
| 14 | #include "ScriptValueIteratorQtWrapper.h" | 14 | #include "ScriptValueIteratorQtWrapper.h" |
| 15 | 15 | ||
| 16 | ScriptValueQtWrapper* ScriptValueQtWrapper::unwrap(ScriptValuePointer val) { | 16 | void ScriptValueQtWrapper::release() { |
| 17 | if (!val) { | 17 | delete this; |
| 18 | return nullptr; | 18 | } |
| 19 | } | ||
| 20 | 19 | ||
| 21 | return dynamic_cast<ScriptValueQtWrapper*>(val.data()); | 20 | ScriptValueProxy* ScriptValueQtWrapper::copy() const { |
| 21 | return new ScriptValueQtWrapper(_engine, _value); | ||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | QScriptValue ScriptValueQtWrapper::fullUnwrap(const ScriptValuePointer& value) const { | 24 | ScriptValueQtWrapper* ScriptValueQtWrapper::unwrap(const ScriptValue& val) { |
| 25 | if (!value) { | 25 | return dynamic_cast<ScriptValueQtWrapper*>(val.ptr()); |
| 26 | return QScriptValue(); | 26 | } |
| 27 | } | 27 | |
| 28 | QScriptValue 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 | ||
| 36 | QScriptValue ScriptValueQtWrapper::fullUnwrap(ScriptEngineQtScript* engine, const ScriptValuePointer& value) { | 37 | QScriptValue 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 | ||
| 48 | ScriptValuePointer ScriptValueQtWrapper::call(const ScriptValuePointer& thisObject, const ScriptValueList& args) { | 46 | ScriptValue 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 | ||
| 58 | ScriptValuePointer ScriptValueQtWrapper::call(const ScriptValuePointer& thisObject, const ScriptValuePointer& arguments) { | 56 | ScriptValue 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 | ||
| 65 | ScriptValuePointer ScriptValueQtWrapper::construct(const ScriptValueList& args) { | 63 | ScriptValue 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 | ||
| 74 | ScriptValuePointer ScriptValueQtWrapper::construct(const ScriptValuePointer& arguments) { | 72 | ScriptValue 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 | ||
| 80 | ScriptValuePointer ScriptValueQtWrapper::data() const { | 78 | ScriptValue 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 | ||
| 85 | ScriptEnginePointer ScriptValueQtWrapper::engine() const { | 83 | ScriptEnginePointer 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 | ||
| 92 | ScriptValueIteratorPointer ScriptValueQtWrapper::newIterator() { | 90 | ScriptValueIteratorPointer ScriptValueQtWrapper::newIterator() const { |
| 93 | return ScriptValueIteratorPointer(new ScriptValueIteratorQtWrapper(_engine, _value)); | 91 | return ScriptValueIteratorPointer(new ScriptValueIteratorQtWrapper(_engine, _value)); |
| 94 | } | 92 | } |
| 95 | 93 | ||
| 96 | ScriptValuePointer ScriptValueQtWrapper::property(const QString& name, const ResolveFlags& mode) const { | 94 | ScriptValue 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 | ||
| 101 | ScriptValuePointer ScriptValueQtWrapper::property(quint32 arrayIndex, const ResolveFlags& mode) const { | 99 | ScriptValue 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 | ||
| 106 | void ScriptValueQtWrapper::setData(const ScriptValuePointer& value) { | 104 | void 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 | ||
| 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) { |
| 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 | ||
| 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) { |
| 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 | ||
| 121 | void ScriptValueQtWrapper::setPrototype(const ScriptValuePointer& prototype) { | 119 | void 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 | ||
| 128 | bool ScriptValueQtWrapper::strictlyEquals(const ScriptValuePointer& other) const { | 126 | bool 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 | ||
| 169 | bool ScriptValueQtWrapper::equalsInternal(const ScriptValuePointer& other) const { | 167 | bool 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 | ||
| 174 | bool ScriptValueQtWrapper::isArrayInternal() const { | 172 | bool ScriptValueQtWrapper::isArray() const { |
| 175 | return _value.isArray(); | 173 | return _value.isArray(); |
| 176 | } | 174 | } |
| 177 | 175 | ||
| 178 | bool ScriptValueQtWrapper::isBoolInternal() const { | 176 | bool ScriptValueQtWrapper::isBool() const { |
| 179 | return _value.isBool(); | 177 | return _value.isBool(); |
| 180 | } | 178 | } |
| 181 | 179 | ||
| 182 | bool ScriptValueQtWrapper::isErrorInternal() const { | 180 | bool ScriptValueQtWrapper::isError() const { |
| 183 | return _value.isError(); | 181 | return _value.isError(); |
| 184 | } | 182 | } |
| 185 | 183 | ||
| 186 | bool ScriptValueQtWrapper::isFunctionInternal() const { | 184 | bool ScriptValueQtWrapper::isFunction() const { |
| 187 | return _value.isFunction(); | 185 | return _value.isFunction(); |
| 188 | } | 186 | } |
| 189 | 187 | ||
| 190 | bool ScriptValueQtWrapper::isNumberInternal() const { | 188 | bool ScriptValueQtWrapper::isNumber() const { |
| 191 | return _value.isNumber(); | 189 | return _value.isNumber(); |
| 192 | } | 190 | } |
| 193 | 191 | ||
| 194 | bool ScriptValueQtWrapper::isNullInternal() const { | 192 | bool ScriptValueQtWrapper::isNull() const { |
| 195 | return _value.isNull(); | 193 | return _value.isNull(); |
| 196 | } | 194 | } |
| 197 | 195 | ||
| 198 | bool ScriptValueQtWrapper::isObjectInternal() const { | 196 | bool ScriptValueQtWrapper::isObject() const { |
| 199 | return _value.isObject(); | 197 | return _value.isObject(); |
| 200 | } | 198 | } |
| 201 | 199 | ||
| 202 | bool ScriptValueQtWrapper::isStringInternal() const { | 200 | bool ScriptValueQtWrapper::isString() const { |
| 203 | return _value.isString(); | 201 | return _value.isString(); |
| 204 | } | 202 | } |
| 205 | 203 | ||
| 206 | bool ScriptValueQtWrapper::isUndefinedInternal() const { | 204 | bool ScriptValueQtWrapper::isUndefined() const { |
| 207 | return _value.isUndefined(); | 205 | return _value.isUndefined(); |
| 208 | } | 206 | } |
| 209 | 207 | ||
| 210 | bool ScriptValueQtWrapper::isValidInternal() const { | 208 | bool ScriptValueQtWrapper::isValid() const { |
| 211 | return _value.isValid(); | 209 | return _value.isValid(); |
| 212 | } | 210 | } |
| 213 | 211 | ||
| 214 | bool ScriptValueQtWrapper::isVariantInternal() const { | 212 | bool ScriptValueQtWrapper::isVariant() const { |
| 215 | return _value.isVariant(); | 213 | return _value.isVariant(); |
| 216 | } | 214 | } |