diff --git a/src/me/topchetoeu/jscript/Filename.java b/src/me/topchetoeu/jscript/Filename.java index ff7d17d..8e87ef6 100644 --- a/src/me/topchetoeu/jscript/Filename.java +++ b/src/me/topchetoeu/jscript/Filename.java @@ -46,6 +46,8 @@ public class Filename { public Filename(String protocol, String path) { + path = path.trim(); + protocol = protocol.trim(); this.protocol = protocol; this.path = path; } diff --git a/src/me/topchetoeu/jscript/Location.java b/src/me/topchetoeu/jscript/Location.java index 40b3138..19f0ef2 100644 --- a/src/me/topchetoeu/jscript/Location.java +++ b/src/me/topchetoeu/jscript/Location.java @@ -1,7 +1,7 @@ package me.topchetoeu.jscript; public class Location implements Comparable { - public static final Location INTERNAL = new Location(0, 0, new Filename("jscript", "internal")); + public static final Location INTERNAL = new Location(0, 0, new Filename("jscript", "native")); private int line; private int start; private Filename filename; diff --git a/src/me/topchetoeu/jscript/engine/debug/V8Message.java b/src/me/topchetoeu/jscript/engine/debug/V8Message.java index 82aa121..c585233 100644 --- a/src/me/topchetoeu/jscript/engine/debug/V8Message.java +++ b/src/me/topchetoeu/jscript/engine/debug/V8Message.java @@ -2,7 +2,6 @@ package me.topchetoeu.jscript.engine.debug; import java.util.Map; -import me.topchetoeu.jscript.Filename; import me.topchetoeu.jscript.json.JSON; import me.topchetoeu.jscript.json.JSONElement; import me.topchetoeu.jscript.json.JSONMap; @@ -33,7 +32,7 @@ public class V8Message { this.params = raw.contains("params") ? raw.map("params") : new JSONMap(); } public V8Message(String raw) { - this(JSON.parse(new Filename("jscript", "json-msg"), raw).map()); + this(JSON.parse(null, raw).map()); } public JSONMap toMap() { diff --git a/src/me/topchetoeu/jscript/json/JSON.java b/src/me/topchetoeu/jscript/json/JSON.java index a16538f..897dcc0 100644 --- a/src/me/topchetoeu/jscript/json/JSON.java +++ b/src/me/topchetoeu/jscript/json/JSON.java @@ -177,6 +177,7 @@ public class JSON { return ParseRes.res(values, n); } public static JSONElement parse(Filename filename, String raw) { + if (filename == null) filename = new Filename("jscript", "json"); var res = parseValue(filename, Parsing.tokenize(filename, raw), 0); if (res.isFailed()) throw new SyntaxException(null, "Invalid JSON given."); else if (res.isError()) throw new SyntaxException(null, res.error); @@ -191,6 +192,7 @@ public class JSON { .replace("\\", "\\\\") .replace("\n", "\\n") .replace("\r", "\\r") + .replace("\t", "\\t") .replace("\"", "\\\"") + "\""; if (el.isList()) { diff --git a/src/me/topchetoeu/jscript/lib/JSONLib.java b/src/me/topchetoeu/jscript/lib/JSONLib.java index 8ea57d5..e9aa8ad 100644 --- a/src/me/topchetoeu/jscript/lib/JSONLib.java +++ b/src/me/topchetoeu/jscript/lib/JSONLib.java @@ -1,17 +1,16 @@ package me.topchetoeu.jscript.lib; -import me.topchetoeu.jscript.Filename; import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.exceptions.SyntaxException; import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.json.JSON; -public class JSONLib { +@Native("JSON") public class JSONLib { @Native public static Object parse(Context ctx, String val) { try { - return JSON.toJs(JSON.parse(new Filename("jscript", "json"), val)); + return JSON.toJs(JSON.parse(null, val)); } catch (SyntaxException e) { throw EngineException.ofSyntax(e.msg); } }