From eb371580afb54e5ebb97c7b9ca2dd7ee4aee64a3 Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Fri, 3 Dec 2021 15:30:12 +0800 Subject: [PATCH] fix: fix bugs in event mechanism --- src/main/java/org/bdware/sc/engine/DesktopEngine.java | 8 ++++---- src/main/java/org/bdware/sc/engine/JSONTool.java | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/bdware/sc/engine/DesktopEngine.java b/src/main/java/org/bdware/sc/engine/DesktopEngine.java index ab9d859..bd09e2a 100644 --- a/src/main/java/org/bdware/sc/engine/DesktopEngine.java +++ b/src/main/java/org/bdware/sc/engine/DesktopEngine.java @@ -459,11 +459,11 @@ public class DesktopEngine extends JSEngine { this.redirectTracePS(ppc); } Invocable cal = engine; - if (fun.isExport() + if (fun.isExport() || // if the function has been registered as event handler - || (fun.isHandler() - && (input.getRequester().length() == 40 - || input.getRequester().equals("event")))) { + (fun.isHandler() && + null != input.getRequester() && + input.getRequester().startsWith("event"))) { Object ret = null; // long start = System.currentTimeMillis(); diff --git a/src/main/java/org/bdware/sc/engine/JSONTool.java b/src/main/java/org/bdware/sc/engine/JSONTool.java index 50f67b1..7380af0 100644 --- a/src/main/java/org/bdware/sc/engine/JSONTool.java +++ b/src/main/java/org/bdware/sc/engine/JSONTool.java @@ -10,8 +10,7 @@ import java.util.Set; public class JSONTool { public static JsonElement convertMirrorToJson(Object ret2) { - JsonElement jsonElement = convertMirrorToJsonInternal(ret2, new HashSet<>()); - return jsonElement; + return convertMirrorToJsonInternal(ret2, new HashSet<>()); } public static Object convertJsonElementToMirror(JsonElement jsonElement) { @@ -57,7 +56,7 @@ public class JSONTool { for (String str : som.getOwnKeys(true)) { try { if (Integer.parseInt(str) >= 0) - jarray.add(convertMirrorToJsonInternal(som.getMember(str),recorded)); + jarray.add(convertMirrorToJsonInternal(som.getMember(str), recorded)); } catch (Exception e) { // System.out.println("[JSONTool] ignore key:"+str); } @@ -66,7 +65,7 @@ public class JSONTool { } else { JsonObject jo = new JsonObject(); for (String str : som.getOwnKeys(true)) { - jo.add(str, convertMirrorToJsonInternal(som.getMember(str),recorded)); + jo.add(str, convertMirrorToJsonInternal(som.getMember(str), recorded)); } return jo; } @@ -83,7 +82,7 @@ public class JSONTool { for (String str : som.getOwnKeys(true)) { try { if (Integer.parseInt(str) >= 0) - jarray.add(convertMirrorToJsonInternal(som.getMember(str),recorded)); + jarray.add(convertMirrorToJsonInternal(som.getMember(str), recorded)); } catch (Exception e) { // System.out.println("[JSONTool] ignore key:"+str); } @@ -92,7 +91,7 @@ public class JSONTool { } else { JsonObject jo = new JsonObject(); for (String str : som.getOwnKeys(true)) { - jo.add(str, convertMirrorToJsonInternal(som.getMember(str),recorded)); + jo.add(str, convertMirrorToJsonInternal(som.getMember(str), recorded)); } return jo; }