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

ghcjs-dom-jsffi JS exceptions can not be caught in Haskell #78

Closed
eskimor opened this issue Aug 19, 2017 · 7 comments
Closed

ghcjs-dom-jsffi JS exceptions can not be caught in Haskell #78

eskimor opened this issue Aug 19, 2017 · 7 comments

Comments

@eskimor
Copy link
Contributor

eskimor commented Aug 19, 2017

According to the ghcjfs-ffi this should be easily fixable by using a safe foreign import as opposed to an unsafe one.

Is the fix really this easy? Are there any good reasons why everything gets imported unsafe?

Note: with jsaddle and ghc JS exceptions can be handled just fine.

@hamishmack
Copy link
Member

Is the fix really this easy? Are there any good reasons why everything gets imported unsafe?

My understanding is that it results in larger (probably slower) JavaScript as it has to wrap each call with try/catch. What functions in particular do we need to handle exceptions from? If we can identify them somehow in the IDL files we can change the generator to use safe for them.

@eskimor
Copy link
Contributor Author

eskimor commented Aug 20, 2017

A function where it was already a problem for me was RTCPeerConnection.close which throws if the connection was already closed. I will checkout the IDL files, whether they say anything about exceptions.

Otherwise I will try to write some benchmark to check for performance implications.

@hamishmack
Copy link
Member

Are you sure it was close that was throwing? The IDL file does not look like it will be helpful https://github.com/WebKit/webkit/blob/master/Source/WebCore/Modules/mediastream/RTCPeerConnection.idl#L97, but interestingly the function setConfiguration in the same interface has a [MayThrowException] attribute.

@eskimor
Copy link
Contributor Author

eskimor commented Aug 20, 2017

I am afraid so, at least on Chrome. But as I just checked, it does not seem to be a standard conform behavior! According to the spec, step 2 says:

If connection's [[isClosed]] slot is true, abort these steps.

so it should not throw, but just do nothing. I will file a bug in Chromium about that!

@eskimor
Copy link
Contributor Author

eskimor commented Aug 20, 2017

Ok, I just rechecked:

uncaught exception in Haskell thread: InvalidStateError: Failed to execute 'close' on 'RTCPeerConnection': The RTCPeerConnection's signalingState is 'closed'.
rts-1a9e85f….js:7062 Error: Failed to execute 'close' on 'RTCPeerConnection': The RTCPeerConnection's signalingState is 'closed'.
    at h$$ghcjszmdomzmjsffizm0zi9zi2zi0zm8wrBcFMn4GK4ObK9AtPw9ZCGHCJSziDOMziJSFFIziGeneratedziRTCPeerConnection_je (out-9e25d10….js:333911)
    at h$runThreadSlice (rts-1a9e85f….js:8017)
    at h$runThreadSliceCatch (rts-1a9e85f….js:7968)
    at h$mainLoop (rts-1a9e85f….js:7963)
    at rts-1a9e85f….js:2460
    at runIfPresent (rts-1a9e85f….js:2478)
    at onGlobalMessage (rts-1a9e85f….js:2512)
VM717:22 

I am going to file a bug report.

@eskimor
Copy link
Contributor Author

eskimor commented Aug 23, 2017

Bug got fixed. Ok, I think the way to go forward would be to import functions marked throwing in the idl files as safe and all others as unsafe. My colleague and I will try to provide a PR soon.

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