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

 ##########
 File path: 
platform/core.network/src/org/netbeans/core/network/proxy/pac/impl/NbPacScriptEvaluator.java
 ##########
 @@ -384,29 +364,14 @@ private PacJsEntryFunction testScriptEngine(ScriptEngine 
eng, boolean doDeepTest
     }
 
     private boolean isJsFunctionAvailable(ScriptEngine eng, String 
functionName, boolean doDeepTest) {
-        // We want to test if the function is there, but without actually 
-        // invoking it.        
-        Object obj = eng.get(functionName);
-        
-        if (!doDeepTest && obj != null) {  
-            // Shallow test. We've established that there's
-            // "something" in the ENGINE_SCOPE with a name like
-            // functionName, and we *hope* it is a function, but we really 
don't
-            // know, therefore we call it a shallow test.
-            return true;
+        try {
+            Object typeofCheck = eng.eval("(function(name) { return typeof 
this[name]; })");
+            Object type = ((Invocable) eng).invokeMethod(typeofCheck, "call", 
null, functionName);
+            return "function".equals(type);
+        } catch (NoSuchMethodException | ScriptException ex) {
+            LOGGER.log(Level.WARNING, null, ex);
+            return false;
         }
-        
-        // For Nashorn post JDK8u40 we can do even deeper validation
-        // using the ScriptObjectMirror class. This will not work for Rhino.
-        if (doDeepTest && obj != null) {
-            if (obj instanceof ScriptObjectMirror) {
-                    ScriptObjectMirror  som = (ScriptObjectMirror) obj;
-                    if (som.isFunction()) {
 
 Review comment:
   `typeof` is more portable check than referencing `ScriptObjectMirror`.

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to