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:
parent
24a973e662
commit
bb399fc79d
1 changed files with 25 additions and 24 deletions
|
@ -856,6 +856,10 @@ public final class RhinoCore {
|
||||||
// the parent prototype info
|
// the parent prototype info
|
||||||
TypeInfo parentType;
|
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
|
// a set of property keys that were present before first script compilation
|
||||||
final Set predefinedProperties;
|
final Set predefinedProperties;
|
||||||
|
|
||||||
|
@ -865,6 +869,7 @@ public final class RhinoCore {
|
||||||
frameworkProto = proto;
|
frameworkProto = proto;
|
||||||
objProto = op;
|
objProto = op;
|
||||||
// remember properties already defined on this object prototype
|
// remember properties already defined on this object prototype
|
||||||
|
compiledProperties = new HashSet();
|
||||||
predefinedProperties = new HashSet();
|
predefinedProperties = new HashSet();
|
||||||
Object[] keys = op.getAllIds();
|
Object[] keys = op.getAllIds();
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
|
@ -899,35 +904,31 @@ public final class RhinoCore {
|
||||||
Set changedProperties = recorder.getChangeSet();
|
Set changedProperties = recorder.getChangeSet();
|
||||||
recorder.clearChangeSet();
|
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++) {
|
// remove all renewed properties from the previously compiled
|
||||||
if (! (keys[i] instanceof String)) {
|
// property names so we can remove those properties that were not
|
||||||
continue;
|
// renewed in this compilation
|
||||||
}
|
compiledProperties.removeAll(changedProperties);
|
||||||
|
|
||||||
String key = (String) keys[i];
|
Iterator it = compiledProperties.iterator();
|
||||||
if (predefinedProperties.contains(key)) {
|
while (it.hasNext()) {
|
||||||
// don't mess with properties we didn't set
|
String key = (String) it.next();
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object value = objProto.get(key, objProto);
|
try {
|
||||||
if (value instanceof FunctionObject) {
|
objProto.setAttributes(key, 0);
|
||||||
// this is probably a HopObject Constructor - don't remove!
|
objProto.delete(key);
|
||||||
continue;
|
} catch (Exception px) {
|
||||||
}
|
System.err.println("Error unsetting property "+key+" on "+
|
||||||
|
frameworkProto.getName());
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update compiled properties
|
||||||
|
compiledProperties = changedProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
// mark this type as updated
|
// mark this type as updated
|
||||||
|
|
Loading…
Add table
Reference in a new issue