Patiencer / fpcjs

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

Unable to call JS Function #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. This is my code

var
  JSRuntime: TFpcJsRuntime;
  JSScript: TFpcJsScript;
  sum : Variant;
  parsed : boolean;

procedure show;
begin
  JSRuntime := TFpcJsRunTime.Create();
  JSScript := JSRuntime.CreateScript();
  parsed := JSScript.Evaluate('function fact(n) { if (n <= 1) return 1; return n * fact(n-1); }');
  //parsed := JSScript.EvaluateFile('test.js');
  sum := JSScript.Call('fact', [5]);

  setsess('foo', 'bar');
  JSScript.SetValue('n',123);
  outln('n=' + String(JSScript.GetValue('n')));
  outln('<br />fact=' + String(JSScript.Call('fact', [5])));
end;

What is the expected output? What do you see instead?
I expect a result from the JSScript.Call but receive nothing

What version of the product are you using? On what operating system?
the current in SVN

Original issue reported on code.google.com by vpsitewo...@gmail.com on 29 Jun 2010 at 5:58

GoogleCodeExporter commented 9 years ago
Please provide these details:
- Version of FPC or Delphi
- Version of libmozjs.so or js3250.dll and origin
- OS name and version, 32/64 bit?

I added your code as test4.dpr here: 
http://code.google.com/p/fpcjs/source/browse/trunk/src/test4.dpr and I tested 
in Windows XP 32bit, in both FPC 2.4.0 and Delphi 7 with js3250.dll from 
Thunderbird 2.0.0.24. I also tested it on Ubuntu 8.04 with 2.4.0 and it works 
fine.

Original comment by Dusan.Ha...@gmail.com on 29 Jun 2010 at 7:26

GoogleCodeExporter commented 9 years ago
I am currently using lazarus 0.9.28.2 beta for FPC version 2.4.0
The dll is most likely the issue then. I downloaded the javascript_bridge from 
mozdev and used it. js3215R.dll
Windows XP 32bit
I am trying the above stated dll and I will respond with my results.

Original comment by vpsitewo...@gmail.com on 29 Jun 2010 at 3:15

GoogleCodeExporter commented 9 years ago
it was the version of the DLL. so, functions are now working. Thank you much 
for your help.

Original comment by vpsitewo...@gmail.com on 29 Jun 2010 at 3:24

GoogleCodeExporter commented 9 years ago
Ok.

Original comment by Dusan.Ha...@gmail.com on 29 Jun 2010 at 3:59

GoogleCodeExporter commented 9 years ago
Your email does not work so I post reply here:

> Can I use TFpcJsScript.RegisterNative to register an object with all of its
> members into the Javascript engine?

No. I don't think so.

> Or is there currently a way to do this in the wrapper?

I just made this simple demo:

http://code.google.com/p/fpcjs/source/browse/trunk/src/test5.dpr

Original comment by Dusan.Ha...@gmail.com on 29 Jun 2010 at 8:27