mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-05 13:37:47 +02:00
* IDs now generated by wasm
This commit is contained in:
parent
b2fd1f356f
commit
83be8b0e13
@ -87,6 +87,9 @@ Type
|
||||
Protected
|
||||
procedure RegisterGlobalObjects; virtual;
|
||||
procedure SetInstanceExports(const AValue: TWasiExports); override;
|
||||
// IDs
|
||||
function GetObjectID: TJOBObjectID;
|
||||
procedure ReleaseJobID(aID: TJOBObjectID);
|
||||
function DecodeUTF16Buffer(Arr : TJSUint16Array) : String;
|
||||
function DecodeUTF8Buffer(Arr : TJSUint8Array) : String;
|
||||
function Invoke_JSResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP: NativeInt; out JSResult: JSValue): TJOBResult; virtual;
|
||||
@ -101,6 +104,7 @@ Type
|
||||
function Invoke_StringResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
|
||||
function Invoke_ObjectResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
|
||||
function Create_JSObject(NameP, NameLen,ArgsP : NativeInt): TJOBObjectID; virtual;
|
||||
function Create_JSObjectAt(NameP, NameLen,ArgsP : NativeInt; aObjID : TJOBObjectID): Longint; virtual;
|
||||
function Invoke_JSValueResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
|
||||
function Invoke_ArrayStringResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
|
||||
function ReleaseObject(ObjId: TJOBObjectID): TJOBResult; virtual;
|
||||
@ -296,6 +300,7 @@ begin
|
||||
aObject[JOBFn_InvokeJSValueResult]:=@Invoke_JSValueResult;
|
||||
aObject[JOBFn_InvokeArrayStringResult]:=@Invoke_ArrayStringResult;
|
||||
aObject[JOBFn_CreateObject]:=@Create_JSObject;
|
||||
aObject[JOBFn_CreateObjectAt]:=@Create_JSObjectAt;
|
||||
aObject[JOBFn_SetMemFromArray]:=@SetMemFromArray;
|
||||
aObject[JOBFn_SetArrayFromMem]:=@SetArrayFromMem;
|
||||
aObject[JOBFn_DebugObject]:=@DebugObject;
|
||||
@ -645,8 +650,46 @@ begin
|
||||
Result:=TJSFunction(fn);
|
||||
end;
|
||||
|
||||
procedure TJSObjectBridge.ReleaseJobID(aID : TJOBObjectID);
|
||||
|
||||
Type
|
||||
TReleaseObjectIDProc = procedure(aID : TJOBObjectID);
|
||||
|
||||
var
|
||||
lProc : TReleaseObjectIDProc;
|
||||
|
||||
begin
|
||||
lProc:=TReleaseObjectIDProc(InstanceExports.functions['AllocateJobObjectID']);
|
||||
if Not assigned(lProc) then
|
||||
Raise EJOBBridge.Create('No function to release job ID');
|
||||
lProc(aID);
|
||||
end;
|
||||
|
||||
function TJSObjectBridge.GetObjectID : TJOBObjectID;
|
||||
|
||||
Type
|
||||
TAllocateObjectIDFunc = Function : TJOBObjectID;
|
||||
|
||||
var
|
||||
lFunc : TAllocateObjectIDFunc;
|
||||
|
||||
begin
|
||||
lFunc:=TAllocateObjectIDFunc(InstanceExports.functions['AllocateJobObjectID']);
|
||||
if Not assigned(lFunc) then
|
||||
Raise EJOBBridge.Create('No function to allocate job ID');
|
||||
Result:=lFunc();
|
||||
end;
|
||||
|
||||
function TJSObjectBridge.Create_JSObject(NameP, NameLen, ArgsP: NativeInt): TJOBObjectID;
|
||||
|
||||
begin
|
||||
Result:=GetObjectID;
|
||||
if Create_JSObjectAt(NameP,NameLen,ArgsP,Result)<>JOBResult_Success then
|
||||
Result:=0;
|
||||
end;
|
||||
|
||||
function TJSObjectBridge.Create_JSObjectAt(NameP, NameLen, ArgsP: NativeInt; aObjID: TJOBObjectID): Longint;
|
||||
|
||||
var
|
||||
ObjName : String;
|
||||
Args: TJSValueDynArray;
|
||||
@ -672,7 +715,7 @@ begin
|
||||
begin
|
||||
fn:=GetObjectConstructor(ObjName);
|
||||
if not Assigned(fn) then
|
||||
exit(0);
|
||||
exit(JOBResult_None);
|
||||
if ArgsP=0 then
|
||||
JSResult:=NewObj(fn,nil)
|
||||
else
|
||||
@ -682,9 +725,12 @@ begin
|
||||
end;
|
||||
end;
|
||||
if not (jsTypeOf(JSResult)='object') then
|
||||
Result:=0
|
||||
Result:=JOBResult_None
|
||||
else
|
||||
Result:=RegisterLocalObject(TJSObject(JSResult));
|
||||
begin
|
||||
RegisterLocalObjectAt(TJSObject(JSResult),aObjID);
|
||||
Result:=JOBResult_Success;
|
||||
end;
|
||||
{$IFDEF VerboseJOB}
|
||||
writeln('Create_JSObject ObjName="',ObjName,'" result: ',Result);
|
||||
{$ENDIF}
|
||||
|
@ -66,6 +66,7 @@ const
|
||||
JOBFn_ReleaseStringResult = 'release_stringresult';
|
||||
JOBFn_InvokeObjectResult = 'invoke_objectresult';
|
||||
JOBFn_CreateObject = 'create_object';
|
||||
JOBFn_CreateObjectAt = 'create_object_at';
|
||||
JOBFn_ReleaseObject = 'release_object';
|
||||
JOBFn_InvokeJSValueResult = 'invoke_jsvalueresult';
|
||||
JOBFn_CallbackHandler = 'JOBCallback';
|
||||
|
Loading…
Reference in New Issue
Block a user