Make sure we enter and exit a Context in serialize()/deserialize().

Do not wrap return object in deserialize().
This commit is contained in:
hns 2005-03-18 13:50:41 +00:00
parent 0dd4dba0f7
commit 892fe4b6e1

View file

@ -461,6 +461,8 @@ public class RhinoEngine implements ScriptingEngine {
* @throws java.io.IOException * @throws java.io.IOException
*/ */
public void serialize(Object obj, OutputStream out) throws IOException { public void serialize(Object obj, OutputStream out) throws IOException {
Context.enter();
try {
// use a special ScriptableOutputStream that unwraps Wrappers // use a special ScriptableOutputStream that unwraps Wrappers
ScriptableOutputStream sout = new ScriptableOutputStream(out, core.global) { ScriptableOutputStream sout = new ScriptableOutputStream(out, core.global) {
protected Object replaceObject(Object obj) throws IOException { protected Object replaceObject(Object obj) throws IOException {
@ -471,6 +473,9 @@ public class RhinoEngine implements ScriptingEngine {
}; };
sout.writeObject(obj); sout.writeObject(obj);
sout.flush(); sout.flush();
} finally {
Context.exit();
}
} }
/** /**
@ -483,9 +488,13 @@ public class RhinoEngine implements ScriptingEngine {
* @throws java.io.IOException * @throws java.io.IOException
*/ */
public Object deserialize(InputStream in) throws IOException, ClassNotFoundException { public Object deserialize(InputStream in) throws IOException, ClassNotFoundException {
Context.enter();
try {
ObjectInputStream sin = new ScriptableInputStream(in, core.global); ObjectInputStream sin = new ScriptableInputStream(in, core.global);
Object deserialized = sin.readObject(); return sin.readObject();
return Context.toObject(deserialized, core.global); } finally {
Context.exit();
}
} }
/** /**