Browse Source

pastojs: fixed concat(a) calling arrayRef

git-svn-id: trunk@46745 -
Mattias Gaertner 5 years ago
parent
commit
6a0ea119e9

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

@@ -13312,7 +13312,7 @@ begin
     {$IFDEF VerbosePas2JS}
     {$IFDEF VerbosePas2JS}
     writeln('TPasToJSConverter.ConvertBuiltInConcatArray Count=',length(El.Params));
     writeln('TPasToJSConverter.ConvertBuiltInConcatArray Count=',length(El.Params));
     {$ENDIF}
     {$ENDIF}
-    Result:=ConvertExpression(Param0,AContext);
+    Result:=CreateArrayRef(El,ConvertExpression(Param0,AContext));
     end
     end
   else
   else
     begin
     begin
@@ -17431,6 +17431,8 @@ function TPasToJSConverter.CreateArrayRef(El: TPasElement; ArrayExpr: TJSElement
 var
 var
   Call: TJSCallExpression;
   Call: TJSCallExpression;
 begin
 begin
+  if ArrayExpr is TJSArrayLiteral then
+    exit(ArrayExpr);
   Call:=CreateCallExpression(El);
   Call:=CreateCallExpression(El);
   Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),GetBIName(pbifnArray_Reference)]);
   Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),GetBIName(pbifnArray_Reference)]);
   Call.AddArg(ArrayExpr);
   Call.AddArg(ArrayExpr);

+ 4 - 4
packages/pastojs/tests/tcmodules.pas

@@ -9855,16 +9855,16 @@ begin
     'this.ArrJSValue = [];',
     'this.ArrJSValue = [];',
     '']),
     '']),
     LinesToStr([ // $mod.$main
     LinesToStr([ // $mod.$main
-    '$mod.ArrInt = $mod.ArrInt;',
+    '$mod.ArrInt = rtl.arrayRef($mod.ArrInt);',
     '$mod.ArrInt = rtl.arrayConcatN($mod.ArrInt, $mod.ArrInt);',
     '$mod.ArrInt = rtl.arrayConcatN($mod.ArrInt, $mod.ArrInt);',
     '$mod.ArrInt = rtl.arrayConcatN($mod.ArrInt, $mod.ArrInt, $mod.ArrInt);',
     '$mod.ArrInt = rtl.arrayConcatN($mod.ArrInt, $mod.ArrInt, $mod.ArrInt);',
-    '$mod.ArrRec = $mod.ArrRec;',
+    '$mod.ArrRec = rtl.arrayRef($mod.ArrRec);',
     '$mod.ArrRec = rtl.arrayConcat($mod.TRec, $mod.ArrRec, $mod.ArrRec);',
     '$mod.ArrRec = rtl.arrayConcat($mod.TRec, $mod.ArrRec, $mod.ArrRec);',
     '$mod.ArrRec = rtl.arrayConcat($mod.TRec, $mod.ArrRec, $mod.ArrRec, $mod.ArrRec);',
     '$mod.ArrRec = rtl.arrayConcat($mod.TRec, $mod.ArrRec, $mod.ArrRec, $mod.ArrRec);',
-    '$mod.ArrSet = $mod.ArrSet;',
+    '$mod.ArrSet = rtl.arrayRef($mod.ArrSet);',
     '$mod.ArrSet = rtl.arrayConcat("refSet", $mod.ArrSet, $mod.ArrSet);',
     '$mod.ArrSet = rtl.arrayConcat("refSet", $mod.ArrSet, $mod.ArrSet);',
     '$mod.ArrSet = rtl.arrayConcat("refSet", $mod.ArrSet, $mod.ArrSet, $mod.ArrSet);',
     '$mod.ArrSet = rtl.arrayConcat("refSet", $mod.ArrSet, $mod.ArrSet, $mod.ArrSet);',
-    '$mod.ArrJSValue = $mod.ArrJSValue;',
+    '$mod.ArrJSValue = rtl.arrayRef($mod.ArrJSValue);',
     '$mod.ArrJSValue = rtl.arrayConcatN($mod.ArrJSValue, $mod.ArrJSValue);',
     '$mod.ArrJSValue = rtl.arrayConcatN($mod.ArrJSValue, $mod.ArrJSValue);',
     '$mod.ArrJSValue = rtl.arrayConcatN($mod.ArrJSValue, $mod.ArrJSValue, $mod.ArrJSValue);',
     '$mod.ArrJSValue = rtl.arrayConcatN($mod.ArrJSValue, $mod.ArrJSValue, $mod.ArrJSValue);',
     '$mod.ArrInt = rtl.arrayConcatN([1], $mod.ArrInt);',
     '$mod.ArrInt = rtl.arrayConcatN([1], $mod.ArrInt);',

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

@@ -1003,7 +1003,7 @@ var rtl = {
       var src = arguments[i];
       var src = arguments[i];
       if (src === null) continue;
       if (src === null) continue;
       if (a===null){
       if (a===null){
-        a=src; // Note: concat(a) does not clone
+        a=rtl.arrayRef(src); // Note: concat(a) does not clone
       } else {
       } else {
         a=a.concat(src);
         a=a.concat(src);
       }
       }