diff --git a/js/rhino/src/org/mozilla/javascript/FunctionObject.java b/js/rhino/src/org/mozilla/javascript/FunctionObject.java index 7e7f11e0e60..7133c442b97 100644 --- a/js/rhino/src/org/mozilla/javascript/FunctionObject.java +++ b/js/rhino/src/org/mozilla/javascript/FunctionObject.java @@ -439,7 +439,7 @@ public class FunctionObject extends NativeFunction implements Serializable { return hasVoidReturn ? Undefined.instance : result; } catch (InvocationTargetException e) { - throw JavaScriptException.wrapException(scope, e); + throw JavaScriptException.wrapException(cx, scope, e); } catch (IllegalAccessException e) { throw WrappedException.wrapException(e); @@ -551,7 +551,7 @@ public class FunctionObject extends NativeFunction implements Serializable { if (target instanceof EcmaError) throw (EcmaError) target; Scriptable scope = thisObj == null ? this : thisObj; - throw JavaScriptException.wrapException(scope, target); + throw JavaScriptException.wrapException(cx, scope, target); } catch (IllegalAccessException e) { throw WrappedException.wrapException(e); @@ -578,7 +578,7 @@ public class FunctionObject extends NativeFunction implements Serializable { } } - private void writeObject(ObjectOutputStream out) + private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); @@ -603,13 +603,13 @@ public class FunctionObject extends NativeFunction implements Serializable { /** * Writes a Constructor or Method object. - * + * * Methods and Constructors are not serializable, so we must serialize * information about the class, the name, and the parameters and * recreate upon deserialization. */ - static void writeMember(ObjectOutputStream out, Member member) - throws IOException + static void writeMember(ObjectOutputStream out, Member member) + throws IOException { if (member == null) { out.writeBoolean(false); @@ -631,7 +631,7 @@ public class FunctionObject extends NativeFunction implements Serializable { /** * Reads a Method or a Constructor from the stream. */ - static Member readMember(ObjectInputStream in) + static Member readMember(ObjectInputStream in) throws IOException, ClassNotFoundException { if (!in.readBoolean()) @@ -666,11 +666,11 @@ public class FunctionObject extends NativeFunction implements Serializable { /** * Writes an array of parameter types to the stream. * - * Requires special handling because primitive types cannot be + * Requires special handling because primitive types cannot be * found upon deserialization by the default Java implementation. */ static void writeParameters(ObjectOutputStream out, Class[] parms) - throws IOException + throws IOException { out.writeShort(parms.length); outer: @@ -687,7 +687,7 @@ public class FunctionObject extends NativeFunction implements Serializable { continue outer; } } - throw new IllegalArgumentException("Primitive " + parm + + throw new IllegalArgumentException("Primitive " + parm + " not found"); } } @@ -695,8 +695,8 @@ public class FunctionObject extends NativeFunction implements Serializable { /** * Reads an array of parameter types from the stream. */ - static Class[] readParameters(ObjectInputStream in) - throws IOException, ClassNotFoundException + static Class[] readParameters(ObjectInputStream in) + throws IOException, ClassNotFoundException { Class[] result = new Class[in.readShort()]; for (int i=0; i < result.length; i++) { diff --git a/js/rhino/src/org/mozilla/javascript/JavaMembers.java b/js/rhino/src/org/mozilla/javascript/JavaMembers.java index 7e8883b6267..44ff51b892e 100644 --- a/js/rhino/src/org/mozilla/javascript/JavaMembers.java +++ b/js/rhino/src/org/mozilla/javascript/JavaMembers.java @@ -86,6 +86,7 @@ class JavaMembers { } if (member instanceof Scriptable) return member; // why is this here? + Context cx = Context.getContext(); Object rval; Class type; try { @@ -113,11 +114,11 @@ class JavaMembers { // Since JavaScriptException is a checked exception, must // wrap the JavaScriptException in a WrappedException throw WrappedException.wrapException( - JavaScriptException.wrapException(scope, e)); + JavaScriptException.wrapException(cx, scope, e)); } // Need to wrap the object before we return it. scope = ScriptableObject.getTopLevelScope(scope); - return NativeJavaObject.wrap(scope, rval, type); + return cx.getWrapFactory().wrap(cx, scope, rval, type); } Member findExplicitFunction(String name, boolean isStatic) { @@ -225,7 +226,8 @@ class JavaMembers { "accessing Java field"); } catch (InvocationTargetException e) { throw WrappedException.wrapException( - JavaScriptException.wrapException(scope, e)); + JavaScriptException.wrapException( + Context.getContext(), scope, e)); } } else { @@ -588,7 +590,8 @@ class FieldAndMethods extends NativeJavaMethod { throw Context.reportRuntimeError1( "msg.java.internal.private", getName()); } - rval = NativeJavaObject.wrap(this, rval, type); + Context cx = Context.getContext(); + rval = cx.getWrapFactory().wrap(cx, this, rval, type); if (rval instanceof Scriptable) { rval = ((Scriptable) rval).getDefaultValue(hint); } diff --git a/js/rhino/src/org/mozilla/javascript/JavaScriptException.java b/js/rhino/src/org/mozilla/javascript/JavaScriptException.java index a48f9ab9fad..584e5efb556 100644 --- a/js/rhino/src/org/mozilla/javascript/JavaScriptException.java +++ b/js/rhino/src/org/mozilla/javascript/JavaScriptException.java @@ -58,14 +58,15 @@ public class JavaScriptException extends Exception { this.value = value; } - static JavaScriptException wrapException(Scriptable scope, + static JavaScriptException wrapException(Context cx, Scriptable scope, Throwable exn) { if (exn instanceof InvocationTargetException) exn = ((InvocationTargetException)exn).getTargetException(); if (exn instanceof JavaScriptException) return (JavaScriptException)exn; - Object wrapper = NativeJavaObject.wrap(scope, exn, Throwable.class); + Object wrapper = cx.getWrapFactory(). + wrap(cx, scope, exn, Throwable.class); return new JavaScriptException(wrapper); } diff --git a/js/rhino/src/org/mozilla/javascript/NativeJavaArray.java b/js/rhino/src/org/mozilla/javascript/NativeJavaArray.java index 158953d9400..8121bef7cef 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeJavaArray.java +++ b/js/rhino/src/org/mozilla/javascript/NativeJavaArray.java @@ -97,8 +97,11 @@ public class NativeJavaArray extends NativeJavaObject { } public Object get(int index, Scriptable start) { - if (0 <= index && index < length) - return NativeJavaObject.wrap(this, Array.get(array, index), cls); + if (0 <= index && index < length) { + Context cx = Context.getContext(); + Object obj = Array.get(array, index); + return cx.getWrapFactory().wrap(cx, this, obj, cls); + } return Undefined.instance; } @@ -110,7 +113,7 @@ public class NativeJavaArray extends NativeJavaObject { public void put(int index, Scriptable start, Object value) { if (0 <= index && index < length) { - Array.set(array, index, NativeJavaObject.coerceType(cls, value, + Array.set(array, index, NativeJavaObject.coerceType(cls, value, true)); return; } diff --git a/js/rhino/src/org/mozilla/javascript/NativeJavaClass.java b/js/rhino/src/org/mozilla/javascript/NativeJavaClass.java index 33feb4035a5..76a07d60922 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeJavaClass.java +++ b/js/rhino/src/org/mozilla/javascript/NativeJavaClass.java @@ -233,7 +233,7 @@ public class NativeJavaClass extends NativeJavaObject implements Function { throw Context.reportRuntimeError3( "msg.bad.ctor.sig", argEx.getMessage(), ctorString, signature); } catch (InvocationTargetException e) { - throw JavaScriptException.wrapException(scope, e); + throw JavaScriptException.wrapException(cx, scope, e); } catch (IllegalAccessException accessEx) { throw Context.reportRuntimeError1( "msg.java.internal.private", accessEx.getMessage()); diff --git a/js/rhino/src/org/mozilla/javascript/NativeJavaMethod.java b/js/rhino/src/org/mozilla/javascript/NativeJavaMethod.java index 5d5a9976450..90fcc36d63e 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeJavaMethod.java +++ b/js/rhino/src/org/mozilla/javascript/NativeJavaMethod.java @@ -262,7 +262,7 @@ public class NativeJavaMethod extends NativeFunction implements Function { "\" in class \"" + meth.getDeclaringClass().getName() + "\" receieved " + accessEx.toString()); } catch (InvocationTargetException e) { - throw JavaScriptException.wrapException(scope, e); + throw JavaScriptException.wrapException(cx, scope, e); } } diff --git a/js/rhino/src/org/mozilla/javascript/NativeJavaObject.java b/js/rhino/src/org/mozilla/javascript/NativeJavaObject.java index 2f59a825675..cf20b42db0f 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeJavaObject.java +++ b/js/rhino/src/org/mozilla/javascript/NativeJavaObject.java @@ -161,6 +161,10 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable { return members.getIds(false); } +/** +@deprecated Use {@link Context#getWrapFactory()} together with calling {@link +WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)} +*/ public static Object wrap(Scriptable scope, Object obj, Class staticType) { Context cx = Context.getContext(); @@ -172,7 +176,6 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable { { if (obj == null) return obj; - Class cls = obj.getClass(); if (staticType != null && staticType.isPrimitive()) { if (staticType == Void.TYPE) return Undefined.instance; @@ -180,15 +183,17 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable { return new Integer((int) ((Character) obj).charValue()); return obj; } - if (cls.isArray()) - return NativeJavaArray.wrap(scope, obj); if (obj instanceof Scriptable) return obj; + Class cls = obj.getClass(); + if (cls.isArray()) + return NativeJavaArray.wrap(scope, obj); if (Context.useJSObject && jsObjectClass != null && staticType != jsObjectClass && jsObjectClass.isInstance(obj)) { try { - return jsObjectGetScriptable.invoke(obj, ScriptRuntime.emptyArgs); + return jsObjectGetScriptable. + invoke(obj, ScriptRuntime.emptyArgs); } catch (InvocationTargetException e) { // Just abandon conversion from JSObject diff --git a/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java b/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java index 7fe0a8765d2..ed05f67643d 100644 --- a/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java +++ b/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java @@ -521,7 +521,8 @@ public class ScriptRuntime { if (className == null) { // Extension: Wrap as a LiveConnect object. - Object wrapped = NativeJavaObject.wrap(scope, val, staticClass); + Object wrapped = cx.getWrapFactory(). + wrap(cx, scope, val, staticClass); if (wrapped instanceof Scriptable) return (Scriptable) wrapped; throw errorWithClassName("msg.invalid.type", val);