summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattias <mattias@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-26 21:02:43 +0000
committermattias <mattias@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-26 21:02:43 +0000
commit16c5a9ecf1133c5ffa58b09811081028ba302927 (patch)
tree0f8e5d48c6b10595c6c095724f487cc2b2e49fa2
parent777a40cb89ae38ff1e747b4fac54cc736808eaad (diff)
downloadfpc-16c5a9ecf1133c5ffa58b09811081028ba302927.tar.gz
pastojs: fixed rtti method flags
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@49268 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--packages/pastojs/src/fppas2js.pp44
-rw-r--r--packages/pastojs/tests/tcmodules.pas54
-rw-r--r--utils/pas2js/dist/rtl.js5
3 files changed, 53 insertions, 50 deletions
diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp
index 0a6deca3df..26983a2843 100644
--- a/packages/pastojs/src/fppas2js.pp
+++ b/packages/pastojs/src/fppas2js.pp
@@ -16575,7 +16575,11 @@ begin
if El.CallingConvention=ccSafeCall then
inc(Flags,pfSafeCall);
if Flags>0 then
+ begin
+ if not (El is TPasFunctionType) then
+ InnerCall.AddArg(CreateLiteralNull(El));
InnerCall.AddArg(CreateLiteralNumber(El,Flags));
+ end;
if El.IsOfObject then
begin
@@ -19828,9 +19832,8 @@ var
begin
Result:=nil;
if Args.Count=0 then
- Result:=CreateLiteralNull(Parent)
+ Result:=TJSArrayLiteral(CreateElement(TJSArrayLiteral,Parent))
else
- begin
try
Params:=TJSArrayLiteral(CreateElement(TJSArrayLiteral,Parent));
for i:=0 to Args.Count-1 do
@@ -19840,7 +19843,6 @@ begin
if Result=nil then
Params.Free;
end;
- end;
end;
procedure TPasToJSConverter.AddRTTIArgument(Arg: TPasArgument;
@@ -20146,6 +20148,7 @@ var
OptionsEl: TJSObjectLiteral;
ResultTypeInfo: TJSElement;
Call: TJSCallExpression;
+ Flags: Integer;
procedure AddOption(const aName: String; JS: TJSElement);
var
@@ -20155,8 +20158,6 @@ var
if OptionsEl=nil then
begin
OptionsEl:=TJSObjectLiteral(CreateElement(TJSObjectLiteral,Proc));
- if ResultTypeInfo=nil then
- Call.AddArg(CreateLiteralNull(Proc));
Call.AddArg(OptionsEl);
end;
ObjLit:=OptionsEl.Elements.AddElement;
@@ -20167,7 +20168,7 @@ var
var
FunName: String;
C: TClass;
- MethodKind, Flags: Integer;
+ MethodKind: Integer;
ResultEl: TPasResultElement;
ProcScope, OverriddenProcScope: TPasProcedureScope;
OverriddenClass: TPasClassType;
@@ -20225,16 +20226,8 @@ begin
// param params as []
Call.AddArg(CreateRTTIArgList(Proc,Proc.ProcType.Args,AContext));
- // param resulttype as typeinfo reference
- if C.InheritsFrom(TPasFunction) then
- begin
- ResultEl:=TPasFunction(Proc).FuncType.ResultEl;
- ResultTypeInfo:=CreateTypeInfoRef(ResultEl.ResultType,AContext,ResultEl);
- if ResultTypeInfo<>nil then
- Call.AddArg(ResultTypeInfo);
- end;
-
- // param options if needed as {}
+ // optional params:
+ ResultTypeInfo:=nil;
Flags:=0;
if Proc.IsStatic then
inc(Flags,pfStatic);
@@ -20244,9 +20237,24 @@ begin
inc(Flags,pfAsync);
if Proc.IsExternal then
inc(Flags,pfExternal);
- if Flags>0 then
- AddOption(GetBIName(pbivnRTTIProcFlags),CreateLiteralNumber(Proc,Flags));
Attr:=aResolver.GetAttributeCalls(Members,Index);
+
+ // param resulttype as typeinfo reference
+ if C.InheritsFrom(TPasFunction) then
+ begin
+ ResultEl:=TPasFunction(Proc).FuncType.ResultEl;
+ ResultTypeInfo:=CreateTypeInfoRef(ResultEl.ResultType,AContext,ResultEl);
+ if ResultTypeInfo<>nil then
+ Call.AddArg(ResultTypeInfo);
+ end;
+ if (ResultTypeInfo=nil) and ((Flags>0) or (length(Attr)>0)) then
+ Call.AddArg(CreateLiteralNull(Proc));
+
+ // flags if needed
+ if (Flags>0) or (length(Attr)>0) then
+ Call.AddArg(CreateLiteralNumber(Proc,Flags));
+
+ // param options if needed as {}
if length(Attr)>0 then
AddOption(GetBIName(pbivnRTTIMemberAttributes),
CreateRTTIAttributes(Attr,Proc,AContext));
diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas
index faadb69ff5..26afc5744c 100644
--- a/packages/pastojs/tests/tcmodules.pas
+++ b/packages/pastojs/tests/tcmodules.pas
@@ -29256,20 +29256,20 @@ begin
CheckSource('TestRTTI_ProcType',
LinesToStr([ // statements
'this.$rtti.$ProcVar("TProcA", {',
- ' procsig: rtl.newTIProcSig(null)',
+ ' procsig: rtl.newTIProcSig([])',
'});',
'this.$rtti.$MethodVar("TMethodB", {',
- ' procsig: rtl.newTIProcSig(null),',
+ ' procsig: rtl.newTIProcSig([]),',
' methodkind: 0',
'});',
'this.$rtti.$ProcVar("TProcC", {',
- ' procsig: rtl.newTIProcSig(null, 2)',
+ ' procsig: rtl.newTIProcSig([], null, 2)',
'});',
'this.$rtti.$ProcVar("TProcD", {',
' procsig: rtl.newTIProcSig([["i", rtl.longint], ["j", rtl.string, 2], ["c", rtl.char, 1], ["d", rtl.double, 4]])',
'});',
'this.$rtti.$ProcVar("TProcE", {',
- ' procsig: rtl.newTIProcSig(null, rtl.nativeint)',
+ ' procsig: rtl.newTIProcSig([], rtl.nativeint)',
'});',
'this.$rtti.$ProcVar("TProcF", {',
' procsig: rtl.newTIProcSig([["p", this.$rtti["TProcA"], 2]], rtl.nativeuint)',
@@ -29578,13 +29578,13 @@ begin
' this.Fly = function () {',
' };',
' var $r = this.$rtti;',
- ' $r.addMethod("Fly", 0, null);',
+ ' $r.addMethod("Fly", 0, []);',
'});',
'rtl.createClass(this, "TEagle", this.TBird, function () {',
' this.Fly = function () {',
' };',
' var $r = this.$rtti;',
- ' $r.addMethod("Fly", 0, null);',
+ ' $r.addMethod("Fly", 0, []);',
'});',
'']),
LinesToStr([ // $mod.$main
@@ -29760,15 +29760,11 @@ begin
' this.$final = function () {',
' };',
' var $r = this.$rtti;',
- ' $r.addMethod("Click", 0, null);',
+ ' $r.addMethod("Click", 0, []);',
' $r.addMethod("Notify", 0, [["Sender", $r]]);',
- ' $r.addMethod("GetNotify", 1, null, rtl.boolean,{flags: 4});',
- ' $r.addMethod("Println", 0, [["a", rtl.longint], ["b", rtl.longint]], null, {',
- ' flags: 2',
- ' });',
- ' $r.addMethod("Fetch", 1, [["URL", rtl.string]], rtl.word, {',
- ' flags: 20',
- ' });',
+ ' $r.addMethod("GetNotify", 1, [], rtl.boolean, 4);',
+ ' $r.addMethod("Println", 0, [["a", rtl.longint], ["b", rtl.longint]], null, 2);',
+ ' $r.addMethod("Fetch", 1, [["URL", rtl.string]], rtl.word, 20);',
'});',
'']),
LinesToStr([ // $mod.$main
@@ -30512,7 +30508,7 @@ begin
' this.$final = function () {',
' };',
' var $r = this.$rtti;',
- ' $r.addMethod("DoIt", 0, null);',
+ ' $r.addMethod("DoIt", 0, []);',
'});',
'rtl.createClass(this, "TSky", this.TObject, function () {',
' this.DoIt = function () {',
@@ -30554,14 +30550,14 @@ begin
' this.DoIt = function () {',
' };',
' var $r = this.$rtti;',
- ' $r.addMethod("DoIt", 0, null);',
+ ' $r.addMethod("DoIt", 0, []);',
'});',
'rtl.createClass(this, "TSky", this.TObject, function () {',
' this.DoIt = function () {',
' $mod.TObject.DoIt.call(this);',
' };',
' var $r = this.$rtti;',
- ' $r.addMethod("DoIt", 0, null);',
+ ' $r.addMethod("DoIt", 0, []);',
'});',
'']),
LinesToStr([ // $mod.$main
@@ -30638,7 +30634,7 @@ begin
'});',
'this.$rtti.$Class("TBridge");',
'this.$rtti.$ProcVar("TProc", {',
- ' procsig: rtl.newTIProcSig(null, this.$rtti["TBridge"])',
+ ' procsig: rtl.newTIProcSig([], this.$rtti["TBridge"])',
'});',
'rtl.createClass(this, "TOger", this.TObject, function () {',
' this.$init = function () {',
@@ -30701,7 +30697,7 @@ begin
' instancetype: this.$rtti["TObject"]',
'});',
'this.$rtti.$ProcVar("TProcA", {',
- ' procsig: rtl.newTIProcSig(null, this.$rtti["TClass"])',
+ ' procsig: rtl.newTIProcSig([], this.$rtti["TClass"])',
'});',
'rtl.createClass(this, "TObject", null, function () {',
' this.$init = function () {',
@@ -31174,10 +31170,10 @@ begin
' eltype: rtl.string',
'});',
'this.$rtti.$ProcVar("TProc", {',
- ' procsig: rtl.newTIProcSig(null)',
+ ' procsig: rtl.newTIProcSig([])',
'});',
'this.$rtti.$MethodVar("TMethod", {',
- ' procsig: rtl.newTIProcSig(null),',
+ ' procsig: rtl.newTIProcSig([]),',
' methodkind: 0',
'});',
'this.StaticArray = rtl.arraySetLength(null,"",2);',
@@ -31462,7 +31458,7 @@ begin
' null,',
' function () {',
' var $r = this.$rtti;',
- ' $r.addMethod("GetItem", 1, null, rtl.longint);',
+ ' $r.addMethod("GetItem", 1, [], rtl.longint);',
' $r.addMethod("SetItem", 0, [["Value", rtl.longint]]);',
' $r.addProperty("Item", 3, rtl.longint, "GetItem", "SetItem");',
' }',
@@ -31529,8 +31525,8 @@ begin
' this.$kind = "com";',
' var $r = this.$rtti;',
' $r.addMethod("QueryInterface", 1, [["iid", $mod.$rtti["TGuid"], 2], ["obj", null, 4]], rtl.longint);',
- ' $r.addMethod("_AddRef", 1, null, rtl.longint);',
- ' $r.addMethod("_Release", 1, null, rtl.longint);',
+ ' $r.addMethod("_AddRef", 1, [], rtl.longint);',
+ ' $r.addMethod("_Release", 1, [], rtl.longint);',
' }',
');',
'rtl.createInterface(',
@@ -31541,7 +31537,7 @@ begin
' this.IUnknown,',
' function () {',
' var $r = this.$rtti;',
- ' $r.addMethod("GetItem", 1, null, rtl.longint);',
+ ' $r.addMethod("GetItem", 1, [], rtl.longint);',
' $r.addMethod("SetItem", 0, [["Value", rtl.longint]]);',
' $r.addProperty("Item", 3, rtl.longint, "GetItem", "SetItem");',
' }',
@@ -31593,7 +31589,7 @@ begin
' return Result;',
' };',
' var $r = this.$rtti;',
- ' $r.addMethod("GetItem", 1, null, rtl.longint);',
+ ' $r.addMethod("GetItem", 1, [], rtl.longint);',
' $r.addProperty("Item", 1, rtl.longint, "GetItem", "");',
'});',
'this.t = null;',
@@ -31681,8 +31677,8 @@ begin
' pas.system.IUnknown,',
' function () {',
' var $r = this.$rtti;',
- ' $r.addMethod("Swoop", 1, null, pas.unit2.$rtti["TWordArray"]);',
- ' $r.addMethod("Glide", 1, null, pas.unit2.$rtti["TArray<System.Word>"]);',
+ ' $r.addMethod("Swoop", 1, [], pas.unit2.$rtti["TWordArray"]);',
+ ' $r.addMethod("Glide", 1, [], pas.unit2.$rtti["TArray<System.Word>"]);',
' }',
');',
'this.Fly = function () {',
@@ -31887,7 +31883,7 @@ begin
' attr: [$mod.TCustomAttribute, "Create$1", [14]]',
' }',
' );',
- ' $r.addMethod("Fly", 0, null, null, {',
+ ' $r.addMethod("Fly", 0, [], null, 0, {',
' attr: [$mod.TCustomAttribute, "Create$1", [15]]',
' });',
'});',
diff --git a/utils/pas2js/dist/rtl.js b/utils/pas2js/dist/rtl.js
index 1c5bc6914d..9209239f8c 100644
--- a/utils/pas2js/dist/rtl.js
+++ b/utils/pas2js/dist/rtl.js
@@ -1354,11 +1354,10 @@ var rtl = {
};
};
};
- tis.addMethod = function(name,methodkind,params,result,options){
+ tis.addMethod = function(name,methodkind,params,result,flags,options){
var t = this.$addMember(name,rtl.tTypeMemberMethod,options);
t.methodkind = methodkind;
- t.procsig = rtl.newTIProcSig(params);
- t.procsig.resulttype = result?result:null;
+ t.procsig = rtl.newTIProcSig(params,result?result:null,flags?flags:0);
this.methods.push(name);
return t;
};