From 9720420ef24466f2b5cf126b727379a0bf59cf06 Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 1 Sep 2020 22:05:50 +0000 Subject: [PATCH] pastojs: fixed concat(a) calling arrayRef --- compiler/packages/pastojs/src/fppas2js.pp | 4 +++- compiler/packages/pastojs/tests/tcmodules.pas | 8 ++++---- compiler/utils/pas2js/dist/rtl.js | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/compiler/packages/pastojs/src/fppas2js.pp b/compiler/packages/pastojs/src/fppas2js.pp index 26c5022..1cd99ae 100644 --- a/compiler/packages/pastojs/src/fppas2js.pp +++ b/compiler/packages/pastojs/src/fppas2js.pp @@ -11930,7 +11930,7 @@ begin {$IFDEF VerbosePas2JS} writeln('TPasToJSConverter.ConvertBuiltInConcatArray Count=',length(El.Params)); {$ENDIF} - Result:=ConvertExpression(Param0,AContext); + Result:=CreateArrayRef(El,ConvertExpression(Param0,AContext)); end else begin @@ -15881,6 +15881,8 @@ function TPasToJSConverter.CreateArrayRef(El: TPasElement; ArrayExpr: TJSElement var Call: TJSCallExpression; begin + if ArrayExpr is TJSArrayLiteral then + exit(ArrayExpr); Call:=CreateCallExpression(El); Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),GetBIName(pbifnArray_Reference)]); Call.AddArg(ArrayExpr); diff --git a/compiler/packages/pastojs/tests/tcmodules.pas b/compiler/packages/pastojs/tests/tcmodules.pas index 4246b70..50e51eb 100644 --- a/compiler/packages/pastojs/tests/tcmodules.pas +++ b/compiler/packages/pastojs/tests/tcmodules.pas @@ -9559,16 +9559,16 @@ begin 'this.ArrJSValue = [];', '']), 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);', - '$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);', - '$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);', - '$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);', '$mod.ArrInt = rtl.arrayConcatN([1], $mod.ArrInt);', diff --git a/compiler/utils/pas2js/dist/rtl.js b/compiler/utils/pas2js/dist/rtl.js index fbd570c..6d55b0e 100644 --- a/compiler/utils/pas2js/dist/rtl.js +++ b/compiler/utils/pas2js/dist/rtl.js @@ -944,7 +944,7 @@ var rtl = { var src = arguments[i]; if (src === null) continue; if (a===null){ - a=src; // Note: concat(a) does not clone + a=rtl.arrayRef(src); // Note: concat(a) does not clone } else { a=a.concat(src); }