Skip to content

Commit b174329

Browse files
authored
Merge pull request #28 from s-ludwig/improve_error_messages
Improve error messages for accessing undefined variables
2 parents f2a02ba + d3c9da5 commit b174329

3 files changed

Lines changed: 11 additions & 12 deletions

File tree

engine/source/dmdscript/dobject.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ import dmdscript.utf;
4848

4949
class ErrorValue: Exception {
5050
Value value;
51-
this(Value* vptr){
52-
super("DMDScript exception");
51+
this(CallContext* cc, Value* vptr){
52+
super(vptr.toString(cc));
5353
value = *vptr;
5454
}
5555
}

engine/source/dmdscript/opcodes.d

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ struct IR
719719
id = (code+1).id;
720720
s = id.value.string;
721721
if(!scope_get(scopex, id))
722-
throw new ErrorValue(Dobject.ReferenceError(cc, errmsgtbl[ERR_UNDEFINED_VAR],s));
722+
throw new ErrorValue(cc, Dobject.ReferenceError(cc, errmsgtbl[ERR_UNDEFINED_VAR],s));
723723
code += 2;
724724
break;
725725
case IRgetscope: // a = s
@@ -797,7 +797,7 @@ struct IR
797797
a = GETa(code);
798798
if(!v)
799799
{
800-
throw new ErrorValue(Dobject.ReferenceError(cc, errmsgtbl[ERR_UNDEFINED_VAR],s));
800+
throw new ErrorValue(cc, Dobject.ReferenceError(cc, errmsgtbl[ERR_UNDEFINED_VAR],s));
801801
//a.putVundefined();
802802
/+
803803
if (b)
@@ -1145,7 +1145,7 @@ struct IR
11451145
o = c.toObject(cc);
11461146
if(!o){
11471147
ErrInfo errinfo;
1148-
throw new ErrorValue(Dobject.RuntimeError(&errinfo,cc,errmsgtbl[ERR_RHS_MUST_BE_OBJECT],"in",c.toString(cc)));
1148+
throw new ErrorValue(cc, Dobject.RuntimeError(&errinfo,cc,errmsgtbl[ERR_RHS_MUST_BE_OBJECT],"in",c.toString(cc)));
11491149
}
11501150
a.putVboolean(o.HasProperty(s));
11511151
code += 4;
@@ -1217,7 +1217,7 @@ struct IR
12171217
Value.copy(a, v);
12181218
}
12191219
else
1220-
throw new ErrorValue(Dobject.ReferenceError(cc,errmsgtbl[ERR_UNDEFINED_VAR], s));
1220+
throw new ErrorValue(cc, Dobject.ReferenceError(cc,errmsgtbl[ERR_UNDEFINED_VAR], s));
12211221
}
12221222
code += 4;
12231223
break;
@@ -1271,7 +1271,7 @@ struct IR
12711271
{
12721272
//GETa(code).putVundefined();
12731273
//FIXED: as per ECMA v5 should throw ReferenceError
1274-
throw new ErrorValue(Dobject.ReferenceError(cc,id.value.string));
1274+
throw new ErrorValue(cc, Dobject.ReferenceError(cc,id.value.string));
12751275
//v = signalingUndefined(id.value.string);
12761276
}
12771277
code += 3;
@@ -1310,7 +1310,7 @@ struct IR
13101310
{
13111311
//GETa(code).putVundefined();
13121312
//FIXED: as per ECMA v5 should throw ReferenceError
1313-
throw new ErrorValue(Dobject.ReferenceError(cc,id.value.string));
1313+
throw new ErrorValue(cc, Dobject.ReferenceError(cc,id.value.string));
13141314
//v = signalingUndefined(id.value.string);
13151315
}
13161316
code += 3;
@@ -2064,7 +2064,6 @@ struct IR
20642064
}
20652065
catch(ErrorValue err)
20662066
{
2067-
import std.stdio; writefln("ERROR: %s", err.toString());
20682067
v = unwindStack(&err.value);
20692068
if(v)//v is exception that was not caught
20702069
return v;

engine/source/dmdscript/value.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct Value
8383
throwRefError(cc);
8484
}
8585
void throwRefError(CallContext* cc) const{
86-
throw new ErrorValue(Dobject.ReferenceError(cc,errmsgtbl[ERR_UNDEFINED_VAR],string));
86+
throw new ErrorValue(cc, Dobject.ReferenceError(cc,errmsgtbl[ERR_UNDEFINED_VAR],string));
8787
}
8888

8989
void putSignalingUndefined(d_string id){
@@ -228,13 +228,13 @@ struct Value
228228
assert(object);
229229
a = object.DefaultValue(cc, v, PreferredType);
230230
if(a)
231-
throw new ErrorValue(cast(Value*)a);
231+
throw new ErrorValue(cc, cast(Value*)a);
232232
if(!v.isPrimitive())
233233
{
234234
ErrInfo errinfo;
235235

236236
v.putVundefined();
237-
throw new ErrorValue(Dobject.RuntimeError(&errinfo, cc, errmsgtbl[ERR_OBJECT_CANNOT_BE_PRIMITIVE]));
237+
throw new ErrorValue(cc, Dobject.RuntimeError(&errinfo, cc, errmsgtbl[ERR_OBJECT_CANNOT_BE_PRIMITIVE]));
238238
}
239239
}
240240
else

0 commit comments

Comments
 (0)