mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-25 01:49:09 +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_ConcatN,
|
||||||
pbifnArray_Copy,
|
pbifnArray_Copy,
|
||||||
pbifnArray_Equal,
|
pbifnArray_Equal,
|
||||||
|
pbifnArray_Insert,
|
||||||
pbifnArray_Length,
|
pbifnArray_Length,
|
||||||
pbifnArray_Reference,
|
pbifnArray_Reference,
|
||||||
pbifnArray_SetLength,
|
pbifnArray_SetLength,
|
||||||
@ -743,6 +744,7 @@ const
|
|||||||
'arrayConcatN', // rtl.arrayConcatN pbifnArray_ConcatN
|
'arrayConcatN', // rtl.arrayConcatN pbifnArray_ConcatN
|
||||||
'arrayCopy', // rtl.arrayCopy pbifnArray_Copy
|
'arrayCopy', // rtl.arrayCopy pbifnArray_Copy
|
||||||
'arrayEq', // rtl.arrayEq pbifnArray_Equal
|
'arrayEq', // rtl.arrayEq pbifnArray_Equal
|
||||||
|
'arrayInsert', // rtl.arrayCopy pbifnArray_Insert
|
||||||
'length', // rtl.length pbifnArray_Length
|
'length', // rtl.length pbifnArray_Length
|
||||||
'arrayRef', // rtl.arrayRef pbifnArray_Reference
|
'arrayRef', // rtl.arrayRef pbifnArray_Reference
|
||||||
'arraySetLength', // rtl.arraySetLength pbifnArray_SetLength
|
'arraySetLength', // rtl.arraySetLength pbifnArray_SetLength
|
||||||
@ -14379,6 +14381,8 @@ end;
|
|||||||
|
|
||||||
function TPasToJSConverter.ConvertBuiltIn_CopyArray(El: TParamsExpr;
|
function TPasToJSConverter.ConvertBuiltIn_CopyArray(El: TParamsExpr;
|
||||||
AContext: TConvertContext): TJSElement;
|
AContext: TConvertContext): TJSElement;
|
||||||
|
// convert copy(Arr,Start,Count)
|
||||||
|
// -> rtl.arrayCopy(type,Arr,Start,Count)
|
||||||
var
|
var
|
||||||
Param: TPasExpr;
|
Param: TPasExpr;
|
||||||
ParamResolved, ElTypeResolved: TPasResolverResult;
|
ParamResolved, ElTypeResolved: TPasResolverResult;
|
||||||
@ -14447,25 +14451,32 @@ end;
|
|||||||
|
|
||||||
function TPasToJSConverter.ConvertBuiltIn_InsertArray(El: TParamsExpr;
|
function TPasToJSConverter.ConvertBuiltIn_InsertArray(El: TParamsExpr;
|
||||||
AContext: TConvertContext): TJSElement;
|
AContext: TConvertContext): TJSElement;
|
||||||
// procedure insert(item,var array,const position)
|
// procedure insert(item,var AnArray,const position)
|
||||||
// -> array.splice(position,0,item);
|
// -> AnArray=rtl.arrayInsert(item,AnArray,position);
|
||||||
var
|
var
|
||||||
ArrEl: TJSElement;
|
|
||||||
Call: TJSCallExpression;
|
Call: TJSCallExpression;
|
||||||
|
AssignSt: TJSSimpleAssignStatement;
|
||||||
begin
|
begin
|
||||||
Result:=nil;
|
Result:=nil;
|
||||||
Call:=nil;
|
AssignSt:=nil;
|
||||||
try
|
try
|
||||||
|
// AnArray=
|
||||||
|
AssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El));
|
||||||
|
AssignSt.LHS:=ConvertExpression(El.Params[1],AContext);
|
||||||
Call:=CreateCallExpression(El);
|
Call:=CreateCallExpression(El);
|
||||||
ArrEl:=ConvertExpression(El.Params[1],AContext);
|
AssignSt.Expr:=Call;
|
||||||
Call.Expr:=CreateDotNameExpr(El,ArrEl,'splice');
|
// rtl.arrayInsert
|
||||||
Call.AddArg(ConvertExpression(El.Params[2],AContext));
|
Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),GetBIName(pbifnArray_Insert)]);
|
||||||
Call.AddArg(CreateLiteralNumber(El,0));
|
// param: item
|
||||||
Call.AddArg(ConvertExpression(El.Params[0],AContext));
|
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
|
finally
|
||||||
if Result=nil then
|
if Result=nil then
|
||||||
Call.Free;
|
AssignSt.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -486,7 +486,7 @@ begin
|
|||||||
' };',
|
' };',
|
||||||
' this.Alter = function (w) {',
|
' this.Alter = function (w) {',
|
||||||
' this.FItems = rtl.arraySetLength(this.FItems, 0, rtl.length(this.FItems) + 1);',
|
' 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);',
|
' this.FItems.splice(2, 3);',
|
||||||
' };',
|
' };',
|
||||||
'}, "TList<System.Word>");',
|
'}, "TList<System.Word>");',
|
||||||
|
@ -10533,13 +10533,13 @@ begin
|
|||||||
'this.ArrArrInt = [];',
|
'this.ArrArrInt = [];',
|
||||||
'']),
|
'']),
|
||||||
LinesToStr([ // $mod.$main
|
LinesToStr([ // $mod.$main
|
||||||
'$mod.ArrInt.splice(2, 0, 1);',
|
'$mod.ArrInt = rtl.arrayInsert(1, $mod.ArrInt, 2);',
|
||||||
'$mod.ArrInt.splice(4, 0, $mod.ArrInt[3]);',
|
'$mod.ArrInt = rtl.arrayInsert($mod.ArrInt[3], $mod.ArrInt, 4);',
|
||||||
'$mod.ArrRec.splice(6, 0, $mod.ArrRec[5]);',
|
'$mod.ArrRec = rtl.arrayInsert($mod.ArrRec[5], $mod.ArrRec, 6);',
|
||||||
'$mod.ArrSet.splice(7, 0, $mod.ArrSet[7]);',
|
'$mod.ArrSet = rtl.arrayInsert($mod.ArrSet[7], $mod.ArrSet, 7);',
|
||||||
'$mod.ArrJSValue.splice(9, 0, $mod.ArrJSValue[8]);',
|
'$mod.ArrJSValue = rtl.arrayInsert($mod.ArrJSValue[8], $mod.ArrJSValue, 9);',
|
||||||
'$mod.ArrJSValue.splice(11, 0, 10);',
|
'$mod.ArrJSValue = rtl.arrayInsert(10, $mod.ArrJSValue, 11);',
|
||||||
'$mod.ArrArrInt.splice(22, 0, [23]);',
|
'$mod.ArrArrInt = rtl.arrayInsert([23], $mod.ArrArrInt, 22);',
|
||||||
'$mod.ArrInt.splice(12, 13);',
|
'$mod.ArrInt.splice(12, 13);',
|
||||||
'$mod.ArrRec.splice(14, 15);',
|
'$mod.ArrRec.splice(14, 15);',
|
||||||
'$mod.ArrSet.splice(17, 18);',
|
'$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){
|
setCharAt: function(s,index,c){
|
||||||
return s.substr(0,index)+c+s.substr(index+1);
|
return s.substr(0,index)+c+s.substr(index+1);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user