Procházet zdrojové kódy

pastojs: default property rtti visibility publishedpublic

mattias před 6 měsíci
rodič
revize
6c7d2f6bac

+ 9 - 7
packages/pastojs/src/fppas2js.pp

@@ -567,7 +567,9 @@ const
   ExtRTTIVisPublic = 2;
   ExtRTTIVisPublished = 3;
   ExtRTTIVisPublicPublished = 4; // in source published, in RTTI public
-  ExtRTTIVisDefault = ExtRTTIVisPublic;
+  ExtRTTIVisDefaultField = ExtRTTIVisPublic;
+  ExtRTTIVisDefaultMethod = ExtRTTIVisPublic;
+  ExtRTTIVisDefaultProperty = ExtRTTIVisPublicPublished;
 
 type
   TPas2JSBuiltInName = (
@@ -20793,7 +20795,7 @@ var
     if JS=nil then exit;
     if OptionsEl=nil then
       begin
-      if ExtVis=ExtRTTIVisDefault then
+      if ExtVis=ExtRTTIVisDefaultField then
         AddExtRTTIVisibility;
       OptionsEl:=TJSObjectLiteral(CreateElement(TJSObjectLiteral,V));
       Call.AddArg(OptionsEl);
@@ -20852,7 +20854,7 @@ begin
     // param typeinfo
     Call.AddArg(JSTypeInfo);
     // extended RTTI
-    if ExtVis<>ExtRTTIVisDefault then
+    if ExtVis<>ExtRTTIVisDefaultField then
       AddExtRTTIVisibility;
 
     // param options if needed as {}
@@ -20892,7 +20894,7 @@ var
     if JS=nil then exit;
     if OptionsEl=nil then
       begin
-      if ExtVis=ExtRTTIVisDefault then
+      if ExtVis=ExtRTTIVisDefaultMethod then
         AddExtRTTIVisibility;
       OptionsEl:=TJSObjectLiteral(CreateElement(TJSObjectLiteral,Proc));
       Call.AddArg(OptionsEl);
@@ -20965,7 +20967,7 @@ begin
 
     // add visibility
     ExtVis:=GetExtRTTIVisibilityParam(Proc,ParentEl.RTTIVisibility.Fields);
-    if ExtVis<>ExtRTTIVisDefault then
+    if ExtVis<>ExtRTTIVisDefaultMethod then
       AddExtRTTIVisibility;
 
     // optional params:
@@ -21035,7 +21037,7 @@ var
     if JS=nil then exit;
     if OptionsEl=nil then
       begin
-      if ExtVis=ExtRTTIVisDefault then
+      if ExtVis=ExtRTTIVisDefaultProperty then
         AddExtRTTIVisibility;
       OptionsEl:=TJSObjectLiteral(CreateElement(TJSObjectLiteral,Prop));
       Call.AddArg(OptionsEl);
@@ -21140,7 +21142,7 @@ begin
 
     // add visibility
     ExtVis:=GetExtRTTIVisibilityParam(Prop,ParentEl.RTTIVisibility.Fields);
-    if ExtVis<>ExtRTTIVisDefault then
+    if ExtVis<>ExtRTTIVisDefaultProperty then
       AddExtRTTIVisibility;
 
     // add option "index"

+ 24 - 25
packages/pastojs/tests/tcmodules.pas

@@ -19123,7 +19123,7 @@ begin
     '    this.FSwiper = undefined;',
     '  };',
     '  var $r = this.$rtti;',
-    '  $r.addProperty("Swiper", 0, $mod.$rtti["JSwiper"], "FSwiper", "FSwiper", 4);',
+    '  $r.addProperty("Swiper", 0, $mod.$rtti["JSwiper"], "FSwiper", "FSwiper");',
     '});',
     '']),
     LinesToStr([ // $mod.$main
@@ -19221,8 +19221,8 @@ begin
     '  };',
     '  var $r = this.$rtti;',
     '  $r.addField("FDate", rtl.string, 4);',
-    '  $r.addProperty("Date", 0, rtl.string, "FDate", "FDate", 4);',
-    '  $r.addProperty("ExtA", 0, rtl.string, "FDate", "FDate", 4);',
+    '  $r.addProperty("Date", 0, rtl.string, "FDate", "FDate");',
+    '  $r.addProperty("ExtA", 0, rtl.string, "FDate", "FDate");',
     '});',
     'this.B = null;',
     'this.o = null;',
@@ -31918,9 +31918,9 @@ begin
     '  this.$final = function () {',
     '  };',
     '  var $r = this.$rtti;',
-    '  $r.addProperty("ColorA", 0, rtl.longint, "FColor", "", 4);',
-    '  $r.addProperty("ColorB", 0, rtl.longint, "", "FColor", 4);',
-    '  $r.addProperty("ColorC", 3, rtl.longint, "GetColor", "SetColor", 4);',
+    '  $r.addProperty("ColorA", 0, rtl.longint, "FColor", "");',
+    '  $r.addProperty("ColorB", 0, rtl.longint, "", "FColor");',
+    '  $r.addProperty("ColorC", 3, rtl.longint, "GetColor", "SetColor");',
     '  $r.addProperty(',
     '    "ColorD",',
     '    8,',
@@ -31932,7 +31932,7 @@ begin
     '      stored: "FColorStored"',
     '    }',
     '  );',
-    '  $r.addProperty("ExtSizeA", 0, rtl.longint, "$extSize", "$extSize", 4);',
+    '  $r.addProperty("ExtSizeA", 0, rtl.longint, "$extSize", "$extSize");',
     '  $r.addProperty(',
     '    "ExtSizeB",',
     '    11,',
@@ -31988,8 +31988,8 @@ begin
     '  this.$final = function () {',
     '  };',
     '  var $r = this.$rtti;',
-    '  $r.addProperty("Items", 3, $r, "GetItems", "SetItems", 4);',
-    '  $r.addProperty("Values", 3, rtl.char, "GetValues", "SetValues", 4);',
+    '  $r.addProperty("Items", 3, $r, "GetItems", "SetItems");',
+    '  $r.addProperty("Values", 3, rtl.char, "GetValues", "SetValues");',
     '});',
     '']),
     LinesToStr([ // $mod.$main
@@ -32042,14 +32042,13 @@ begin
     '    "SetWord",',
     '    1',
     '  );',
-    '  $r.addProperty("PublicWord", 1, rtl.word, "GetWord", "");',
+    '  $r.addProperty("PublicWord", 1, rtl.word, "GetWord", "", 2);',
     '  $r.addProperty(',
     '    "PublishedWord",',
     '    0,',
     '    rtl.word,',
     '    "FWord",',
-    '    "",',
-    '    4',
+    '    ""',
     '  );',
     '});',
     '']),
@@ -32095,9 +32094,9 @@ begin
     '  this.$final = function () {',
     '  };',
     '  var $r = this.$rtti;',
-    '  $r.addProperty("Color", 0, pas.unit1.$rtti["TColor"], "fColor", "", 4);',
-    '  $r.addProperty("Alias", 0, pas.unit1.$rtti["TColor"], "fAlias", "", 4);',
-    '  $r.addProperty("TypeAlias", 0, $mod.$rtti["TColorTypeAlias"], "fTypeAlias", "", 4);',
+    '  $r.addProperty("Color", 0, pas.unit1.$rtti["TColor"], "fColor", "");',
+    '  $r.addProperty("Alias", 0, pas.unit1.$rtti["TColor"], "fAlias", "");',
+    '  $r.addProperty("TypeAlias", 0, $mod.$rtti["TColorTypeAlias"], "fTypeAlias", "");',
     '});',
     '']),
     LinesToStr([ // $mod.$main
@@ -32283,8 +32282,8 @@ begin
     '  this.$final = function () {',
     '  };',
     '  var $r = this.$rtti;',
-    '  $r.addProperty("BoolA", 0, rtl.boolean, "FB", "", 4);',
-    '  $r.addProperty("BoolB", 4, rtl.boolean, "FB", "", 4);',
+    '  $r.addProperty("BoolA", 0, rtl.boolean, "FB", "");',
+    '  $r.addProperty("BoolB", 4, rtl.boolean, "FB", "");',
     '  $r.addProperty(',
     '    "BoolC",',
     '    8,',
@@ -32296,7 +32295,7 @@ begin
     '      stored: "FB"',
     '    }',
     '  );',
-    '  $r.addProperty("BoolD", 0, rtl.boolean, "FB", "", 4);',
+    '  $r.addProperty("BoolD", 0, rtl.boolean, "FB", "");',
     '  $r.addProperty(',
     '    "BoolE",',
     '    12,',
@@ -32637,7 +32636,7 @@ begin
     '      Default: 1',
     '    }',
     '  );',
-    '  $r.addProperty("B", 0, rtl.byte, "FB", "", 4);',
+    '  $r.addProperty("B", 0, rtl.byte, "FB", "");',
     '});',
     '']),
     LinesToStr([ // $mod.$main
@@ -32750,11 +32749,11 @@ begin
     '  this.$final = function () {',
     '  };',
     '  var $r = this.$rtti;',
-    '  $r.addProperty("Flag", 0, rtl.longint, "FFlag", "", 4);',
+    '  $r.addProperty("Flag", 0, rtl.longint, "FFlag", "");',
     '});',
     'rtl.createClass(this, "TSky", this.TObject, function () {',
     '  var $r = this.$rtti;',
-    '  $r.addProperty("Flag", 0, rtl.longint, "", "FFlag", 4);',
+    '  $r.addProperty("Flag", 0, rtl.longint, "", "FFlag");',
     '});',
     '']),
     LinesToStr([ // $mod.$main
@@ -32808,7 +32807,7 @@ begin
     '  var $r = this.$rtti;',
     '  $r.addField("FBridge", $mod.$rtti["TBridge"], 4);',
     '  $r.addMethod("SetBridge", 0, [["Value", $mod.$rtti["TBridge"]]], 4);',
-    '  $r.addProperty("Bridge", 2, $mod.$rtti["TBridge"], "FBridge", "SetBridge", 4);',
+    '  $r.addProperty("Bridge", 2, $mod.$rtti["TBridge"], "FBridge", "SetBridge");',
     '});',
     'rtl.createClass(this, "TBridge", this.TObject, function () {',
     '  this.$init = function () {',
@@ -33620,7 +33619,7 @@ begin
     '    var $r = this.$rtti;',
     '    $r.addMethod("GetItem", 1, [], rtl.longint);',
     '    $r.addMethod("SetItem", 0, [["Value", rtl.longint]]);',
-    '    $r.addProperty("Item", 3, rtl.longint, "GetItem", "SetItem");',
+    '    $r.addProperty("Item", 3, rtl.longint, "GetItem", "SetItem", 2);',
     '  }',
     ');',
     'this.DoIt = function (t) {',
@@ -33699,7 +33698,7 @@ begin
     '    var $r = this.$rtti;',
     '    $r.addMethod("GetItem", 1, [], rtl.longint);',
     '    $r.addMethod("SetItem", 0, [["Value", rtl.longint]]);',
-    '    $r.addProperty("Item", 3, rtl.longint, "GetItem", "SetItem");',
+    '    $r.addProperty("Item", 3, rtl.longint, "GetItem", "SetItem", 2);',
     '  }',
     ');',
     'this.i = null;',
@@ -33750,7 +33749,7 @@ begin
     '  };',
     '  var $r = this.$rtti;',
     '  $r.addMethod("GetItem", 1, [], 4, rtl.longint);',
-    '  $r.addProperty("Item", 1, rtl.longint, "GetItem", "", 4);',
+    '  $r.addProperty("Item", 1, rtl.longint, "GetItem", "");',
     '});',
     'this.t = null;',
     '']),

+ 4 - 4
utils/pas2js/dist/rtl.js

@@ -1393,14 +1393,14 @@ var rtl = {
       t.name = name;
       this.members[name] = t;
       this.names.push(name);
-      t.visibility = vis?vis:2;
+      t.visibility = vis;
       if (rtl.isObject(options)){
         for (var key in options) if (options.hasOwnProperty(key)) t[key] = options[key];
       };
       return t;
     };
     tis.addField = function(name,type,vis,options){
-      var t = this.$addMember(name,rtl.tTypeMemberField,vis,options);
+      var t = this.$addMember(name,rtl.tTypeMemberField,vis?vis:2,options);
       if (rtl.debug_rtti){
         if (!rtl.is(type,rtl.tTypeInfo)) throw 'invalid type "'+type+'", "'+this.name+'.'+name+'"';
       };
@@ -1421,14 +1421,14 @@ var rtl = {
       };
     };
     tis.addMethod = function(name,methodkind,params,vis,result,flags,options){
-      var t = this.$addMember(name,rtl.tTypeMemberMethod,vis,options);
+      var t = this.$addMember(name,rtl.tTypeMemberMethod,vis?vis:2,options);
       t.methodkind = methodkind;
       t.procsig = rtl.newTIProcSig(params,result,flags);
       this.methods.push(name);
       return t;
     };
     tis.addProperty = function(name,flags,result,getter,setter,vis,options){
-      var t = this.$addMember(name,rtl.tTypeMemberProperty,vis,options);
+      var t = this.$addMember(name,rtl.tTypeMemberProperty,vis?vis:4,options);
       t.flags = flags;
       t.typeinfo = result;
       t.getter = getter;