I recently came across a question called "Capturing Nashorn's Global Variables" that got me thinking. I'm facing limitations when it comes to capturing the assignment of variables to the global object.
For example, let's say I evaluate the script "a = 10." What if I want to trigger a listener to notify something once 'a' has been added to the scope? Currently, the only option seems to be inspecting the global object after the script is evaluated.
Now, what if I need to intercept an object being assigned to the global scope and replace it with another? If I were using Bindings, I could potentially implement put and redirect it elsewhere:
public Object put(String name, Object value) {
//put a string version of the object in the scope
return delegate.put(name, value+"");
}
This way, if the code 'a=10' gets evaluated, it would store "10" in the scope instead of just 10.
While it's convenient to have a Bindings interface to work with, it can be frustrating that I can't apply a similar implementation to the global object. ScriptObjectMirror is final, so I can't override it or manipulate the subsequent call to the internal ScriptObject. Am I overlooking something here?