#1 Re: SyNode » Adding JavaScript support for mORMot framework » 2016-07-25 18:04:11

Int

@mpv Looks exiting. I'm looking forward to see the release! Is it available already?

#3 Re: SyNode » Adding JavaScript support for mORMot framework » 2016-05-22 12:45:57

Int

@mpv, SM45 - is released (https://developer.mozilla.org/en-US/doc … eleases/45)! I'd be glad to hear if you have any plans of wrapping it! Or maybe you've done a most of work already! I'm so excited to know!

#4 Free Pascal Compiler » RTTI features provided by mORMot for FPC. » 2016-03-22 23:45:24

Int
Replies: 1

I was searching for some information about extending FPC's RTTI features and I came across mORMot. Now I'm a bit confused: is there any additional RTTI features provided by mormot for FPC?

I'd like to explain what I'd like to do:

- Get property list of Object (for published properties it works fine with typinfo unit; delphi's RTTI allows to work with public properties also, is it possible in FPC; anyway typinfo is okay so far);
- Get (and set) property value by name; (it also works with published properties via typinfo);
- Call method of Object by its name; e.g.:

function CallMethod(Object: TObject; Name: String; Params: array of Variant): Variant; // or something like that

...

CallMethod(Form1, 'SetBounds', [1, 1, 200, 200]); 

I didn't realize how to do it at all so far. There is MethodAddress, but I cannot understand how to pass arguments to found method dynamically.

If I'm not mistaken It can be done via Delphi's RTTI.Invoke; But what can I use in FPC?
I'm asking here because I found some info about mORMot's implementation of Invoke (e.g. http://forum.lazarus.freepascal.org/ind … c=30678.0)

Can it help me to call methods the way I described before?
Is there additional features in mORMot that I can use to implement some features like ones in Delphi's RTTI unit ?

#5 Re: SyNode » Adding JavaScript support for mORMot framework » 2016-03-12 13:55:08

Int

How soon is it going to happen? A didn't found SM45 release date so far sad But the question is more about your work on the wrapper. How long might it take to wrap whole api of SM for Delphi? What about compatibility between current version and coming (based on SM45)? Are you going to provide the same api of wrapper?

#6 Re: SyNode » Adding JavaScript support for mORMot framework » 2016-03-12 12:05:02

Int

@mpv Are you going to maintain SM24 as JS-engine or to switch to the newer version of SM (or may be v8 or another)? What is the future of this project? Have you already made any progress in wrapping SM 38?

#7 Re: SyNode » Adding JavaScript support for mORMot framework » 2016-03-09 12:14:26

Int

I've found a solution for Lazarus crashes with Math.pow!

SynCommons, line 44185:

{ TSynFPUException }

function TSynFPUException._AddRef: {$ifdef FPC}longint{$else}integer{$endif};
begin
  if fRefCount=0 then begin
    fSaved8087 := Get8087CW;
    Set8087CW(fExpected8087); // set FPU exceptions mask
  end;
  inc(fRefCount);
  result := 1; // should never be 0 (mark release of TSynFPUException instance)
end;  

There is this code in mormot. I've found this article http://wiki.freepascal.org/Lazarus/FPC_Libraries I didn't read it completely but there is a line

Set8087CW(Get8087CW or $3f);

So.. I tried to change code to:

SynCommons, line 44185:

{ TSynFPUException }

function TSynFPUException._AddRef: {$ifdef FPC}longint{$else}integer{$endif};
begin
  if fRefCount=0 then begin
    fSaved8087 := Get8087CW or $3f;  
    Set8087CW(fExpected8087); // set FPU exceptions mask
  end;
  inc(fRefCount);
  result := 1; // should never be 0 (mark release of TSynFPUException instance)
end;  

And it's worked out. Now in my case Evaluate returns +Inf as I expected!
It would be great if you take a look at the article, because I'm not sure if this solve the problem completely and in a correct way.
The final solution might be something like

fSaved8087 := Get8087CW{$ifdef FPC} or $3f {$endif}; 

#8 Re: SyNode » Adding JavaScript support for mORMot framework » 2016-03-09 01:17:55

Int

1) Could you please give a bit more information about setting a valid FPU? I don't think I try get value from JS.
For example this code res := fEngine.Evaluate('(Math.pow(99,999)==1)');  crashes with "External: SIGFPE" (in Lazarus) - so I suppose in my case the problem is about valid FPU.

I like the idea of compatibility with Delphi7/FPC by the way it was one of the reasons to switch to this project. And as far as I know that means no full RTTI features. But what about using TypInfo unit to access published properties in run-time?
Or may be there are some disadvantages related this way? Is there any kind of API wrapping such features?

How deep SM units integrated with Mormot? What do you think about forking into separated project? It might make development (and using) of SM wrapper easier for people who don't know mormot.

#9 Re: SyNode » Adding JavaScript support for mORMot framework » 2016-03-08 17:16:25

Int

I'm back. Sorry for disappearing. I was wrong about the example - it works fine.

I faced a problem with big numbers:

Math.pow(99, 999);

this simple JS code leads to crash application.

In any other runtime (chrome, ff, node) it works fine and returns Infinity; Is it possible to avoid crashes in such cases?

Important note: this post is really helpful http://synopse.info/forum/viewtopic.php … 072#p10072
Without these changes even this code:

a = 0xFF000000

crashes app.

Also I tried to build mozjs-24.dll (it's really not much easy), and finally I've got binaries but wrong one. Could you please tell which flags did you use to build dll? Or any difference from https://developer.mozilla.org/en-US/doc … umentation It'll be useful for ones who decide to build their own binaries.

Are these http://synopse.info/forum/viewtopic.php … 201#p10201 RTTI features available already. An opportunity to write something like

var inst = new TMyClass();
inst.write('some arg');
inst.myProp;

- seems exiting for me.

Which RTTI features are implemented already?

I feel that I need more documentation sad First of all I'd like to see a list of provided features and the nearest plans to understand what can I do with mormot and what do I need to implement by myself.

Now I'm trying to migrate my little project from delphi-javascript. But mostly I'm explore features of mormot's spider monkey bindings. So may be I'll be able to contribute somehow.

#10 Re: SyNode » Adding JavaScript support for mORMot framework » 2016-02-23 07:35:07

Int

I've read a chapter (http://synopse.info/files/html/Synopse% … ml#TITL_79) but an example from there doesn't seem to work in my case:

function TMyClass.MyFunction(const This: variant; const Args: array of variant): variant;
var global: variant;
begin
  TSMVariantData(This).GetGlobal(global);
  global.anotherFunction(Args[0],Args[1],'test');
  // same as:
  global := TSMVariantData(This).SMObject.Engine.Global;
  global.anotherFunction(Args[0],Args[1],'test');
  // but you may also write directly:
  with TSMVariantData(This).SMObject.Engine do
    Global.anotherFunction(Args[0],Args[1],'test');
  result := AnyTextFileToSynUnicode(Args[0]);
end;

Maybe that to run this code I need specific version of Delphi.

#11 Re: SyNode » Adding JavaScript support for mORMot framework » 2016-02-23 07:30:03

Int

@mvp

Is there an opportunity to pass TSMObject to a function and receive another TSMObject back.

Now I can see how to do something like this:

// pascal:

function js.test(const This: variant; const Args: array of variant): variant;
begin
    Result := Args[0] + Args[1];
end;    

...

Engine.RegisterMethod(Engine.GlobalObj, 'test', test, 2);

...

// js:

test(1, 2) // -> 3

It works fine so far. But I'd like to be able to work with objects. E.g.:

// pascal:

function js.test(const This: variant; const Args: array of variant): variant;
var
    obj, resObj: TSMObject;
    num1, num2, res: Integer;    
begin
    
    // get properties:
    obj := {some magic...} (Args[0]);
    num1 := obj.GetPropVariant('num1'); // not sure about syntax here
    num2 := obj.GetPropVariant('num2'); // not sure about syntax here

    // logic:
    res := num1 + num2;

    // set result:
    Engine.NewObject(resObj); 
    resObj.DefineProperty('result', res);
    Result := resObj;
end;    

...

Engine.RegisterMethod(Engine.GlobalObj, 'test', test, 2);

...

// js:

test({num1: 1, num2: 2}) // -> {result: 3}

And by the way is it possible to pass a callback to function? E.g.:

//js:
test(1, 2, function(res){console.log(res)})

#12 Re: SyNode » Adding JavaScript support for mORMot framework » 2015-11-18 22:48:52

Int

Hello! I'm searching for JS interpreter for Delphi or FreePascal/Lazarus. So I found that project and this forum but I still don't understand a few points:

- can I use only js-engine without whole framework?
- how strictly is it bound to version of SpiderMonkey?
- are you going to support Ecmascript 2015 (ES6)?
- do you have separate repositories for js-engine project and whole framework on GitHub (or any other alternative)?

I'd be glad for some Hello-World example of js interpretation. I've found [http://synopse.info/files/synsm.7z] this binaries, but I didn't find sources for that.

Board footer

Powered by FluxBB