RFR: 8159589: ScriptObjectMirror.clear() should remove all enumerable properties
Hannes Wallnöfer
hannes.wallnoefer at oracle.com
Fri Jun 17 13:54:43 UTC 2016
Please review JDK-8159589: ScriptObjectMirror.clear() should remove all enumerable properties:
Bug: https://bugs.openjdk.java.net/browse/JDK-8159589
Webrev: http://cr.openjdk.java.net/~hannesw/8159589/webrev.00/
In our current implementation, ScriptObjectMirror.clear() observes JS semantics by not clearing properties that are non-configurable, and even throwing type error when invoking clear() on an object that contains such properties.
IMO, there’s no need to follow JS semantics since we’re calling the method from outside of JS. With this change, clear() will remove all enumerable properties. This also makes the method consistent with size() and isEmpty(), which previously could return values > 0 and false after calling clear().
On a practical note, this is really convenient with global objects as it can be used to return globals to their initial state after an eval, removing all declared vars and functions but leaving the (non-enumerable) built-ins.
Hannes
More information about the nashorn-dev
mailing list