Browse Source

pastojs: if jsvalue then, while jsvalue do, repeat until jsvalue

git-svn-id: trunk@35888 -
Mattias Gaertner 8 years ago
parent
commit
9464a009a8
2 changed files with 41 additions and 2 deletions
  1. 15 2
      packages/pastojs/src/fppas2js.pp
  2. 26 0
      packages/pastojs/tests/tcmodules.pas

+ 15 - 2
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>
 - $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

+ 26 - 0
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);