Only manage those properties that were set in previous script compilations,

and never manage predefined properties because they may be set
unintentionally by code like Image.foo = bar. Should fix bug 397.
This commit is contained in:
hns 2005-01-25 07:57:55 +00:00
parent 24a973e662
commit bb399fc79d

View file

@ -856,6 +856,10 @@ public final class RhinoCore {
// the parent prototype info
TypeInfo parentType;
// a set of property keys that were in script compilation.
// Used to decide which properties should be removed if not renewed.
Set compiledProperties;
// a set of property keys that were present before first script compilation
final Set predefinedProperties;
@ -865,6 +869,7 @@ public final class RhinoCore {
frameworkProto = proto;
objProto = op;
// remember properties already defined on this object prototype
compiledProperties = new HashSet();
predefinedProperties = new HashSet();
Object[] keys = op.getAllIds();
for (int i = 0; i < keys.length; i++) {
@ -899,35 +904,31 @@ public final class RhinoCore {
Set changedProperties = recorder.getChangeSet();
recorder.clearChangeSet();
Object[] keys = objProto.getAllIds();
// ignore all properties that were defined before we started
// compilation. We won't manage these properties, even
// if they were set during compilation.
changedProperties.removeAll(predefinedProperties);
for (int i = 0; i < keys.length; i++) {
if (! (keys[i] instanceof String)) {
continue;
}
// remove all renewed properties from the previously compiled
// property names so we can remove those properties that were not
// renewed in this compilation
compiledProperties.removeAll(changedProperties);
String key = (String) keys[i];
if (predefinedProperties.contains(key)) {
// don't mess with properties we didn't set
continue;
}
Iterator it = compiledProperties.iterator();
while (it.hasNext()) {
String key = (String) it.next();
Object value = objProto.get(key, objProto);
if (value instanceof FunctionObject) {
// this is probably a HopObject Constructor - don't remove!
continue;
}
if (!changedProperties.contains(key)) {
try {
objProto.setAttributes(key, 0);
objProto.delete(key);
} catch (Exception px) {
System.err.println("Error unsetting property "+key+" on "+
frameworkProto.getName());
}
try {
objProto.setAttributes(key, 0);
objProto.delete(key);
} catch (Exception px) {
System.err.println("Error unsetting property "+key+" on "+
frameworkProto.getName());
}
}
// update compiled properties
compiledProperties = changedProperties;
}
// mark this type as updated