Skip to content

Commit 256cf0f

Browse files
committed
[[ LCB ]] Make sure you cannot call context handlers except from an LCB frame.
1 parent 475e1b9 commit 256cf0f

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

libscript/src/script-instance.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ bool MCScriptThrowNotAHandlerValueError(MCValueRef p_value)
286286
return MCErrorCreateAndThrow(kMCScriptNotAHandlerValueErrorTypeInfo, "value", p_value, nil);
287287
}
288288

289+
bool MCScriptThrowCannotCallContextHandlerError(MCScriptModuleRef p_module, MCScriptDefinition *p_handler)
290+
{
291+
return MCErrorCreateAndThrow(kMCScriptCannotCallContextHandlerErrorTypeInfo, "module", p_module -> name, "handler", MCScriptGetNameOfDefinitionInModule(p_module, p_handler), nil);
292+
}
293+
289294
///////////
290295

291296
MCScriptVariableDefinition *MCScriptDefinitionAsVariable(MCScriptDefinition *self)
@@ -465,6 +470,11 @@ static bool MCScriptCallHandlerOfInstanceDirect(MCScriptInstanceRef self, MCScri
465470
MCTypeInfoRef t_signature;
466471
t_signature = self -> module -> types[p_handler -> type] -> typeinfo;
467472

473+
// If the handler is of context scope, then we cannot call it directly - only
474+
// from a LCB frame.
475+
if (p_handler -> scope == kMCScriptHandlerScopeContext)
476+
return MCScriptThrowCannotCallContextHandlerError(self -> module, p_handler);
477+
468478
// Check the number of arguments.
469479
uindex_t t_required_param_count;
470480
t_required_param_count = MCHandlerTypeInfoGetParameterCount(t_signature);

libscript/src/script-object.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ MCTypeInfoRef kMCScriptNoMatchingHandlerErrorTypeInfo;
3636
MCTypeInfoRef kMCScriptCannotSetReadOnlyPropertyErrorTypeInfo;
3737
MCTypeInfoRef kMCScriptInvalidPropertyValueErrorTypeInfo;
3838
MCTypeInfoRef kMCScriptNotAHandlerValueErrorTypeInfo;
39+
MCTypeInfoRef kMCScriptCannotCallContextHandlerErrorTypeInfo;
3940

4041
////////////////////////////////////////////////////////////////////////////////
4142

@@ -268,6 +269,7 @@ bool MCScriptInitialize(void)
268269
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.CannotSetReadOnlyPropertyError"), MCSTR("Cannot set read-only property %{module}.%{property}"), kMCScriptCannotSetReadOnlyPropertyErrorTypeInfo);
269270
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.PropertyValueTypeError"), MCSTR("Value is not of correct type for setting property - expected type %{type} for setting property %{module}.%{property}"), kMCScriptInvalidPropertyValueErrorTypeInfo);
270271
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.NotAHandlerValueError"), MCSTR("Value is not a handler"), kMCScriptNotAHandlerValueErrorTypeInfo);
272+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.CannotCallContextHandlerError"), MCSTR("Cannot call context handler"), kMCScriptCannotCallContextHandlerErrorTypeInfo);
271273
}
272274

273275
return true;

libscript/src/script-private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern MCTypeInfoRef kMCScriptNoMatchingHandlerErrorTypeInfo;
4141
extern MCTypeInfoRef kMCScriptCannotSetReadOnlyPropertyErrorTypeInfo;
4242
extern MCTypeInfoRef kMCScriptInvalidPropertyValueErrorTypeInfo;
4343
extern MCTypeInfoRef kMCScriptNotAHandlerValueErrorTypeInfo;
44+
extern MCTypeInfoRef kMCScriptCannotCallContextHandlerErrorTypeInfo;
4445

4546
////////////////////////////////////////////////////////////////////////////////
4647

0 commit comments

Comments
 (0)