mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 11:09:42 +02:00
pastojs: fixed insert(item,array,pos) when array=nil
git-svn-id: trunk@49073 -
(cherry picked from commit 97fd8638d5
)
This commit is contained in:
parent
f53a486595
commit
761d2c7551
@ -555,6 +555,7 @@ type
|
||||
pbifnArray_ConcatN,
|
||||
pbifnArray_Copy,
|
||||
pbifnArray_Equal,
|
||||
pbifnArray_Insert,
|
||||
pbifnArray_Length,
|
||||
pbifnArray_Reference,
|
||||
pbifnArray_SetLength,
|
||||
@ -743,6 +744,7 @@ const
|
||||
'arrayConcatN', // rtl.arrayConcatN pbifnArray_ConcatN
|
||||
'arrayCopy', // rtl.arrayCopy pbifnArray_Copy
|
||||
'arrayEq', // rtl.arrayEq pbifnArray_Equal
|
||||
'arrayInsert', // rtl.arrayCopy pbifnArray_Insert
|
||||
'length', // rtl.length pbifnArray_Length
|
||||
'arrayRef', // rtl.arrayRef pbifnArray_Reference
|
||||
'arraySetLength', // rtl.arraySetLength pbifnArray_SetLength
|
||||
@ -14379,6 +14381,8 @@ end;
|
||||
|
||||
function TPasToJSConverter.ConvertBuiltIn_CopyArray(El: TParamsExpr;
|
||||
AContext: TConvertContext): TJSElement;
|
||||
// convert copy(Arr,Start,Count)
|
||||
// -> rtl.arrayCopy(type,Arr,Start,Count)
|
||||
var
|
||||
Param: TPasExpr;
|
||||
ParamResolved, ElTypeResolved: TPasResolverResult;
|
||||
@ -14447,25 +14451,32 @@ end;
|
||||
|
||||
function TPasToJSConverter.ConvertBuiltIn_InsertArray(El: TParamsExpr;
|
||||
AContext: TConvertContext): TJSElement;
|
||||
// procedure insert(item,var array,const position)
|
||||
// -> array.splice(position,0,item);
|
||||
// procedure insert(item,var AnArray,const position)
|
||||
// -> AnArray=rtl.arrayInsert(item,AnArray,position);
|
||||
var
|
||||
ArrEl: TJSElement;
|
||||
Call: TJSCallExpression;
|
||||
AssignSt: TJSSimpleAssignStatement;
|
||||
begin
|
||||
Result:=nil;
|
||||
Call:=nil;
|
||||
AssignSt:=nil;
|
||||
try
|
||||
// AnArray=
|
||||
AssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El));
|
||||
AssignSt.LHS:=ConvertExpression(El.Params[1],AContext);
|
||||
Call:=CreateCallExpression(El);
|
||||
ArrEl:=ConvertExpression(El.Params[1],AContext);
|
||||
Call.Expr:=CreateDotNameExpr(El,ArrEl,'splice');
|
||||
Call.AddArg(ConvertExpression(El.Params[2],AContext));
|
||||
Call.AddArg(CreateLiteralNumber(El,0));
|
||||
AssignSt.Expr:=Call;
|
||||
// rtl.arrayInsert
|
||||
Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),GetBIName(pbifnArray_Insert)]);
|
||||
// param: item
|
||||
Call.AddArg(ConvertExpression(El.Params[0],AContext));
|
||||
Result:=Call;
|
||||
// param: AnArray
|
||||
Call.AddArg(ConvertExpression(El.Params[1],AContext));
|
||||
// param: position
|
||||
Call.AddArg(ConvertExpression(El.Params[2],AContext));
|
||||
Result:=AssignSt;
|
||||
finally
|
||||
if Result=nil then
|
||||
Call.Free;
|
||||
AssignSt.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -486,7 +486,7 @@ begin
|
||||
' };',
|
||||
' this.Alter = function (w) {',
|
||||
' this.FItems = rtl.arraySetLength(this.FItems, 0, rtl.length(this.FItems) + 1);',
|
||||
' this.FItems.splice(2, 0, w);',
|
||||
' this.FItems = rtl.arrayInsert(w, this.FItems, 2);',
|
||||
' this.FItems.splice(2, 3);',
|
||||
' };',
|
||||
'}, "TList<System.Word>");',
|
||||
|
@ -10533,13 +10533,13 @@ begin
|
||||
'this.ArrArrInt = [];',
|
||||
'']),
|
||||
LinesToStr([ // $mod.$main
|
||||
'$mod.ArrInt.splice(2, 0, 1);',
|
||||
'$mod.ArrInt.splice(4, 0, $mod.ArrInt[3]);',
|
||||
'$mod.ArrRec.splice(6, 0, $mod.ArrRec[5]);',
|
||||
'$mod.ArrSet.splice(7, 0, $mod.ArrSet[7]);',
|
||||
'$mod.ArrJSValue.splice(9, 0, $mod.ArrJSValue[8]);',
|
||||
'$mod.ArrJSValue.splice(11, 0, 10);',
|
||||
'$mod.ArrArrInt.splice(22, 0, [23]);',
|
||||
'$mod.ArrInt = rtl.arrayInsert(1, $mod.ArrInt, 2);',
|
||||
'$mod.ArrInt = rtl.arrayInsert($mod.ArrInt[3], $mod.ArrInt, 4);',
|
||||
'$mod.ArrRec = rtl.arrayInsert($mod.ArrRec[5], $mod.ArrRec, 6);',
|
||||
'$mod.ArrSet = rtl.arrayInsert($mod.ArrSet[7], $mod.ArrSet, 7);',
|
||||
'$mod.ArrJSValue = rtl.arrayInsert($mod.ArrJSValue[8], $mod.ArrJSValue, 9);',
|
||||
'$mod.ArrJSValue = rtl.arrayInsert(10, $mod.ArrJSValue, 11);',
|
||||
'$mod.ArrArrInt = rtl.arrayInsert([23], $mod.ArrArrInt, 22);',
|
||||
'$mod.ArrInt.splice(12, 13);',
|
||||
'$mod.ArrRec.splice(14, 15);',
|
||||
'$mod.ArrSet.splice(17, 18);',
|
||||
|
8
utils/pas2js/dist/rtl.js
vendored
8
utils/pas2js/dist/rtl.js
vendored
@ -1040,6 +1040,14 @@ var rtl = {
|
||||
}
|
||||
},
|
||||
|
||||
arrayInsert: function(item, arr, index){
|
||||
if (arr){
|
||||
return arr.splice(index,0,item);
|
||||
} else {
|
||||
return [item];
|
||||
}
|
||||
},
|
||||
|
||||
setCharAt: function(s,index,c){
|
||||
return s.substr(0,index)+c+s.substr(index+1);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user