Kaynağa Gözat

pastojs: typecast jsvalue to record, bug #31982

git-svn-id: trunk@36459 -
Mattias Gaertner 8 yıl önce
ebeveyn
işleme
fbdd04b8ab

+ 5 - 1
packages/pastojs/src/fppas2js.pp

@@ -248,6 +248,7 @@ Works:
 - dotted unit names, namespaces
 
 ToDos:
+- change some == into ===
 - constant evaluation
 - static arrays
 - property index specifier
@@ -257,6 +258,7 @@ ToDos:
     - defaultvalue
   - type alias type
   - documentation
+- sourcemaps
 - move local types to unit scope
 - local var absolute
 - FuncName:= (instead of Result:=)
@@ -5449,6 +5451,7 @@ begin
       TargetProcType:=TPasProcedure(Decl).ProcType
     else if (C=TPasClassType)
         or (C=TPasClassOfType)
+        or (C=TPasRecordType)
         or (C=TPasEnumType)
         or (C=TPasArrayType) then
       begin
@@ -5465,7 +5468,8 @@ begin
         if JSBaseType=pbtJSValue then
           begin
           if (C=TPasClassType)
-              or (C=TPasClassOfType) then
+              or (C=TPasClassOfType)
+              or (C=TPasRecordType) then
             begin
             // TObject(jsvalue)  ->  rtl.getObject(jsvalue)
             Call:=CreateCallExpression(El);

+ 34 - 0
packages/pastojs/tests/tcmodules.pas

@@ -323,6 +323,7 @@ type
     Procedure TestRecordElementFromFuncResult_AsParams;
     Procedure TestRecordElementFromWith_AsParams;
     Procedure TestRecord_Equal;
+    Procedure TestRecord_TypeCastJSValueToRecord;
     // ToDo: const record
 
     // classes
@@ -5936,6 +5937,39 @@ begin
     '']));
 end;
 
+procedure TTestModule.TestRecord_TypeCastJSValueToRecord;
+begin
+  StartProgram(false);
+  Add('type');
+  Add('  TRecord = record');
+  Add('    i: longint;');
+  Add('  end;');
+  Add('var');
+  Add('  Jv: jsvalue;');
+  Add('  Rec: trecord;');
+  Add('begin');
+  Add('  rec:=trecord(jv);');
+  ConvertProgram;
+  CheckSource('TestRecord_TypeCastJSValueToRecord',
+    LinesToStr([ // statements
+    'this.TRecord = function (s) {',
+    '  if (s) {',
+    '    this.i = s.i;',
+    '  } else {',
+    '    this.i = 0;',
+    '  };',
+    '  this.$equal = function (b) {',
+    '    return this.i == b.i;',
+    '  };',
+    '};',
+    'this.Jv = undefined;',
+    'this.Rec = new $mod.TRecord();'
+    ]),
+    LinesToStr([
+    '$mod.Rec = new $mod.TRecord(rtl.getObject($mod.Jv));',
+    '']));
+end;
+
 procedure TTestModule.TestClass_TObjectDefaultConstructor;
 begin
   StartProgram(false);