mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-28 21:00:28 +02:00
* Fix memleak, objects created directly are owned by webassembly
This commit is contained in:
parent
36112193dc
commit
5bdef935f9
@ -335,7 +335,8 @@ type
|
|||||||
constructor JOBCast(const Intf: IJSObject); overload;
|
constructor JOBCast(const Intf: IJSObject); overload;
|
||||||
constructor JOBCreateFromID(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)
|
||||||
constructor JOBCreateGlobal(const aID: UnicodeString); virtual;
|
constructor JOBCreateGlobal(const aID: UnicodeString); virtual;
|
||||||
constructor JOBCreate(Args : Array of const);
|
constructor JOBCreate(const Args : Array of const);
|
||||||
|
constructor JOBCreate(aOwnsObjectID : Boolean; const Args : Array of const);
|
||||||
class function JSClassName : UnicodeString; virtual;
|
class function JSClassName : UnicodeString; virtual;
|
||||||
class function Cast(const Intf: IJSObject): IJSObject; overload;
|
class function Cast(const Intf: IJSObject): IJSObject; overload;
|
||||||
constructor Create; virtual;
|
constructor Create; virtual;
|
||||||
@ -1470,7 +1471,7 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Data:=TJOB_ArrayOfByte.Create(aBytes,aLen);
|
Data:=TJOB_ArrayOfByte.Create(aBytes,aLen);
|
||||||
JobCreate([Data]);
|
JobCreate(True,[Data]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TJSTypedArray.Create(aBytes: TBytes);
|
constructor TJSTypedArray.Create(aBytes: TBytes);
|
||||||
@ -1478,7 +1479,7 @@ var
|
|||||||
Data : TJOB_JSValue;
|
Data : TJOB_JSValue;
|
||||||
begin
|
begin
|
||||||
Data:=TJOB_ArrayOfByte.Create(aBytes);
|
Data:=TJOB_ArrayOfByte.Create(aBytes);
|
||||||
JobCreate([Data]);
|
JobCreate(True,[Data]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TJSTypedArray.Cast(const Intf: IJSObject): IJSTypedArray;
|
class function TJSTypedArray.Cast(const Intf: IJSObject): IJSTypedArray;
|
||||||
@ -2422,11 +2423,8 @@ end;
|
|||||||
constructor TJOB_ArrayOfByte.Create(const TheValues: PByte; TheLen: NativeUInt);
|
constructor TJOB_ArrayOfByte.Create(const TheValues: PByte; TheLen: NativeUInt);
|
||||||
begin
|
begin
|
||||||
inherited Create(jjvkArrayOfByte);
|
inherited Create(jjvkArrayOfByte);
|
||||||
Writeln('A');
|
|
||||||
Values:=TheValues;
|
Values:=TheValues;
|
||||||
Writeln('B');
|
|
||||||
Len:=TheLen;
|
Len:=TheLen;
|
||||||
Writeln('C');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TJOB_ArrayOfByte.Create(const TheValues: TBytes);
|
constructor TJOB_ArrayOfByte.Create(const TheValues: TBytes);
|
||||||
@ -3016,8 +3014,13 @@ begin
|
|||||||
FJOBObjectIDOwner:=true;
|
FJOBObjectIDOwner:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TJSObject.JOBCreate(Args : Array of const);
|
constructor TJSObject.JOBCreate(const Args: array of const);
|
||||||
|
|
||||||
|
begin
|
||||||
|
JOBCreate(True,Args);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TJSObject.JOBCreate(aOwnsObjectID: Boolean; const Args: array of const);
|
||||||
var
|
var
|
||||||
N : Unicodestring;
|
N : Unicodestring;
|
||||||
InvokeArgs: PByte;
|
InvokeArgs: PByte;
|
||||||
@ -3028,6 +3031,7 @@ begin
|
|||||||
InvokeArgs:=CreateInvokeJSArgs(Args)
|
InvokeArgs:=CreateInvokeJSArgs(Args)
|
||||||
else
|
else
|
||||||
InvokeArgs:=Nil;
|
InvokeArgs:=Nil;
|
||||||
|
FJOBObjectIDOwner:=aOwnsObjectID;
|
||||||
FJobObjectID:=__job_create_object(PWideChar(N),Length(N),InvokeArgs);
|
FJobObjectID:=__job_create_object(PWideChar(N),Length(N),InvokeArgs);
|
||||||
{$IFDEF VERBOSEJOB}
|
{$IFDEF VERBOSEJOB}
|
||||||
Writeln('[',ClassName,'] Created new object with ID: ',FJobObjectID);
|
Writeln('[',ClassName,'] Created new object with ID: ',FJobObjectID);
|
||||||
@ -3049,11 +3053,14 @@ end;
|
|||||||
constructor TJSObject.Create;
|
constructor TJSObject.Create;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
JOBCreate([]);
|
JOBCreate(True,[]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TJSObject.Destroy;
|
destructor TJSObject.Destroy;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF VERBOSEJOB}
|
||||||
|
Writeln('Destroying ',ClassName,': Owning JOB object ID: ',FJOBObjectIDOwner);
|
||||||
|
{$ENDIF}
|
||||||
if FJOBCastSrc<>nil then
|
if FJOBCastSrc<>nil then
|
||||||
FJOBCastSrc:=nil
|
FJOBCastSrc:=nil
|
||||||
else if (JOBObjectID>=0) and JOBObjectIDOwner then
|
else if (JOBObjectID>=0) and JOBObjectIDOwner then
|
||||||
@ -3206,8 +3213,7 @@ begin
|
|||||||
Result:=UTF8Encode(InvokeJSUnicodeStringResult(aName,Args,Invoke));
|
Result:=UTF8Encode(InvokeJSUnicodeStringResult(aName,Args,Invoke));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.InvokeJSLongIntResult(const aName: UTF8string;
|
function TJSObject.InvokeJSLongIntResult(const aName: UTF8String; const args: array of const; Invoke: TJOBInvokeType): LongInt;
|
||||||
const args: array of const; Invoke: TJOBInvokeType): LongInt;
|
|
||||||
var
|
var
|
||||||
d: Double;
|
d: Double;
|
||||||
begin
|
begin
|
||||||
@ -3218,8 +3224,7 @@ begin
|
|||||||
Result:=Trunc(d);
|
Result:=Trunc(d);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.InvokeJSMaxIntResult(const aName: UTF8string;
|
function TJSObject.InvokeJSMaxIntResult(const aName: UTF8String; const args: array of const; Invoke: TJOBInvokeType): int64;
|
||||||
const args: array of const; Invoke: TJOBInvokeType): int64;
|
|
||||||
var
|
var
|
||||||
d: Double;
|
d: Double;
|
||||||
begin
|
begin
|
||||||
@ -3230,14 +3235,13 @@ begin
|
|||||||
Result:=Trunc(d);
|
Result:=Trunc(d);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.InvokeJSTypeOf(const aName: UTF8string;
|
function TJSObject.InvokeJSTypeOf(const aName: UTF8String; const Args: array of const): TJOBResult;
|
||||||
const Args: array of const): TJOBResult;
|
|
||||||
begin
|
begin
|
||||||
Result:=InvokeJSNoResultFunc(aName,Args,@__job_invoke_noresult,jiGetTypeOf);
|
Result:=InvokeJSNoResultFunc(aName,Args,@__job_invoke_noresult,jiGetTypeOf);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.InvokeJSUnicodeStringArrayResult(const aName: UTF8string;
|
function TJSObject.InvokeJSUnicodeStringArrayResult(const aName: UTF8String; const Args: array of const; Invoke: TJOBInvokeType
|
||||||
const Args: array of const; Invoke: TJOBInvokeType): TUnicodeStringDynArray;
|
): TUnicodeStringDynArray;
|
||||||
var
|
var
|
||||||
ResultP: NativeInt;
|
ResultP: NativeInt;
|
||||||
aError: TJOBResult;
|
aError: TJOBResult;
|
||||||
@ -3253,110 +3257,102 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.ReadJSPropertyBoolean(const aName: UTF8string): boolean;
|
function TJSObject.ReadJSPropertyBoolean(const aName: UTF8String): boolean;
|
||||||
begin
|
begin
|
||||||
Result:=InvokeJSBooleanResult(aName,[],jiGet);
|
Result:=InvokeJSBooleanResult(aName,[],jiGet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.ReadJSPropertyDouble(const aName: UTF8string): double;
|
function TJSObject.ReadJSPropertyDouble(const aName: UTF8String): double;
|
||||||
begin
|
begin
|
||||||
Result:=InvokeJSDoubleResult(aName,[],jiGet);
|
Result:=InvokeJSDoubleResult(aName,[],jiGet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.ReadJSPropertyUnicodeString(const aName: UTF8string
|
function TJSObject.ReadJSPropertyUnicodeString(const aName: UTF8String): UnicodeString;
|
||||||
): UnicodeString;
|
|
||||||
begin
|
begin
|
||||||
Result:=InvokeJSUnicodeStringResult(aName,[],jiGet);
|
Result:=InvokeJSUnicodeStringResult(aName,[],jiGet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.ReadJSPropertyObject(const aName: UTF8string;
|
function TJSObject.ReadJSPropertyObject(const aName: UTF8String; aResultClass: TJSObjectClass): TJSObject;
|
||||||
aResultClass: TJSObjectClass): TJSObject;
|
|
||||||
begin
|
begin
|
||||||
Result:=InvokeJSObjectResult(aName,[],aResultClass,jiGet);
|
Result:=InvokeJSObjectResult(aName,[],aResultClass,jiGet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.ReadJSPropertyUtf8String(const aName: UTF8string): UTF8string;
|
function TJSObject.ReadJSPropertyUtf8String(const aName: UTF8String): UTF8String;
|
||||||
begin
|
begin
|
||||||
Result:=InvokeJSUtf8StringResult(aName,[],jiGet);
|
Result:=InvokeJSUtf8StringResult(aName,[],jiGet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.ReadJSPropertyLongInt(const aName: UTF8string): LongInt;
|
function TJSObject.ReadJSPropertyLongInt(const aName: UTF8String): LongInt;
|
||||||
begin
|
begin
|
||||||
Result:=InvokeJSLongIntResult(aName,[],jiGet);
|
Result:=InvokeJSLongIntResult(aName,[],jiGet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.ReadJSPropertyInt64(const aName: UTF8string): Int64;
|
function TJSObject.ReadJSPropertyInt64(const aName: UTF8String): Int64;
|
||||||
begin
|
begin
|
||||||
Result:=Trunc(InvokeJSDoubleResult(aName,[],jiGet));
|
Result:=Trunc(InvokeJSDoubleResult(aName,[],jiGet));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.ReadJSPropertyValue(const aName: UTF8string): TJOB_JSValue;
|
function TJSObject.ReadJSPropertyValue(const aName: UTF8String): TJOB_JSValue;
|
||||||
begin
|
begin
|
||||||
Result:=InvokeJSValueResult(aName,[],jiGet);
|
Result:=InvokeJSValueResult(aName,[],jiGet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.ReadJSPropertyVariant(const aName: UTF8string): Variant;
|
function TJSObject.ReadJSPropertyVariant(const aName: UTF8String): Variant;
|
||||||
begin
|
begin
|
||||||
Result:=InvokeJSVariantResult(aName,[],jiGet);
|
Result:=InvokeJSVariantResult(aName,[],jiGet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSObject.ReadJSPropertyMethod(const aName: UTF8string): TMethod;
|
function TJSObject.ReadJSPropertyMethod(const aName: UTF8String): TMethod;
|
||||||
begin
|
begin
|
||||||
// Result:=InvokeJSVariantResult(aName,[],jiGet);
|
// Result:=InvokeJSVariantResult(aName,[],jiGet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSObject.WriteJSPropertyBoolean(const aName: UTF8string; Value: Boolean);
|
procedure TJSObject.WriteJSPropertyBoolean(const aName: UTF8String; Value: Boolean);
|
||||||
begin
|
begin
|
||||||
InvokeJSNoResult(aName,[Value],jiSet);
|
InvokeJSNoResult(aName,[Value],jiSet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSObject.WriteJSPropertyDouble(const aName: UTF8string; Value: Double);
|
procedure TJSObject.WriteJSPropertyDouble(const aName: UTF8String; Value: Double);
|
||||||
begin
|
begin
|
||||||
InvokeJSNoResult(aName,[Value],jiSet);
|
InvokeJSNoResult(aName,[Value],jiSet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSObject.WriteJSPropertyUnicodeString(const aName: UTF8string;
|
procedure TJSObject.WriteJSPropertyUnicodeString(const aName: UTF8String; const Value: UnicodeString);
|
||||||
const Value: UnicodeString);
|
|
||||||
begin
|
begin
|
||||||
InvokeJSNoResult(aName,[Value],jiSet);
|
InvokeJSNoResult(aName,[Value],jiSet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSObject.WriteJSPropertyUtf8String(const aName: UTF8string;
|
procedure TJSObject.WriteJSPropertyUtf8String(const aName: UTF8String; const Value: UTF8String);
|
||||||
const Value: UTF8String);
|
|
||||||
begin
|
begin
|
||||||
InvokeJSNoResult(aName,[Value],jiSet);
|
InvokeJSNoResult(aName,[Value],jiSet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSObject.WriteJSPropertyObject(const aName: UTF8string; Value: IJSObject
|
procedure TJSObject.WriteJSPropertyObject(const aName: UTF8String; Value: IJSObject);
|
||||||
);
|
|
||||||
begin
|
begin
|
||||||
InvokeJSNoResult(aName,[Value],jiSet);
|
InvokeJSNoResult(aName,[Value],jiSet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSObject.WriteJSPropertyLongInt(const aName: UTF8string; Value: LongInt);
|
procedure TJSObject.WriteJSPropertyLongInt(const aName: UTF8String; Value: LongInt);
|
||||||
begin
|
begin
|
||||||
InvokeJSNoResult(aName,[Value],jiSet);
|
InvokeJSNoResult(aName,[Value],jiSet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSObject.WriteJSPropertyInt64(const aName: UTF8string; Value: Int64);
|
procedure TJSObject.WriteJSPropertyInt64(const aName: UTF8String; Value: Int64);
|
||||||
begin
|
begin
|
||||||
InvokeJSNoResult(aName,[Value],jiSet);
|
InvokeJSNoResult(aName,[Value],jiSet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSObject.WriteJSPropertyValue(const aName: UTF8string;
|
procedure TJSObject.WriteJSPropertyValue(const aName: UTF8String; Value: TJOB_JSValue);
|
||||||
Value: TJOB_JSValue);
|
|
||||||
begin
|
begin
|
||||||
InvokeJSNoResult(aName,[Value],jiSet);
|
InvokeJSNoResult(aName,[Value],jiSet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSObject.WriteJSPropertyVariant(const aName: UTF8string;
|
procedure TJSObject.WriteJSPropertyVariant(const aName: UTF8String; const Value: Variant);
|
||||||
const Value: Variant);
|
|
||||||
begin
|
begin
|
||||||
InvokeJSNoResult(aName,[Value],jiSet);
|
InvokeJSNoResult(aName,[Value],jiSet);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSObject.WriteJSPropertyMethod(const aName: UTF8string;
|
procedure TJSObject.WriteJSPropertyMethod(const aName: UTF8String; const Value: TMethod);
|
||||||
const Value: TMethod);
|
|
||||||
begin
|
begin
|
||||||
// TODO InvokeJSNoResult(aName,[Value],jiSet);
|
// TODO InvokeJSNoResult(aName,[Value],jiSet);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user