Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Generation for JSFFI/JSADDLE #3

Open
epsilonhalbe opened this issue Aug 28, 2017 · 5 comments
Open

Code Generation for JSFFI/JSADDLE #3

epsilonhalbe opened this issue Aug 28, 2017 · 5 comments

Comments

@epsilonhalbe
Copy link
Contributor

Hi I am studying the code generation - in order to make function calls safe - where necessary.
This ticket is a follow up - to provide a PR for ghcjs/ghcjs-dom#78
I have had a look at the idl-files in webkitgtk-2.17.2, as well as some of hdirect-0.21.

To make the unsafe foreign function calls safe - I guess one would have to modify

domconv-webkit-jsffi.hs
701:           H.HsForeignImport nullLoc (if promise then "javascript interruptible" else "javascript") H.HsUnsafe jsimpl (H.HsIdent defop) tpsig
952:           H.HsForeignImport nullLoc (if promise then "javascript interruptible" else "javascript") H.HsUnsafe jsimpl (H.HsIdent defop) tpsig

(maybe a few more) and change the H.HsUnsafe - dependently if there are *MayThrowException annotations in the idl-files, which are used to genereate the Haskell bindings.

Status of DOMCONV

If I understood correctly there is

domconv-webkit/domconv-webkit-jsffi.hs

889:    constructorRaises | I.ExtAttr (I.Id "ConstructorRaisesException") [] `elem` at = [I.Raises ["RaisesException"]]

domconv-webkit/domconv-webkit-jsaddle.hs

879:    constructorRaises | I.ExtAttr (I.Id "ConstructorRaisesException") [] `elem` at = [I.Raises ["RaisesException"]]

and in the syntax/parser files

domconv-webkit/hdirect-0.21/OmgParser.y
556:getter_decl :: { (Id, [Param], [Raises], Maybe Context)  }
562:setter_decl :: { (Id, [Param], [Raises], Maybe Context)  }
568:deleter_decl :: { (Id, [Param], [Raises], Maybe Context)  }
616:raises_expr :: { Raises }
617:   : RAISES '(' scoped_name_list ')' { Raises (reverse $3) }
618:   | GETTER RAISES '(' scoped_name_list ')' { GetRaises (reverse $4) }
619:   | SETTER RAISES '(' scoped_name_list ')' { SetRaises (reverse $4) }
621:raises_exprs :: { [Raises] }

domconv-webkit/hdirect-0.21/IDLSyn.lhs
30: | Attribute  [Id] Bool Type [Raises] [ExtAttribute]
31: | DictionaryAttribute  [Id] Bool Type [Raises] [ExtAttribute]
32: | Operation  Id Type {-[Param]-} [Raises] (Maybe Context) [ExtAttribute]
139:data Raises = GetRaises [Name] | SetRaises [Name] | Raises [Name] deriving ( Eq, Ord, Show )
140:getterRaises = filter isGet
142:        isGet (SetRaises _) = False
144:setterRaises = filter isSet
146:        isSet (GetRaises _) = False

domconv-webkit/hdirect-0.21/OmgParser.hs
63:        | HappyAbsSyn80 (Maybe Raises)

that relate to exception parsing.

But I do not understand which parts in the idl-files they resemble - I tried to > ack "ConstructorRaisesException" in the webkit-2.17.2 directory (ack) without any results.

Status of IDL-Files

On the other hand searching for MayThrowException which can be found in for example in Websocket.idl.

    [SetterMayThrowException] attribute DOMString binaryType;

    [MayThrowException] void send(ArrayBuffer data);
    [MayThrowException] void send(ArrayBufferView data);
    [MayThrowException] void send(Blob data);
    [MayThrowException] void send(USVString data);

    [MayThrowException] void close(optional [Clamp] unsigned short code, optional DOMString reason);

There is yields no result in the domconv-webkit files.

The only idl files where I found "ConstructorRaisesException - is some ancient webkit repository of adobe adobe/webkit from 2012.

Questions

  • Could you give me some info how to modify the parsers to incude the MayThrowException?
  • What are the RaisesException statements in the existing parsers for?
@hamishmack
Copy link
Member

The things in square brackets like MayThrowException should be parsed as ExtAttribute values. Search the code for ExtAttr for examples of how to check them.

@epsilonhalbe
Copy link
Contributor Author

ah good - I'll have a go at that thx

@epsilonhalbe
Copy link
Contributor Author

Hi - I have made a few modifications and want to test them - could you tell me how I would do that?

When I call stack exec -- domconv-webkit-jsffi it tells me to call it with webgtk.idl -Iwebkit-2.17.5/Source/WebCore, but I don't have a webkit.idl - and if I call it with webkitgtk-2.17.2/Source/WebCore/Modules/websockets/WebSocket.idl -I... I get an error about a non-existing ghcjs-dom-jsffi/reexported-modules.txt

@hamishmack
Copy link
Member

Sorry, I missed this somehow.

The idea is that you run domconv-webkit-jsffi in a clone of the ghcjs-dom git repo. So it will pick up this webkit.idl file.

When using domconv-webkit-jsaddle you run it in a clone of the jsaddle-dom git repo (it also contains a webkit.idl file.

@epsilonhalbe
Copy link
Contributor Author

should I provide a pr for ghcjs-dom-jsffi, which uses the new code generator?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants