Bug 156946 - [WebIDL] Make ExceptionCode the first parameter instead of the last when using [RaisesException]
Summary: [WebIDL] Make ExceptionCode the first parameter instead of the last when usin...
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Bindings (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-22 21:33 PDT by Chris Dumez
Modified: 2016-11-08 09:04 PST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2016-04-22 21:33:16 PDT
Make ExceptionCode the first parameter instead of the last when using [RaisesException].

Whenever a method is marked as [RaisesException], we currently pass an extra ExceptionCode& as last parameter to the implementation method. The issue with it being last is when we have optional parameters. This forces people to add overloads instead of using inline default parameter values in the C++.

E.g.
IDL:
[RaisesException] ScriptProcessorNode createScriptProcessor(unsigned long bufferSize, optional unsigned long numberOfInputChannels, optional unsigned long numberOfOutputChannels);
    
C++:
RefPtr<ScriptProcessorNode> createScriptProcessor(size_t bufferSize, ExceptionCode&);
RefPtr<ScriptProcessorNode> createScriptProcessor(size_t bufferSize, size_t numberOfInputChannels, ExceptionCode&);
RefPtr<ScriptProcessorNode> createScriptProcessor(size_t bufferSize, size_t numberOfInputChannels, size_t numberOfOutputChannels, ExceptionCode&);

Would become:
RefPtr<ScriptProcessorNode> createScriptProcessor(ExceptionCode&, size_t bufferSize, size_t numberOfInputChannels = 2, size_t numberOfOutputChannels = 2);
Comment 1 Chris Dumez 2016-04-22 21:33:31 PDT
Any objections?
Comment 2 Darin Adler 2016-04-23 17:00:54 PDT
A better approach would be to come up with a way for the return value to be a union of the other return value type and an ExceptionCode. We could make a class template that is a bit like Optional<> that allows a value either of type T or an ExceptionCode. This would be more elegant than an out argument, regardless of argument ordering.
Comment 3 Chris Dumez 2016-04-23 17:32:31 PDT
(In reply to comment #2)
> A better approach would be to come up with a way for the return value to be
> a union of the other return value type and an ExceptionCode. We could make a
> class template that is a bit like Optional<> that allows a value either of
> type T or an ExceptionCode. This would be more elegant than an out argument,
> regardless of argument ordering.

Ok, that sound worth exploring indeed.
Comment 4 youenn fablet 2016-04-24 05:00:06 PDT
Sounds good to me.
I am not sure whether we would like to remove RaisesException keyword, but it seems like this may help doing  meta programming.
Comment 5 Darin Adler 2016-04-24 10:00:51 PDT
(In reply to comment #4)
> I am not sure whether we would like to remove RaisesException keyword, but
> it seems like this may help doing  meta programming.

I would very much like to remove those keywords about raising exceptions if we can get the code generated in a way that’s still just as efficient. And I agree there’s a good chance we can with overloading and various meta-programming techniques.
Comment 6 Darin Adler 2016-11-08 09:04:20 PST
I did the ExceptionOr thing, so we won’t have to do this.