diff --git a/.gitignore b/.gitignore index a9183b5..7ade55d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ .vs obj bin +*.zip +*.nupkg diff --git a/DScript.Demo/testscript.js b/DScript.Demo/testscript.js index 1b05888..af89758 100644 --- a/DScript.Demo/testscript.js +++ b/DScript.Demo/testscript.js @@ -1,6 +1,11 @@ var MyClass = { doSomethingComplicated: function (x, y) { - return Math.pow(--x, ++y) / 10.0; + this.doSomethingElse(x, y); + }, + + doSomethingElse: function (a,b) { + + return Math.pow(--a, ++b) / 10.0; } }; @@ -23,10 +28,12 @@ console.log(p); try { var x = 1; - throw "this broke"; + var obj = { message: "turd", doStuff: function () { } }; + + throw obj; } catch (ex) { - var pns = "Exception message: " + ex; + var pns = "Exception message: " + ex.message; console.log(pns); } diff --git a/DScript/DScript.csproj b/DScript/DScript.csproj index 9f10dc3..75de9ed 100644 --- a/DScript/DScript.csproj +++ b/DScript/DScript.csproj @@ -5,6 +5,8 @@ LICENSE https://github.com/bizzehdee/DScript https://github.com/bizzehdee/DScript + 2.0.0 + Darren Horrocks diff --git a/DScript/JITException.cs b/DScript/JITException.cs index 48675af..bdadcd5 100644 --- a/DScript/JITException.cs +++ b/DScript/JITException.cs @@ -16,5 +16,12 @@ public JITException(string message) : { } + + public JITException(ScriptVar varObj) + { + VarObj = varObj; + } + + public ScriptVar VarObj { get; } } } diff --git a/DScript/ScriptEngine.FunctionCall.cs b/DScript/ScriptEngine.FunctionCall.cs index 51bfa45..d3364a2 100644 --- a/DScript/ScriptEngine.FunctionCall.cs +++ b/DScript/ScriptEngine.FunctionCall.cs @@ -77,6 +77,8 @@ private ScriptVarLink FunctionCall(ref bool execute, ScriptVarLink function, Scr //callStack.PushBack(string.Format("{0} from line {1}", function.Name, currentLexer.LineNumber)); + callStack.Push(function); + if (function.Var.IsNative) { var func = function.Var.GetCallback(); @@ -104,7 +106,7 @@ private ScriptVarLink FunctionCall(ref bool execute, ScriptVarLink function, Scr } } - //callStack.PopBack(); + callStack.Pop(); scopes.PopBack(); var returnVar = new ScriptVarLink(returnVarLink.Var, null); diff --git a/DScript/ScriptEngine.Statement.cs b/DScript/ScriptEngine.Statement.cs index b250d6c..b7c0192 100644 --- a/DScript/ScriptEngine.Statement.cs +++ b/DScript/ScriptEngine.Statement.cs @@ -332,10 +332,9 @@ private void Statement(ref bool execute) var v = catchBlock?.Var?.FirstChild; if(v != null) { - catchScope.AddChild(v.Name, new ScriptVar(ex.Message)); + catchScope.AddChild(v.Name, ex.VarObj); } - var oldLex = currentLexer; var newLex = new ScriptLex(catchBlock.Var.String); currentLexer = newLex; @@ -377,7 +376,7 @@ private void Statement(ref bool execute) { currentLexer.Match(ScriptLex.LexTypes.RThrow); - var message = string.Empty; + ScriptVar message = new ScriptVar(); if (currentLexer.TokenType == (ScriptLex.LexTypes)';') { @@ -387,7 +386,7 @@ private void Statement(ref bool execute) { var res = Base(ref execute); - message = res.Var.String; + message = res.Var; } throw new JITException(message); diff --git a/DScript/ScriptEngine.cs b/DScript/ScriptEngine.cs index e017aba..68ba97d 100644 --- a/DScript/ScriptEngine.cs +++ b/DScript/ScriptEngine.cs @@ -64,7 +64,7 @@ protected virtual void Dispose(bool disposing) private readonly ScriptVar objectClass; private readonly ScriptVar arrayClass; private List scopes; - //private List callStack; + private Stack callStack; private ScriptLex currentLexer; @@ -77,7 +77,7 @@ public ScriptEngine() currentLexer = null; scopes = new List(); - //callStack = new List(); + callStack = new Stack(); Root = (new ScriptVar(null, ScriptVar.Flags.Object)).Ref(); @@ -100,15 +100,16 @@ public void Execute(string code) var oldLex = currentLexer; var oldScopes = scopes; scopes = new List(); - //var oldCallStack = callStack; scopes.Clear(); scopes.PushBack(Root); + var rootLink = new ScriptVarLink(Root, "root"); + + callStack.Push(rootLink); + using (currentLexer = new ScriptLex(code)) { - //callStack.Clear(); - var execute = true; while (currentLexer.TokenType != 0) @@ -132,13 +133,12 @@ public void Execute(string code) throw; } } - - } + callStack.Pop(); + currentLexer = oldLex; scopes = oldScopes; - //callStack = oldCallStack; } public ScriptVarLink EvalComplex(string code)