Commiting Hannes Wallnoefer patch to allow LiveConnect to convert JS Date to Java Data, see http://bugzilla.mozilla.org/show_bug.cgi?id=201326

This commit is contained in:
igor%mir2.org 2003-04-12 10:48:39 +00:00
Родитель 1ca2e83bf8
Коммит f426f26c1d
3 изменённых файлов: 26 добавлений и 5 удалений

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

@ -79,6 +79,10 @@ final class NativeDate extends IdScriptable {
return super.getDefaultValue(typeHint);
}
double getJSTimeValue() {
return date;
}
protected void fillConstructorProperties
(Context cx, IdFunction ctor, boolean sealed)
{

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

@ -43,6 +43,7 @@ import java.io.*;
import java.lang.reflect.*;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Date;
/**
* This class reflects non-Array Java objects into the JavaScript environment. It
@ -372,11 +373,13 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
case JSTYPE_OBJECT:
// Other objects takes #1-#3 spots
if (fromObj instanceof NativeArray && to.isArray()) {
// This is a native array conversion to a java array
// Array conversions are all equal, and preferable to object
// and string conversion, per LC3.
result = 1;
if (to.isArray()) {
if (fromObj instanceof NativeArray) {
// This is a native array conversion to a java array
// Array conversions are all equal, and preferable to object
// and string conversion, per LC3.
result = 1;
}
}
else if (to == ScriptRuntime.ObjectClass) {
result = 2;
@ -384,6 +387,12 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
else if (to == ScriptRuntime.StringClass) {
result = 3;
}
else if (to == ScriptRuntime.DateClass) {
if (fromObj instanceof NativeDate) {
// This is a native date to java date conversion
result = 1;
}
}
else if (to.isPrimitive() || to != Boolean.TYPE) {
result = 3 + NativeJavaObject.getSizeRank(to);
}
@ -624,6 +633,13 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
else if (type.isInstance(value)) {
return value;
}
else if (type == ScriptRuntime.DateClass
&& value instanceof NativeDate)
{
double time = ((NativeDate)value).getJSTimeValue();
// XXX: This will replace NaN by 0
return new Date((long)time);
}
else if (type.isArray() && value instanceof NativeArray) {
// Make a new java array, and coerce the JS array components
// to the target (component) type.

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

@ -82,6 +82,7 @@ public class ScriptRuntime {
public final static Class FunctionClass = Function.class;
public final static Class ClassClass = Class.class;
public final static Class SerializableClass = java.io.Serializable.class;
public final static Class DateClass = java.util.Date.class;
// Can not use .class as Comparable is only since JDK 1.2
public final static Class