Browse Source

* SetLastIndex

Michael Van Canneyt 11 months ago
parent
commit
9f374e3d23

+ 20 - 1
packages/wasm-utils/src/wasm.pas2js.regexp.pas

@@ -74,6 +74,7 @@ Type
     function RegExpGetFlags(aExprID : TWasmRegExpID; aFlags : PLongint) : TWasmRegexpResult;
     function RegExpGetFlags(aExprID : TWasmRegExpID; aFlags : PLongint) : TWasmRegexpResult;
     function RegExpGetExpression(aExprID : TWasmRegExpID; aExp : PByte; aExpLen : PLongint) : TWasmRegexpResult;
     function RegExpGetExpression(aExprID : TWasmRegExpID; aExp : PByte; aExpLen : PLongint) : TWasmRegexpResult;
     function RegExpGetLastIndex(aExprID : TWasmRegExpID; aLastIndex : PLongint) : TWasmRegexpResult;
     function RegExpGetLastIndex(aExprID : TWasmRegExpID; aLastIndex : PLongint) : TWasmRegexpResult;
+    function RegExpSetLastIndex(aExprID : TWasmRegExpID; aLastIndex : Longint) : TWasmRegexpResult;
     function RegExpGetResultMatch(aExprID : TWasmRegExpID; aIndex : Longint; Res : PByte; ResLen : PLongint) : TWasmRegexpResult;
     function RegExpGetResultMatch(aExprID : TWasmRegExpID; aIndex : Longint; Res : PByte; ResLen : PLongint) : TWasmRegexpResult;
     function RegExpGetGroupCount(aExprID : TWasmRegExpID; aCount: PLongint) : TWasmRegexpResult;
     function RegExpGetGroupCount(aExprID : TWasmRegExpID; aCount: PLongint) : TWasmRegexpResult;
     function RegExpGetGroupName(aExprID : TWasmRegExpID; aIndex : Longint; aName : PByte; aNameLen : PLongint) : TWasmRegexpResult;
     function RegExpGetGroupName(aExprID : TWasmRegExpID; aIndex : Longint; aName : PByte; aNameLen : PLongint) : TWasmRegexpResult;
@@ -419,6 +420,23 @@ begin
   if lRegExp=Nil then
   if lRegExp=Nil then
     Exit(WASMRE_RESULT_INVALIDID);
     Exit(WASMRE_RESULT_INVALIDID);
   Env.SetMemInfoInt32(aLastIndex,lRegexp.RegExp.lastIndex);
   Env.SetMemInfoInt32(aLastIndex,lRegexp.RegExp.lastIndex);
+  Result:=WASMRE_RESULT_SUCCESS;
+end;
+
+function TWasmRegExpAPI.RegExpSetLastIndex(aExprID: TWasmRegExpID; aLastIndex: Longint): TWasmRegexpResult;
+var
+  lRegExp : TWasmRegExp;
+
+begin
+  {$IFNDEF NOLOGAPICALLS}
+  If LogAPICalls then
+    LogCall('RegExp.Deallocate(%d)',[aExprID]);
+  {$ENDIF}
+  lRegExp:=FindRegExp(aExprID);
+  if lRegExp=Nil then
+    Exit(WASMRE_RESULT_INVALIDID);
+  lRegexp.RegExp.lastIndex:=aLastIndex;
+  Result:=WASMRE_RESULT_SUCCESS;
 end;
 end;
 
 
 function TWasmRegExpAPI.RegExpGetResultMatch(aExprID: TWasmRegExpID; aIndex: Longint; Res: PByte; ResLen: PLongint
 function TWasmRegExpAPI.RegExpGetResultMatch(aExprID: TWasmRegExpID; aIndex: Longint; Res: PByte; ResLen: PLongint
@@ -603,7 +621,7 @@ begin
   Result:=FNextID;
   Result:=FNextID;
 end;
 end;
 
 
-function TWasmRegExpAPI.FindRegExp(aID: TWasmRegExpID): TWasmRegexp;
+function TWasmRegExpAPI.FindRegExp(aID: TWasmRegExpID): TWasmRegExp;
 var
 var
   Value : JSValue;
   Value : JSValue;
 
 
@@ -624,6 +642,7 @@ begin
   AObject[regexpFN_GetFlags]:=@RegExpGetFlags;
   AObject[regexpFN_GetFlags]:=@RegExpGetFlags;
   AObject[regexpFN_GetExpression]:=@RegExpGetExpression;
   AObject[regexpFN_GetExpression]:=@RegExpGetExpression;
   AObject[regexpFN_GetLastIndex]:=@RegExpGetLastIndex;
   AObject[regexpFN_GetLastIndex]:=@RegExpGetLastIndex;
+  AObject[regexpFN_SetLastIndex]:=@RegExpSetLastIndex;
   AObject[regexpFN_GetResultMatch]:=@RegExpGetResultMatch;
   AObject[regexpFN_GetResultMatch]:=@RegExpGetResultMatch;
   AObject[regexpFN_GetGroupCount]:=@RegExpGetGroupCount;
   AObject[regexpFN_GetGroupCount]:=@RegExpGetGroupCount;
   AObject[regexpFN_GetGroupName]:=@RegExpGetGroupName;
   AObject[regexpFN_GetGroupName]:=@RegExpGetGroupName;

+ 3 - 1
packages/wasm-utils/src/wasm.regexp.shared.pp

@@ -1,7 +1,7 @@
 {
 {
     This file is part of the Free Component Library
     This file is part of the Free Component Library
 
 
-    Webassembly RegExp API - Shared definitions
+    Webassembly RegExp API - Shared constants & functions
     Copyright (c) 2024 by Michael Van Canneyt [email protected]
     Copyright (c) 2024 by Michael Van Canneyt [email protected]
 
 
     See the file COPYING.FPC, included in this distribution,
     See the file COPYING.FPC, included in this distribution,
@@ -12,6 +12,7 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 
  **********************************************************************}
  **********************************************************************}
+
 unit wasm.regexp.shared;
 unit wasm.regexp.shared;
 
 
 {$mode ObjFPC}{$H+}
 {$mode ObjFPC}{$H+}
@@ -66,6 +67,7 @@ Const
   regexpFN_GetFlags = 'get_flags';
   regexpFN_GetFlags = 'get_flags';
   regexpFN_GetExpression = 'get_expression';
   regexpFN_GetExpression = 'get_expression';
   regexpFN_GetLastIndex = 'get_last_index';
   regexpFN_GetLastIndex = 'get_last_index';
+  regexpFN_SetLastIndex = 'set_last_index';
   regexpFN_GetResultMatch = 'get_result_match';
   regexpFN_GetResultMatch = 'get_result_match';
   regexpFN_GetGroupCount = 'get_group_count';
   regexpFN_GetGroupCount = 'get_group_count';
   regexpFN_GetGroupName = 'get_group_name';
   regexpFN_GetGroupName = 'get_group_name';