Showing the changes to libraries/script-engine/src/AssetScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -28,12 +28,9 @@ · 27 unmodified lines | ||
| 28 | 28 | #include "ScriptEngine.h" |
| 29 | 29 | #include "ScriptEngineLogging.h" |
| 30 | 30 | |
| 31 | −AssetScriptingInterface::AssetScriptingInterface(QObject* parent) : BaseAssetScriptingInterface(parent) { | |
| 32 | − if (auto engine = qobject_cast<QScriptEngine*>(parent)) { | |
| 33 | − registerMetaTypes(engine); | |
| 34 | − } | |
| 35 | −} | |
| 36 | −#define JS_ASSERT(cond, error) { if (!this->jsAssert(cond, error)) { return; } } | |
| 31 | +AssetScriptingInterface::AssetScriptingInterface(QObject* parent) : BaseAssetScriptingInterface(parent) {} | |
| 32 | + | |
| 33 | +#define JS_VERIFY(cond, error) { if (!this->jsVerify(cond, error)) { return; } } | |
| 37 | 34 | |
| 38 | 35 | void AssetScriptingInterface::uploadData(QString data, QScriptValue callback) { |
| 39 | 36 | auto handler = makeScopedHandlerObject(thisObject(), callback); |
| @@ -176,8 +173,8 @@ void AssetScriptingInterface::sendFakedHandshake() { · 136 unmodified lines | ||
| 176 | 173 | void AssetScriptingInterface::getMapping(QString asset, QScriptValue callback) { |
| 177 | 174 | auto path = AssetUtils::getATPUrl(asset).path(); |
| 178 | 175 | auto handler = makeScopedHandlerObject(thisObject(), callback); |
| 179 | − JS_ASSERT(AssetUtils::isValidFilePath(path), "invalid ATP file path: " + asset + "(path:"+path+")"); | |
| 180 | − JS_ASSERT(callback.isFunction(), "expected second parameter to be a callback function"); | |
| 176 | + JS_VERIFY(AssetUtils::isValidFilePath(path), "invalid ATP file path: " + asset + "(path:"+path+")"); | |
| 177 | + JS_VERIFY(callback.isFunction(), "expected second parameter to be a callback function"); | |
| 181 | 178 | qDebug() << ">>getMapping//getAssetInfo" << path; |
| 182 | 179 | Promise promise = getAssetInfo(path); |
| 183 | 180 | promise->ready([this, handler](QString error, QVariantMap result) { |
| @@ -186,14 +183,14 @@ void AssetScriptingInterface::getMapping(QString asset, QScriptValue callback) { · 2 unmodified lines | ||
| 186 | 183 | }); |
| 187 | 184 | } |
| 188 | 185 | |
| 189 | −bool AssetScriptingInterface::jsAssert(bool condition, const QString& error) { | |
| 186 | +bool AssetScriptingInterface::jsVerify(bool condition, const QString& error) { | |
| 190 | 187 | if (condition) { |
| 191 | 188 | return true; |
| 192 | 189 | } |
| 193 | 190 | if (context()) { |
| 194 | 191 | context()->throwError(error); |
| 195 | 192 | } else { |
| 196 | − qDebug() << "WARNING -- jsAssert failed outside of a valid JS context: " + error; | |
| 193 | + qDebug() << "WARNING -- jsVerify failed outside of a valid JS context: " + error; | |
| 197 | 194 | } |
| 198 | 195 | return false; |
| 199 | 196 | } |
| @@ -202,7 +199,7 @@ void AssetScriptingInterface::jsCallback(const QScriptValue& handler, · 2 unmodified lines | ||
| 202 | 199 | const QScriptValue& error, const QScriptValue& result) { |
| 203 | 200 | Q_ASSERT(thread() == QThread::currentThread()); |
| 204 | 201 | auto errorValue = !error.toBool() ? QScriptValue::NullValue : error; |
| 205 | − JS_ASSERT(handler.isObject() && handler.property("callback").isFunction(), | |
| 202 | + JS_VERIFY(handler.isObject() && handler.property("callback").isFunction(), | |
| 206 | 203 | QString("jsCallback -- .callback is not a function (%1)") |
| 207 | 204 | .arg(handler.property("callback").toVariant().typeName())); |
| 208 | 205 | ::callScopedHandlerObject(handler, errorValue, result); |
| @@ -217,11 +214,11 @@ void AssetScriptingInterface::jsCallback(const QScriptValue& handler, · 8 unmodified lines | ||
| 217 | 214 | } |
| 218 | 215 | |
| 219 | 216 | void AssetScriptingInterface::deleteAsset(QScriptValue options, QScriptValue scope, QScriptValue callback) { |
| 220 | − jsAssert(false, "TODO: deleteAsset API"); | |
| 217 | + jsVerify(false, "TODO: deleteAsset API"); | |
| 221 | 218 | } |
| 222 | 219 | |
| 223 | 220 | void AssetScriptingInterface::getAsset(QScriptValue options, QScriptValue scope, QScriptValue callback) { |
| 224 | − JS_ASSERT(options.isObject() || options.isString(), "expected request options Object or URL as first parameter"); | |
| 221 | + JS_VERIFY(options.isObject() || options.isString(), "expected request options Object or URL as first parameter"); | |
| 225 | 222 | |
| 226 | 223 | auto decompress = options.property("decompress").toBool() || options.property("compressed").toBool(); |
| 227 | 224 | auto responseType = options.property("responseType").toString().toLower(); |
| @@ -235,11 +232,11 @@ void AssetScriptingInterface::getAsset(QScriptValue options, QScriptValue scope, · 7 unmodified lines | ||
| 235 | 232 | auto asset = AssetUtils::getATPUrl(url).path(); |
| 236 | 233 | auto handler = makeScopedHandlerObject(scope, callback); |
| 237 | 234 | |
| 238 | − JS_ASSERT(handler.property("callback").isFunction(), | |
| 235 | + JS_VERIFY(handler.property("callback").isFunction(), | |
| 239 | 236 | QString("Invalid callback function (%1)").arg(handler.property("callback").toVariant().typeName())); |
| 240 | − JS_ASSERT(AssetUtils::isValidHash(asset) || AssetUtils::isValidFilePath(asset), | |
| 237 | + JS_VERIFY(AssetUtils::isValidHash(asset) || AssetUtils::isValidFilePath(asset), | |
| 241 | 238 | QString("Invalid ATP url '%1'").arg(url)); |
| 242 | − JS_ASSERT(RESPONSE_TYPES.contains(responseType), | |
| 239 | + JS_VERIFY(RESPONSE_TYPES.contains(responseType), | |
| 243 | 240 | QString("Invalid responseType: '%1' (expected: %2)").arg(responseType).arg(RESPONSE_TYPES.join(" | "))); |
| 244 | 241 | |
| 245 | 242 | Promise resolved = makePromise("resolved"); |
| @@ -283,9 +280,9 @@ void AssetScriptingInterface::resolveAsset(QScriptValue options, QScriptValue sc · 37 unmodified lines | ||
| 283 | 280 | auto asset = AssetUtils::getATPUrl(url).path(); |
| 284 | 281 | auto handler = makeScopedHandlerObject(scope, callback); |
| 285 | 282 | |
| 286 | − JS_ASSERT(AssetUtils::isValidFilePath(asset) || AssetUtils::isValidHash(asset), | |
| 283 | + JS_VERIFY(AssetUtils::isValidFilePath(asset) || AssetUtils::isValidHash(asset), | |
| 287 | 284 | "expected options to be an asset URL or request options containing .url property"); |
| 288 | − JS_ASSERT(handler.property("callback").isFunction(), "invalid callback function"); | |
| 285 | + JS_VERIFY(handler.property("callback").isFunction(), "invalid callback function"); | |
| 289 | 286 | getAssetInfo(asset)->ready([=](QString error, QVariantMap result) { |
| 290 | 287 | qDebug() << "//resolveAsset/getAssetInfo" << error << result.value("hash"); |
| 291 | 288 | jsCallback(handler, error, result); |
| @@ -348,11 +345,11 @@ void AssetScriptingInterface::putAsset(QScriptValue options, QScriptValue scope, · 56 unmodified lines | ||
| 348 | 345 | data.toString().toUtf8() : |
| 349 | 346 | qscriptvalue_cast<QByteArray>(data); |
| 350 | 347 | |
| 351 | − JS_ASSERT(path.isEmpty() || AssetUtils::isValidFilePath(path), | |
| 348 | + JS_VERIFY(path.isEmpty() || AssetUtils::isValidFilePath(path), | |
| 352 | 349 | QString("expected valid ATP file path '%1' ('%2')").arg(rawPath).arg(path)); |
| 353 | − JS_ASSERT(handler.property("callback").isFunction(), | |
| 350 | + JS_VERIFY(handler.property("callback").isFunction(), | |
| 354 | 351 | "invalid callback function"); |
| 355 | − JS_ASSERT(dataByteArray.size() > 0, | |
| 352 | + JS_VERIFY(dataByteArray.size() > 0, | |
| 356 | 353 | QString("expected non-zero .data (got %1 / #%2 bytes)") |
| 357 | 354 | .arg(data.toVariant().typeName()) |
| 358 | 355 | .arg(dataByteArray.size())); |