|
4 | 4 | using System.Diagnostics;
|
5 | 5 | using System.Diagnostics.CodeAnalysis;
|
6 | 6 | using System.Runtime.CompilerServices;
|
| 7 | +using Microsoft.JavaScript.NodeApi.Runtime; |
7 | 8 | using static Microsoft.JavaScript.NodeApi.Runtime.JSRuntime;
|
| 9 | +using static Microsoft.JavaScript.NodeApi.Runtime.NodejsRuntime; |
8 | 10 |
|
9 | 11 | namespace Microsoft.JavaScript.NodeApi;
|
10 | 12 |
|
@@ -61,28 +63,17 @@ public static T ThrowIfFailed<T>(this napi_status status,
|
61 | 63 | }
|
62 | 64 |
|
63 | 65 | [StackTraceHidden]
|
64 |
| - public static void ThrowIfFailed([DoesNotReturnIf(true)] this node_embedding_status status, |
| 66 | + public static void ThrowIfFailed([DoesNotReturnIf(true)] this NodeEmbeddingStatus status, |
65 | 67 | [CallerMemberName] string memberName = "",
|
66 | 68 | [CallerFilePath] string sourceFilePath = "",
|
67 | 69 | [CallerLineNumber] int sourceLineNumber = 0)
|
68 | 70 | {
|
69 |
| - if (status == node_embedding_status.ok) |
| 71 | + if (status == NodeEmbeddingStatus.OK) |
70 | 72 | return;
|
71 |
| - |
72 |
| - throw new JSException($"Error in {memberName} at {sourceFilePath}:{sourceLineNumber}"); |
73 |
| - } |
74 |
| - |
75 |
| - // Throw if status is not napi_ok. Otherwise, return the provided value. |
76 |
| - // This function helps writing compact wrappers for the interop calls. |
77 |
| - [StackTraceHidden] |
78 |
| - public static T ThrowIfFailed<T>(this node_embedding_status status, |
79 |
| - T value, |
80 |
| - [CallerMemberName] string memberName = "", |
81 |
| - [CallerFilePath] string sourceFilePath = "", |
82 |
| - [CallerLineNumber] int sourceLineNumber = 0) |
83 |
| - { |
84 |
| - status.ThrowIfFailed(memberName, sourceFilePath, sourceLineNumber); |
85 |
| - return value; |
| 73 | + throw new JSException($""" |
| 74 | + Error in {memberName} at {sourceFilePath}:{sourceLineNumber} |
| 75 | + {NodeEmbedding.JSRuntime.EmbeddingGetLastErrorMessage()} |
| 76 | + """); |
86 | 77 | }
|
87 | 78 | }
|
88 | 79 |
|
0 commit comments