You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2019/05/24 12:53:28 UTC

[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #1092: Using Scripting API in platform/core.network

JaroslavTulach commented on a change in pull request #1092: Using Scripting API in platform/core.network
URL: https://github.com/apache/netbeans/pull/1092#discussion_r287345914
 
 

 ##########
 File path: platform/core.network/src/org/netbeans/core/network/proxy/pac/impl/NbPacScriptEvaluator.java
 ##########
 @@ -336,37 +330,59 @@ private PacScriptEngine getScriptEngine(String pacSource) throws PacParsingExcep
 
             // Do some minimal testing of the validity of the PAC Script.
             final PacJsEntryFunction jsMainFunction;
-            if (nashornJava8u40Available) {
-                jsMainFunction = testScriptEngine(engine, true);
-            } else {
-                jsMainFunction = testScriptEngine(engine, false);
-            }
+            jsMainFunction = testScriptEngine(engine, false);
             
             return new PacScriptEngine(engine, jsMainFunction);
         } catch (ScriptException ex) {
             throw new  PacParsingException(ex);
         }
     }
     
-    private boolean getNashornJava8u40Available() {
+    private boolean isNashornFactory(ScriptEngineFactory f) {
         try {
             Class<?> klass = Class.forName("jdk.nashorn.api.scripting.NashornScriptEngineFactory");
+            return klass.isInstance(f);
         } catch (ClassNotFoundException ex) {
             return false;
         }
-        return true;
     }
-    
-    private ScriptEngine getNashornJSScriptEngine() {
-        NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
-        return factory.getScriptEngine(new ClassFilterPacHelpers());
+
+    private ScriptEngine secureEngineEngine(ScriptEngine e) {
+        try {
+            ScriptEngineFactory f = e.getFactory();
+            final Class<? extends ScriptEngineFactory> factoryClass = f.getClass();
+            final ClassLoader factoryClassLoader = factoryClass.getClassLoader();
+            Class<?> filterClass = Class.forName("jdk.nashorn.api.scripting.ClassFilter", true, factoryClassLoader);
+            Method createMethod = factoryClass.getMethod("getScriptEngine", filterClass);
+            Object filter = java.lang.reflect.Proxy.newProxyInstance(factoryClassLoader, new Class[] { filterClass }, (Object proxy, Method method, Object[] args) -> {
+                return false;
+            });
+            return (ScriptEngine) createMethod.invoke(f, filter);
 
 Review comment:
   There is `pac-test-getclass.js` now.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists