Browse Source

rtl: added TJSError.Stack and Exception.NodeJSError

mattias 6 years ago
parent
commit
52ade4b10c
2 changed files with 21 additions and 5 deletions
  1. 6 0
      packages/rtl/js.pas
  2. 15 5
      packages/rtl/sysutils.pas

+ 6 - 0
packages/rtl/js.pas

@@ -690,12 +690,18 @@ type
   TJSError = Class external name 'Error'
   private
     FMessage: String; external name 'message';
+    {$ifdef NodeJS}
+    FStack: JSValue; external name 'stack';
+    {$endif}
   Public
     Constructor new;
     Constructor new(Const aMessage : string);
     Constructor new(Const aMessage,aFileName : string);
     Constructor new(Const aMessage,aFileName : string; aLineNumber : NativeInt);
     Property Message : String Read FMessage;
+    {$ifdef NodeJS}
+    Property Stack: JSValue read FStack;
+    {$endif}
   end;
 
 

+ 15 - 5
packages/rtl/sysutils.pas

@@ -58,6 +58,9 @@ type
   private
     fMessage: String;
     fHelpContext: Integer;
+    {$ifdef NodeJS}
+    FNodeJSError: TJSError;
+    {$endif}
   public
     constructor Create(const Msg: String); reintroduce;
     constructor CreateFmt(const Msg: string; const Args: array of jsvalue);
@@ -66,6 +69,9 @@ type
     function ToString: String; override;
     property HelpContext: Integer read fHelpContext write fHelpContext;
     property Message: String read fMessage write fMessage;
+    {$ifdef NodeJS}
+    property NodeJSError: TJSError read FNodeJSError write FNodeJSError;
+    {$endif}
   end;
 
   ExceptClass = class of Exception;
@@ -2034,25 +2040,29 @@ end;
 constructor Exception.Create(const Msg: String);
 begin
   fMessage:=Msg;
+  {$ifdef nodejs}
+  FNodeJSError:=TJSError.new;
+  {$endif}
 end;
 
-constructor Exception.CreateFmt(const Msg: string; const Args: array of JSValue);
+constructor Exception.CreateFmt(const Msg: string; const Args: array of jsvalue
+  );
 begin
   //writeln('Exception.CreateFmt START ',ClassName,' "',Msg,'" Args=',Args);
-  fMessage:=Format(Msg,Args);
+  Create(Format(Msg,Args));
   //writeln('Exception.CreateFmt END ',ClassName,' "',Msg,'" fMessage=',fMessage);
 end;
 
 constructor Exception.CreateHelp(const Msg: String; AHelpContext: Integer);
 begin
-  fMessage:=Msg;
+  Create(Msg);
   fHelpContext:=AHelpContext;
 end;
 
 constructor Exception.CreateFmtHelp(const Msg: string;
-  const Args: array of JSValue; AHelpContext: Integer);
+  const Args: array of jsvalue; AHelpContext: Integer);
 begin
-  fMessage:=Format(Msg,Args);
+  Create(Format(Msg,Args));
   fHelpContext:=AHelpContext;
 end;