mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 13:06:18 +02:00
pastojs: fixed helpers pass args
git-svn-id: trunk@41298 -
This commit is contained in:
parent
739723bc54
commit
ddaac687d4
@ -7305,13 +7305,13 @@ begin
|
|||||||
begin
|
begin
|
||||||
RightRefDecl:=aResolver.GetPasPropertySetter(TPasProperty(RightRefDecl));
|
RightRefDecl:=aResolver.GetPasPropertySetter(TPasProperty(RightRefDecl));
|
||||||
if RightRefDecl=nil then
|
if RightRefDecl=nil then
|
||||||
RaiseNotSupported(RightEl,AContext,20190128153754);
|
DoError(20190211111137,nNoMemberIsProvidedToAccessProperty,sNoMemberIsProvidedToAccessProperty,[],RightEl);
|
||||||
end;
|
end;
|
||||||
caRead:
|
caRead:
|
||||||
begin
|
begin
|
||||||
RightRefDecl:=aResolver.GetPasPropertyGetter(TPasProperty(RightRefDecl));
|
RightRefDecl:=aResolver.GetPasPropertyGetter(TPasProperty(RightRefDecl));
|
||||||
if RightRefDecl=nil then
|
if RightRefDecl=nil then
|
||||||
RaiseNotSupported(RightEl,AContext,20190128153829);
|
DoError(20190211111038,nNoMemberIsProvidedToAccessProperty,sNoMemberIsProvidedToAccessProperty,[],RightEl);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -17189,7 +17189,9 @@ var
|
|||||||
|
|
||||||
PathExpr:=nil;
|
PathExpr:=nil;
|
||||||
SetterArgName:='';
|
SetterArgName:='';
|
||||||
if LeftJS.ClassType=TJSLiteral then
|
if LeftJS=nil then
|
||||||
|
DoError(20190211105946,nNoMemberIsProvidedToAccessProperty,sNoMemberIsProvidedToAccessProperty,[],PosEl)
|
||||||
|
else if LeftJS.ClassType=TJSLiteral then
|
||||||
begin
|
begin
|
||||||
// getter is a const
|
// getter is a const
|
||||||
// convert to {get:function(){return value},set:function(v){ error }}
|
// convert to {get:function(){return value},set:function(v){ error }}
|
||||||
@ -17389,14 +17391,14 @@ begin
|
|||||||
RaiseNotSupported(PosEl,AContext,20190201163453,GetResolverResultDbg(LeftResolved));
|
RaiseNotSupported(PosEl,AContext,20190201163453,GetResolverResultDbg(LeftResolved));
|
||||||
if (IdentEl is TPasClassType) then
|
if (IdentEl is TPasClassType) then
|
||||||
begin
|
begin
|
||||||
// ClassType.HelperCall -> HelperType.HelperCall.apply(ClassType,args?)
|
// ClassType.HelperCall -> HelperType.HelperCall.call(ClassType,args?)
|
||||||
if TPasClassType(LeftResolved.IdentEl).IsExternal then
|
if TPasClassType(LeftResolved.IdentEl).IsExternal then
|
||||||
RaiseNotSupported(PosEl,AContext,20190201165636);
|
RaiseNotSupported(PosEl,AContext,20190201165636);
|
||||||
SelfJS:=CreateReferencePathExpr(LeftResolved.IdentEl,AContext);
|
SelfJS:=CreateReferencePathExpr(LeftResolved.IdentEl,AContext);
|
||||||
end
|
end
|
||||||
else if (LoTypeEl.ClassType=TPasClassType) and (rrfReadable in LeftResolved.Flags) then
|
else if (LoTypeEl.ClassType=TPasClassType) and (rrfReadable in LeftResolved.Flags) then
|
||||||
begin
|
begin
|
||||||
// ClassInstance.HelperCall -> HelperType.HelperCall.apply(ClassInstance.$class,args?)
|
// ClassInstance.HelperCall -> HelperType.HelperCall.call(ClassInstance.$class,args?)
|
||||||
if TPasClassType(LeftResolved.LoTypeEl).IsExternal then
|
if TPasClassType(LeftResolved.LoTypeEl).IsExternal then
|
||||||
RaiseNotSupported(PosEl,AContext,20190201165656);
|
RaiseNotSupported(PosEl,AContext,20190201165656);
|
||||||
SelfJS:=ConvertLeftExpr;
|
SelfJS:=ConvertLeftExpr;
|
||||||
@ -17405,7 +17407,7 @@ begin
|
|||||||
end
|
end
|
||||||
else if (LoTypeEl.ClassType=TPasClassOfType) and (rrfReadable in LeftResolved.Flags) then
|
else if (LoTypeEl.ClassType=TPasClassOfType) and (rrfReadable in LeftResolved.Flags) then
|
||||||
begin
|
begin
|
||||||
// ClassOfVar.HelperCall -> HelperType.HelperCall.apply(ClassOfVar,args?)
|
// ClassOfVar.HelperCall -> HelperType.HelperCall.call(ClassOfVar,args?)
|
||||||
SelfJS:=ConvertLeftExpr;
|
SelfJS:=ConvertLeftExpr;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -17419,7 +17421,7 @@ begin
|
|||||||
RaiseNotSupported(PosEl,AContext,20190201170843);
|
RaiseNotSupported(PosEl,AContext,20190201170843);
|
||||||
if (LoTypeEl is TPasClassType) and (rrfReadable in LeftResolved.Flags) then
|
if (LoTypeEl is TPasClassType) and (rrfReadable in LeftResolved.Flags) then
|
||||||
begin
|
begin
|
||||||
// ClassInstance.HelperCall -> HelperType.HelperCall.apply(ClassInstance,args?)
|
// ClassInstance.HelperCall -> HelperType.HelperCall.call(ClassInstance,args?)
|
||||||
SelfJS:=ConvertLeftExpr;
|
SelfJS:=ConvertLeftExpr;
|
||||||
end
|
end
|
||||||
else if HelperForType.ClassType=TPasClassType then
|
else if HelperForType.ClassType=TPasClassType then
|
||||||
@ -17427,7 +17429,7 @@ begin
|
|||||||
RaiseNotSupported(PosEl,AContext,20190203171241)
|
RaiseNotSupported(PosEl,AContext,20190203171241)
|
||||||
else if (LoTypeEl is TPasRecordType) and (rrfReadable in LeftResolved.Flags) then
|
else if (LoTypeEl is TPasRecordType) and (rrfReadable in LeftResolved.Flags) then
|
||||||
begin
|
begin
|
||||||
// RecordInstance.HelperCall -> HelperType.HelperCall.apply(RecordInstance,args?)
|
// RecordInstance.HelperCall -> HelperType.HelperCall.call(RecordInstance,args?)
|
||||||
SelfJS:=ConvertLeftExpr;
|
SelfJS:=ConvertLeftExpr;
|
||||||
end
|
end
|
||||||
else if IdentEl<>nil then
|
else if IdentEl<>nil then
|
||||||
@ -17440,7 +17442,7 @@ begin
|
|||||||
or (C=TPasResultElement)
|
or (C=TPasResultElement)
|
||||||
or (C=TPasEnumValue) then
|
or (C=TPasEnumValue) then
|
||||||
begin
|
begin
|
||||||
// Left.HelperCall -> HelperType.HelperCall.apply({get,set},args?)
|
// Left.HelperCall -> HelperType.HelperCall.call({get,set},args?)
|
||||||
SelfJS:=CreateReference(PosEl,LeftResolved);
|
SelfJS:=CreateReference(PosEl,LeftResolved);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -17448,12 +17450,12 @@ begin
|
|||||||
end
|
end
|
||||||
else if (LeftResolved.ExprEl<>nil) and (rrfReadable in LeftResolved.Flags) then
|
else if (LeftResolved.ExprEl<>nil) and (rrfReadable in LeftResolved.Flags) then
|
||||||
begin
|
begin
|
||||||
// LeftExpr.HelperCall -> HelperType.HelperCall.apply({get,set},args?)
|
// LeftExpr.HelperCall -> HelperType.HelperCall.call({get,set},args?)
|
||||||
SelfJS:=CreateReference(PosEl,LeftResolved);
|
SelfJS:=CreateReference(PosEl,LeftResolved);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
// Literal.HelperCall -> HelperType.HelperCall.apply({p: Literal,get,set},args?)
|
// Literal.HelperCall -> HelperType.HelperCall.call({p: Literal,get,set},args?)
|
||||||
{$IFDEF VerbosePas2JS}
|
{$IFDEF VerbosePas2JS}
|
||||||
writeln('TPasToJSConverter.CreateCallHelperMethod Left=',GetObjName(Left),' LeftResolved=',GetResolverResultDbg(LeftResolved));
|
writeln('TPasToJSConverter.CreateCallHelperMethod Left=',GetObjName(Left),' LeftResolved=',GetResolverResultDbg(LeftResolved));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -17500,11 +17502,11 @@ begin
|
|||||||
if (SelfJS=nil) and not IsStatic then
|
if (SelfJS=nil) and not IsStatic then
|
||||||
RaiseNotSupported(PosEl,AContext,20190203171010,GetResolverResultDbg(LeftResolved));
|
RaiseNotSupported(PosEl,AContext,20190203171010,GetResolverResultDbg(LeftResolved));
|
||||||
|
|
||||||
// create HelperType.HelperCall.apply(SelfJS)
|
// create HelperType.HelperCall.call(SelfJS)
|
||||||
Call:=CreateCallExpression(Expr);
|
Call:=CreateCallExpression(Expr);
|
||||||
ProcPath:=CreateReferencePath(Proc,AContext,rpkPathAndName);
|
ProcPath:=CreateReferencePath(Proc,AContext,rpkPathAndName);
|
||||||
if not IsStatic then
|
if not IsStatic then
|
||||||
ProcPath:=ProcPath+'.apply';
|
ProcPath:=ProcPath+'.call';
|
||||||
Call.Expr:=CreatePrimitiveDotExpr(ProcPath,Expr);
|
Call.Expr:=CreatePrimitiveDotExpr(ProcPath,Expr);
|
||||||
if SelfJS<>nil then
|
if SelfJS<>nil then
|
||||||
begin
|
begin
|
||||||
@ -17527,7 +17529,7 @@ begin
|
|||||||
caAssign:
|
caAssign:
|
||||||
begin
|
begin
|
||||||
// call property setter, e.g. left.prop:=RightSide
|
// call property setter, e.g. left.prop:=RightSide
|
||||||
// -> HelperType.HelperSetter.apply(SelfJS,RightSide)
|
// -> HelperType.HelperSetter.call(SelfJS,RightSide)
|
||||||
// append index and RightSide
|
// append index and RightSide
|
||||||
Result:=AppendPropertyAssignArgs(Call,Prop,TAssignContext(AContext),PosEl);
|
Result:=AppendPropertyAssignArgs(Call,Prop,TAssignContext(AContext),PosEl);
|
||||||
Call:=nil;
|
Call:=nil;
|
||||||
@ -17605,9 +17607,9 @@ begin
|
|||||||
// The $new function:
|
// The $new function:
|
||||||
// this.$new = function(fnname,args){
|
// this.$new = function(fnname,args){
|
||||||
// record:
|
// record:
|
||||||
// return this[fnname].call(TRecType.$new(),args);
|
// return this[fnname].apply(TRecType.$new(),args);
|
||||||
// other:
|
// other:
|
||||||
// return this[fnname].call({p:SelfJS,get,set},args);
|
// return this[fnname].apply({p:SelfJS,get,set},args);
|
||||||
// }
|
// }
|
||||||
ReturnSt:=TJSReturnStatement(CreateElement(TJSReturnStatement,El));
|
ReturnSt:=TJSReturnStatement(CreateElement(TJSReturnStatement,El));
|
||||||
AddToSourceElements(New_Src,ReturnSt);
|
AddToSourceElements(New_Src,ReturnSt);
|
||||||
@ -17617,7 +17619,7 @@ begin
|
|||||||
Call.Expr:=DotExpr;
|
Call.Expr:=DotExpr;
|
||||||
BracketExpr:=TJSBracketMemberExpression(CreateElement(TJSBracketMemberExpression,El));
|
BracketExpr:=TJSBracketMemberExpression(CreateElement(TJSBracketMemberExpression,El));
|
||||||
DotExpr.MExpr:=BracketExpr;
|
DotExpr.MExpr:=BracketExpr;
|
||||||
DotExpr.Name:='call';
|
DotExpr.Name:='apply';
|
||||||
BracketExpr.MExpr:=CreatePrimitiveDotExpr('this',El);
|
BracketExpr.MExpr:=CreatePrimitiveDotExpr('this',El);
|
||||||
BracketExpr.Name:=CreatePrimitiveDotExpr(FunName,El);
|
BracketExpr.Name:=CreatePrimitiveDotExpr(FunName,El);
|
||||||
SelfJS:=CreateValInit(HelperForType,nil,El,New_FuncContext);
|
SelfJS:=CreateValInit(HelperForType,nil,El,New_FuncContext);
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user