File: 0001-Always-use-internal-JavaScript-engine.patch

package info (click to toggle)
eprosima-idl-parser 4.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 972 kB
  • sloc: java: 8,700; sh: 122; xml: 88; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 2,408 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
Date: Fri, 19 Apr 2024 13:04:59 +0200
Subject: Always use internal JavaScript engine

As long as the Nashorn engine is not packaged for Debian, this package
will only work with OpenJDK < 14.

Forwarded: not-needed
---
 .../java/com/eprosima/idl/context/Context.java     | 29 +++++++++++++++-------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/eprosima/idl/context/Context.java b/src/main/java/com/eprosima/idl/context/Context.java
index 1cb2808..39c575b 100644
--- a/src/main/java/com/eprosima/idl/context/Context.java
+++ b/src/main/java/com/eprosima/idl/context/Context.java
@@ -1439,15 +1439,7 @@ public class Context
 
     public static ScriptEngine getJSScriptEngine()
     {
-        if (Double.parseDouble(System.getProperty("java.specification.version")) < 11)
-        {
-            return new ScriptEngineManager().getEngineByName("js");
-        }
-        else
-        {
-            return new org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory()
-                           .getScriptEngine();
-        }
+        return new ScriptEngineManager().getEngineByName("js");
     }
 
     public String evaluate_literal(
@@ -1490,6 +1482,25 @@ public class Context
         try
         {
             ScriptEngine engine = getJSScriptEngine();
+            if (engine == null)
+            {
+                // Fallback for simple expressions
+                for (Definition definition : m_definitions)
+                {
+                    if (definition.isIsConstDeclaration())
+                    {
+                        ConstDeclaration const_decl = (ConstDeclaration)definition;
+                        if (const_decl.getTypeCode().isPrimitive() || const_decl.getTypeCode().isIsStringType() || const_decl.getTypeCode().isIsWStringType())
+                        {
+                            if (str == const_decl.getScopedname())
+                                return const_decl.getValue();
+                            if (const_decl.getScope() == getScope() && str == const_decl.getName())
+                                return const_decl.getValue();
+                        }
+                    }
+                }
+                return str;
+            }
             aux_str = engine.eval(aux_str).toString();
         }
         catch (ScriptException se)