Showing the changes to libraries/script-engine/src/ScriptValue.cpp (1 of 170 files). Show all
Unified · Split
| @@ -0,0 +1,236 @@ | |||
| 1 | // | ||
| 2 | // ScriptValue.cpp | ||
| 3 | // libraries/script-engine/src | ||
| 4 | // | ||
| 5 | // Created by Heather Anderson on 9/2/21. | ||
| 6 | // Copyright 2021 Vircadia contributors. | ||
| 7 | // | ||
| 8 | // Distributed under the Apache License, Version 2.0. | ||
| 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | ||
| 10 | // | ||
| 11 | |||
| 12 | #include "ScriptValue.h" | ||
| 13 | |||
| 14 | #include "ScriptEngineLogging.h" | ||
| 15 | |||
| 16 | |||
| 17 | class ScriptValueProxyNull : public ScriptValueProxy { | ||
| 18 | public: | ||
| 19 | virtual void release(); | ||
| 20 | virtual ScriptValueProxy* copy() const; | ||
| 21 | |||
| 22 | public: | ||
| 23 | virtual ScriptValue call(const ScriptValue& thisObject = ScriptValue(), const ScriptValueList& args = ScriptValueList()); | ||
| 24 | virtual ScriptValue call(const ScriptValue& thisObject, const ScriptValue& arguments); | ||
| 25 | virtual ScriptValue construct(const ScriptValueList& args = ScriptValueList()); | ||
| 26 | virtual ScriptValue construct(const ScriptValue& arguments); | ||
| 27 | virtual ScriptValue data() const; | ||
| 28 | virtual ScriptEnginePointer engine() const; | ||
| 29 | virtual bool equals(const ScriptValue& other) const; | ||
| 30 | virtual bool isArray() const; | ||
| 31 | virtual bool isBool() const; | ||
| 32 | virtual bool isError() const; | ||
| 33 | virtual bool isFunction() const; | ||
| 34 | virtual bool isNumber() const; | ||
| 35 | virtual bool isNull() const; | ||
| 36 | virtual bool isObject() const; | ||
| 37 | virtual bool isString() const; | ||
| 38 | virtual bool isUndefined() const; | ||
| 39 | virtual bool isValid() const; | ||
| 40 | virtual bool isVariant() const; | ||
| 41 | virtual ScriptValueIteratorPointer newIterator() const; | ||
| 42 | virtual ScriptValue property(const QString& name, | ||
| 43 | const ScriptValue::ResolveFlags& mode = ScriptValue::ResolvePrototype) const; | ||
| 44 | virtual ScriptValue property(quint32 arrayIndex, | ||
| 45 | const ScriptValue::ResolveFlags& mode = ScriptValue::ResolvePrototype) const; | ||
| 46 | virtual void setData(const ScriptValue& val); | ||
| 47 | virtual void setProperty(const QString& name, | ||
| 48 | const ScriptValue& value, | ||
| 49 | const ScriptValue::PropertyFlags& flags = ScriptValue::KeepExistingFlags); | ||
| 50 | virtual void setProperty(quint32 arrayIndex, | ||
| 51 | const ScriptValue& value, | ||
| 52 | const ScriptValue::PropertyFlags& flags = ScriptValue::KeepExistingFlags); | ||
| 53 | virtual void setPrototype(const ScriptValue& prototype); | ||
| 54 | virtual bool strictlyEquals(const ScriptValue& other) const; | ||
| 55 | |||
| 56 | virtual bool toBool() const; | ||
| 57 | virtual qint32 toInt32() const; | ||
| 58 | virtual double toInteger() const; | ||
| 59 | virtual double toNumber() const; | ||
| 60 | virtual QString toString() const; | ||
| 61 | virtual quint16 toUInt16() const; | ||
| 62 | virtual quint32 toUInt32() const; | ||
| 63 | virtual QVariant toVariant() const; | ||
| 64 | virtual QObject* toQObject() const; | ||
| 65 | }; | ||
| 66 | |||
| 67 | static ScriptValueProxyNull SCRIPT_VALUE_NULL; | ||
| 68 | |||
| 69 | ScriptValue::ScriptValue() : _proxy(&SCRIPT_VALUE_NULL) {} | ||
| 70 | |||
| 71 | void ScriptValueProxyNull::release() { | ||
| 72 | // do nothing, we're a singlet | ||
| 73 | } | ||
| 74 | |||
| 75 | ScriptValueProxy* ScriptValueProxyNull::copy() const { | ||
| 76 | // return ourselves, we're a singlet | ||
| 77 | return const_cast <ScriptValueProxyNull*>(this); | ||
| 78 | } | ||
| 79 | |||
| 80 | ScriptValue ScriptValueProxyNull::call(const ScriptValue& thisObject, const ScriptValueList& args) { | ||
| 81 | Q_ASSERT(false); | ||
| 82 | qCWarning(scriptengine_script, "ScriptValue::call made to empty value"); | ||
| 83 | return ScriptValue(); | ||
| 84 | } | ||
| 85 | |||
| 86 | ScriptValue ScriptValueProxyNull::call(const ScriptValue& thisObject, const ScriptValue& arguments) { | ||
| 87 | Q_ASSERT(false); | ||
| 88 | qCWarning(scriptengine_script, "ScriptValue::call made to empty value"); | ||
| 89 | return ScriptValue(); | ||
| 90 | } | ||
| 91 | |||
| 92 | ScriptValue ScriptValueProxyNull::construct(const ScriptValueList& args) { | ||
| 93 | Q_ASSERT(false); | ||
| 94 | qCWarning(scriptengine_script, "ScriptValue::construct called on empty value"); | ||
| 95 | return ScriptValue(); | ||
| 96 | } | ||
| 97 | |||
| 98 | ScriptValue ScriptValueProxyNull::construct(const ScriptValue& arguments) { | ||
| 99 | Q_ASSERT(false); | ||
| 100 | qCWarning(scriptengine_script, "ScriptValue::construct called on empty value"); | ||
| 101 | return ScriptValue(); | ||
| 102 | } | ||
| 103 | |||
| 104 | ScriptValue ScriptValueProxyNull::data() const { | ||
| 105 | return ScriptValue(); | ||
| 106 | } | ||
| 107 | |||
| 108 | ScriptEnginePointer ScriptValueProxyNull::engine() const { | ||
| 109 | Q_ASSERT(false); | ||
| 110 | qCWarning(scriptengine_script, "ScriptValue::engine called on empty value"); | ||
| 111 | return ScriptEnginePointer(); | ||
| 112 | } | ||
| 113 | |||
| 114 | bool ScriptValueProxyNull::equals(const ScriptValue& other) const { | ||
| 115 | return other.isUndefined(); | ||
| 116 | } | ||
| 117 | |||
| 118 | bool ScriptValueProxyNull::isArray() const { | ||
| 119 | return false; | ||
| 120 | } | ||
| 121 | |||
| 122 | bool ScriptValueProxyNull::isBool() const { | ||
| 123 | return false; | ||
| 124 | } | ||
| 125 | |||
| 126 | bool ScriptValueProxyNull::isError() const { | ||
| 127 | return false; | ||
| 128 | } | ||
| 129 | |||
| 130 | bool ScriptValueProxyNull::isFunction() const { | ||
| 131 | return false; | ||
| 132 | } | ||
| 133 | |||
| 134 | bool ScriptValueProxyNull::isNumber() const { | ||
| 135 | return false; | ||
| 136 | } | ||
| 137 | |||
| 138 | bool ScriptValueProxyNull::isNull() const { | ||
| 139 | return false; | ||
| 140 | } | ||
| 141 | |||
| 142 | bool ScriptValueProxyNull::isObject() const { | ||
| 143 | return false; | ||
| 144 | } | ||
| 145 | |||
| 146 | bool ScriptValueProxyNull::isString() const { | ||
| 147 | return false; | ||
| 148 | } | ||
| 149 | |||
| 150 | bool ScriptValueProxyNull::isUndefined() const { | ||
| 151 | return true; | ||
| 152 | } | ||
| 153 | |||
| 154 | bool ScriptValueProxyNull::isValid() const { | ||
| 155 | return false; | ||
| 156 | } | ||
| 157 | |||
| 158 | bool ScriptValueProxyNull::isVariant() const { | ||
| 159 | return false; | ||
| 160 | } | ||
| 161 | |||
| 162 | ScriptValueIteratorPointer ScriptValueProxyNull::newIterator() const { | ||
| 163 | Q_ASSERT(false); | ||
| 164 | qCWarning(scriptengine_script, "ScriptValue::newIterator called on empty value"); | ||
| 165 | return ScriptValueIteratorPointer(); | ||
| 166 | } | ||
| 167 | |||
| 168 | ScriptValue ScriptValueProxyNull::property(const QString& name, const ScriptValue::ResolveFlags& mode) const { | ||
| 169 | return ScriptValue(); | ||
| 170 | } | ||
| 171 | |||
| 172 | ScriptValue ScriptValueProxyNull::property(quint32 arrayIndex, const ScriptValue::ResolveFlags& mode) const { | ||
| 173 | return ScriptValue(); | ||
| 174 | } | ||
| 175 | |||
| 176 | void ScriptValueProxyNull::setData(const ScriptValue& val) { | ||
| 177 | Q_ASSERT(false); | ||
| 178 | qCWarning(scriptengine_script, "ScriptValue::setData called on empty value"); | ||
| 179 | } | ||
| 180 | |||
| 181 | void ScriptValueProxyNull::setProperty(const QString& name, | ||
| 182 | const ScriptValue& value, const ScriptValue::PropertyFlags& flags) { | ||
| 183 | Q_ASSERT(false); | ||
| 184 | qCWarning(scriptengine_script, "ScriptValue::setProperty called on empty value"); | ||
| 185 | } | ||
| 186 | |||
| 187 | void ScriptValueProxyNull::setProperty(quint32 arrayIndex, | ||
| 188 | const ScriptValue& value, const ScriptValue::PropertyFlags& flags) { | ||
| 189 | Q_ASSERT(false); | ||
| 190 | qCWarning(scriptengine_script, "ScriptValue::setProperty called on empty value"); | ||
| 191 | } | ||
| 192 | |||
| 193 | void ScriptValueProxyNull::setPrototype(const ScriptValue& prototype) { | ||
| 194 | Q_ASSERT(false); | ||
| 195 | qCWarning(scriptengine_script, "ScriptValue::setPrototype called on empty value"); | ||
| 196 | } | ||
| 197 | |||
| 198 | bool ScriptValueProxyNull::strictlyEquals(const ScriptValue& other) const { | ||
| 199 | return !other.isValid(); | ||
| 200 | } | ||
| 201 | |||
| 202 | bool ScriptValueProxyNull::toBool() const { | ||
| 203 | return false; | ||
| 204 | } | ||
| 205 | |||
| 206 | qint32 ScriptValueProxyNull::toInt32() const { | ||
| 207 | return 0; | ||
| 208 | } | ||
| 209 | |||
| 210 | double ScriptValueProxyNull::toInteger() const { | ||
| 211 | return 0; | ||
| 212 | } | ||
| 213 | |||
| 214 | double ScriptValueProxyNull::toNumber() const { | ||
| 215 | return 0; | ||
| 216 | } | ||
| 217 | |||
| 218 | QString ScriptValueProxyNull::toString() const { | ||
| 219 | return QString(); | ||
| 220 | } | ||
| 221 | |||
| 222 | quint16 ScriptValueProxyNull::toUInt16() const { | ||
| 223 | return 0; | ||
| 224 | } | ||
| 225 | |||
| 226 | quint32 ScriptValueProxyNull::toUInt32() const { | ||
| 227 | return 0; | ||
| 228 | } | ||
| 229 | |||
| 230 | QVariant ScriptValueProxyNull::toVariant() const { | ||
| 231 | return QVariant(); | ||
| 232 | } | ||
| 233 | |||
| 234 | QObject* ScriptValueProxyNull::toQObject() const { | ||
| 235 | return nullptr; | ||
| 236 | } | ||