mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-18 16:49:05 +02:00
wasmjob: added class functions cast
This commit is contained in:
parent
0be56c255f
commit
0303bf9da9
@ -39,6 +39,7 @@ Type
|
|||||||
function Invoke_StringResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
|
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 Invoke_ObjectResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
|
||||||
function Invoke_JSValueResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; 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;
|
function ReleaseObject(ObjId: TJOBObjectID): TJOBResult; virtual;
|
||||||
function GetStringResult(ResultP: NativeInt): TJOBResult; virtual;
|
function GetStringResult(ResultP: NativeInt): TJOBResult; virtual;
|
||||||
function ReleaseStringResult: TJOBResult; virtual;
|
function ReleaseStringResult: TJOBResult; virtual;
|
||||||
@ -143,6 +144,7 @@ begin
|
|||||||
aObject[JOBFn_InvokeObjectResult]:=@Invoke_ObjectResult;
|
aObject[JOBFn_InvokeObjectResult]:=@Invoke_ObjectResult;
|
||||||
aObject[JOBFn_ReleaseObject]:=@ReleaseObject;
|
aObject[JOBFn_ReleaseObject]:=@ReleaseObject;
|
||||||
aObject[JOBFn_InvokeJSValueResult]:=@Invoke_JSValueResult;
|
aObject[JOBFn_InvokeJSValueResult]:=@Invoke_JSValueResult;
|
||||||
|
aObject[JOBFn_InvokeArrayStringResult]:=@Invoke_ArrayStringResult;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObjectBridge.FindObject(ObjId: TJOBObjectID): TJSObject;
|
function TJSObjectBridge.FindObject(ObjId: TJOBObjectID): TJSObject;
|
||||||
@ -406,6 +408,22 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TJSObjectBridge.Invoke_ArrayStringResult(ObjId: TJOBObjectID; NameP,
|
||||||
|
NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult;
|
||||||
|
var
|
||||||
|
JSResult: JSValue;
|
||||||
|
begin
|
||||||
|
// invoke
|
||||||
|
Result:=Invoke_JSResult(ObjId,NameP,NameLen,Invoke,ArgsP,JSResult);
|
||||||
|
if Result<>JOBResult_Success then
|
||||||
|
exit;
|
||||||
|
raise EJOBBridge.Create('TJSObjectBridge.Invoke_ArrayStringResult not yet implemented');
|
||||||
|
// check result type
|
||||||
|
//exit(GetJOBResult(JSResult));
|
||||||
|
Result:=JOBResult_String;
|
||||||
|
if ResultP=0 then ;
|
||||||
|
end;
|
||||||
|
|
||||||
function TJSObjectBridge.ReleaseObject(ObjId: TJOBObjectID): TJOBResult;
|
function TJSObjectBridge.ReleaseObject(ObjId: TJOBObjectID): TJOBResult;
|
||||||
begin
|
begin
|
||||||
{$IFDEF VerboseJOB}
|
{$IFDEF VerboseJOB}
|
||||||
@ -710,7 +728,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObjectBridge.EatCallbackResult(View: TJSDataView;
|
function TJSObjectBridge.EatCallbackResult(View: TJSDataView;
|
||||||
ResultP: TWasmNativeInt): JSValue;
|
ResultP: TWasmNativeInt): jsvalue;
|
||||||
var
|
var
|
||||||
p: TWasmNativeInt;
|
p: TWasmNativeInt;
|
||||||
aType: Byte;
|
aType: Byte;
|
||||||
|
@ -13,6 +13,9 @@ type
|
|||||||
|
|
||||||
IJSDate = interface(IJSObject)
|
IJSDate = interface(IJSObject)
|
||||||
['{F12818EA-542E-488C-A3C5-279E05639E9E}']
|
['{F12818EA-542E-488C-A3C5-279E05639E9E}']
|
||||||
|
function Create(aYear: NativeInt; aMonth: NativeInt; aDayOfMonth: NativeInt = 1;
|
||||||
|
TheHours: NativeInt = 0; TheMinutes: NativeInt = 0; TheSeconds: NativeInt = 0;
|
||||||
|
TheMilliseconds: NativeInt = 0): IJSDate;
|
||||||
function toLocaleDateString: UnicodeString; overload; // date in locale timezone, no time
|
function toLocaleDateString: UnicodeString; overload; // date in locale timezone, no time
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -20,7 +23,8 @@ type
|
|||||||
|
|
||||||
TJSDate = class(TJSObject,IJSDate)
|
TJSDate = class(TJSObject,IJSDate)
|
||||||
public
|
public
|
||||||
class function Create(aYear: NativeInt; aMonth: NativeInt; aDayOfMonth: NativeInt = 1;
|
class function Cast(Intf: IJSObject): IJSDate; overload;
|
||||||
|
function Create(aYear: NativeInt; aMonth: NativeInt; aDayOfMonth: NativeInt = 1;
|
||||||
TheHours: NativeInt = 0; TheMinutes: NativeInt = 0; TheSeconds: NativeInt = 0;
|
TheHours: NativeInt = 0; TheMinutes: NativeInt = 0; TheSeconds: NativeInt = 0;
|
||||||
TheMilliseconds: NativeInt = 0): IJSDate;
|
TheMilliseconds: NativeInt = 0): IJSDate;
|
||||||
function toLocaleDateString: UnicodeString; overload; // date in locale timezone, no time
|
function toLocaleDateString: UnicodeString; overload; // date in locale timezone, no time
|
||||||
@ -33,7 +37,12 @@ implementation
|
|||||||
|
|
||||||
{ TJSDate }
|
{ TJSDate }
|
||||||
|
|
||||||
class function TJSDate.Create(aYear: NativeInt; aMonth: NativeInt;
|
class function TJSDate.Cast(Intf: IJSObject): IJSDate;
|
||||||
|
begin
|
||||||
|
Result:=TJSDate.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TJSDate.Create(aYear: NativeInt; aMonth: NativeInt;
|
||||||
aDayOfMonth: NativeInt; TheHours: NativeInt; TheMinutes: NativeInt;
|
aDayOfMonth: NativeInt; TheHours: NativeInt; TheMinutes: NativeInt;
|
||||||
TheSeconds: NativeInt; TheMilliseconds: NativeInt): IJSDate;
|
TheSeconds: NativeInt; TheMilliseconds: NativeInt): IJSDate;
|
||||||
begin
|
begin
|
||||||
@ -46,7 +55,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
JSDate:=TJSDate.CreateFromID(JOBObjIdDate);
|
JSDate:=TJSDate.JOBCreateFromID(JOBObjIdDate);
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -257,8 +257,8 @@ type
|
|||||||
|
|
||||||
TJSObject = class(TInterfacedObject,IJSObject)
|
TJSObject = class(TInterfacedObject,IJSObject)
|
||||||
private
|
private
|
||||||
FObjectID: TJOBObjectID;
|
FJOBObjectID: TJOBObjectID;
|
||||||
FCastSrc: IJSObject;
|
FJOBCastSrc: IJSObject;
|
||||||
protected
|
protected
|
||||||
type
|
type
|
||||||
TJOBInvokeNoResultFunc = function(
|
TJOBInvokeNoResultFunc = function(
|
||||||
@ -291,11 +291,12 @@ type
|
|||||||
procedure InvokeJS_RaiseResultMismatchStr(const aName: string; const Expected, Actual: string); virtual;
|
procedure InvokeJS_RaiseResultMismatchStr(const aName: string; const Expected, Actual: string); virtual;
|
||||||
function CreateInvokeJSArgs(const Args: array of const): PByte; virtual;
|
function CreateInvokeJSArgs(const Args: array of const): PByte; virtual;
|
||||||
public
|
public
|
||||||
constructor Cast(Intf: IJSObject);
|
constructor JOBCast(Intf: IJSObject); overload;
|
||||||
constructor CreateFromID(aID: TJOBObjectID); virtual; // use this only for the owner (it will release it on free)
|
constructor JOBCreateFromID(aID: TJOBObjectID); virtual; // use this only for the owner (it will release it on free)
|
||||||
|
class function Cast(Intf: IJSObject): IJSObject; overload;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
property ObjectID: TJOBObjectID read FObjectID;
|
property JOBObjectID: TJOBObjectID read FJOBObjectID;
|
||||||
property CastSrc: IJSObject read FCastSrc; // nil means it is the owner, otherwise it is a typecast
|
property JOBCastSrc: IJSObject read FJOBCastSrc; // nil means it is the owner, otherwise it is a typecast
|
||||||
// call a function
|
// call a function
|
||||||
procedure InvokeJSNoResult(const aName: string; Const Args: Array of const; Invoke: TJOBInvokeType = jiCall); virtual;
|
procedure InvokeJSNoResult(const aName: string; Const Args: Array of const; Invoke: TJOBInvokeType = jiCall); virtual;
|
||||||
function InvokeJSBooleanResult(const aName: string; Const Args: Array of const; Invoke: TJOBInvokeType = jiCall): Boolean; virtual;
|
function InvokeJSBooleanResult(const aName: string; Const Args: Array of const; Invoke: TJOBInvokeType = jiCall): Boolean; virtual;
|
||||||
@ -693,7 +694,7 @@ begin
|
|||||||
inc(p);
|
inc(p);
|
||||||
ObjId:=PLongWord(p)^;
|
ObjId:=PLongWord(p)^;
|
||||||
inc(p,4);
|
inc(p,4);
|
||||||
Result:=aResultClass.CreateFromID(ObjId);
|
Result:=aResultClass.JOBCreateFromID(ObjId);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise EJSArgParse.Create(JOBArgNames[p^]);
|
raise EJSArgParse.Create(JOBArgNames[p^]);
|
||||||
@ -754,7 +755,7 @@ begin
|
|||||||
inc(p);
|
inc(p);
|
||||||
ObjId:=PLongWord(p)^;
|
ObjId:=PLongWord(p)^;
|
||||||
inc(p,4);
|
inc(p,4);
|
||||||
Obj:=TJSObject.CreateFromID(ObjId);
|
Obj:=TJSObject.JOBCreateFromID(ObjId);
|
||||||
Result:=TJOB_Object.Create(Obj);
|
Result:=TJOB_Object.Create(Obj);
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
@ -845,7 +846,7 @@ begin
|
|||||||
if Obj=nil then
|
if Obj=nil then
|
||||||
Result:=AllocNil
|
Result:=AllocNil
|
||||||
else
|
else
|
||||||
Result:=AllocObjId(Obj.ObjectID);
|
Result:=AllocObjId(Obj.JOBObjectID);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJOBCallbackHelper.AllocObjId(ObjId: TJOBObjectID): PByte;
|
function TJOBCallbackHelper.AllocObjId(ObjId: TJOBObjectID): PByte;
|
||||||
@ -1059,12 +1060,12 @@ end;
|
|||||||
|
|
||||||
function TJSObject.GetJSObjectID: TJOBObjectID;
|
function TJSObject.GetJSObjectID: TJOBObjectID;
|
||||||
begin
|
begin
|
||||||
Result:=FObjectID;
|
Result:=FJOBObjectID;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.GetJSObjectCastSrc: IJSObject;
|
function TJSObject.GetJSObjectCastSrc: IJSObject;
|
||||||
begin
|
begin
|
||||||
Result:=FCastSrc;
|
Result:=FJOBCastSrc;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.GetPascalClassName: string;
|
function TJSObject.GetPascalClassName: string;
|
||||||
@ -1107,11 +1108,11 @@ var
|
|||||||
InvokeArgs: PByte;
|
InvokeArgs: PByte;
|
||||||
begin
|
begin
|
||||||
if length(Args)=0 then
|
if length(Args)=0 then
|
||||||
Result:=InvokeFunc(ObjectID,PChar(aName),length(aName),InvokeGetToInt[Invoke],nil)
|
Result:=InvokeFunc(JOBObjectID,PChar(aName),length(aName),InvokeGetToInt[Invoke],nil)
|
||||||
else begin
|
else begin
|
||||||
InvokeArgs:=CreateInvokeJSArgs(Args);
|
InvokeArgs:=CreateInvokeJSArgs(Args);
|
||||||
try
|
try
|
||||||
Result:=InvokeFunc(ObjectID,PChar(aName),length(aName),InvokeGetToInt[Invoke],InvokeArgs);
|
Result:=InvokeFunc(JOBObjectID,PChar(aName),length(aName),InvokeGetToInt[Invoke],InvokeArgs);
|
||||||
finally
|
finally
|
||||||
if InvokeArgs<>nil then
|
if InvokeArgs<>nil then
|
||||||
FreeMem(InvokeArgs);
|
FreeMem(InvokeArgs);
|
||||||
@ -1126,11 +1127,11 @@ var
|
|||||||
InvokeArgs: PByte;
|
InvokeArgs: PByte;
|
||||||
begin
|
begin
|
||||||
if length(Args)=0 then
|
if length(Args)=0 then
|
||||||
Result:=InvokeFunc(ObjectID,PChar(aName),length(aName),InvokeGetToInt[Invoke],nil,ResultP)
|
Result:=InvokeFunc(JOBObjectID,PChar(aName),length(aName),InvokeGetToInt[Invoke],nil,ResultP)
|
||||||
else begin
|
else begin
|
||||||
InvokeArgs:=CreateInvokeJSArgs(Args);
|
InvokeArgs:=CreateInvokeJSArgs(Args);
|
||||||
try
|
try
|
||||||
Result:=InvokeFunc(ObjectID,PChar(aName),length(aName),InvokeGetToInt[Invoke],InvokeArgs,ResultP);
|
Result:=InvokeFunc(JOBObjectID,PChar(aName),length(aName),InvokeGetToInt[Invoke],InvokeArgs,ResultP);
|
||||||
finally
|
finally
|
||||||
if InvokeArgs<>nil then
|
if InvokeArgs<>nil then
|
||||||
FreeMem(InvokeArgs);
|
FreeMem(InvokeArgs);
|
||||||
@ -1143,7 +1144,7 @@ var
|
|||||||
E: EJSInvoke;
|
E: EJSInvoke;
|
||||||
begin
|
begin
|
||||||
E:=EJSInvoke.Create(Msg);
|
E:=EJSInvoke.Create(Msg);
|
||||||
E.ObjectID:=ObjectID;
|
E.ObjectID:=JOBObjectID;
|
||||||
E.FuncName:=aName;
|
E.FuncName:=aName;
|
||||||
raise E;
|
raise E;
|
||||||
end;
|
end;
|
||||||
@ -1152,8 +1153,8 @@ procedure TJSObject.InvokeJS_RaiseResultMismatch(const aName: string;
|
|||||||
Expected, Actual: TJOBResult);
|
Expected, Actual: TJOBResult);
|
||||||
begin
|
begin
|
||||||
case Actual of
|
case Actual of
|
||||||
JOBResult_UnknownObjId: InvokeJS_Raise(aName,'unknown object id '+IntToStr(ObjectID));
|
JOBResult_UnknownObjId: InvokeJS_Raise(aName,'unknown object id '+IntToStr(JOBObjectID));
|
||||||
JOBResult_NotAFunction: InvokeJS_Raise(aName,'object '+IntToStr(ObjectID)+' does not have a function "'+aName+'"');
|
JOBResult_NotAFunction: InvokeJS_Raise(aName,'object '+IntToStr(JOBObjectID)+' does not have a function "'+aName+'"');
|
||||||
else
|
else
|
||||||
InvokeJS_RaiseResultMismatchStr(aName,JOBResult_Names[Expected],JOBResult_Names[Actual]);
|
InvokeJS_RaiseResultMismatchStr(aName,JOBResult_Names[Expected],JOBResult_Names[Actual]);
|
||||||
end;
|
end;
|
||||||
@ -1162,7 +1163,7 @@ end;
|
|||||||
procedure TJSObject.InvokeJS_RaiseResultMismatchStr(const aName: string;
|
procedure TJSObject.InvokeJS_RaiseResultMismatchStr(const aName: string;
|
||||||
const Expected, Actual: string);
|
const Expected, Actual: string);
|
||||||
begin
|
begin
|
||||||
InvokeJS_Raise(aName,'expected '+Expected+', but got '+Actual+' from object '+IntToStr(ObjectID)+' function "'+aName+'"');
|
InvokeJS_Raise(aName,'expected '+Expected+', but got '+Actual+' from object '+IntToStr(JOBObjectID)+' function "'+aName+'"');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.CreateInvokeJSArgs(const Args: array of const): PByte;
|
function TJSObject.CreateInvokeJSArgs(const Args: array of const): PByte;
|
||||||
@ -1551,7 +1552,7 @@ begin
|
|||||||
p^:=JOBArgNil;
|
p^:=JOBArgNil;
|
||||||
inc(p);
|
inc(p);
|
||||||
end else if Obj is TJSObject then
|
end else if Obj is TJSObject then
|
||||||
AddObjectID(TJSObject(Obj).ObjectID)
|
AddObjectID(TJSObject(Obj).JOBObjectID)
|
||||||
else if Obj is TJOB_JSValue then
|
else if Obj is TJOB_JSValue then
|
||||||
begin
|
begin
|
||||||
JSValue:=TJOB_JSValue(Obj);
|
JSValue:=TJOB_JSValue(Obj);
|
||||||
@ -1623,26 +1624,31 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TJSObject.Cast(Intf: IJSObject);
|
constructor TJSObject.JOBCast(Intf: IJSObject);
|
||||||
begin
|
begin
|
||||||
FObjectID:=Intf.GetJSObjectID;
|
FJOBObjectID:=Intf.GetJSObjectID;
|
||||||
FCastSrc:=Intf.GetJSObjectCastSrc;
|
FJOBCastSrc:=Intf.GetJSObjectCastSrc;
|
||||||
if FCastSrc=nil then
|
if FJOBCastSrc=nil then
|
||||||
FCastSrc:=Intf;
|
FJOBCastSrc:=Intf;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TJSObject.CreateFromID(aID: TJOBObjectID);
|
constructor TJSObject.JOBCreateFromID(aID: TJOBObjectID);
|
||||||
begin
|
begin
|
||||||
FObjectID:=aID;
|
FJOBObjectID:=aID;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TJSObject.Cast(Intf: IJSObject): IJSObject;
|
||||||
|
begin
|
||||||
|
Result:=JOBCast(Intf);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TJSObject.Destroy;
|
destructor TJSObject.Destroy;
|
||||||
begin
|
begin
|
||||||
if FCastSrc<>nil then
|
if FJOBCastSrc<>nil then
|
||||||
FCastSrc:=nil
|
FJOBCastSrc:=nil
|
||||||
else if ObjectID>=0 then
|
else if JOBObjectID>=0 then
|
||||||
__job_release_object(ObjectID);
|
__job_release_object(JOBObjectID);
|
||||||
FObjectID:=0;
|
FJOBObjectID:=0;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1719,7 +1725,7 @@ begin
|
|||||||
if aError<>JOBResult_Object then
|
if aError<>JOBResult_Object then
|
||||||
InvokeJS_RaiseResultMismatch(aName,JOBResult_Object,aError);
|
InvokeJS_RaiseResultMismatch(aName,JOBResult_Object,aError);
|
||||||
|
|
||||||
Result:=aResultClass.CreateFromID(NewObjId);
|
Result:=aResultClass.JOBCreateFromID(NewObjId);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.InvokeJSValueResult(const aName: string;
|
function TJSObject.InvokeJSValueResult(const aName: string;
|
||||||
@ -1748,7 +1754,7 @@ begin
|
|||||||
JOBResult_Function,
|
JOBResult_Function,
|
||||||
JOBResult_Object:
|
JOBResult_Object:
|
||||||
begin
|
begin
|
||||||
Obj:=TJSObject.CreateFromID(PJOBObjectID(p)^);
|
Obj:=TJSObject.JOBCreateFromID(PJOBObjectID(p)^);
|
||||||
Result:=TJOB_Object.Create(Obj);
|
Result:=TJOB_Object.Create(Obj);
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
@ -1943,7 +1949,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
JSObject:=TJSObject.CreateFromID(JOBObjIdObject) as IJSObject;
|
JSObject:=TJSObject.JOBCreateFromID(JOBObjIdObject) as IJSObject;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ unit JOB_Web;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, JOB_Shared, JOB_WAsm;
|
Classes, SysUtils, JOB_Shared, JOB_WAsm, JOB_JS;
|
||||||
|
|
||||||
type
|
type
|
||||||
IJSEvent = interface;
|
IJSEvent = interface;
|
||||||
@ -17,7 +17,7 @@ type
|
|||||||
|
|
||||||
TJSEventHandler = function(Event: IJSEventListenerEvent): boolean of object;
|
TJSEventHandler = function(Event: IJSEventListenerEvent): boolean of object;
|
||||||
|
|
||||||
IJSEventTarget = interface
|
IJSEventTarget = interface(IJSObject)
|
||||||
['{1883145B-C826-47D1-9C63-47546BA536BD}']
|
['{1883145B-C826-47D1-9C63-47546BA536BD}']
|
||||||
procedure addEventListener(const aName: UnicodeString; const aListener: TJSEventHandler);
|
procedure addEventListener(const aName: UnicodeString; const aListener: TJSEventHandler);
|
||||||
end;
|
end;
|
||||||
@ -25,6 +25,7 @@ type
|
|||||||
{ TJSEventTarget }
|
{ TJSEventTarget }
|
||||||
|
|
||||||
TJSEventTarget = class(TJSObject,IJSEventTarget)
|
TJSEventTarget = class(TJSObject,IJSEventTarget)
|
||||||
|
class function Cast(Intf: IJSObject): IJSEventTarget; overload;
|
||||||
procedure addEventListener(const aName: UnicodeString; const aListener: TJSEventHandler);
|
procedure addEventListener(const aName: UnicodeString; const aListener: TJSEventHandler);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ type
|
|||||||
{ TJSNode }
|
{ TJSNode }
|
||||||
|
|
||||||
TJSNode = class(TJSEventTarget,IJSNode)
|
TJSNode = class(TJSEventTarget,IJSNode)
|
||||||
|
class function Cast(Intf: IJSObject): IJSNode; overload;
|
||||||
function GetInnerText: UnicodeString;
|
function GetInnerText: UnicodeString;
|
||||||
procedure SetInnerText(const AValue: UnicodeString);
|
procedure SetInnerText(const AValue: UnicodeString);
|
||||||
end;
|
end;
|
||||||
@ -50,28 +52,50 @@ type
|
|||||||
['{A160069E-378F-4B76-BE64-1979A28B9EEA}']
|
['{A160069E-378F-4B76-BE64-1979A28B9EEA}']
|
||||||
function childElementCount : Integer;
|
function childElementCount : Integer;
|
||||||
function firstElementChild : IJSElement;
|
function firstElementChild : IJSElement;
|
||||||
|
function Getid: UnicodeString;
|
||||||
function GetInnerHTML: UnicodeString;
|
function GetInnerHTML: UnicodeString;
|
||||||
function GetName: UnicodeString;
|
function GetName: UnicodeString;
|
||||||
|
function GetOuterHTML: UnicodeString;
|
||||||
function Get_ClassName: UnicodeString;
|
function Get_ClassName: UnicodeString;
|
||||||
|
procedure append(const aNode : IJSElement); overload;
|
||||||
|
procedure append(const aText : UnicodeString); overload;
|
||||||
|
procedure Setid(const AValue: UnicodeString);
|
||||||
procedure SetInnerHTML(const AValue: UnicodeString);
|
procedure SetInnerHTML(const AValue: UnicodeString);
|
||||||
procedure SetName(const AValue: UnicodeString);
|
procedure SetName(const AValue: UnicodeString);
|
||||||
|
procedure SetOuterHTML(const AValue: UnicodeString);
|
||||||
procedure Set_ClassName(const AValue: UnicodeString);
|
procedure Set_ClassName(const AValue: UnicodeString);
|
||||||
property Name: UnicodeString read GetName write SetName;
|
property Name: UnicodeString read GetName write SetName;
|
||||||
property _ClassName: UnicodeString read Get_ClassName write Set_ClassName;
|
property _ClassName: UnicodeString read Get_ClassName write Set_ClassName;
|
||||||
|
property id : UnicodeString read Getid write Setid;
|
||||||
property InnerHTML: UnicodeString read GetInnerHTML write SetInnerHTML;
|
property InnerHTML: UnicodeString read GetInnerHTML write SetInnerHTML;
|
||||||
|
property OuterHTML : UnicodeString read GetOuterHTML write SetOuterHTML;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJSElement }
|
{ TJSElement }
|
||||||
|
|
||||||
TJSElement = class(TJSNode,IJSElement)
|
TJSElement = class(TJSNode,IJSElement)
|
||||||
function childElementCount : Integer;
|
private
|
||||||
function firstElementChild : IJSElement;
|
function Getid: UnicodeString;
|
||||||
function GetInnerHTML: UnicodeString;
|
function GetInnerHTML: UnicodeString;
|
||||||
function GetName: UnicodeString;
|
function GetName: UnicodeString;
|
||||||
|
function GetOuterHTML: UnicodeString;
|
||||||
function Get_ClassName: UnicodeString;
|
function Get_ClassName: UnicodeString;
|
||||||
|
procedure Setid(const AValue: UnicodeString);
|
||||||
procedure SetInnerHTML(const AValue: UnicodeString);
|
procedure SetInnerHTML(const AValue: UnicodeString);
|
||||||
procedure SetName(const AValue: UnicodeString);
|
procedure SetName(const AValue: UnicodeString);
|
||||||
|
procedure SetOuterHTML(const AValue: UnicodeString);
|
||||||
procedure Set_ClassName(const AValue: UnicodeString);
|
procedure Set_ClassName(const AValue: UnicodeString);
|
||||||
|
public
|
||||||
|
class function Cast(Intf: IJSObject): IJSElement; overload;
|
||||||
|
procedure append(const aText : UnicodeString); overload;
|
||||||
|
procedure append(const aNode : IJSElement); overload;
|
||||||
|
function childElementCount : Integer;
|
||||||
|
function firstElementChild : IJSElement;
|
||||||
|
property Name : UnicodeString read GetName write SetName;
|
||||||
|
property _className : UnicodeString read Get_ClassName write Set_ClassName;
|
||||||
|
property id : UnicodeString read Getid write Setid;
|
||||||
|
property InnerHTML : UnicodeString read GetInnerHTML write SetInnerHTML;
|
||||||
|
property OuterHTML : UnicodeString read GetOuterHTML write SetOuterHTML;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ IJSEvent }
|
{ IJSEvent }
|
||||||
@ -85,20 +109,33 @@ type
|
|||||||
{ TJSEvent }
|
{ TJSEvent }
|
||||||
|
|
||||||
TJSEvent = class(TJSObject,IJSEvent)
|
TJSEvent = class(TJSObject,IJSEvent)
|
||||||
|
class function Cast(Intf: IJSObject): IJSEvent; overload;
|
||||||
function CurrentTargetElement: IJSElement;
|
function CurrentTargetElement: IJSElement;
|
||||||
function TargetElement: IJSElement;
|
function TargetElement: IJSElement;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ IJSUIEvent }
|
||||||
|
|
||||||
IJSUIEvent = interface(IJSEvent)
|
IJSUIEvent = interface(IJSEvent)
|
||||||
['{A1234998-5180-4905-B820-10FAB9B2DD12}']
|
['{A1234998-5180-4905-B820-10FAB9B2DD12}']
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TJSUIEvent }
|
||||||
|
|
||||||
TJSUIEvent = class(TJSEvent,IJSUIEvent)
|
TJSUIEvent = class(TJSEvent,IJSUIEvent)
|
||||||
|
class function Cast(Intf: IJSObject): IJSUIEvent; overload;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ IJSMouseEvent }
|
||||||
|
|
||||||
IJSMouseEvent = interface(IJSUIEvent)
|
IJSMouseEvent = interface(IJSUIEvent)
|
||||||
['{B91DC727-1164-43AE-8481-55421D3148C4}']
|
['{B91DC727-1164-43AE-8481-55421D3148C4}']
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TJSMouseEvent }
|
||||||
|
|
||||||
TJSMouseEvent = class(TJSUIEvent,IJSMouseEvent)
|
TJSMouseEvent = class(TJSUIEvent,IJSMouseEvent)
|
||||||
|
class function Cast(Intf: IJSObject): IJSMouseEvent; overload;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TJSHTMLClickEventHandler = function(aEvent: IJSMouseEvent) : boolean of object;
|
TJSHTMLClickEventHandler = function(aEvent: IJSMouseEvent) : boolean of object;
|
||||||
@ -107,24 +144,62 @@ type
|
|||||||
|
|
||||||
IJSHTMLElement = interface(IJSElement)
|
IJSHTMLElement = interface(IJSElement)
|
||||||
['{D50E53E1-5B3B-4DA4-ACB0-1FD0DE32B711}']
|
['{D50E53E1-5B3B-4DA4-ACB0-1FD0DE32B711}']
|
||||||
|
function Gettitle: UnicodeString;
|
||||||
|
procedure Settitle(const AValue: UnicodeString);
|
||||||
procedure set_onclick(const h: TJSHTMLClickEventHandler);
|
procedure set_onclick(const h: TJSHTMLClickEventHandler);
|
||||||
|
property title: UnicodeString read Gettitle write Settitle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJSHTMLElement }
|
{ TJSHTMLElement }
|
||||||
|
|
||||||
TJSHTMLElement = class(TJSElement,IJSHTMLElement)
|
TJSHTMLElement = class(TJSElement,IJSHTMLElement)
|
||||||
|
private
|
||||||
|
function Gettitle: UnicodeString;
|
||||||
|
procedure Settitle(const AValue: UnicodeString);
|
||||||
|
public
|
||||||
|
class function Cast(Intf: IJSObject): IJSHTMLElement; overload;
|
||||||
procedure set_onclick(const h: TJSHTMLClickEventHandler);
|
procedure set_onclick(const h: TJSHTMLClickEventHandler);
|
||||||
|
property title: UnicodeString read Gettitle write Settitle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ IJSHTMLButtonElement }
|
||||||
|
|
||||||
|
IJSHTMLButtonElement = interface(IJSHTMLElement)
|
||||||
|
['{81DC2F80-FEF4-4705-A6DC-A04B2E32B72D}']
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TJSHTMLButtonElement }
|
||||||
|
|
||||||
|
TJSHTMLButtonElement = class(TJSHTMLElement,IJSHTMLButtonElement)
|
||||||
|
class function Cast(Intf: IJSObject): IJSHTMLButtonElement; overload;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ IJSHTMLDivElement }
|
||||||
|
|
||||||
|
IJSHTMLDivElement = interface(IJSHTMLElement)
|
||||||
|
['{A02A19B2-85B6-4C96-9281-AF90459E1CEC}']
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TJSHTMLDivElement }
|
||||||
|
|
||||||
|
TJSHTMLDivElement = class(TJSHTMLElement,IJSHTMLDivElement)
|
||||||
|
class function Cast(Intf: IJSObject): IJSHTMLDivElement; overload;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ IJSDocument }
|
||||||
|
|
||||||
IJSDocument = interface(IJSNode)
|
IJSDocument = interface(IJSNode)
|
||||||
['{CC3FB7C1-C4ED-4BBC-80AB-7B6C2989E026}']
|
['{CC3FB7C1-C4ED-4BBC-80AB-7B6C2989E026}']
|
||||||
|
function createElement(const tagName : UnicodeString) : IJSElement; overload;
|
||||||
function getElementById(const aID : UnicodeString) : IJSElement;
|
function getElementById(const aID : UnicodeString) : IJSElement;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJSDocument }
|
{ TJSDocument }
|
||||||
|
|
||||||
TJSDocument = class(TJSNode,IJSDocument)
|
TJSDocument = class(TJSNode,IJSDocument)
|
||||||
function getElementById(const aID : UnicodeString) : IJSElement;
|
class function Cast(Intf: IJSObject): IJSDocument; overload;
|
||||||
|
function createElement(const tagName : UnicodeString) : IJSElement; overload;
|
||||||
|
function getElementById(const aID : UnicodeString) : IJSElement; overload;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ IJSWindow }
|
{ IJSWindow }
|
||||||
@ -138,6 +213,7 @@ type
|
|||||||
{ TJSWindow }
|
{ TJSWindow }
|
||||||
|
|
||||||
TJSWindow = class(TJSObject,IJSWindow)
|
TJSWindow = class(TJSObject,IJSWindow)
|
||||||
|
class function Cast(Intf: IJSObject): IJSWindow; overload;
|
||||||
procedure addEventListener(const aName: UnicodeString; const aListener: TJSEventHandler);
|
procedure addEventListener(const aName: UnicodeString; const aListener: TJSEventHandler);
|
||||||
procedure Alert(Const Msg: UnicodeString);
|
procedure Alert(Const Msg: UnicodeString);
|
||||||
end;
|
end;
|
||||||
@ -169,8 +245,41 @@ begin
|
|||||||
Result:=H.AllocBool(TJSEventHandler(aMethod)(Event));
|
Result:=H.AllocBool(TJSEventHandler(aMethod)(Event));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TJSHTMLDivElement }
|
||||||
|
|
||||||
|
class function TJSHTMLDivElement.Cast(Intf: IJSObject): IJSHTMLDivElement;
|
||||||
|
begin
|
||||||
|
Result:=TJSHTMLDivElement.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TJSHTMLButtonElement }
|
||||||
|
|
||||||
|
class function TJSHTMLButtonElement.Cast(Intf: IJSObject): IJSHTMLButtonElement;
|
||||||
|
begin
|
||||||
|
Result:=TJSHTMLButtonElement.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TJSMouseEvent }
|
||||||
|
|
||||||
|
class function TJSMouseEvent.Cast(Intf: IJSObject): IJSMouseEvent;
|
||||||
|
begin
|
||||||
|
Result:=TJSMouseEvent.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TJSUIEvent }
|
||||||
|
|
||||||
|
class function TJSUIEvent.Cast(Intf: IJSObject): IJSUIEvent;
|
||||||
|
begin
|
||||||
|
Result:=TJSUIEvent.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TJSEventTarget }
|
{ TJSEventTarget }
|
||||||
|
|
||||||
|
class function TJSEventTarget.Cast(Intf: IJSObject): IJSEventTarget;
|
||||||
|
begin
|
||||||
|
Result:=TJSEventTarget.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TJSEventTarget.addEventListener(const aName: UnicodeString;
|
procedure TJSEventTarget.addEventListener(const aName: UnicodeString;
|
||||||
const aListener: TJSEventHandler);
|
const aListener: TJSEventHandler);
|
||||||
var
|
var
|
||||||
@ -186,6 +295,21 @@ end;
|
|||||||
|
|
||||||
{ TJSHTMLElement }
|
{ TJSHTMLElement }
|
||||||
|
|
||||||
|
function TJSHTMLElement.Gettitle: UnicodeString;
|
||||||
|
begin
|
||||||
|
Result:=ReadJSPropertyUnicodeString('title');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJSHTMLElement.Settitle(const AValue: UnicodeString);
|
||||||
|
begin
|
||||||
|
WriteJSPropertyUnicodeString('title',AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TJSHTMLElement.Cast(Intf: IJSObject): IJSHTMLElement;
|
||||||
|
begin
|
||||||
|
Result:=TJSHTMLElement.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TJSHTMLElement.set_onclick(const h: TJSHTMLClickEventHandler);
|
procedure TJSHTMLElement.set_onclick(const h: TJSHTMLClickEventHandler);
|
||||||
var
|
var
|
||||||
cb1: TJOB_Method;
|
cb1: TJOB_Method;
|
||||||
@ -200,6 +324,11 @@ end;
|
|||||||
|
|
||||||
{ TJSEvent }
|
{ TJSEvent }
|
||||||
|
|
||||||
|
class function TJSEvent.Cast(Intf: IJSObject): IJSEvent;
|
||||||
|
begin
|
||||||
|
Result:=TJSEvent.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
function TJSEvent.CurrentTargetElement: IJSElement;
|
function TJSEvent.CurrentTargetElement: IJSElement;
|
||||||
begin
|
begin
|
||||||
Result:=ReadJSPropertyObject('currentTargetElement',TJSElement) as IJSElement;
|
Result:=ReadJSPropertyObject('currentTargetElement',TJSElement) as IJSElement;
|
||||||
@ -212,6 +341,11 @@ end;
|
|||||||
|
|
||||||
{ TJSNode }
|
{ TJSNode }
|
||||||
|
|
||||||
|
class function TJSNode.Cast(Intf: IJSObject): IJSNode;
|
||||||
|
begin
|
||||||
|
Result:=TJSNode.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
function TJSNode.GetInnerText: UnicodeString;
|
function TJSNode.GetInnerText: UnicodeString;
|
||||||
begin
|
begin
|
||||||
Result:=ReadJSPropertyUnicodeString('innerText');
|
Result:=ReadJSPropertyUnicodeString('innerText');
|
||||||
@ -224,6 +358,41 @@ end;
|
|||||||
|
|
||||||
{ TJSElement }
|
{ TJSElement }
|
||||||
|
|
||||||
|
function TJSElement.Getid: UnicodeString;
|
||||||
|
begin
|
||||||
|
Result:=ReadJSPropertyUnicodeString('id');
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TJSElement.GetOuterHTML: UnicodeString;
|
||||||
|
begin
|
||||||
|
Result:=ReadJSPropertyUnicodeString('outerHTML');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJSElement.Setid(const AValue: UnicodeString);
|
||||||
|
begin
|
||||||
|
WriteJSPropertyUnicodeString('id',AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJSElement.SetOuterHTML(const AValue: UnicodeString);
|
||||||
|
begin
|
||||||
|
WriteJSPropertyUnicodeString('outerHTML',AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TJSElement.Cast(Intf: IJSObject): IJSElement;
|
||||||
|
begin
|
||||||
|
Result:=TJSElement.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJSElement.append(const aText: UnicodeString);
|
||||||
|
begin
|
||||||
|
InvokeJSNoResult('append',[aText]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJSElement.append(const aNode: IJSElement);
|
||||||
|
begin
|
||||||
|
InvokeJSNoResult('append',[aNode]);
|
||||||
|
end;
|
||||||
|
|
||||||
function TJSElement.childElementCount: Integer;
|
function TJSElement.childElementCount: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=ReadJSPropertyLongInt('childElementCount');
|
Result:=ReadJSPropertyLongInt('childElementCount');
|
||||||
@ -266,6 +435,16 @@ end;
|
|||||||
|
|
||||||
{ TJSDocument }
|
{ TJSDocument }
|
||||||
|
|
||||||
|
class function TJSDocument.Cast(Intf: IJSObject): IJSDocument;
|
||||||
|
begin
|
||||||
|
Result:=TJSDocument.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TJSDocument.createElement(const tagName: UnicodeString): IJSElement;
|
||||||
|
begin
|
||||||
|
Result:=InvokeJSObjectResult('createElement',[tagName],TJSElement) as IJSElement;
|
||||||
|
end;
|
||||||
|
|
||||||
function TJSDocument.getElementById(const aID: UnicodeString): IJSElement;
|
function TJSDocument.getElementById(const aID: UnicodeString): IJSElement;
|
||||||
begin
|
begin
|
||||||
Result:=InvokeJSObjectResult('getElementById',[aID],TJSElement) as IJSElement;
|
Result:=InvokeJSObjectResult('getElementById',[aID],TJSElement) as IJSElement;
|
||||||
@ -273,6 +452,11 @@ end;
|
|||||||
|
|
||||||
{ TJSWindow }
|
{ TJSWindow }
|
||||||
|
|
||||||
|
class function TJSWindow.Cast(Intf: IJSObject): IJSWindow;
|
||||||
|
begin
|
||||||
|
Result:=TJSWindow.JOBCast(Intf);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TJSWindow.addEventListener(const aName: UnicodeString;
|
procedure TJSWindow.addEventListener(const aName: UnicodeString;
|
||||||
const aListener: TJSEventHandler);
|
const aListener: TJSEventHandler);
|
||||||
var
|
var
|
||||||
@ -292,8 +476,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
JSDocument:=TJSDocument.CreateFromID(JOBObjIdDocument);
|
JSDocument:=TJSDocument.JOBCreateFromID(JOBObjIdDocument);
|
||||||
JSWindow:=TJSWindow.CreateFromID(JOBObjIdWindow);
|
JSWindow:=TJSWindow.JOBCreateFromID(JOBObjIdWindow);
|
||||||
finalization
|
finalization
|
||||||
JSDocument.Free;
|
JSDocument.Free;
|
||||||
JSWindow.Free;
|
JSWindow.Free;
|
||||||
|
Loading…
Reference in New Issue
Block a user