Skip to content

Commit

Permalink
Wrapper for external exceptions. Fix for #297
Browse files Browse the repository at this point in the history
  • Loading branch information
nilproject committed Oct 22, 2023
1 parent 1aad724 commit 49b0037
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions NiL.JS/Core/Interop/NativeError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using NiL.JS.BaseLibrary;

namespace NiL.JS.Core.Interop;

public sealed class NativeError : Error
{
public NativeError(string message) : base(message)
{
}

public Exception exception { get; set; }
}
3 changes: 2 additions & 1 deletion NiL.JS/Statements/TryCatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NiL.JS.BaseLibrary;
using NiL.JS.Core;
using NiL.JS.Expressions;
using NiL.JS.Core.Interop;

namespace NiL.JS.Statements
{
Expand Down Expand Up @@ -233,7 +234,7 @@ private void catchHandler(Context context, Exception e)
else
#endif
{
cvar = e is JSException ? (e as JSException).Error.CloneImpl(false) : context.GlobalContext.ProxyValue(e);
cvar = e is JSException ? (e as JSException).Error.CloneImpl(false) : context.GlobalContext.ProxyValue(new NativeError(e.Message) { exception = e });
}

cvar._attributes |= JSValueAttributesInternal.DoNotDelete;
Expand Down

0 comments on commit 49b0037

Please sign in to comment.