Added try/catch in JSPortal for installing/executing JS functions
Docs
This commit is contained in:
@@ -19,8 +19,7 @@ namespace {
|
||||
|
||||
bridge: The parent bridge object (provides access to bridge methods)
|
||||
--------------------------------------------------------------------*/
|
||||
GetAccounts::GetAccounts() : JSBridgeMethod{"GetAccounts", [&]() { return getAccounts(); }} {
|
||||
} //GetAccounts::GetAccounts
|
||||
GetAccounts::GetAccounts() : JSBridgeMethod{"GetAccounts", [&]() { return getAccounts(); }} {}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
|
||||
@@ -21,17 +21,15 @@ namespace connector::interfac::browser::bridge {
|
||||
@param bridge The parent bridge object (provides access to bridge methods)
|
||||
*/
|
||||
GetAccounts();
|
||||
/*!
|
||||
Cppy constructor
|
||||
@param bridge The parent bridge object (provides access to bridge methods)
|
||||
*/
|
||||
GetAccounts(const GetAccounts& source) = default;
|
||||
|
||||
/*!
|
||||
Object cloning
|
||||
@return A clone of this object
|
||||
*/
|
||||
GetAccounts* clonePtr() const override { return new GetAccounts{*this}; }
|
||||
|
||||
// MARK: - Functions (const)
|
||||
|
||||
/*!
|
||||
Get an argument instance for the function (used to deserialise/unpack incoming arguments)
|
||||
@return An argument instance
|
||||
|
||||
@@ -68,11 +68,14 @@ namespace speckle::interfac::browser {
|
||||
template<typename FunctionBinding>
|
||||
bool JSPortal<FunctionBinding>::execute(const speckle::utility::String& code) const {
|
||||
#ifdef ARCHICAD
|
||||
auto engine = getJSEngine();
|
||||
return engine ? engine->ExecuteJS(code) : false;
|
||||
#else
|
||||
return false; //Implement as required
|
||||
try {
|
||||
auto engine = getJSEngine();
|
||||
return engine ? engine->ExecuteJS(code) : false;
|
||||
} catch(...) {
|
||||
///TODO: Need to discuss the best course of action to notify of a failure
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
} //JSPortal<FunctionBinding>::execute
|
||||
|
||||
|
||||
@@ -86,19 +89,28 @@ namespace speckle::interfac::browser {
|
||||
template<typename FunctionBinding>
|
||||
bool JSPortal<FunctionBinding>::install(std::shared_ptr<JSObject<FunctionBinding>> object) {
|
||||
#ifdef ARCHICAD
|
||||
auto engine = getJSEngine();
|
||||
if (!engine)
|
||||
return false;
|
||||
JS::Object* acObject = new JS::Object(object->getName());
|
||||
for (auto& function : *object) {
|
||||
acObject->AddItem(new JS::Function(function->getName(), [&] (GS::Ref<JS::Base> args) {
|
||||
return function->execute(args);
|
||||
}));
|
||||
}
|
||||
if (engine->RegisterAsynchJSObject(acObject)) {
|
||||
base::push_back(object);
|
||||
object->setPortal(*this);
|
||||
return true;
|
||||
try {
|
||||
auto engine = getJSEngine();
|
||||
if (!engine)
|
||||
return false;
|
||||
JS::Object* acObject = new JS::Object(object->getName());
|
||||
for (auto& function : *object) {
|
||||
acObject->AddItem(new JS::Function(function->getName(), [&] (GS::Ref<JS::Base> args) {
|
||||
try {
|
||||
return function->execute(args);
|
||||
} catch(...) {
|
||||
///TODO: Need to discuss the best course of action to notify of a failure
|
||||
}
|
||||
return GS::Ref<JS::Base>{};
|
||||
}));
|
||||
}
|
||||
if (engine->RegisterAsynchJSObject(acObject)) {
|
||||
base::push_back(object);
|
||||
object->setPortal(*this);
|
||||
return true;
|
||||
}
|
||||
} catch(...) {
|
||||
///TODO: Need to discuss the best course of action to notify of a failure
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user