Bad scripting system behavior
The way the scripting system works, every object has the same methods. E.g. the document has a tagCount method. But if you call it the script crashes. These methods are poison to work with when trying to write generalized scripts — methods should either return reasonable values (if you have a tagCount method it should return the number of tags and not crash if there are no tags) or have the decency not to crash when called (correctly!).
It would be different if the C3D7 (a) reported the correct error (which is "this function always crashes when called from this object which shouldn't have it, sorry"), and (b) did not report the line number as -MAXINT because then you wouldn't need to hunt down which method(s) you're calling explode whenever they're called. I even had trouble fixing this by bisection because so many things started crashing when I generalized my carefully ducktyped code (if it walks like a duck and quacks like a duck it shouldn't explode like a bomb).
e.g.
The way the scripting system works, every object has the same methods. E.g. the document has a tagCount method. But if you call it the script crashes. These methods are poison to work with when trying to write generalized scripts — methods should either return reasonable values (if you have a tagCount method it should return the number of tags and not crash if there are no tags) or have the decency not to crash when called (correctly!).
It would be different if the C3D7 (a) reported the correct error (which is "this function always crashes when called from this object which shouldn't have it, sorry"), and (b) did not report the line number as -MAXINT because then you wouldn't need to hunt down which method(s) you're calling explode whenever they're called. I even had trouble fixing this by bisection because so many things started crashing when I generalized my carefully ducktyped code (if it walks like a duck and quacks like a duck it shouldn't explode like a bomb).
e.g.
Code:
obj = doc.selectedObject() || doc;
for(var i = 0; i < doc.tagCount(); i++){} // explodes
Code:
obj = doc.selectedObject() || doc;
if(obj.tagCount){
for(var i = 0; i < doc.tagCount(); i++){} // also explodes
}
Attachments
Last edited: