in src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java [169:193]
private Map<String, Object> setBoundProperties(Scriptable scope, Bindings bindings) {
Map<String, Object> replacedProperties = new HashMap<String, Object>();
for (Object entryObject : bindings.entrySet()) {
Entry<?, ?> entry = (Entry<?, ?>) entryObject;
String name = (String) entry.getKey();
Object value = entry.getValue();
if (value instanceof LazyBindings.Supplier) {
value = ((LazyBindings.Supplier) value).get();
}
if (value != null) {
// get the current property value, if set
if (ScriptableObject.hasProperty(scope, name)) {
replacedProperties.put(name, ScriptableObject.getProperty(scope, name));
}
// wrap the new value and set it
Object wrapped = ScriptRuntime.toObject(scope, value);
ScriptableObject.putProperty(scope, name, wrapped);
}
}
return replacedProperties;
}