setprop(): report error on writing to unwritable property
This commit is contained in:
parent
6e72aa6a57
commit
e3c2cf3abc
1 changed files with 4 additions and 2 deletions
|
@ -222,17 +222,19 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
|
||||||
|
|
||||||
SGPropertyNode* props = globals->get_props();
|
SGPropertyNode* props = globals->get_props();
|
||||||
naRef val = args[argc-1];
|
naRef val = args[argc-1];
|
||||||
|
bool ret;
|
||||||
try {
|
try {
|
||||||
if(naIsString(val)) props->setStringValue(buf, naStr_data(val));
|
if(naIsString(val)) ret = props->setStringValue(buf, naStr_data(val));
|
||||||
else {
|
else {
|
||||||
naRef n = naNumValue(val);
|
naRef n = naNumValue(val);
|
||||||
if(naIsNil(n))
|
if(naIsNil(n))
|
||||||
naRuntimeError(c, "setprop() value is not string or number");
|
naRuntimeError(c, "setprop() value is not string or number");
|
||||||
props->setDoubleValue(buf, n.num);
|
ret = props->setDoubleValue(buf, n.num);
|
||||||
}
|
}
|
||||||
} catch (const string& err) {
|
} catch (const string& err) {
|
||||||
naRuntimeError(c, (char *)err.c_str());
|
naRuntimeError(c, (char *)err.c_str());
|
||||||
}
|
}
|
||||||
|
if(!ret) naRuntimeError(c, "setprop(): property is not writable");
|
||||||
return naNil();
|
return naNil();
|
||||||
#undef BUFLEN
|
#undef BUFLEN
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue