-
-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add better debugger view support via debugger attributes (#1656)
- Loading branch information
Showing
10 changed files
with
237 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,89 @@ | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using Esprima; | ||
using Jint; | ||
using Jint.Native; | ||
using Jint.Native.Json; | ||
using Jint.Runtime; | ||
|
||
namespace Jint.Repl | ||
var engine = new Engine(cfg => cfg | ||
.AllowClr() | ||
); | ||
|
||
engine | ||
.SetValue("print", new Action<object>(Console.WriteLine)) | ||
.SetValue("load", new Func<string, object>( | ||
path => engine.Evaluate(File.ReadAllText(path))) | ||
); | ||
|
||
var filename = args.Length > 0 ? args[0] : ""; | ||
if (!string.IsNullOrEmpty(filename)) | ||
{ | ||
internal static class Program | ||
if (!File.Exists(filename)) | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
var engine = new Engine(cfg => cfg | ||
.AllowClr() | ||
); | ||
|
||
engine | ||
.SetValue("print", new Action<object>(Console.WriteLine)) | ||
.SetValue("load", new Func<string, object>( | ||
path => engine.Evaluate(File.ReadAllText(path))) | ||
); | ||
Console.WriteLine("Could not find file: {0}", filename); | ||
} | ||
|
||
var filename = args.Length > 0 ? args[0] : ""; | ||
if (!string.IsNullOrEmpty(filename)) | ||
{ | ||
if (!File.Exists(filename)) | ||
{ | ||
Console.WriteLine("Could not find file: {0}", filename); | ||
} | ||
var script = File.ReadAllText(filename); | ||
engine.Evaluate(script, "repl"); | ||
return; | ||
} | ||
|
||
var script = File.ReadAllText(filename); | ||
engine.Evaluate(script, "repl"); | ||
return; | ||
} | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); | ||
var version = fvi.FileVersion; | ||
|
||
var assembly = Assembly.GetExecutingAssembly(); | ||
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); | ||
var version = fvi.FileVersion; | ||
Console.WriteLine("Welcome to Jint ({0})", version); | ||
Console.WriteLine("Type 'exit' to leave, " + | ||
"'print()' to write on the console, " + | ||
"'load()' to load scripts."); | ||
Console.WriteLine(); | ||
|
||
Console.WriteLine("Welcome to Jint ({0})", version); | ||
Console.WriteLine("Type 'exit' to leave, " + | ||
"'print()' to write on the console, " + | ||
"'load()' to load scripts."); | ||
Console.WriteLine(); | ||
var defaultColor = Console.ForegroundColor; | ||
var parserOptions = new ParserOptions | ||
{ | ||
Tolerant = true, | ||
RegExpParseMode = RegExpParseMode.AdaptToInterpreted | ||
}; | ||
|
||
var defaultColor = Console.ForegroundColor; | ||
var parserOptions = new ParserOptions | ||
{ | ||
Tolerant = true, | ||
RegExpParseMode = RegExpParseMode.AdaptToInterpreted | ||
}; | ||
var serializer = new JsonSerializer(engine); | ||
|
||
var serializer = new JsonSerializer(engine); | ||
while (true) | ||
{ | ||
Console.ForegroundColor = defaultColor; | ||
Console.Write("jint> "); | ||
var input = Console.ReadLine(); | ||
if (input is "exit" or ".exit") | ||
{ | ||
return; | ||
} | ||
|
||
while (true) | ||
try | ||
{ | ||
var result = engine.Evaluate(input, parserOptions); | ||
JsValue str = result; | ||
if (!result.IsPrimitive() && result is not IPrimitiveInstance) | ||
{ | ||
str = serializer.Serialize(result, JsValue.Undefined, " "); | ||
if (str == JsValue.Undefined) | ||
{ | ||
Console.ForegroundColor = defaultColor; | ||
Console.Write("jint> "); | ||
var input = Console.ReadLine(); | ||
if (input is "exit" or ".exit") | ||
{ | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
var result = engine.Evaluate(input, parserOptions); | ||
JsValue str = result; | ||
if (!result.IsPrimitive() && result is not IPrimitiveInstance) | ||
{ | ||
str = serializer.Serialize(result, JsValue.Undefined, " "); | ||
if (str == JsValue.Undefined) | ||
{ | ||
str = result; | ||
} | ||
} | ||
else if (result.IsString()) | ||
{ | ||
str = serializer.Serialize(result, JsValue.Undefined, JsValue.Undefined); | ||
} | ||
Console.WriteLine(str); | ||
} | ||
catch (JavaScriptException je) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine(je.ToString()); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine(e.Message); | ||
} | ||
str = result; | ||
} | ||
} | ||
else if (result.IsString()) | ||
{ | ||
str = serializer.Serialize(result, JsValue.Undefined, JsValue.Undefined); | ||
} | ||
Console.WriteLine(str); | ||
} | ||
catch (JavaScriptException je) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine(je.ToString()); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine(e.Message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.