Fix crash when toString returns null value (#8067)

* Fix crash when toString returns null value

* Return a string from NullUnit toString

* Begone redundancy

* Unwrap before null check to ensure non-nullability
This commit is contained in:
buthed010203
2023-01-07 11:28:01 -05:00
committed by GitHub
parent c0b819ec9b
commit a5fd29e56d
2 changed files with 24 additions and 18 deletions

View File

@@ -45,8 +45,10 @@ public class Scripts implements Disposable{
try{
Object o = context.evaluateString(scope, text, "console.js", 1);
if(o instanceof NativeJavaObject n) o = n.unwrap();
if(o instanceof Undefined) o = "undefined";
return String.valueOf(o);
if(o == null) o = "null";
else if(o instanceof Undefined) o = "undefined";
var out = o.toString();
return out == null ? "null" : out;
}catch(Throwable t){
return getError(t, false);
}