* Synchronize get() and set() to hopefully get rid of weird property read errors.
* Do not access static fields through instance variable
This commit is contained in:
parent
04d8589d29
commit
3d6da7803d
1 changed files with 18 additions and 5 deletions
|
@ -85,12 +85,25 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override ScriptableObject.put() to implement PropertyRecorder interface.
|
* Override ScriptableObject.get() to synchronize it.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param start
|
||||||
|
* @return the property for the given name
|
||||||
|
*/
|
||||||
|
public synchronized Object get(String name, Scriptable start) {
|
||||||
|
return super.get(name, start);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override ScriptableObject.put() to implement PropertyRecorder interface
|
||||||
|
* and to synchronize method.
|
||||||
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* @param start
|
* @param start
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
public void put(String name, Scriptable start, Object value) {
|
public synchronized void put(String name, Scriptable start, Object value) {
|
||||||
// register property for PropertyRecorder interface
|
// register property for PropertyRecorder interface
|
||||||
if (isRecording) {
|
if (isRecording) {
|
||||||
changedProperties.add(name);
|
changedProperties.add(name);
|
||||||
|
@ -519,7 +532,7 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
"the serialization to");
|
"the serialization to");
|
||||||
}
|
}
|
||||||
Object obj = args[0];
|
Object obj = args[0];
|
||||||
String filename = cx.toString(args[1]);
|
String filename = Context.toString(args[1]);
|
||||||
FileOutputStream fos = new FileOutputStream(filename);
|
FileOutputStream fos = new FileOutputStream(filename);
|
||||||
Scriptable scope = ScriptableObject.getTopLevelScope(thisObj).getPrototype();
|
Scriptable scope = ScriptableObject.getTopLevelScope(thisObj).getPrototype();
|
||||||
// use a ScriptableOutputStream that unwraps Wrappers
|
// use a ScriptableOutputStream that unwraps Wrappers
|
||||||
|
@ -542,13 +555,13 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
throw Context.reportRuntimeError(
|
throw Context.reportRuntimeError(
|
||||||
"Expected a filename to read the serialization from");
|
"Expected a filename to read the serialization from");
|
||||||
}
|
}
|
||||||
String filename = cx.toString(args[0]);
|
String filename = Context.toString(args[0]);
|
||||||
FileInputStream fis = new FileInputStream(filename);
|
FileInputStream fis = new FileInputStream(filename);
|
||||||
Scriptable scope = ScriptableObject.getTopLevelScope(thisObj).getPrototype();
|
Scriptable scope = ScriptableObject.getTopLevelScope(thisObj).getPrototype();
|
||||||
ObjectInputStream in = new ScriptableInputStream(fis, scope);
|
ObjectInputStream in = new ScriptableInputStream(fis, scope);
|
||||||
Object deserialized = in.readObject();
|
Object deserialized = in.readObject();
|
||||||
in.close();
|
in.close();
|
||||||
return cx.toObject(deserialized, scope);
|
return Context.toObject(deserialized, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue