From 8a441383c3ebcbf4b2051e57c180970564b22cca Mon Sep 17 00:00:00 2001 From: HarlonWang <81813780@qq.com> Date: Tue, 30 Jul 2024 15:29:11 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=A9=BA?= =?UTF-8?q?=E5=88=A4=E6=96=AD=20&=20=E4=BC=98=E5=8C=96=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=80=8F=E5=87=BA=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../whl/quickjs/wrapper/QuickJSContext.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/wrapper-java/src/main/java/com/whl/quickjs/wrapper/QuickJSContext.java b/wrapper-java/src/main/java/com/whl/quickjs/wrapper/QuickJSContext.java index 187a825..cebc8f8 100644 --- a/wrapper-java/src/main/java/com/whl/quickjs/wrapper/QuickJSContext.java +++ b/wrapper-java/src/main/java/com/whl/quickjs/wrapper/QuickJSContext.java @@ -251,6 +251,10 @@ public Object evaluate(String script) { } public Object evaluate(String script, String fileName) { + if (script == null) { + throw new NullPointerException("Script cannot be null with " + fileName); + } + checkSameThread(); checkDestroyed(); return evaluate(context, script, fileName); @@ -503,6 +507,10 @@ public byte[] compile(String source) { } public byte[] compile(String source, String fileName) { + if (source == null) { + throw new NullPointerException("Script cannot be null with " + fileName); + } + checkSameThread(); checkDestroyed(); @@ -514,6 +522,10 @@ public byte[] compileModule(String source) { } public byte[] compileModule(String source, String fileName) { + if (source == null) { + throw new NullPointerException("Script cannot be null with " + fileName); + } + checkSameThread(); checkDestroyed(); @@ -521,6 +533,10 @@ public byte[] compileModule(String source, String fileName) { } public Object execute(byte[] code) { + if (code == null) { + throw new NullPointerException("Bytecode cannot be null"); + } + checkSameThread(); checkDestroyed(); @@ -528,9 +544,12 @@ public Object execute(byte[] code) { } public Object evaluateModule(String script, String moduleName) { + if (script == null) { + throw new NullPointerException("Script cannot be null with " + moduleName); + } + checkSameThread(); checkDestroyed(); - return evaluateModule(context, script, moduleName); } From 04058b153ff158dc52f04328f161d81d555ab36c Mon Sep 17 00:00:00 2001 From: HarlonWang <81813780@qq.com> Date: Thu, 1 Aug 2024 16:03:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../androidTest/java/com/whl/quickjs/wrapper/QuickJSTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrapper-android/src/androidTest/java/com/whl/quickjs/wrapper/QuickJSTest.java b/wrapper-android/src/androidTest/java/com/whl/quickjs/wrapper/QuickJSTest.java index 727804f..72f8176 100644 --- a/wrapper-android/src/androidTest/java/com/whl/quickjs/wrapper/QuickJSTest.java +++ b/wrapper-android/src/androidTest/java/com/whl/quickjs/wrapper/QuickJSTest.java @@ -963,7 +963,7 @@ public void testNullExceptionWithEval() { @Test public void testNullExceptionWithCompile() { thrown.expect(NullPointerException.class); - thrown.expectMessage("Source code cannot be null"); + thrown.expectMessage("Script cannot be null with unknown.js"); QuickJSContext context = createContext(); context.compile(null); From 0b19450beb1a18de56ee3727f56a255756d5a325 Mon Sep 17 00:00:00 2001 From: HarlonWang <81813780@qq.com> Date: Thu, 1 Aug 2024 16:08:49 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E7=BB=9F=E4=B8=80=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../whl/quickjs/wrapper/QuickJSContext.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/wrapper-java/src/main/java/com/whl/quickjs/wrapper/QuickJSContext.java b/wrapper-java/src/main/java/com/whl/quickjs/wrapper/QuickJSContext.java index cebc8f8..059420d 100644 --- a/wrapper-java/src/main/java/com/whl/quickjs/wrapper/QuickJSContext.java +++ b/wrapper-java/src/main/java/com/whl/quickjs/wrapper/QuickJSContext.java @@ -502,34 +502,34 @@ public Object parse(String json) { return parseJSON(context, json); } - public byte[] compile(String source) { - return compile(source, UNKNOWN_FILE); + public byte[] compile(String script) { + return compile(script, UNKNOWN_FILE); } - public byte[] compile(String source, String fileName) { - if (source == null) { + public byte[] compile(String script, String fileName) { + if (script == null) { throw new NullPointerException("Script cannot be null with " + fileName); } checkSameThread(); checkDestroyed(); - return compile(context, source, fileName, false); + return compile(context, script, fileName, false); } - public byte[] compileModule(String source) { - return compileModule(source, UNKNOWN_FILE); + public byte[] compileModule(String script) { + return compileModule(script, UNKNOWN_FILE); } - public byte[] compileModule(String source, String fileName) { - if (source == null) { + public byte[] compileModule(String script, String fileName) { + if (script == null) { throw new NullPointerException("Script cannot be null with " + fileName); } checkSameThread(); checkDestroyed(); - return compile(context, source, fileName, true); + return compile(context, script, fileName, true); } public Object execute(byte[] code) {