* Get rid of maybeEmitUncaughtException * Mostly get rid of makeError * Introduce exception hierarchy, change exceptions to shared_ptr * Simplify exception throwing code
Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 10 files). Show all
Unified · Split
| @@ -132,7 +132,7 @@ void EntityScriptingInterface::releaseEntityPacketSenderMessages(bool wait) { · 131 unmodified lines | ||
| 132 | 132 | void EntityScriptingInterface::attachDefaultEventHandlers(ScriptManager* manager) { |
| 133 | 133 | // Connect up ALL the handlers to the global entities object's signals. |
| 134 | 134 | // (We could go signal by signal, or even handler by handler, but I don't think the efficiency is worth the complexity.) |
| 135 | − | |
| 135 | + | |
| 136 | 136 | // Bug? These handlers are deleted when entityID is deleted, which is nice. |
| 137 | 137 | // But if they are created by an entity script on a different entity, should they also be deleted when the entity script unloads? |
| 138 | 138 | // E.g., suppose a bow has an entity script that causes arrows to be created with a potential lifetime greater than the bow, |
| @@ -194,7 +194,7 @@ void EntityScriptingInterface::attachDefaultEventHandlers(ScriptManager* manager · 55 unmodified lines | ||
| 194 | 194 | }; |
| 195 | 195 | |
| 196 | 196 | /*@jsdoc |
| 197 | − * <p>The name of an entity event. When the entity event occurs, any function that has been registered for that event | |
| 197 | + * <p>The name of an entity event. When the entity event occurs, any function that has been registered for that event | |
| 198 | 198 | * via {@link Script.addEventHandler} is called with parameters per the entity event.</p> |
| 199 | 199 | * <table> |
| 200 | 200 | * <thead> |
| @@ -782,7 +782,7 @@ QUuid EntityScriptingInterface::cloneEntity(const QUuid& entityIDToClone) { · 581 unmodified lines | ||
| 782 | 782 | } else if (cloneAvatarEntity) { |
| 783 | 783 | return addEntityInternal(properties, entity::HostType::AVATAR); |
| 784 | 784 | } else { |
| 785 | − // setLastEdited timestamp to 0 to ensure this entity gets updated with the properties | |
| 785 | + // setLastEdited timestamp to 0 to ensure this entity gets updated with the properties | |
| 786 | 786 | // from the server-created entity, don't change this unless you know what you are doing |
| 787 | 787 | properties.setLastEdited(0); |
| 788 | 788 | bool success = addLocalEntityCopy(properties, newEntityID, true); |
| @@ -1255,7 +1255,7 @@ void EntityScriptingInterface::setNonPersistentEntitiesScriptEngine(std::shared_ · 466 unmodified lines | ||
| 1255 | 1255 | |
| 1256 | 1256 | void EntityScriptingInterface::callEntityMethod(const QUuid& id, const QString& method, const QStringList& params) { |
| 1257 | 1257 | PROFILE_RANGE(script_entities, __FUNCTION__); |
| 1258 | − | |
| 1258 | + | |
| 1259 | 1259 | auto entity = getEntityTree()->findEntityByEntityItemID(id); |
| 1260 | 1260 | if (entity) { |
| 1261 | 1261 | std::lock_guard<std::recursive_mutex> lock(_entitiesScriptEngineLock); |
| @@ -1605,7 +1605,7 @@ bool EntityScriptingInterface::queryPropertyMetadata(const QUuid& entityID, · 343 unmodified lines | ||
| 1605 | 1605 | #endif |
| 1606 | 1606 | if (!handler.property("callback").isFunction()) { |
| 1607 | 1607 | qDebug() << "!handler.callback.isFunction" << manager; |
| 1608 | − engine->raiseException(engine->makeError(engine->newValue("callback is not a function"), "TypeError")); | |
| 1608 | + engine->raiseException("callback is not a function", "TypeError"); | |
| 1609 | 1609 | return false; |
| 1610 | 1610 | } |
| 1611 | 1611 | |
| @@ -1628,8 +1628,7 @@ bool EntityScriptingInterface::queryPropertyMetadata(const QUuid& entityID, · 16 unmodified lines | ||
| 1628 | 1628 | } else if (name == "serverScripts") { |
| 1629 | 1629 | return request.serverScripts(entityID, handler); |
| 1630 | 1630 | } else { |
| 1631 | − engine->raiseException(engine->makeError(engine->newValue("metadata for property " + name + " is not yet queryable"))); | |
| 1632 | − engine->maybeEmitUncaughtException(__FUNCTION__); | |
| 1631 | + engine->raiseException("metadata for property " + name + " is not yet queryable"); | |
| 1633 | 1632 | return false; |
| 1634 | 1633 | } |
| 1635 | 1634 | } |
| @@ -1644,8 +1643,7 @@ bool EntityScriptingInterface::getServerScriptStatus(const QUuid& entityID, Scri · 8 unmodified lines | ||
| 1644 | 1643 | Q_ASSERT(QThread::currentThread() == engine->thread()); |
| 1645 | 1644 | Q_ASSERT(QThread::currentThread() == engine->manager()->thread()); |
| 1646 | 1645 | if (!manager) { |
| 1647 | − engine->raiseException(engine->makeError(engine->newValue("This script does not belong to a ScriptManager"))); | |
| 1648 | − engine->maybeEmitUncaughtException(__FUNCTION__); | |
| 1646 | + engine->raiseException("This script does not belong to a ScriptManager"); | |
| 1649 | 1647 | return false; |
| 1650 | 1648 | } |
| 1651 | 1649 | |
| @@ -2015,17 +2013,17 @@ EntityItemPointer EntityScriptingInterface::checkForTreeEntityAndTypeMatch(const · 363 unmodified lines | ||
| 2015 | 2013 | if (!_entityTree) { |
| 2016 | 2014 | return EntityItemPointer(); |
| 2017 | 2015 | } |
| 2018 | − | |
| 2016 | + | |
| 2019 | 2017 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); |
| 2020 | 2018 | if (!entity) { |
| 2021 | 2019 | qCDebug(entities) << "EntityScriptingInterface::checkForTreeEntityAndTypeMatch - no entity with ID" << entityID; |
| 2022 | 2020 | return entity; |
| 2023 | 2021 | } |
| 2024 | − | |
| 2022 | + | |
| 2025 | 2023 | if (entityType != EntityTypes::Unknown && entity->getType() != entityType) { |
| 2026 | 2024 | return EntityItemPointer(); |
| 2027 | 2025 | } |
| 2028 | − | |
| 2026 | + | |
| 2029 | 2027 | return entity; |
| 2030 | 2028 | } |
| 2031 | 2029 | |