You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2019/12/02 11:20:35 UTC

[sling-org-apache-sling-scripting-sightly-js-provider] branch master updated: SLING-8865 - Enhance the HTL runtime and script engine to take advantage of the support for lazy bindings

This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-js-provider.git


The following commit(s) were added to refs/heads/master by this push:
     new bfca509  SLING-8865 - Enhance the HTL runtime and script engine to take advantage of the support for lazy bindings
bfca509 is described below

commit bfca5095b4741713cbcd38100c07691a21b83d7d
Author: Radu Cotescu <17...@users.noreply.github.com>
AuthorDate: Mon Dec 2 12:20:29 2019 +0100

    SLING-8865 - Enhance the HTL runtime and script engine to take advantage of the support for lazy bindings
    
    * switched from SimpleBindings to LazyBindings
---
 pom.xml                                                             | 2 +-
 .../org/apache/sling/scripting/sightly/js/impl/JsEnvironment.java   | 6 +++---
 .../sightly/js/impl/jsapi/ProxyAsyncScriptableFactory.java          | 4 ++--
 .../scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java  | 3 ++-
 4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/pom.xml b/pom.xml
index d5c796d..0747924 100644
--- a/pom.xml
+++ b/pom.xml
@@ -96,7 +96,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.5.0</version>
+            <version>2.21.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsEnvironment.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsEnvironment.java
index 2e88a35..98671f3 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsEnvironment.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsEnvironment.java
@@ -28,11 +28,11 @@ import javax.script.Compilable;
 import javax.script.ScriptContext;
 import javax.script.ScriptEngine;
 import javax.script.ScriptException;
-import javax.script.SimpleBindings;
 import javax.script.SimpleScriptContext;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.scripting.LazyBindings;
 import org.apache.sling.scripting.core.ScriptNameAwareReader;
 import org.apache.sling.scripting.sightly.SightlyException;
 import org.apache.sling.scripting.sightly.js.impl.async.AsyncContainer;
@@ -58,7 +58,7 @@ public class JsEnvironment {
 
     public JsEnvironment(ScriptEngine jsEngine) {
         this.jsEngine = jsEngine;
-        engineBindings = new SimpleBindings();
+        engineBindings = new LazyBindings();
         TimingBindingsValuesProvider.INSTANCE.addBindings(engineBindings);
     }
 
@@ -92,7 +92,7 @@ public class JsEnvironment {
     }
 
     private Bindings buildBindings(Resource scriptResource, Bindings local, Bindings arguments, CommonJsModule commonJsModule) {
-        Bindings bindings = new SimpleBindings();
+        Bindings bindings = new LazyBindings();
         bindings.putAll(engineBindings);
         DependencyResolver dependencyResolver = new DependencyResolver(scriptResource, this, local);
         UseFunction useFunction = new UseFunction(dependencyResolver, arguments);
diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/ProxyAsyncScriptableFactory.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/ProxyAsyncScriptableFactory.java
index 00b1ee5..180dcde 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/ProxyAsyncScriptableFactory.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/ProxyAsyncScriptableFactory.java
@@ -21,10 +21,10 @@ import java.util.Set;
 
 import javax.script.Bindings;
 import javax.script.ScriptEngine;
-import javax.script.SimpleBindings;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.LazyBindings;
 import org.apache.sling.scripting.sightly.js.impl.JsEnvironment;
 import org.apache.sling.scripting.sightly.js.impl.rhino.HybridObject;
 import org.mozilla.javascript.Scriptable;
@@ -47,7 +47,7 @@ public class ProxyAsyncScriptableFactory {
 
     public void registerProxies(ResourceResolver resourceResolver, JsEnvironment environment, Bindings bindings) {
         slyBindingsValuesProvider.initialise(resourceResolver, environment, bindings);
-        Bindings bindingsCopy = new SimpleBindings();
+        Bindings bindingsCopy = new LazyBindings();
         for (String factoryName : slyBindingsValuesProvider.getScriptPaths().keySet()) {
             ShadowScriptableObject shadowScriptableObject = new ShadowScriptableObject(factoryName, bindingsCopy);
             bindings.put(factoryName, shadowScriptableObject);
diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java
index 87905a1..c129202 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java
@@ -34,6 +34,7 @@ import javax.servlet.http.HttpServletRequest;
 import org.apache.commons.io.IOUtils;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.LazyBindings;
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.scripting.sightly.SightlyException;
@@ -203,7 +204,7 @@ public class SlyBindingsValuesProvider {
     }
 
     private Bindings createBindings(Bindings global) {
-        Bindings bindings = new SimpleBindings();
+        Bindings bindings = new LazyBindings();
         bindings.putAll(global);
         TimingBindingsValuesProvider.INSTANCE.addBindings(bindings);
         return bindings;