The issue with promises used as parameter for methods was a compile time issue. I cannot see this being related to a runtime JavaScript issue.
Although I can also not directly see a relationship to an issue with _AddRef() calls, we did this week a fix in rtl.js you might test with to see if it helps. rtl.zip (11.8 KB)
This error, however, refers to a call in XData. And the problem still exists.
But I'm not sure if it has something to do with promises or is just a side effect.
I've now temporarily fixed the error.
I've modified the SendRequestAsync function in XData.Web.Connection.pas as follows:
//function TXDataWebConnection.SendRequestAsync( Request: IHttpRequest): IHttpResponse;
function TXDataWebConnection.SendRequestAsync( Request: IHttpRequest): TJSPromise;
//var
// Promise: TJSPromise;
begin
//Promise := TJSPromise.new(
Result := TJSPromise.new(
procedure(resolve, reject: TJSPromiseResolver)
begin
SendRequest(
Request,
procedure(Response: IHttpResponse)
begin
if Assigned(Response) then
Response._AddRef;
//resolve(Response);
resolve(JSValue(Response));
end,
procedure
begin
reject(Exception.Create('Request error: ' + Request.Uri));
end
);
end
);
//Exit(Promise);
end;
Due to the stricter validation, the function now returns a TJSPromise (internally as a JSValue).
I had to replace my call
Response := TAwait.Exec<IHttpResponse>( Conn.SendRequestAsync( THttpRequest.Create( myFile)));
// Wrong number of parameters specified for call to "function await(aType,TJSPromise):aType
The latest pas2js transpiler is more strict wrt async functions and check more strictly that these return a TJSPromise. So, the change to make TJSPromise the result type is correct. With TAwait, this can be caught with: