Skip to content

Commit c4f30ab

Browse files
committed
[[ Script ]] Correct functionality of Query methods in MCScript
The definition querying methods should return false if the module is not usable or the definition could not be found - they should not throw (as they are used to check whether a module includes a given named definition!).
1 parent 40529a2 commit c4f30ab

File tree

2 files changed

+22
-38
lines changed

2 files changed

+22
-38
lines changed

libscript/include/libscript/script.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,31 +186,36 @@ bool MCScriptListDependencyNamesOfModule(MCScriptModuleRef module, /* copy */ MC
186186
// Returns a list of the constants defined by the module.
187187
bool MCScriptListConstantNamesOfModule(MCScriptModuleRef module, /* copy */ MCProperListRef& r_constant_names);
188188

189-
// Queries the value of the given constant.
189+
// Queries the value of the given constant. If the constant doesn't exist, or
190+
// module is not usable, false is returned.
190191
bool MCScriptQueryConstantOfModule(MCScriptModuleRef module, MCNameRef name, /* get */ MCValueRef& r_constant_value);
191192

192193
// Returns a list of properties implemented by the module.
193194
bool MCScriptListPropertyNamesOfModule(MCScriptModuleRef module, /* copy */ MCProperListRef& r_property_names);
194195

195-
// Queries the type of the given property. If the setting type is nil, then the property
196-
// is read-only.
196+
// Queries the type of the given property. If the setting type is nil, then the
197+
// property is read-only. If the property doesn't exist, or module is not
198+
// usable, false is returned.
197199
bool MCScriptQueryPropertyOfModule(MCScriptModuleRef module, MCNameRef property, /* get */ MCTypeInfoRef& r_getter, /* get */ MCTypeInfoRef& r_setter);
198200

199201
// Returns a list of the events declared by the module.
200202
bool MCScriptListEventNamesOfModule(MCScriptModuleRef module, /* copy */ MCProperListRef& r_event_names);
201203

202-
// Query the signature of the given event.
204+
// Query the signature of the given event. If the event doesn't exist, or
205+
// module is not usable, false is returned.
203206
bool MCScriptQueryEventOfModule(MCScriptModuleRef module, MCNameRef event, /* get */ MCTypeInfoRef& r_signature);
204207

205208
// Returns a list of the handlers declared by the module.
206209
bool MCScriptListHandlerNamesOfModule(MCScriptModuleRef module, /* copy */ MCProperListRef& r_handler_names);
207210

208-
// Query the signature of the given handler.
211+
// Query the signature of the given handler. If the handler doesn't exist, or
212+
// module is not usable, false is returned.
209213
bool MCScriptQueryHandlerSignatureOfModule(MCScriptModuleRef module, MCNameRef handler, /* get */ MCTypeInfoRef& r_signature);
210214

211215
// Copy the names of the parameters in the signature of the given handler.
212216
// Note: If the module has had debugging info stripped, the list will be all
213-
// empty names.
217+
// empty names. If the handler doesn't exist, or module is not usable, false is
218+
// returned.
214219
bool MCScriptListHandlerParameterNamesOfModule(MCScriptModuleRef module, MCNameRef handler, /* copy */ MCProperListRef& r_names);
215220

216221
// Emit an interface definition for the module.

libscript/src/script-module.cpp

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -829,25 +829,6 @@ bool MCScriptEnsureModuleIsUsable(MCScriptModuleRef self)
829829

830830
////////////////////////////////////////////////////////////////////////////////
831831

832-
static bool
833-
__MCScriptThrowModuleNotUsableError(MCScriptModuleRef self)
834-
{
835-
return MCErrorThrowGenericWithMessage(MCSTR("%{name} not usable"),
836-
"name", self -> name,
837-
nil);
838-
}
839-
840-
static bool
841-
__MCScriptThrowDefinitionNotFoundInModuleError(MCScriptModuleRef self,
842-
MCScriptDefinitionKind p_kind,
843-
MCNameRef p_name)
844-
{
845-
return MCErrorThrowGenericWithMessage(MCSTR("%{kind} definition %{name} not found in %{module}"),
846-
"kind", __MCScriptDefinitionKindToString(p_kind),
847-
"name", p_name,
848-
"module", self->name);
849-
}
850-
851832
static bool
852833
__MCScriptCopyDefinitionsOfModule(MCScriptModuleRef self,
853834
MCScriptDefinitionKind p_kind,
@@ -915,15 +896,13 @@ bool MCScriptQueryConstantOfModule(MCScriptModuleRef self, MCNameRef p_constant,
915896
MCScriptConstantDefinition *t_constant_def = nil;
916897

917898
if (!self -> is_usable)
918-
return __MCScriptThrowModuleNotUsableError(self);
899+
return false;
919900

920901
if (!MCScriptLookupConstantDefinitionInModule(self,
921902
p_constant,
922903
t_constant_def))
923904
{
924-
return __MCScriptThrowDefinitionNotFoundInModuleError(self,
925-
kMCScriptDefinitionKindConstant,
926-
p_constant);
905+
return false;
927906
}
928907

929908
r_constant_value = self->values[t_constant_def->value];
@@ -943,10 +922,10 @@ bool MCScriptQueryPropertyOfModule(MCScriptModuleRef self, MCNameRef p_property,
943922
MCScriptPropertyDefinition *t_def;
944923

945924
if (!self -> is_usable)
946-
return __MCScriptThrowModuleNotUsableError(self);
925+
return false;
947926

948927
if (!MCScriptLookupPropertyDefinitionInModule(self, p_property, t_def))
949-
return __MCScriptThrowDefinitionNotFoundInModuleError(self, kMCScriptDefinitionKindProperty, p_property);
928+
return false;
950929

951930
MCScriptDefinition *t_getter;
952931
t_getter = t_def -> getter != 0 ? self -> definitions[t_def -> getter - 1] : nil;
@@ -989,10 +968,10 @@ bool MCScriptQueryEventOfModule(MCScriptModuleRef self, MCNameRef p_event, /* ge
989968
MCScriptEventDefinition *t_def;
990969

991970
if (!self -> is_usable)
992-
return __MCScriptThrowModuleNotUsableError(self);
971+
return false;
993972

994973
if (!MCScriptLookupEventDefinitionInModule(self, p_event, t_def))
995-
return __MCScriptThrowDefinitionNotFoundInModuleError(self, kMCScriptDefinitionKindEvent, p_event);
974+
return false;
996975

997976
r_signature = self -> types[t_def -> type] -> typeinfo;
998977

@@ -1011,10 +990,10 @@ bool MCScriptQueryHandlerSignatureOfModule(MCScriptModuleRef self, MCNameRef p_h
1011990
MCScriptHandlerDefinition *t_def;
1012991

1013992
if (!self -> is_usable)
1014-
return __MCScriptThrowModuleNotUsableError(self);
993+
return false;
1015994

1016995
if (!MCScriptLookupHandlerDefinitionInModule(self, p_handler, t_def))
1017-
return __MCScriptThrowDefinitionNotFoundInModuleError(self, kMCScriptDefinitionKindProperty, p_handler);
996+
return false;
1018997

1019998
r_signature = self -> types[t_def -> type] -> typeinfo;
1020999

@@ -1027,12 +1006,12 @@ bool MCScriptCopyHandlerParameterNamesOfModule(MCScriptModuleRef self, MCNameRef
10271006

10281007
if (!self -> is_usable)
10291008
{
1030-
return __MCScriptThrowModuleNotUsableError(self);
1031-
}
1009+
return false;
1010+
}
10321011

10331012
if (!MCScriptLookupHandlerDefinitionInModule(self, p_handler, t_def))
10341013
{
1035-
return __MCScriptThrowDefinitionNotFoundInModuleError(self, kMCScriptDefinitionKindHandler, p_handler);
1014+
return false;
10361015
}
10371016

10381017
MCAutoProperListRef t_names;

0 commit comments

Comments
 (0)