fix: rethrow SyntaxException from compilation as EngineException

This commit is contained in:
TopchetoEU 2024-09-04 10:44:44 +03:00
parent 93c246ad97
commit 5359c54694
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4

View File

@ -8,17 +8,22 @@ import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.JavaScript; import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.runtime.debug.DebugContext; import me.topchetoeu.jscript.runtime.debug.DebugContext;
import me.topchetoeu.jscript.runtime.exceptions.EngineException; import me.topchetoeu.jscript.runtime.exceptions.EngineException;
import me.topchetoeu.jscript.runtime.exceptions.SyntaxException;
import me.topchetoeu.jscript.runtime.values.Value; import me.topchetoeu.jscript.runtime.values.Value;
import me.topchetoeu.jscript.runtime.values.functions.CodeFunction; import me.topchetoeu.jscript.runtime.values.functions.CodeFunction;
public interface Compiler { public interface Compiler {
public static final Compiler DEFAULT = (env, filename, raw) -> { public static final Compiler DEFAULT = (env, filename, raw) -> {
var res = JavaScript.compile(env, filename, raw); try {
var body = res.body(); var res = JavaScript.compile(env, filename, raw);
DebugContext.get(env).onSource(filename, raw); var body = res.body();
registerFunc(env, body, res); DebugContext.get(env).onSource(filename, raw);
registerFunc(env, body, res);
return body; return body;
}
catch (SyntaxException e) {
throw EngineException.ofSyntax(e.loc + ": " + e.msg);
}
}; };
public Key<Compiler> KEY = Key.of(); public Key<Compiler> KEY = Key.of();