Browse Source

* Use import object logging

Michael Van Canneyt 7 months ago
parent
commit
22746ebdc3

+ 17 - 6
packages/wasm-utils/src/wasm.pas2js.httpapi.pas

@@ -89,11 +89,12 @@ Type
   TWasmHTTPAPI = class(TImportExtension)
   private
     FNextRequestID : TWasmHTTPRequestID;
-    FLogApiCalls: Boolean;
     FRequests : TJSOBject;
     class function ContentTypeIsString(aType: String): boolean;
+    function GetLogApiCalls: Boolean;
     function ReadRequest(aRequest :PWasmHTTPRequest) : TWasmHTTPRequest;
     function RequestExecute(aRequestID: TWasmHTTPRequestID): TWasmHTTPResult;
+    procedure SetLogApiCalls(AValue: Boolean);
   Protected
     Procedure LogCall(const Msg : String);
     Procedure LogCall(Const Fmt : String; const Args : Array of const);
@@ -113,7 +114,7 @@ Type
     Constructor Create(aEnv: TPas2JSWASIEnvironment); override;
     Procedure FillImportObject(aObject: TJSObject); override;
     Function ImportName : String; override;
-    property LogApiCalls : Boolean Read FLogApiCalls Write FLogApiCalls;
+    property LogApiCalls : Boolean Read GetLogApiCalls Write SetLogApiCalls;
   end;
 
 Function CacheToString(aCache : Integer) : String;
@@ -318,6 +319,11 @@ begin
   end;
 end;
 
+function TWasmHTTPAPI.GetLogApiCalls: Boolean;
+begin
+  Result:=LogAPI;
+end;
+
 function TWasmHTTPAPI.ReadRequest(aRequest: PWasmHTTPRequest): TWasmHTTPRequest;
 
 Var
@@ -416,16 +422,16 @@ end;
 procedure TWasmHTTPAPI.LogCall(const Msg: String);
 begin
   {$IFNDEF NOLOGAPICALLS}
-  If not LogAPICalls then exit;
-  Writeln(Msg);
+  if LogAPI then
+    DoLog(Msg);
   {$ENDIF}
 end;
 
 procedure TWasmHTTPAPI.LogCall(const Fmt: String; const Args: array of const);
 begin
   {$IFNDEF NOLOGAPICALLS}
-  If not LogAPICalls then exit;
-  Writeln(Format(Fmt,Args));
+  if LogAPI then
+    DoLog(Fmt,Args);
   {$ENDIF}
 end;
 
@@ -524,6 +530,11 @@ begin
   Result:=WASMHTTP_RESULT_SUCCESS;
 end;
 
+procedure TWasmHTTPAPI.SetLogApiCalls(AValue: Boolean);
+begin
+  LogAPI:=aValue;
+end;
+
 function TWasmHTTPAPI.RequestDeallocate(aRequestID: TWasmHTTPRequestID): TWasmHTTPResult;
 
 var

+ 12 - 11
packages/wasm-utils/src/wasm.pas2js.regexp.pas

@@ -60,9 +60,9 @@ Type
     FLogAPICalls: Boolean;
     FNextID : TWasmRegexpID;
     FRegExps : TJSObject;
+    function GetLogAPICalls: Boolean;
+    procedure SetLogAPICalls(AValue: Boolean);
   protected
-    procedure DoError(const Msg : String);
-    Procedure DoError(Const Fmt : String; const Args : Array of const);
     Procedure LogCall(const Msg : String);
     Procedure LogCall(Const Fmt : String; const Args : Array of const);
     Function GetNextID : TWasmRegExpID;
@@ -85,7 +85,7 @@ Type
     constructor Create(aEnv: TPas2JSWASIEnvironment); override;
     procedure FillImportObject(aObject: TJSObject); override;
     function ImportName: String; override;
-    Property LogAPICalls : Boolean Read FLogAPICalls Write FLogAPICalls;
+    Property LogAPICalls : Boolean Read GetLogAPICalls Write SetLogAPICalls;
   end;
 
 implementation
@@ -589,29 +589,30 @@ begin
   FRegExps:=TJSObject.new;
 end;
 
-procedure TWasmRegExpAPI.DoError(const Msg: String);
+function TWasmRegExpAPI.GetLogAPICalls: Boolean;
 begin
-  Console.Error(Msg);
+  Result:=LogAPI;
 end;
 
-procedure TWasmRegExpAPI.DoError(const Fmt: String; const Args: array of const);
+procedure TWasmRegExpAPI.SetLogAPICalls(AValue: Boolean);
 begin
-  Console.Error(Format(Fmt,Args));
+  LogAPI:=aValue;
 end;
 
+
 procedure TWasmRegExpAPI.LogCall(const Msg: String);
 begin
   {$IFNDEF NOLOGAPICALLS}
-  If not LogAPICalls then exit;
-  Writeln(Msg);
+  if LogAPI then
+    DoLog(Msg);
   {$ENDIF}
 end;
 
 procedure TWasmRegExpAPI.LogCall(const Fmt: String; const Args: array of const);
 begin
   {$IFNDEF NOLOGAPICALLS}
-  If not LogAPICalls then exit;
-  Writeln(Format(Fmt,Args));
+  if LogAPI then
+    DoLog(Fmt,Args);
   {$ENDIF}
 end;
 

+ 20 - 8
packages/wasm-utils/src/wasm.pas2js.timer.pas

@@ -24,16 +24,17 @@ Type
 
   TWasmTimerAPI = class(TImportExtension)
   private
-    FLogApiCalls: Boolean;
     function AllocateTimer(ainterval: longint; userdata: TWasmPointer): TWasmTimerID;
     procedure DeallocateTimer(timerid: TWasmTimerID);
+    function GetLogApiCalls: Boolean;
+    procedure SetLogApiCalls(AValue: Boolean);
   Protected
     Procedure LogCall(const Msg : String);
     Procedure LogCall(Const Fmt : String; const Args : Array of const);
   Public
     function ImportName: String; override;
     procedure FillImportObject(aObject: TJSObject); override;
-    property LogAPICalls : Boolean Read FLogApiCalls Write FLogApiCalls;
+    property LogAPICalls : Boolean Read GetLogApiCalls Write SetLogApiCalls;
   end;
 
 
@@ -45,16 +46,15 @@ implementation
 procedure TWasmTimerAPI.LogCall(const Msg: String);
 begin
 {$IFNDEF NOLOGAPICALLS}
-  If not LogAPICalls then exit;
-  Writeln('TimerApi.'+Msg);
+  DoLog(Msg);
 {$ENDIF}
 end;
 
 procedure TWasmTimerAPI.LogCall(const Fmt: String; const Args: array of const);
 begin
 {$IFNDEF NOLOGAPICALLS}
-  If not LogAPICalls then exit;
-  Writeln('TimerApi.'+Format(Fmt,Args));
+  if LogAPI then
+    DoLog(Fmt,Args);
 {$ENDIF}
 end;
 
@@ -71,7 +71,7 @@ begin
 end;
 
 
-function TWasmTimerApi.AllocateTimer(ainterval: longint; userdata: TWasmPointer): TWasmTimerID;
+function TWasmTimerAPI.AllocateTimer(ainterval: longint; userdata: TWasmPointer): TWasmTimerID;
 
 var
   aTimerID : TWasmTimerID;
@@ -121,10 +121,12 @@ begin
   {$ENDIF}
 end;
 
-procedure TWasmTimerApi.DeallocateTimer(timerid: TWasmTimerID);
+procedure TWasmTimerAPI.DeallocateTimer(timerid: TWasmTimerID);
 begin
+  {$IFNDEF NOLOGAPICALLS}
   If LogAPICalls then
     LogCall('DeAllocateTimer(%d)',[TimerID]);
+  {$ENDIF}
   {$IFDEF JOB_WORKER}
   self_.clearInterval(TimerID);
   {$else}
@@ -132,6 +134,16 @@ begin
   {$endif}
 end;
 
+function TWasmTimerAPI.GetLogApiCalls: Boolean;
+begin
+  Result:=LogAPI;
+end;
+
+procedure TWasmTimerAPI.SetLogApiCalls(AValue: Boolean);
+begin
+  LogAPI:=aValue;
+end;
+
 
 end.
 

+ 27 - 211
packages/wasm-utils/src/wasm.pas2js.websocketapi.pas

@@ -60,17 +60,16 @@ Type
 
 
   TWasmBaseWebSocketAPI = class(TImportExtension)
+  private
     FNextID : TWasmWebsocketID;
     FSockets : TJSObject;
     FEncoder : TJSTextEncoder;
     FDecoder : TJSTextDecoder;
-  private
-    FLogAPICalls: Boolean;
     function CheckCallbackRes(Res: TWebsocketCallBackResult; const aOperation: string): Boolean;
+    function GetLogAPICalls: Boolean;
     procedure HandleSendMessage(aSocket: TWasmWebSocket; aMessage: TJSUInt8Array; aType: TWasmWebSocketMessageType);
+    procedure SetLogAPICalls(AValue: Boolean);
   Protected
-    procedure DoError(const Msg : String);
-    Procedure DoError(Const Fmt : String; const Args : Array of const);
     Procedure LogCall(const Msg : String);
     Procedure LogCall(Const Fmt : String; const Args : Array of const);
     Function GetNextID : TWasmWebsocketID;
@@ -82,7 +81,7 @@ Type
     Procedure HandleError(aSocket : TWasmWebSocket);
     Procedure HandleBinaryMessage(aSocket : TWasmWebSocket; aMessage : TJSArrayBuffer);
     Procedure HandleStringMessage(aSocket : TWasmWebSocket; aMessage : String);
-    function WebsocketAllocate(aURL : PByte; aUrlLen : Longint; aProtocols : PByte; aProtocolLen : Longint; aUserData : TWasmPointer; aWebsocketID : PWasmWebSocketID) : TWasmWebsocketResult; virtual; abstract;
+    function WebsocketAllocate(aURL : PByte; aUrlLen : Longint; aProtocols : PByte; aProtocolLen : Longint; aUserData : TWasmPointer; aWebsocketID : TWasmWebSocketID) : TWasmWebsocketResult; virtual; abstract;
     function WebsocketDeAllocate(aWebsocketID : TWasmWebSocketID) : TWasmWebsocketResult; virtual; abstract;
     function WebsocketClose(aWebsocketID : TWasmWebSocketID; aCode : Longint; aReason : PByte; aReasonLen : Longint) : TWasmWebsocketResult; virtual; abstract;
     function WebsocketSend(aWebsocketID : TWasmWebSocketID; aData : PByte; aDataLen : Longint; aType : Longint) : TWasmWebsocketResult; virtual; abstract;
@@ -93,7 +92,7 @@ Type
     procedure FillImportObject(aObject: TJSObject); override;
     function AllocateBuffer(aSocket: TWasmWebSocket; aLen: Longint): TWasmPointer;
     function ImportName: String; override;
-    property LogAPICalls : Boolean Read FLogAPICalls Write FLogAPICalls;
+    property LogAPICalls : Boolean Read GetLogAPICalls Write SetLogAPICalls;
   end;
 
   { TWasmWebSocketAPI }
@@ -104,32 +103,12 @@ Type
   private
   Protected
     function CreateWebSocket(aID: Integer; aUserData: TWasmPointer; aUrl, aProtocols: string): TWasmWebSocket;
-    function WebsocketAllocate(aURL : PByte; aUrlLen : Longint; aProtocols : PByte; aProtocolLen : Longint; aUserData : TWasmPointer; aWebsocketID : PWasmWebSocketID) : TWasmWebsocketResult; override;
+    function WebsocketAllocate(aURL : PByte; aUrlLen : Longint; aProtocols : PByte; aProtocolLen : Longint; aUserData : TWasmPointer; aWebsocketID : TWasmWebSocketID) : TWasmWebsocketResult; override;
     function WebsocketDeAllocate(aWebsocketID : TWasmWebSocketID) : TWasmWebsocketResult; override;
     function WebsocketClose(aWebsocketID : TWasmWebSocketID; aCode : Longint; aReason : PByte; aReasonLen : Longint) : TWasmWebsocketResult; override;
     function WebsocketSend(aWebsocketID : TWasmWebSocketID; aData : PByte; aDataLen : Longint; aType : Longint) : TWasmWebsocketResult; override;
   end;
 
-  { TWorkerWebSocketAPI }
-
-  TWorkerWebSocketAPI = class(TWasmBaseWebSocketAPI)
-  private
-    FSharedMem: TJSSharedArrayBuffer;
-    FArray : TJSUint8Array;
-    FView : TJSDataView;
-    procedure SetSharedMem(AValue: TJSSharedArrayBuffer);
-  protected
-    function AwaitResult: TWasmWebsocketResult;
-  Public
-    function LockMem : boolean;
-    procedure UnlockMem;
-    function WebsocketAllocate(aURL : PByte; aUrlLen : Longint; aProtocols : PByte; aProtocolLen : Longint; aUserData : TWasmPointer; aWebsocketID : PWasmWebSocketID) : TWasmWebsocketResult; override;
-    function WebsocketDeAllocate(aWebsocketID : TWasmWebSocketID) : TWasmWebsocketResult; override;
-    function WebsocketClose(aWebsocketID : TWasmWebSocketID; aCode : Longint; aReason : PByte; aReasonLen : Longint) : TWasmWebsocketResult; override;
-    function WebsocketSend(aWebsocketID : TWasmWebSocketID; aData : PByte; aDataLen : Longint; aType : Longint) : TWasmWebsocketResult; override;
-    property SharedMem : TJSSharedArrayBuffer Read FSharedMem Write SetSharedMem;
-  end;
-
 
 
 implementation
@@ -143,8 +122,8 @@ implementation
 procedure TWasmBaseWebSocketAPI.LogCall(const Msg: String);
 begin
   {$IFNDEF NOLOGAPICALLS}
-  If not LogAPICalls then exit;
-  Writeln(Msg);
+  if LogAPI then
+    DoLog('WebSocket: '+Msg);
   {$ENDIF}
 end;
 
@@ -153,8 +132,8 @@ procedure TWasmBaseWebSocketAPI.LogCall(const Fmt: String; const Args: array of
 
 begin
   {$IFNDEF NOLOGAPICALLS}
-  If not LogAPICalls then exit;
-  Writeln(Format(Fmt,Args));
+  If LogAPI then
+    DoLog(Format(Fmt,Args));
   {$ENDIF}
 end;
 
@@ -166,17 +145,6 @@ begin
 end;
 
 
-procedure TWasmBaseWebSocketAPI.DoError(const Msg: String);
-begin
-  Console.Error(Msg);
-end;
-
-
-procedure TWasmBaseWebSocketAPI.DoError(const Fmt: String; const Args: array of const);
-begin
-  Console.Error(Format(Fmt,Args));
-end;
-
 
 function TWasmBaseWebSocketAPI.GetWebsocket(aID: TWasmWebSocketID): TWasmWebSocket;
 
@@ -220,6 +188,11 @@ begin
     DoError('Error during %s call, exit status %d',[aOperation,Res]);
 end;
 
+function TWasmBaseWebSocketAPI.GetLogAPICalls: Boolean;
+begin
+  Result:=LogAPI;
+end;
+
 
 // Callbacks for TWasmWebSocket, calls exported routines from webassembly module.
 
@@ -353,6 +326,11 @@ begin
     end;
 end;
 
+procedure TWasmBaseWebSocketAPI.SetLogAPICalls(AValue: Boolean);
+begin
+  LogAPI:=aValue;
+end;
+
 
 procedure TWasmBaseWebSocketAPI.HandleBinaryMessage(aSocket: TWasmWebSocket; aMessage: TJSArrayBuffer);
 
@@ -383,35 +361,31 @@ begin
 end;
 
 function TWasmWebSocketAPI.WebsocketAllocate(aURL: PByte; aUrlLen: Longint; aProtocols: PByte; aProtocolLen: Longint;
-  aUserData: TWasmPointer; aWebsocketID: PWasmWebSocketID): TWasmWebsocketResult;
+  aUserData: TWasmPointer; aWebsocketID: TWasmWebSocketID): TWasmWebsocketResult;
 
 var
   lURL,lProtocols : String;
   lSocket : TWasmWebSocket;
-  lID : TWasmWebsocketID;
 
 begin
   lURL:=env.GetUTF8StringFromMem(aURL,aUrlLen);
   lProtocols:=env.GetUTF8StringFromMem(aProtocols,aProtocolLen);
   {$IFNDEF NOLOGAPICALLS}
   If LogAPICalls then
-    LogCall('HTTP.WebSocketAllocate("%s","%s",%d,[%x])',[lURL,lProtocols,aUserData,aWebSocketID]);
+    LogCall('HTTP.WebSocketAllocate("%s","%s",%d,%d)',[lURL,lProtocols,aUserData,aWebSocketID]);
   {$ENDIF}
   if (lUrl='') then
     Exit(WASMWS_RESULT_NO_URL);
-  lID:=GetNextID;
-  lSocket:=CreateWebSocket(lID,aUserData,lURL,lProtocols);
+  if Assigned(GetWebsocket(aWebSocketID)) then
+    Exit(WASMWS_RESULT_DUPLICATEID);
+  lSocket:=CreateWebSocket(aWebsocketID,aUserData,lURL,lProtocols);
   if Assigned(lSocket) then
-    begin
-    env.SetMemInfoInt32(aWebSocketID,lID);
-    Result:=WASMWS_RESULT_SUCCESS;
-    end
+    Result:=WASMWS_RESULT_SUCCESS
   else
     Result:=WASMWS_RESULT_ERROR;
-
 {$IFNDEF NOLOGAPICALLS}
   If LogAPICalls then
-    LogCall('HTTP.WebSocketAllocate("%s","%s",%d,[%x]) => %d',[lURL,lProtocols,aUserData,aWebSocketID,lID]);
+    LogCall('HTTP.WebSocketAllocate("%s","%s",%d,%d) => %d',[lURL,lProtocols,aUserData,aWebSocketID,Result]);
 {$ENDIF}
 end;
 
@@ -476,164 +450,6 @@ begin
   Result:=WASMWS_RESULT_SUCCESS;
 end;
 
-{ TWorkerWebSocketAPI }
-
-procedure TWorkerWebSocketAPI.SetSharedMem(AValue: TJSSharedArrayBuffer);
-begin
-  if FSharedMem=AValue then Exit;
-  FSharedMem:=AValue;
-  if Assigned(aValue) then
-    begin
-    FArray:=TJSUint8Array.New(FSharedMem);
-    FView:=TJSDataView.New(FSharedMem);
-    end
-  else
-    begin
-    FArray:=Nil;
-    FView:=Nil;
-    end
-end;
-
-function TWorkerWebSocketAPI.LockMem: boolean;
-
-
-begin
-  // Wait while it is set.
-  Result:=Assigned(FView);
-  if Result then
-    TJSAtomics.wait(FArray,WASM_SHMSG_SEMAPHORE,WASM_SEM_SET);
-  // Now, when here we definitely have value WASM_SEM_NOT_SET
-end;
-
-function TWorkerWebSocketAPI.AwaitResult : TWasmWebsocketResult;
-
-var
-  S : String;
-
-begin
-  if not Assigned(FView) then
-    Result:=WASMWS_RESULT_FAILEDLOCK
-  else
-    begin
-    S:=TJSAtomics.wait(FArray,WASM_SHMSG_SEMAPHORE,WASM_SEM_SET);
-    if s='ok' then
-      Result:=TJSAtomics.load(FArray,WASM_SHMSG_RESULT) // get a result
-    else // no result
-      Result:=WASMWS_RESULT_FAILEDLOCK;
-    end;
-end;
-
-
-procedure TWorkerWebSocketAPI.UnlockMem;
-begin
-  // Set and notify.
-  if not Assigned(FView) then
-    exit;
-  TJSAtomics.store(FArray, WASM_SHMSG_SEMAPHORE, WASM_SEM_SET);
-  TJSAtomics.notify(FArray, WASM_SHMSG_SEMAPHORE, 1);
-end;
-
-function TWorkerWebSocketAPI.WebsocketAllocate(aURL: PByte; aUrlLen: Longint; aProtocols: PByte; aProtocolLen: Longint;
-  aUserData: TWasmPointer; aWebsocketID: PWasmWebSocketID): TWasmWebsocketResult;
-
-
-var
-  lID : TWasmWebsocketID;
-  lTmp : TJSUint8Array;
-  lProtocolOffset : Longint;
-
-begin
-  lID:=GetNextID;
-  if (aURLLen+aProtocolLen)>(FArray.byteLength-WASM_SHMSG_FIXED_LEN) then
-     Exit(WASMWS_RESULT_INVALIDSIZE);
-  if (aURLLen<=0) then
-    Exit(WASMWS_RESULT_INVALIDSIZE);
-  if (aProtocolLen<0) then
-    Exit(WASMWS_RESULT_INVALIDSIZE);
-  if Not LockMem then
-    Exit(WASMWS_RESULT_FAILEDLOCK);
-  try
-    FView.setInt32(WASM_SHMSG_WEBSOCKETID,lID,Env.IsLittleEndian);
-    FView.setInt8(WASM_SHMSG_OPERATION,WASM_WSOPERATION_CREATE);
-    FView.setInt32(WASM_SHMSG_CREATE_USERDATA,aUserData,Env.IsLittleEndian);
-    FView.setInt32(WASM_SHMSG_CREATE_URL_LENGTH,aUrlLen,Env.IsLittleEndian);
-    FView.setInt32(WASM_SHMSG_CREATE_PROTOCOL_LENGTH,aProtocolLen,Env.IsLittleEndian);
-    // Write URL to shared buffer (it may no longer exist when the message is treated)
-    lTmp:=TJSUInt8Array.New(FSharedMem,aURL,aUrlLen);
-    FArray._set(lTmp,WASM_SHMSG_CREATE_URL_DATA);
-    // Write protocols if they are present.
-    if aProtocolLen>0 then
-      begin
-      lTmp:=TJSUInt8Array.New(FSharedMem,aProtocols,aProtocolLen);
-      lProtocolOffset:=WASM_SHMSG_CREATE_PROTOCOL_DATA_OFFSET+aURLLen;
-      FArray._set(lTmp,lProtocolOffset);
-      end;
-    // Result:=AwaitResult;
-  finally
-    UnlockMem;
-  end;
-  getModuleMemoryDataView.setInt32(aWebsocketID,lID);
-  Result:=WASMWS_RESULT_SUCCESS;
-end;
-
-function TWorkerWebSocketAPI.WebsocketDeAllocate(aWebsocketID: TWasmWebSocketID): TWasmWebsocketResult;
-
-begin
-  if Not LockMem then
-    Exit(WASMWS_RESULT_FAILEDLOCK);
-  try
-    FView.setInt32(WASM_SHMSG_WEBSOCKETID,aWebsocketID,Env.IsLittleEndian);
-    FView.setInt8(WASM_SHMSG_OPERATION,WASM_WSOPERATION_FREE);
-    // Result:=AwaitResult;
-  finally
-    UnlockMem;
-  end;
-  Result:=WASMWS_RESULT_SUCCESS;
-end;
-
-function TWorkerWebSocketAPI.WebsocketClose(aWebsocketID: TWasmWebSocketID; aCode: Longint; aReason: PByte; aReasonLen: Longint): TWasmWebsocketResult;
-
-var
-  lTmp : TJSUint8Array;
-
-begin
-  if Not LockMem then
-    Exit(WASMWS_RESULT_FAILEDLOCK);
-  try
-    FView.setInt32(WASM_SHMSG_WEBSOCKETID,aWebsocketID,Env.IsLittleEndian);
-    FView.setInt8(WASM_SHMSG_OPERATION,WASM_WSOPERATION_CLOSE);
-    FView.setInt32(WASM_SHMSG_CLOSE_CODE,aCode,Env.IsLittleEndian);
-    FView.setInt32(WASM_SHMSG_CLOSE_REASON_LENGTH,aReasonLen,Env.IsLittleEndian);
-    if aReasonLen>0 then
-      begin
-      lTmp:=TJSUInt8Array.New(FSharedMem,aReason,aReasonLen);
-      FArray._set(lTmp,WASM_SHMSG_CLOSE_REASON_DATA);
-      end;
-    // Result:=AwaitResult;
-  finally
-    UnlockMem;
-  end;
-  Result:=WASMWS_RESULT_SUCCESS;
-end;
-
-
-function TWorkerWebSocketAPI.WebsocketSend(aWebsocketID: TWasmWebSocketID; aData: PByte; aDataLen: Longint; aType: Longint
-  ): TWasmWebsocketResult;
-
-begin
-  if Not LockMem then
-    Exit(WASMWS_RESULT_FAILEDLOCK);
-  try
-    FView.setInt32(WASM_SHMSG_WEBSOCKETID,aWebsocketID,Env.IsLittleEndian);
-    FView.setInt8(WASM_SHMSG_OPERATION,WASM_WSOPERATION_SEND);
-    FView.setInt32(WASM_SHMSG_SEND_DATA_LENGTH,aDataLen,Env.IsLittleEndian);
-    FView.setInt32(WASM_SHMSG_SEND_DATA_TYPE,aType);
-    FView.setInt32(WASM_SHMSG_SEND_DATA_ADDRESS,aData,Env.IsLittleEndian);
-    // Result:=AwaitResult;
-  finally
-    UnlockMem;
-  end;
-end;
 
 
 constructor TWasmBaseWebSocketAPI.Create(aEnv: TPas2JSWASIEnvironment);

+ 8 - 7
packages/wasm-utils/src/wasm.websocket.shared.pas

@@ -18,13 +18,6 @@ unit wasm.websocket.shared;
 
 interface
 
-uses
-  {$IFDEF FPC_DOTTEDUNITS}
-  System.SysUtils;
-  {$ELSE}
-  sysutils;
-  {$ENDIF}
-
 Type
   TWasmWebsocketResult = longint;
   TWasmWebsocketID = longint;
@@ -47,6 +40,8 @@ Const
   WASMWS_RESULT_INVALIDID   = -3;
   WASMWS_RESULT_FAILEDLOCK  = -4;
   WASMWS_RESULT_INVALIDSIZE = -5;
+  WASMWS_RESULT_NOSHAREDMEM = -6;
+  WASMWS_RESULT_DUPLICATEID = -7;
 
   WASMWS_CALLBACK_SUCCESS   = 0;
   WASMWS_CALLBACK_NOHANDLER = -1;
@@ -125,6 +120,12 @@ const
 
   WASM_SHMSG_FIXED_LEN = WASM_SHMSG_CREATE_URL_DATA+4;
 
+const
+  // These are for workers. Must be lowercase. Command names are lowercased.
+  cmdEnableLog = 'enablelog';
+  cmdDisableLog = 'disablelog';
+  cmdWebsocketSharedMem = 'websocketmem';
+
 implementation
 
 end.