Patiencer / fpcjs

Automatically exported from code.google.com/p/fpcjs
0 stars 0 forks source link

Negative Value #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Dear all,
I am trying to use this project with Delphi 2007. It's working, but, I am 
getting a problem with negative values.

Please, take a look at the example bellow:

var x;
var x1;

x = 10;
x1 = x*-1;

Result:
x = 10
x1 = -2147483647

Could you guys help me?

Best regards,

Marcio

Original issue reported on code.google.com by engma...@gmail.com on 3 Jul 2012 at 8:10

GoogleCodeExporter commented 9 years ago
Works for me (Windows 7 64bit, delphi 7)
Try attached dlls.

Original comment by Dusan.Ha...@gmail.com on 4 Jul 2012 at 5:50

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thanks a lot for your feedback. I found the problem:
I made some comments in the function JSValToInt 

function JSValToInt(val: jsval): Integer;
begin
  Result := val shr 1;
  //shr doesn't handle signed types in the same way as C. If the source was
  //negative then merge in the missing 1 in position 31.
  //{$IFDEF FPC} ****COMMENT
  if val < 0 then
    Result := Result-maxint-1;
  //{$ELSE} ****COMMENT
  //if val < 0 then
    //Result := -Result;
  //{$ENDIF} ****COMMENT
end;

Original comment by engma...@gmail.com on 4 Jul 2012 at 12:40

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Checkout new version, I added 4 functions to TFpcJsScript for direct typecast, 
that double version works for your case.

    function GetValueAsInteger(APropertyName : string) : integer; 
    function GetValueAsDouble(APropertyName : string) : double; 
    function GetValueAsString(APropertyName : string) : string; 
    function GetValueAsBoolean(APropertyName : string) : boolean; 

I was able to reproduce it althought I'm not sure what is causing this 
behaviour on delphi, I use it mostly in fpc. The results of test6 on windows 
are:

USING FPC on windows:

  a in script = 10
  b in script = -10

  a in pascal = 10
  b in pascal = -10
  a in pascal = 10 (AsInteger)
  b in pascal = -10 (AsInteger)
  integer(a) in pascal = 10 (AsInteger)
  integer(b) in pascal = -10 (AsInteger)
  a in pascal = 10.0000000000 (AsDouble)
  b in pascal = -10.0000000000 (AsDouble)

USING DELPHI 7 on windows 7 64 bit:

  a in script = 10
  b in script = -2147483638

  a in pascal = 10
  b in pascal = -2147483638
  a in pascal = 10 (AsInteger)
  b in pascal = -2147483638 (AsInteger)
  integer(a) in pascal = 10 (AsInteger)
  integer(b) in pascal = -2147483638 (AsInteger)
  a in pascal = 10.0000000000 (AsDouble)
  b in pascal = -10.0000000000 (AsDouble)

Original comment by Dusan.Ha...@gmail.com on 4 Jul 2012 at 12:50

GoogleCodeExporter commented 9 years ago
Perfect, I commited fixed js15decl.pas, thank you very much.

Original comment by Dusan.Ha...@gmail.com on 6 Jul 2012 at 5:45

GoogleCodeExporter commented 9 years ago
Marking as fixed

Original comment by Dusan.Ha...@gmail.com on 6 Jul 2012 at 5:45