Fixing bug 255891: just without throwing exceptions about non-js values for compatibility.

This commit is contained in:
igor%mir2.org 2004-08-17 18:33:38 +00:00
Родитель d585d5fc3e
Коммит 012b5ccb2b
2 изменённых файлов: 26 добавлений и 20 удалений

Просмотреть файл

@ -399,18 +399,5 @@ public class Kit
{
throw new IllegalStateException("FAILED ASSERTION");
}
/**
* Throws RuntimeException to indicate that x does not have a valid JS type.
*
* The function never returns and its return type is RuntimeException
* to allow to indicate unrechable code via
* <tt>throw Kit.badTypeJS(x)</tt>.
*/
public static RuntimeException badTypeJS(Object x)
throws RuntimeException
{
throw new IllegalArgumentException("Type "+x.getClass().getName()+" of "+x+" is not valid JS type");
}
}

Просмотреть файл

@ -236,7 +236,9 @@ public class ScriptRuntime {
double d = ((Number) val).doubleValue();
return (d == d && d != 0.0);
}
throw Kit.badTypeJS(val);
warnAboutNonJSObject(val);
return true;
}
public static boolean toBoolean(Object[] args, int index) {
@ -265,7 +267,9 @@ public class ScriptRuntime {
return toNumber((String) val);
if (val instanceof Boolean)
return ((Boolean) val).booleanValue() ? 1 : +0.0;
throw Kit.badTypeJS(val);
warnAboutNonJSObject(val);
return NaN;
}
public static double toNumber(Object[] args, int index) {
@ -727,7 +731,8 @@ public class ScriptRuntime {
}
return toString(value);
}
throw Kit.badTypeJS(value);
warnAboutNonJSObject(value);
return value.toString();
}
static String defaultObjectToSource(Context cx, Scriptable scope,
@ -2533,7 +2538,8 @@ public class ScriptRuntime {
}
return false;
} else {
throw Kit.badTypeJS(x);
warnAboutNonJSObject(x);
return x == y;
}
}
@ -2559,7 +2565,8 @@ public class ScriptRuntime {
}
y = toPrimitive(y);
} else {
throw Kit.badTypeJS(y);
warnAboutNonJSObject(y);
return false;
}
}
}
@ -2586,7 +2593,8 @@ public class ScriptRuntime {
y = toPrimitive(y);
continue;
} else {
throw Kit.badTypeJS(y);
warnAboutNonJSObject(y);
return false;
}
}
}
@ -2620,7 +2628,8 @@ public class ScriptRuntime {
return ((Wrapper)x).unwrap() == ((Wrapper)y).unwrap();
}
} else {
throw Kit.badTypeJS(x);
warnAboutNonJSObject(x);
return x == y;
}
return false;
}
@ -3158,6 +3167,16 @@ public class ScriptRuntime {
return typeError1("msg.isnt.function", msg);
}
private static void warnAboutNonJSObject(Object nonJSObject)
{
String message =
"RHINO USAGE WARNING: Missed Context.javaToJS() conversion:\n"
+"Rhino runtime detected object "+nonJSObject+" of class "+nonJSObject.getClass().getName()+" where it expected String, Number, Boolean or Scriptable instance. Please check your code for missig Context.javaToJS() call.";
Context.reportWarning(message);
// Just to be sure that it would be noticed
System.err.println(message);
}
public static RegExpProxy getRegExpProxy(Context cx)
{
return cx.getRegExpProxy();