History

Further exception work on V8

* Get rid of maybeEmitUncaughtException * Mostly get rid of makeError * Introduce exception hierarchy, change exceptions to shared_ptr * Simplify exception throwing code

Dale Glass committed 3 years ago

Commit 67e7a731 parent c0e62c510 files · +249 −260Browse files

Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 10 files). Show all

Unified · Split

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