Hey all,
I want to make a custom Scriptable object "false" when evaluated in a
boolean context. Just as an empty string evaluates as false, I would like
to make an object that evaluates to false depending on its contents.
My first reaction is to overload getDefaultValue(Class<?> hint), but this is
ignored.
Inspection of the ScriptRuntime.toBoolean method reveals:
if (val instanceof Scriptable) {
if (val instanceof ScriptableObject &&
((ScriptableObject) val).avoidObjectDetection())
{
return false;
}*
if (Context.getContext().isVersionECMA1()) {
// pure ECMA
return true;
}*
// ECMA extension
val = ((Scriptable) val).getDefaultValue(BooleanClass);
if (val instanceof Scriptable)
throw errorWithClassName("msg.primitive.expected", val);
continue;
}
Context.isVersionECMA1 gives me the following...
final boolean isVersionECMA1()
{
return version == VERSION_DEFAULT || version >= VERSION_1_3;
}
Which means I have four options...
1. set my JavaScript version to < 1.3 (which is not an option, since I would
like functionality from JavaScript 1.7)
2. HACK #1: overloading avoidObjectDetection to return true----this works,
but is a hack that also has the side-effect of typeof myObject ==
"undefined"
3. HACK #2: make my class extend Number, and return 0.0 for doubleValue()...
probably not a good idea
4. post to this list and see if there is another solution. :-)
What is the best way to do this?
Cheers!
Marcello
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino