Browse Source

fcl-passrc: allow external class function async

git-svn-id: trunk@45518 -
Mattias Gaertner 5 years ago
parent
commit
683c5c8faf
2 changed files with 12 additions and 6 deletions
  1. 1 1
      packages/fcl-passrc/src/pasresolver.pp
  2. 11 5
      utils/pas2js/docs/translation.html

+ 1 - 1
packages/fcl-passrc/src/pasresolver.pp

@@ -6839,7 +6839,7 @@ begin
           RaiseMsg(20170216151616,nInvalidXModifierY,
           RaiseMsg(20170216151616,nInvalidXModifierY,
             sInvalidXModifierY,[GetElementTypeName(Proc),'external, '+ModifierNames[pm]],Proc);
             sInvalidXModifierY,[GetElementTypeName(Proc),'external, '+ModifierNames[pm]],Proc);
       for ptm in Proc.ProcType.Modifiers do
       for ptm in Proc.ProcType.Modifiers do
-        if not (ptm in [ptmOfObject,ptmIsNested,ptmStatic,ptmVarargs,ptmReferenceTo]) then
+        if not (ptm in [ptmOfObject,ptmIsNested,ptmStatic,ptmVarargs,ptmReferenceTo,ptmAsync]) then
           RaiseMsg(20170411171224,nInvalidXModifierY,
           RaiseMsg(20170411171224,nInvalidXModifierY,
             sInvalidXModifierY,[GetElementTypeName(Proc),'external, '+ProcTypeModifiers[ptm]],Proc);
             sInvalidXModifierY,[GetElementTypeName(Proc),'external, '+ProcTypeModifiers[ptm]],Proc);
       end;
       end;

+ 11 - 5
utils/pas2js/docs/translation.html

@@ -2994,14 +2994,15 @@ End.
 
 
     <div class="section">
     <div class="section">
     <h2 id="async">Async/AWait</h2>
     <h2 id="async">Async/AWait</h2>
-    Pas2js supports the JS operators async/await to simplify the use of Promise.
-    The await operator corresponds to two intrinsic Pas2js functions:
+    Pas2js supports the JS operators async and await to simplify the use of Promise.
+    The await operator corresponds to three intrinsic Pas2js functions:
     <ul>
     <ul>
-    <li><i>function await(const Expr: T): T;</i>  // implicit promise</li>
+    <li><i>function await(AsyncFunctionWithResultT): T;</i>  // implicit promise</li>
     <li><i>function await(aType; p: TJSPromise): aType;</i>  // explicit promise requires the resolved type</li>
     <li><i>function await(aType; p: TJSPromise): aType;</i>  // explicit promise requires the resolved type</li>
+    <li><i>function await(const Expr: T): T;</i>  // implicit promise</li>
     </ul>
     </ul>
     The await function can only be used inside a procedure with the async modifier.<br>
     The await function can only be used inside a procedure with the async modifier.<br>
-    For example:
+    Example for the explicit promise:
     <table class="sample">
     <table class="sample">
       <tbody>
       <tbody>
         <tr>
         <tr>
@@ -3030,7 +3031,7 @@ procedure AsyncCall; async;
 var s: string;
 var s: string;
 begin
 begin
   writeln('calling');
   writeln('calling');
-  s := await(string,resolveAfter2Seconds());
+  s := await(string,resolveAfter2Seconds()); // does not check if result is really a string
   writeln(s); // expected output: 'resolved'
   writeln(s); // expected output: 'resolved'
 end;
 end;
 
 
@@ -3067,6 +3068,11 @@ end.
         </tr>
         </tr>
       </tbody>
       </tbody>
     </table>
     </table>
+    Notes:
+    <ul>
+      <li>The await function does only compile time checks, no runtime checks.</li>
+      <li></li>
+    </ul>
     </div>
     </div>