Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit f611506

Browse files
committed
[[ ComposedWidgets ]] Make sure GetPropertyOfWidget throws an error if the property is not present.
1 parent 0f8220e commit f611506

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

libscript/src/script-instance.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,16 @@ bool MCScriptThrowCannotCallContextHandlerError(MCScriptModuleRef p_module, MCSc
294294
return MCErrorCreateAndThrow(kMCScriptCannotCallContextHandlerErrorTypeInfo, "module", p_module -> name, "handler", MCScriptGetNameOfDefinitionInModule(p_module, p_handler), nil);
295295
}
296296

297+
bool MCScriptThrowHandlerNotFoundError(MCScriptModuleRef p_module, MCNameRef p_handler)
298+
{
299+
return MCErrorCreateAndThrow(kMCScriptHandlerNotFoundErrorTypeInfo, "module", p_module -> name, "handler", p_handler, nil);
300+
}
301+
302+
bool MCScriptThrowPropertyNotFoundError(MCScriptModuleRef p_module, MCNameRef p_property)
303+
{
304+
return MCErrorCreateAndThrow(kMCScriptPropertyNotFoundErrorTypeInfo, "module", p_module -> name, "property", p_property, nil);
305+
}
306+
297307
///////////
298308

299309
MCScriptVariableDefinition *MCScriptDefinitionAsVariable(MCScriptDefinition *self)
@@ -333,7 +343,7 @@ bool MCScriptGetPropertyOfInstance(MCScriptInstanceRef self, MCNameRef p_propert
333343
// Lookup the definition (throws if not found).
334344
MCScriptPropertyDefinition *t_definition;
335345
if (!MCScriptLookupPropertyDefinitionInModule(self -> module, p_property, t_definition))
336-
return false;
346+
return MCScriptThrowPropertyNotFoundError(self -> module, p_property);
337347

338348
MCScriptDefinition *t_getter;
339349
t_getter = t_definition -> getter != 0 ? self -> module -> definitions[t_definition -> getter - 1] : nil;
@@ -386,10 +396,10 @@ bool MCScriptSetPropertyOfInstance(MCScriptInstanceRef self, MCNameRef p_propert
386396
{
387397
__MCScriptValidateObjectAndKind__(self, kMCScriptObjectKindInstance);
388398

389-
// Lookup the definition (throws if not found).
399+
// Lookup the definition.
390400
MCScriptPropertyDefinition *t_definition;
391401
if (!MCScriptLookupPropertyDefinitionInModule(self -> module, p_property, t_definition))
392-
return false;
402+
return MCScriptThrowPropertyNotFoundError(self -> module, p_property);
393403

394404
MCScriptDefinition *t_setter;
395405
t_setter = t_definition -> setter != 0 ? self -> module -> definitions[t_definition -> setter - 1] : nil;
@@ -517,7 +527,7 @@ bool MCScriptCallHandlerOfInstance(MCScriptInstanceRef self, MCNameRef p_handler
517527
// Lookup the definition (throws if not found).
518528
MCScriptHandlerDefinition *t_definition;
519529
if (!MCScriptLookupHandlerDefinitionInModule(self -> module, p_handler, t_definition))
520-
return MCErrorThrowGeneric(MCSTR("handler not found"));
530+
return MCScriptThrowHandlerNotFoundError(self -> module, p_handler);
521531

522532
return MCScriptCallHandlerOfInstanceDirect(self, t_definition, p_arguments, p_argument_count, r_value);
523533
}

libscript/src/script-object.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ MCTypeInfoRef kMCScriptCannotSetReadOnlyPropertyErrorTypeInfo;
3737
MCTypeInfoRef kMCScriptInvalidPropertyValueErrorTypeInfo;
3838
MCTypeInfoRef kMCScriptNotAHandlerValueErrorTypeInfo;
3939
MCTypeInfoRef kMCScriptCannotCallContextHandlerErrorTypeInfo;
40+
MCTypeInfoRef kMCScriptHandlerNotFoundErrorTypeInfo;
41+
MCTypeInfoRef kMCScriptPropertyNotFoundErrorTypeInfo;
4042

4143
////////////////////////////////////////////////////////////////////////////////
4244

@@ -269,6 +271,10 @@ bool MCScriptInitialize(void)
269271
return false;
270272
if (!MCNamedErrorTypeInfoCreate(MCNAME("livecode.lang.CannotCallContextHandlerError"), MCNAME("runtime"), MCSTR("Cannot call context handler"), kMCScriptCannotCallContextHandlerErrorTypeInfo))
271273
return false;
274+
if (!MCNamedErrorTypeInfoCreate(MCNAME("livecode.lang.HandlerNotFoundError"), MCNAME("runtime"), MCSTR("No handler %{handler} in module %{module}"), kMCScriptHandlerNotFoundErrorTypeInfo))
275+
return false;
276+
if (!MCNamedErrorTypeInfoCreate(MCNAME("livecode.lang.PropertyNotFoundError"), MCNAME("runtime"), MCSTR("No property %{property} in module %{module}"), kMCScriptHandlerNotFoundErrorTypeInfo))
277+
return false;
272278
}
273279

274280
return true;

libscript/src/script-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ extern MCTypeInfoRef kMCScriptCannotSetReadOnlyPropertyErrorTypeInfo;
4242
extern MCTypeInfoRef kMCScriptInvalidPropertyValueErrorTypeInfo;
4343
extern MCTypeInfoRef kMCScriptNotAHandlerValueErrorTypeInfo;
4444
extern MCTypeInfoRef kMCScriptCannotCallContextHandlerErrorTypeInfo;
45+
extern MCTypeInfoRef kMCScriptPropertyNotFoundErrorTypeInfo;
46+
extern MCTypeInfoRef kMCScriptHandlerNotFoundErrorTypeInfo;
4547

4648
////////////////////////////////////////////////////////////////////////////////
4749

0 commit comments

Comments
 (0)