History

trying JS_VERIFY on for size (instead of JS_ASSERT)

humbletim committed 8 years ago

Commit d2a3a711 parent dc4210a2 files · +19 −22Browse files

Showing the changes to libraries/script-engine/src/AssetScriptingInterface.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/AssetScriptingInterface.cpp+18−21
@@ -28,12 +28,9 @@ · 27 unmodified lines
2828 #include "ScriptEngine.h"
2929 #include "ScriptEngineLogging.h"
3030
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; } }
3734
3835 void AssetScriptingInterface::uploadData(QString data, QScriptValue callback) {
3936 auto handler = makeScopedHandlerObject(thisObject(), callback);
@@ -176,8 +173,8 @@ void AssetScriptingInterface::sendFakedHandshake() { · 136 unmodified lines
176173 void AssetScriptingInterface::getMapping(QString asset, QScriptValue callback) {
177174 auto path = AssetUtils::getATPUrl(asset).path();
178175 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");
181178 qDebug() << ">>getMapping//getAssetInfo" << path;
182179 Promise promise = getAssetInfo(path);
183180 promise->ready([this, handler](QString error, QVariantMap result) {
@@ -186,14 +183,14 @@ void AssetScriptingInterface::getMapping(QString asset, QScriptValue callback) { · 2 unmodified lines
186183 });
187184 }
188185
189−bool AssetScriptingInterface::jsAssert(bool condition, const QString& error) {
186+bool AssetScriptingInterface::jsVerify(bool condition, const QString& error) {
190187 if (condition) {
191188 return true;
192189 }
193190 if (context()) {
194191 context()->throwError(error);
195192 } 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;
197194 }
198195 return false;
199196 }
@@ -202,7 +199,7 @@ void AssetScriptingInterface::jsCallback(const QScriptValue& handler, · 2 unmodified lines
202199 const QScriptValue& error, const QScriptValue& result) {
203200 Q_ASSERT(thread() == QThread::currentThread());
204201 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(),
206203 QString("jsCallback -- .callback is not a function (%1)")
207204 .arg(handler.property("callback").toVariant().typeName()));
208205 ::callScopedHandlerObject(handler, errorValue, result);
@@ -217,11 +214,11 @@ void AssetScriptingInterface::jsCallback(const QScriptValue& handler, · 8 unmodified lines
217214 }
218215
219216 void AssetScriptingInterface::deleteAsset(QScriptValue options, QScriptValue scope, QScriptValue callback) {
220− jsAssert(false, "TODO: deleteAsset API");
217+ jsVerify(false, "TODO: deleteAsset API");
221218 }
222219
223220 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");
225222
226223 auto decompress = options.property("decompress").toBool() || options.property("compressed").toBool();
227224 auto responseType = options.property("responseType").toString().toLower();
@@ -235,11 +232,11 @@ void AssetScriptingInterface::getAsset(QScriptValue options, QScriptValue scope, · 7 unmodified lines
235232 auto asset = AssetUtils::getATPUrl(url).path();
236233 auto handler = makeScopedHandlerObject(scope, callback);
237234
238− JS_ASSERT(handler.property("callback").isFunction(),
235+ JS_VERIFY(handler.property("callback").isFunction(),
239236 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),
241238 QString("Invalid ATP url '%1'").arg(url));
242− JS_ASSERT(RESPONSE_TYPES.contains(responseType),
239+ JS_VERIFY(RESPONSE_TYPES.contains(responseType),
243240 QString("Invalid responseType: '%1' (expected: %2)").arg(responseType).arg(RESPONSE_TYPES.join(" | ")));
244241
245242 Promise resolved = makePromise("resolved");
@@ -283,9 +280,9 @@ void AssetScriptingInterface::resolveAsset(QScriptValue options, QScriptValue sc · 37 unmodified lines
283280 auto asset = AssetUtils::getATPUrl(url).path();
284281 auto handler = makeScopedHandlerObject(scope, callback);
285282
286− JS_ASSERT(AssetUtils::isValidFilePath(asset) || AssetUtils::isValidHash(asset),
283+ JS_VERIFY(AssetUtils::isValidFilePath(asset) || AssetUtils::isValidHash(asset),
287284 "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");
289286 getAssetInfo(asset)->ready([=](QString error, QVariantMap result) {
290287 qDebug() << "//resolveAsset/getAssetInfo" << error << result.value("hash");
291288 jsCallback(handler, error, result);
@@ -348,11 +345,11 @@ void AssetScriptingInterface::putAsset(QScriptValue options, QScriptValue scope, · 56 unmodified lines
348345 data.toString().toUtf8() :
349346 qscriptvalue_cast<QByteArray>(data);
350347
351− JS_ASSERT(path.isEmpty() || AssetUtils::isValidFilePath(path),
348+ JS_VERIFY(path.isEmpty() || AssetUtils::isValidFilePath(path),
352349 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(),
354351 "invalid callback function");
355− JS_ASSERT(dataByteArray.size() > 0,
352+ JS_VERIFY(dataByteArray.size() > 0,
356353 QString("expected non-zero .data (got %1 / #%2 bytes)")
357354 .arg(data.toVariant().typeName())
358355 .arg(dataByteArray.size()));