#1 2019-08-14 09:57:55

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Bug in jsval?

I think jsval.asDouble have some problem, if I set a double it works:

function test(aData: double): double; <-- aData = 200.45
var
  myvar: jsval;
begin
  myvar.asDouble := aData;
  Result myvar.asDouble  <-- return 200.45
end;

but if I set a integer it doesn't work:

function test(aData: double): double; <-- aData = 200
var
  myvar: jsval;
begin
  myvar.asDouble := aData;
  Result myvar.asDouble  <-- return NAN
end;

I know that I can use jsval.asInteger but in my case I don't know if entry variable is a integer or double (generally it is double but in some case an integer). Anyhow I think asDouble should handle this.

Offline

#2 2019-08-14 12:04:51

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,539
Website

Re: Bug in jsval?

Setter works correctly - there is an if inside setter and in case actual value is integer we assign int to jsval and set a jsval type to int.

So before use a getter you should check the actual variable type

if myvar.isDouble then
  myvar.asDouble
else if myvar.isInteger then
  myvar.asInteger
else
  throw

Offline

Board footer

Powered by FluxBB