Browse Source

rtl: changed JSArguments from array to TJSFunctionArguments

mattias 6 years ago
parent
commit
84e7aa5e90
2 changed files with 31 additions and 12 deletions
  1. 10 1
      packages/rtl/js.pas
  2. 21 11
      packages/rtl/system.pas

+ 10 - 1
packages/rtl/js.pas

@@ -728,10 +728,19 @@ type
     function _finally(value : TJSPromiseFinallyHandler): TJSPromise;
   end;
 
+  TJSFunctionArguments = class external name 'arguments'
+  private
+    FLength: NativeInt; external name 'length';
+    function GetElements(Index: NativeInt): JSValue; external name '[]';
+    procedure SetElements(Index: NativeInt; const AValue: JSValue); external name '[]';
+  public
+    property Length: NativeInt read FLength;
+    property Elements[Index: NativeInt]: JSValue read GetElements write SetElements; default;
+  end;
 
 var
   // This can be used in procedures/functions to provide access to the 'arguments' array.
-  JSArguments: TJSValueDynArray; external name 'arguments';
+  JSArguments: TJSFunctionArguments; external name 'arguments';
   // This can be used in all code to access the javascript 'this' object.
   JSThis: TJSObject; external name 'this';
   // This can be used in catch blocks to access the JS throw value

+ 21 - 11
packages/rtl/system.pas

@@ -291,12 +291,12 @@ procedure val(const S: String; out b : boolean; out Code: Integer); overload;
 function StringOfChar(c: Char; l: NativeInt): String;
 function Lo(i: word): byte; overload;
 function Lo(i: smallint): byte; overload;
-function Lo(i: longint): byte; overload;
-function Lo(i: longword): byte; overload;
+function Lo(i: longword): word; overload;
+function Lo(i: longint): word; overload;
 function Hi(i: word): byte; overload;
 function Hi(i: smallint): byte; overload;
-function Hi(i: longword): byte; overload;
-function Hi(i: longint): byte; overload;
+function Hi(i: longword): word; overload;
+function Hi(i: longint): word; overload;
 
 {*****************************************************************************
                           Other functions
@@ -439,9 +439,19 @@ begin
     Target:=copy(t,1,Index-1)+Insertion+copy(t,Index,length(t));
 end;
 
+type
+  TJSArguments = class external name 'arguments'
+  private
+    FLength: NativeInt; external name 'length';
+    function GetElements(Index: NativeInt): JSValue; external name '[]';
+    procedure SetElements(Index: NativeInt; const AValue: JSValue); external name '[]';
+  public
+    property Length: NativeInt read FLength;
+    property Elements[Index: NativeInt]: JSValue read GetElements write SetElements; default;
+  end;
 var
   WriteBuf: String;
-  JSArguments: array of JSValue; external name 'arguments';
+  JSArguments: TJSArguments; external name 'arguments';
   WriteCallBack : TConsoleHandler;
 
 Function SetWriteCallBack(H : TConsoleHandler) : TConsoleHandler;
@@ -455,7 +465,7 @@ procedure Write;
 var
   i: Integer;
 begin
-  for i:=0 to length(JSArguments)-1 do
+  for i:=0 to JSArguments.Length-1 do
     if Assigned(WriteCallBack) then
       WriteCallBack(JSArguments[i],False)
     else
@@ -469,7 +479,7 @@ var
   s: String;
 
 begin
-  L:=length(JSArguments)-1;
+  L:=JSArguments.Length-1;
   if Assigned(WriteCallBack) then
     begin
     for i:=0 to L do
@@ -626,12 +636,12 @@ begin
   Result:=i and $ff;
 end;
 
-function Lo(i: longint): byte;
+function Lo(i: longword): word;
 begin
   Result:=i and $ffff;
 end;
 
-function Lo(i: longword): byte;
+function Lo(i: longint): word;
 begin
   Result:=i and $ffff;
 end;
@@ -646,12 +656,12 @@ begin
   Result:=(i shr 8) and $ff;
 end;
 
-function Hi(i: longword): byte;
+function Hi(i: longword): word;
 begin
   Result:=(i shr 16) and $ffff;
 end;
 
-function Hi(i: longint): byte;
+function Hi(i: longint): word;
 begin
   Result:=(i shr 16) and $ffff;
 end;