setTimeout(() => { console.log("(timeout 1000) Current time: ", new Date()) });
setTimeout(() => { console.log("(timeout 1000) Current time: ", new Date()) }, 1000);
setTimeout(c => { c.log("(timeout 1000) Current time: ", new Date()) }, 1000, console);
Such a script will run fine on Windows (i386-win32). However, it will fail on Windows (x86_64) with the following error:
This issue was observed on Delphi 10.1 Berlin. It seems like this issue happens in the PostTimedTask
method because the FuncArgs
variable is declared as an array[0..0] of JsValueRef
instead of an array of JsValueRef
. I was able to fix the issue by changing the PostTimedTask
method like so:
function PostTimedTask(Args: PJsValueRefArray; ArgCount: Word; CallbackState: Pointer; RepeatCount: Integer): JsValueRef;
var
DataModule: TDataModuleMain absolute CallbackState;
AMessage: TTaskMessage;
Delay: Cardinal;
FuncArgs: array of JsValueRef;
I: Integer;
begin
Result := JsUndefinedValue;
if ArgCount < 2 then // thisarg, function to call, optional: delay, function args
raise Exception.Create('Invalid arguments');
if ArgCount >= 3 then
Delay := JsNumberToInt(Args^[2])
else
Delay := 0;
if ArgCount >= 4 then
begin
SetLength(FuncArgs, ArgCount - 3);
for I := 0 to ArgCount - 4 do
FuncArgs[I] := Args^[I + 3];
end;
AMessage := TTaskMessage.Create(DataModule.Context, Args^[1], Args^[0], FuncArgs, Delay, RepeatCount);
try
DataModule.Context.PostMessage(AMessage);
except
AMessage.Free;
raise;
end;
end;
My fix would also need to be tested on the FreePascal compiler and on the Linux and Darwin platforms.
Let me know your thoughts and if you are open to me making further tests and creating a PR.