Implement specially NativeJavaObject.getDefaultValue for java.lang.Boolean to match the behavior of JS Boolean object.

This commit is contained in:
igor%mir2.org 2004-10-31 00:15:57 +00:00
parent 5e4041c8e1
commit 58aceb81d9

View File

@ -180,40 +180,40 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
return "JavaObject"; return "JavaObject";
} }
Function getConverter(String converterName) { public Object getDefaultValue(Class hint)
Object converterFunction = get(converterName, this);
if (converterFunction instanceof Function) {
return (Function) converterFunction;
}
return null;
}
Object callConverter(Function converterFunction)
{ {
Function f = (Function) converterFunction;
return f.call(Context.getContext(), f.getParentScope(),
this, ScriptRuntime.emptyArgs);
}
Object callConverter(String converterName)
{
Function converter = getConverter(converterName);
if (converter == null) {
return javaObject.toString();
}
return callConverter(converter);
}
public Object getDefaultValue(Class hint) {
Object value; Object value;
if (hint == null) {
if (javaObject instanceof Boolean) {
hint = ScriptRuntime.BooleanClass;
}
}
if (hint == null || hint == ScriptRuntime.StringClass) { if (hint == null || hint == ScriptRuntime.StringClass) {
value = javaObject.toString(); value = javaObject.toString();
} else if (hint == ScriptRuntime.BooleanClass) {
value = callConverter("booleanValue");
} else if (hint == ScriptRuntime.NumberClass) {
value = callConverter("doubleValue");
} else { } else {
throw Context.reportRuntimeError0("msg.default.value"); String converterName;
if (hint == ScriptRuntime.BooleanClass) {
converterName = "booleanValue";
} else if (hint == ScriptRuntime.NumberClass) {
converterName = "doubleValue";
} else {
throw Context.reportRuntimeError0("msg.default.value");
}
Object converterObject = get(converterName, this);
if (converterObject instanceof Function) {
Function f = (Function)converterObject;
value = f.call(Context.getContext(), f.getParentScope(),
this, ScriptRuntime.emptyArgs);
} else {
if (hint == ScriptRuntime.NumberClass
&& javaObject instanceof Boolean)
{
boolean b = ((Boolean)javaObject).booleanValue();
value = ScriptRuntime.wrapNumber(b ? 1.0 : 0.0);
} else {
value = javaObject.toString();
}
}
} }
return value; return value;
} }