Skip to content

Commit dcc479c

Browse files
committed
[[ Bug 19486 ]] Foreign handler bind failure should throw an error
This patch ensures that if foreign handler binding fails, and the bind was required, and not optional then an appropriate error object is thrown.
1 parent b5e7df2 commit dcc479c

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

docs/notes/19486.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# LiveCode Builder Virtual Machine
2+
## Foreign Function Interface
3+
4+
# [19486] Failure to bind foreign handlers should provide meaningful error

libscript/src/script-instance.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,15 @@ __MCScriptResolveForeignFunctionBinding(MCScriptInstanceRef p_instance,
750750
*t_function);
751751
if (t_pointer == nullptr)
752752
{
753-
return false;
753+
if (r_bound == nullptr)
754+
{
755+
return MCScriptThrowUnableToResolveForeignHandlerError(p_instance,
756+
p_handler);
757+
}
758+
759+
*r_bound = false;
760+
761+
return true;
754762
}
755763

756764
p_handler -> native . function = t_pointer;
@@ -799,11 +807,20 @@ __MCScriptResolveForeignFunctionBinding(MCScriptInstanceRef p_instance,
799807
if (!MCJavaCheckSignature(t_signature,
800808
*t_arguments,
801809
*t_return,
802-
p_handler -> java . call_type))
803-
return false;
810+
p_handler -> java . call_type) ||
811+
!MCJavaVMInitialize())
812+
{
813+
if (r_bound == nullptr)
814+
{
815+
return false;
816+
}
817+
818+
MCErrorReset();
804819

805-
if (!MCJavaVMInitialize())
806-
return false;
820+
*r_bound = false;
821+
822+
return true;
823+
}
807824

808825
void *t_method_id = MCJavaGetMethodId(*t_class_name, *t_function, *t_arguments, *t_return, p_handler -> java . call_type);
809826

@@ -815,7 +832,8 @@ __MCScriptResolveForeignFunctionBinding(MCScriptInstanceRef p_instance,
815832
{
816833
if (r_bound == nullptr)
817834
{
818-
return false;
835+
return MCScriptThrowUnableToResolveForeignHandlerError(p_instance,
836+
p_handler);
819837
}
820838
*r_bound = false;
821839

0 commit comments

Comments
 (0)