mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-07 11:07:47 +02:00
wasmjob: TJOBCallback using helper directly
This commit is contained in:
parent
bd37d75f26
commit
c97286593c
@ -103,18 +103,6 @@ type
|
||||
function AsString: string; override;
|
||||
end;
|
||||
|
||||
TJOBCallback = function(const aMethod: TMethod; Args: PByte): PByte;
|
||||
|
||||
{ TJOB_JSValueMethod }
|
||||
|
||||
TJOB_JSValueMethod = class(TJOB_JSValue)
|
||||
public
|
||||
Value: TMethod;
|
||||
Invoke: TJOBCallback;
|
||||
constructor Create(const aMethod: TMethod; const AnInvoke: TJOBCallback);
|
||||
function AsString: string; override;
|
||||
end;
|
||||
|
||||
TJOBInvokeType = (
|
||||
jiCall, // call function
|
||||
jiGet, // read property
|
||||
@ -127,6 +115,44 @@ type
|
||||
TJSObject = class;
|
||||
TJSObjectClass = class of TJSObject;
|
||||
|
||||
{ TJOBCallbackHelper - parse callback arguments and create result }
|
||||
|
||||
TJOBCallbackHelper = record
|
||||
p: PByte;
|
||||
Index: integer;
|
||||
Count: integer;
|
||||
procedure Init(Args: PByte);
|
||||
function GetType: byte; // see JOBArg* constants, keeps p
|
||||
procedure Skip;
|
||||
function GetBoolean: boolean;
|
||||
function GetDouble: double;
|
||||
function GetString: UnicodeString;
|
||||
function GetObject(aResultClass: TJSObjectClass): TJSObject;
|
||||
function GetValue: TJOB_JSValue;
|
||||
|
||||
function AllocUndefined: PByte;
|
||||
function AllocBool(b: boolean): PByte;
|
||||
function AllocLongint(i: longint): PByte;
|
||||
function AllocDouble(const d: double): PByte;
|
||||
function AllocString(const s: UnicodeString): PByte;
|
||||
function AllocNil: PByte;
|
||||
function AllocIntf(Intf: IJSObject): PByte;
|
||||
function AllocObject(Obj: TJSObject): PByte;
|
||||
function AllocObjId(ObjId: TJOBObjectID): PByte;
|
||||
end;
|
||||
|
||||
TJOBCallback = function(const aMethod: TMethod; var H: TJOBCallbackHelper): PByte;
|
||||
|
||||
{ TJOB_JSValueMethod }
|
||||
|
||||
TJOB_JSValueMethod = class(TJOB_JSValue)
|
||||
public
|
||||
Value: TMethod;
|
||||
Invoke: TJOBCallback;
|
||||
constructor Create(const aMethod: TMethod; const AnInvoke: TJOBCallback);
|
||||
function AsString: string; override;
|
||||
end;
|
||||
|
||||
{ IJSObject }
|
||||
|
||||
IJSObject = interface
|
||||
@ -232,32 +258,6 @@ type
|
||||
function NewJSObject(Const Args: Array of const; aResultClass: TJSObjectClass): TJSObject; virtual;
|
||||
end;
|
||||
|
||||
{ TJOBCallbackHelper - parse callback arguments and create result }
|
||||
|
||||
TJOBCallbackHelper = record
|
||||
p: PByte;
|
||||
Index: integer;
|
||||
Count: integer;
|
||||
procedure Init(Args: PByte);
|
||||
function GetType: byte; // see JOBArg* constants, keeps p
|
||||
procedure Skip;
|
||||
function GetBoolean: boolean;
|
||||
function GetDouble: double;
|
||||
function GetString: UnicodeString;
|
||||
function GetObject(aResultClass: TJSObjectClass): TJSObject;
|
||||
function GetValue: TJOB_JSValue;
|
||||
|
||||
function AllocUndefined: PByte;
|
||||
function AllocBool(b: boolean): PByte;
|
||||
function AllocLongint(i: longint): PByte;
|
||||
function AllocDouble(const d: double): PByte;
|
||||
function AllocString(const s: UnicodeString): PByte;
|
||||
function AllocNil: PByte;
|
||||
function AllocIntf(Intf: IJSObject): PByte;
|
||||
function AllocObject(Obj: TJSObject): PByte;
|
||||
function AllocObjId(ObjId: TJOBObjectID): PByte;
|
||||
end;
|
||||
|
||||
var
|
||||
JSObject: TJSObject;
|
||||
|
||||
@ -380,13 +380,15 @@ function JOBCallback(const Func: TJOBCallback; Data, Code: Pointer; Args: PByte
|
||||
): PByte;
|
||||
var
|
||||
m: TMethod;
|
||||
h: TJOBCallbackHelper;
|
||||
begin
|
||||
Result:=nil;
|
||||
try
|
||||
//writeln('JOBCallback');
|
||||
m.Data:=Data;
|
||||
m.Code:=Code;
|
||||
Result:=Func(m,Args);
|
||||
h.Init(Args);
|
||||
Result:=Func(m,h);
|
||||
finally
|
||||
if Args<>nil then
|
||||
FreeMem(Args);
|
||||
|
@ -146,31 +146,27 @@ var
|
||||
JSDocument: TJSDocument;
|
||||
JSWindow: TJSWindow;
|
||||
|
||||
function JOBCallTJSHTMLClickEventHandler(const aMethod: TMethod; Args: PByte): PByte;
|
||||
function JOBCallTJSEventHandler(const aMethod: TMethod; Args: PByte): PByte;
|
||||
function JOBCallTJSHTMLClickEventHandler(const aMethod: TMethod; var H: TJOBCallbackHelper): PByte;
|
||||
function JOBCallTJSEventHandler(const aMethod: TMethod; var H: TJOBCallbackHelper): PByte;
|
||||
|
||||
implementation
|
||||
|
||||
function JOBCallTJSHTMLClickEventHandler(const aMethod: TMethod; Args: PByte
|
||||
): PByte;
|
||||
function JOBCallTJSHTMLClickEventHandler(const aMethod: TMethod;
|
||||
var H: TJOBCallbackHelper): PByte;
|
||||
var
|
||||
h: TJOBCallbackHelper;
|
||||
Event: IJSMouseEvent;
|
||||
begin
|
||||
h.Init(Args);
|
||||
Event:=h.GetObject(TJSMouseEvent) as IJSMouseEvent;
|
||||
Result:=h.AllocBool(TJSHTMLClickEventHandler(aMethod)(Event));
|
||||
Event:=H.GetObject(TJSMouseEvent) as IJSMouseEvent;
|
||||
Result:=H.AllocBool(TJSHTMLClickEventHandler(aMethod)(Event));
|
||||
end;
|
||||
|
||||
function JOBCallTJSEventHandler(const aMethod: TMethod; Args: PByte
|
||||
): PByte;
|
||||
function JOBCallTJSEventHandler(const aMethod: TMethod;
|
||||
var H: TJOBCallbackHelper): PByte;
|
||||
var
|
||||
h: TJOBCallbackHelper;
|
||||
Event: IJSEventListenerEvent;
|
||||
begin
|
||||
h.Init(Args);
|
||||
Event:=h.GetObject(TJSEventListenerEvent) as IJSEventListenerEvent;
|
||||
Result:=h.AllocBool(TJSEventHandler(aMethod)(Event));
|
||||
Event:=H.GetObject(TJSEventListenerEvent) as IJSEventListenerEvent;
|
||||
Result:=H.AllocBool(TJSEventHandler(aMethod)(Event));
|
||||
end;
|
||||
|
||||
{ TJSEventTarget }
|
||||
|
Loading…
Reference in New Issue
Block a user