UnitValue vs. null issue.
Hi Folks,
Has anyone come across an issue where a valid UnitValue object is considered null? I've tested this in Mac versions of: ID CS6, ID CC 2014, and when running the script within ExtendScript Toolkit v4.0.0.1. I haven't tried this on Windows.
var x = .1;
var uv = new UnitValue(x, "pt");
$.writeln(uv);
if (uv === null)
{
// uv is incorrectly considered null when (uv.value > -1.0 && uv.value < 1.0)
$.writeln("uv is null!");
}
// Output:
// 0.1 pt
// uv is null!
It appears that a UnitValue object is considered to be null by ExtendScript when its value property (the x variable in the code above) is a fraction of 1. i.e.,(uv.value > -1.0 && uv.value < 1.0).
And, yes, this issue can be worked around using a try/catch:
function IsUVNull(theUV)
{
// Returns true if null; false otherwise.
try
{
var dummy = theUV.constructor;
return false;
}
catch (e)
{
return true;
}
}
Am I missing something, or is ExtendScript just picking on me. Again. 😉
On the plus side, maybe I finally found a situation where null actually is an object!
-- Jim