mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 19:49:12 +02:00
* Add TypedArray constructor
This commit is contained in:
parent
7fe602ebb0
commit
2a4f4ef420
@ -50,7 +50,8 @@ Type
|
|||||||
jjvkMethod,
|
jjvkMethod,
|
||||||
jjvkDictionary,
|
jjvkDictionary,
|
||||||
jjvkArrayOfJSValue,
|
jjvkArrayOfJSValue,
|
||||||
jjvkArrayOfDouble
|
jjvkArrayOfDouble,
|
||||||
|
jjvkArrayOfByte
|
||||||
);
|
);
|
||||||
TJOB_JSValueKinds = set of TJOB_JSValueKind;
|
TJOB_JSValueKinds = set of TJOB_JSValueKind;
|
||||||
|
|
||||||
@ -64,7 +65,8 @@ const
|
|||||||
'Method',
|
'Method',
|
||||||
'Dictionary',
|
'Dictionary',
|
||||||
'ArrayOfJSValue',
|
'ArrayOfJSValue',
|
||||||
'ArrayOfDouble'
|
'ArrayOfDouble',
|
||||||
|
'ArrayOfByte'
|
||||||
);
|
);
|
||||||
|
|
||||||
JOB_Undefined = Pointer(1);
|
JOB_Undefined = Pointer(1);
|
||||||
@ -110,6 +112,7 @@ type
|
|||||||
function AsString: UTF8string; override;
|
function AsString: UTF8string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
IJSObject = interface;
|
IJSObject = interface;
|
||||||
|
|
||||||
{ TJOB_Object }
|
{ TJOB_Object }
|
||||||
@ -217,6 +220,19 @@ type
|
|||||||
constructor Create(const TheValues: TDoubleDynArray);
|
constructor Create(const TheValues: TDoubleDynArray);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TJOB_ArrayOfDouble }
|
||||||
|
|
||||||
|
{ TJOB_ArrayOfByte }
|
||||||
|
|
||||||
|
TJOB_ArrayOfByte = class(TJOB_ArrayBase)
|
||||||
|
public
|
||||||
|
Values: PByte;
|
||||||
|
Len : NativeUInt;
|
||||||
|
constructor Create(const TheValues: PByte; TheLen : NativeUInt);
|
||||||
|
constructor Create(const TheValues: TBytes);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
IJSArray = interface;
|
IJSArray = interface;
|
||||||
|
|
||||||
{ IJSObject }
|
{ IJSObject }
|
||||||
@ -694,6 +710,8 @@ type
|
|||||||
|
|
||||||
TJSTypedArray = class(TJSObject,IJSTypedArray)
|
TJSTypedArray = class(TJSObject,IJSTypedArray)
|
||||||
public
|
public
|
||||||
|
constructor Create(aBytes : PByte; aLen : NativeUInt);
|
||||||
|
constructor Create(aBytes : TBytes);
|
||||||
class function Cast(const Intf: IJSObject): IJSTypedArray; overload;
|
class function Cast(const Intf: IJSObject): IJSTypedArray; overload;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -707,6 +725,7 @@ type
|
|||||||
|
|
||||||
TJSInt8Array = class(TJSTypedArray,IJSInt8Array)
|
TJSInt8Array = class(TJSTypedArray,IJSInt8Array)
|
||||||
public
|
public
|
||||||
|
class function JSClassName: UnicodeString; override;
|
||||||
class function Cast(const Intf: IJSObject): IJSInt8Array; overload;
|
class function Cast(const Intf: IJSObject): IJSInt8Array; overload;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -720,6 +739,7 @@ type
|
|||||||
|
|
||||||
TJSUint8Array = class(TJSTypedArray,IJSUint8Array)
|
TJSUint8Array = class(TJSTypedArray,IJSUint8Array)
|
||||||
public
|
public
|
||||||
|
class function JSClassName: UnicodeString; override;
|
||||||
class function Cast(const Intf: IJSObject): IJSUint8Array; overload;
|
class function Cast(const Intf: IJSObject): IJSUint8Array; overload;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -733,6 +753,7 @@ type
|
|||||||
|
|
||||||
TJSUint8ClampedArray = class(TJSTypedArray,IJSUint8ClampedArray)
|
TJSUint8ClampedArray = class(TJSTypedArray,IJSUint8ClampedArray)
|
||||||
public
|
public
|
||||||
|
class function JSClassName: UnicodeString; override;
|
||||||
class function Cast(const Intf: IJSObject): IJSUint8ClampedArray; overload;
|
class function Cast(const Intf: IJSObject): IJSUint8ClampedArray; overload;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1405,14 +1426,24 @@ end;
|
|||||||
|
|
||||||
{ TJSUint8ClampedArray }
|
{ TJSUint8ClampedArray }
|
||||||
|
|
||||||
|
class function TJSUint8ClampedArray.JSClassName: UnicodeString;
|
||||||
|
begin
|
||||||
|
Result:='Uint8ClampedArray';
|
||||||
|
end;
|
||||||
|
|
||||||
class function TJSUint8ClampedArray.Cast(const Intf: IJSObject
|
class function TJSUint8ClampedArray.Cast(const Intf: IJSObject
|
||||||
): IJSUint8ClampedArray;
|
): IJSUint8ClampedArray;
|
||||||
begin
|
begin
|
||||||
Result:=TJSUint8ClampedArray.Cast(Intf);
|
Result:=TJSUint8ClampedArray.JobCast(Intf);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJSUInt8Array }
|
{ TJSUInt8Array }
|
||||||
|
|
||||||
|
class function TJSUint8Array.JSClassName: UnicodeString;
|
||||||
|
begin
|
||||||
|
Result:='Uint8Array';
|
||||||
|
end;
|
||||||
|
|
||||||
class function TJSUint8Array.Cast(const Intf: IJSObject): IJSUint8Array;
|
class function TJSUint8Array.Cast(const Intf: IJSObject): IJSUint8Array;
|
||||||
begin
|
begin
|
||||||
Result:=TJSUInt8Array.Cast(Intf);
|
Result:=TJSUInt8Array.Cast(Intf);
|
||||||
@ -1420,13 +1451,36 @@ end;
|
|||||||
|
|
||||||
{ TJSInt8Array }
|
{ TJSInt8Array }
|
||||||
|
|
||||||
|
class function TJSInt8Array.JSClassName: UnicodeString;
|
||||||
|
begin
|
||||||
|
Result:='Int8Array';
|
||||||
|
end;
|
||||||
|
|
||||||
class function TJSInt8Array.Cast(const Intf: IJSObject): IJSInt8Array;
|
class function TJSInt8Array.Cast(const Intf: IJSObject): IJSInt8Array;
|
||||||
begin
|
begin
|
||||||
Result:=TJSInt8Array.Cast(Intf);
|
Result:=TJSInt8Array.JobCast(Intf);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJSTypedArray }
|
{ TJSTypedArray }
|
||||||
|
|
||||||
|
constructor TJSTypedArray.Create(aBytes: PByte; aLen: NativeUInt);
|
||||||
|
|
||||||
|
var
|
||||||
|
Data : TJOB_JSValue;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Data:=TJOB_ArrayOfByte.Create(aBytes,aLen);
|
||||||
|
JobCreate([Data]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TJSTypedArray.Create(aBytes: TBytes);
|
||||||
|
var
|
||||||
|
Data : TJOB_JSValue;
|
||||||
|
begin
|
||||||
|
Data:=TJOB_ArrayOfByte.Create(aBytes);
|
||||||
|
JobCreate([Data]);
|
||||||
|
end;
|
||||||
|
|
||||||
class function TJSTypedArray.Cast(const Intf: IJSObject): IJSTypedArray;
|
class function TJSTypedArray.Cast(const Intf: IJSObject): IJSTypedArray;
|
||||||
begin
|
begin
|
||||||
Result:=TJSTypedArray.Cast(Intf);
|
Result:=TJSTypedArray.Cast(Intf);
|
||||||
@ -2363,6 +2417,23 @@ begin
|
|||||||
Values:=TheValues;
|
Values:=TheValues;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TJOB_ArrayOfByte }
|
||||||
|
|
||||||
|
constructor TJOB_ArrayOfByte.Create(const TheValues: PByte; TheLen: NativeUInt);
|
||||||
|
begin
|
||||||
|
inherited Create(jjvkArrayOfByte);
|
||||||
|
Writeln('A');
|
||||||
|
Values:=TheValues;
|
||||||
|
Writeln('B');
|
||||||
|
Len:=TheLen;
|
||||||
|
Writeln('C');
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TJOB_ArrayOfByte.Create(const TheValues: TBytes);
|
||||||
|
begin
|
||||||
|
Create(PByte(TheValues),length(TheValues))
|
||||||
|
end;
|
||||||
|
|
||||||
{ TJSObject }
|
{ TJSObject }
|
||||||
|
|
||||||
function TJSObject.GetJSObjectID: TJOBObjectID;
|
function TJSObject.GetJSObjectID: TJOBObjectID;
|
||||||
@ -2713,6 +2784,18 @@ var
|
|||||||
PPointer(p)^:=@TJOB_ArrayOfDouble(aValue).Values[0];
|
PPointer(p)^:=@TJOB_ArrayOfDouble(aValue).Values[0];
|
||||||
inc(p,sizeof(Pointer));
|
inc(p,sizeof(Pointer));
|
||||||
end;
|
end;
|
||||||
|
jjvkArrayOfByte:
|
||||||
|
begin
|
||||||
|
Prep(1+SizeOf(NativeInt)+SizeOf(Pointer),JOBArgArrayOfByte);
|
||||||
|
i:=TJOB_ArrayOfByte(aValue).Len;
|
||||||
|
PNativeInt(p)^:=i;
|
||||||
|
inc(p,SizeOf(NativeInt));
|
||||||
|
if i=0 then
|
||||||
|
PPointer(p)^:=nil
|
||||||
|
else
|
||||||
|
PPointer(p)^:=@TJOB_ArrayOfByte(aValue).Values[0];
|
||||||
|
inc(p,sizeof(Pointer));
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3350,7 +3433,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
Writeln('x');
|
||||||
JSObject:=TJSObject.JOBCreateGlobal('Object') as IJSObject;
|
JSObject:=TJSObject.JOBCreateGlobal('Object') as IJSObject;
|
||||||
|
Writeln('y');
|
||||||
JSDate:=TJSDate.JOBCreateGlobal('Date') as IJSDate;
|
JSDate:=TJSDate.JOBCreateGlobal('Date') as IJSDate;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user