From 9464a009a8f6a3f8e07016ed066b45a77e2fa9f3 Mon Sep 17 00:00:00 2001 From: Mattias Gaertner Date: Sat, 22 Apr 2017 09:16:37 +0000 Subject: [PATCH] pastojs: if jsvalue then, while jsvalue do, repeat until jsvalue git-svn-id: trunk@35888 - --- packages/pastojs/src/fppas2js.pp | 17 +++++++++++++++-- packages/pastojs/tests/tcmodules.pas | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp index f6a1b67ce2..4823d0684f 100644 --- a/packages/pastojs/src/fppas2js.pp +++ b/packages/pastojs/src/fppas2js.pp @@ -245,7 +245,11 @@ Works: - use 0o for octal literals ToDos: -- bark if there is an overload in the same unit with same signature +- if jsvalue then +- constant evaluation +- integer ranges +- static arrays +- property index specifier - RTTI - stored false/true - class property @@ -259,7 +263,6 @@ ToDos: - $modeswitch -> define - $modeswitch- -> turn off - check memleaks -- integer range - @@ compare method in delphi mode - make records more lightweight - dotted unit names, namespaces @@ -848,6 +851,8 @@ type procedure FinishVariable(El: TPasVariable); override; procedure FinishProcedureType(El: TPasProcedureType); override; procedure FinishPropertyOfClass(PropEl: TPasProperty); override; + procedure CheckConditionExpr(El: TPasExpr; + const ResolvedEl: TPasResolverResult); override; procedure CheckNewInstanceFunction(ClassScope: TPas2JSClassScope); virtual; function AddExternalName(const aName: string; El: TPasElement): TPasIdentifier; virtual; function FindExternalName(const aName: String): TPasIdentifier; virtual; @@ -2154,6 +2159,14 @@ begin end; end; +procedure TPas2JSResolver.CheckConditionExpr(El: TPasExpr; + const ResolvedEl: TPasResolverResult); +begin + if (ResolvedEl.BaseType=btCustom) and (IsJSBaseType(ResolvedEl,pbtJSValue)) then + exit; + inherited CheckConditionExpr(El, ResolvedEl); +end; + procedure TPas2JSResolver.CheckNewInstanceFunction(ClassScope: TPas2JSClassScope ); var diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas index e407325442..fae24c7a2b 100644 --- a/packages/pastojs/tests/tcmodules.pas +++ b/packages/pastojs/tests/tcmodules.pas @@ -431,6 +431,7 @@ type Procedure TestJSValue_AssignToJSValue; Procedure TestJSValue_TypeCastToBaseType; Procedure TestJSValue_Equal; + Procedure TestJSValue_If; Procedure TestJSValue_Enum; Procedure TestJSValue_ClassInstance; Procedure TestJSValue_ClassOf; @@ -10986,6 +10987,31 @@ begin ''])); end; +procedure TTestModule.TestJSValue_If; +begin + StartProgram(false); + Add([ + 'var', + ' v: jsvalue;', + 'begin', + ' if v then ;', + ' while v do ;', + ' repeat until v;', + '']); + ConvertProgram; + CheckSource('TestJSValue_If', + LinesToStr([ // statements + 'this.v = undefined;', + '']), + LinesToStr([ // $mod.$main + 'if ($mod.v) ;', + 'while($mod.v){', + '};', + 'do{', + '} while(!$mod.v);', + ''])); +end; + procedure TTestModule.TestJSValue_Enum; begin StartProgram(false);