1
0
Fork 0

setprop(): report error on writing to unwritable property

This commit is contained in:
mfranz 2007-10-10 19:24:17 +00:00
parent 6e72aa6a57
commit e3c2cf3abc

View file

@ -222,17 +222,19 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
SGPropertyNode* props = globals->get_props();
naRef val = args[argc-1];
bool ret;
try {
if(naIsString(val)) props->setStringValue(buf, naStr_data(val));
if(naIsString(val)) ret = props->setStringValue(buf, naStr_data(val));
else {
naRef n = naNumValue(val);
if(naIsNil(n))
naRuntimeError(c, "setprop() value is not string or number");
props->setDoubleValue(buf, n.num);
ret = props->setDoubleValue(buf, n.num);
}
} catch (const string& err) {
naRuntimeError(c, (char *)err.c_str());
}
if(!ret) naRuntimeError(c, "setprop(): property is not writable");
return naNil();
#undef BUFLEN
}