Bug 69799

Summary: Extra arguments for JavaScript Constructors should come first
Product: WebKit Reporter: Anna Cavender <annacc>
Component: WebCore JavaScriptAssignee: Anna Cavender <annacc>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, darin, haraken, sam, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 69801    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch for landing none

Description Anna Cavender 2011-10-10 16:36:09 PDT
Especially for JavaScript Constructors that have optional arguments, having the extra parameters (ScriptExecutionContext and ExceptionCode) come at the end of the argument list is inconvenient and forces authors to make these important arguments optional when likely they are not.
Comment 1 Anna Cavender 2011-10-10 17:07:46 PDT
Created attachment 110442 [details]
Patch
Comment 2 Gyuyoung Kim 2011-10-10 17:12:33 PDT
Comment on attachment 110442 [details]
Patch

Attachment 110442 [details] did not pass efl-ews (efl):
Output: http://queues.webkit.org/results/10025131
Comment 3 Adam Barth 2011-10-10 17:13:45 PDT
Comment on attachment 110442 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=110442&action=review

> Source/WebCore/css/WebKitCSSMatrix.h:42
> -    static PassRefPtr<WebKitCSSMatrix> create(const String& s, ExceptionCode& ec)
> +    static PassRefPtr<WebKitCSSMatrix> create(ExceptionCode& ec, const String& s)

Usually the ExceptionCode is the last argument.
Comment 4 Early Warning System Bot 2011-10-10 17:14:09 PDT
Comment on attachment 110442 [details]
Patch

Attachment 110442 [details] did not pass qt-ews (qt):
Output: http://queues.webkit.org/results/10028061
Comment 5 Anna Cavender 2011-10-10 17:14:26 PDT
haraken, I'm adding you as you seem to be working in this area too.  I'm open to suggestions.
Comment 6 Darin Adler 2011-10-10 17:36:30 PDT
Who are these authors you are talking about, who have to make these arguments optional?

This change looks like a V8-only change. What about the original WebKit JavaScript engine?
Comment 7 Kentaro Hara 2011-10-10 17:39:13 PDT
(In reply to comment #5)
> haraken, I'm adding you as you seem to be working in this area too.  I'm open to suggestions.

I agree to this change. I am waiting for this patch landed!

- I am afraid that this change will break JSC build. You need to change the corresponding custom constructors in JSC too.

- I think it is OK to make changes only for WebKitCSSMatrix, EventSource and Worker in this patch, but please note that there are other custom constructors that are putting ScriptExecutionContext as the last argument. (As far as I see, all the custom constructors that are using ScriptExecutionContext are putting it as the last argument.) Please make a follow-up patch for fixing it. (If you do not want to do it, I can do it instead.)
Comment 8 Darin Adler 2011-10-10 17:41:38 PDT
I’m sorry, this does not look right to me. Why does it matter whether these arguments are first or last? The arguments are passed from generated code; the arguments should not be optional.
Comment 9 Anna Cavender 2011-10-10 17:46:44 PDT
Thanks everyone for the feedback!

As for why authors might need optional arguments, I suppose I am suggesting this for selfish reasons as I will need to do something like this:
cue = new TextTrackCue( id, startTime, endTime, text [, settings [, pauseOnExit ] ] )
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#texttrackcue

As for other JavaScript engines, yes I see now that I need to do that.  haraken, I'd love some help with that as I won't know what other classes will be broken by this patch beyond the ones that use V8.
Comment 10 Adam Barth 2011-10-10 17:54:08 PDT
> Why does it matter whether these arguments are first or last? The arguments are passed from
> generated code; the arguments should not be optional.

These context objects can be added by the code generator both for constructors and for normal function members.  For normal function members, we pass them in at the beginning.  For constructor functions, we pass them in at the end.

This patch is mostly about consistency between these two approaches.  We've been moving WebKit's IDL to be closer to WebIDL, which treats the constructor more like a normal function (e.g., you can specify the types of the arguments like you would for a normal function).
Comment 11 Kentaro Hara 2011-10-10 17:59:02 PDT
(In reply to comment #10)
> > Why does it matter whether these arguments are first or last? The arguments are passed from
> > generated code; the arguments should not be optional.
> 
> These context objects can be added by the code generator both for constructors and for normal function members.  For normal function members, we pass them in at the beginning.  For constructor functions, we pass them in at the end.
> 
> This patch is mostly about consistency between these two approaches.  We've been moving WebKit's IDL to be closer to WebIDL, which treats the constructor more like a normal function (e.g., you can specify the types of the arguments like you would for a normal function).

I agree to the idea. I think that it is possible to solve the current problem by setting [CallWithDefaultValue] or [CallWithNullValue] for |settings| and |pauseOnExit|, but moving ScriptExecutionContext to the beginning makes more sense for consistency.
Comment 12 Kentaro Hara 2011-10-10 18:08:50 PDT
(In reply to comment #9)
> As for other JavaScript engines, yes I see now that I need to do that.  haraken, I'd love some help with that as I won't know what other classes will be broken by this patch beyond the ones that use V8.

OK, please make changes for WebKitCSSMatrix, EventSource and Worker in this patch. I think that this change won't break anything, since the constructors that are putting ScriptExecutionContext at the end and are using CodeGeneratorV8.pm are only the above three. I will make a follow-up patch for making the similar changes for other custom constructors that are not using CodeGeneratorV8.pm.
Comment 13 Anna Cavender 2011-10-11 11:15:34 PDT
Created attachment 110543 [details]
Patch
Comment 14 Anna Cavender 2011-10-11 12:42:01 PDT
Created attachment 110558 [details]
Patch

including changes to test files
Comment 15 Adam Barth 2011-10-11 12:46:15 PDT
Comment on attachment 110558 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=110558&action=review

Assuming this builds, this looks great.

> Source/WebCore/ChangeLog:4
> +        IDL constructors that use ConstrcutorWith=ScriptExecutionContext.

ConstrcutorWith <-- typo
Comment 16 Anna Cavender 2011-10-12 10:42:00 PDT
Created attachment 110701 [details]
Patch for landing
Comment 17 Adam Barth 2011-10-12 12:27:29 PDT
Comment on attachment 110701 [details]
Patch for landing

Clearing flags on attachment: 110701

Committed r97287: <http://trac.webkit.org/changeset/97287>
Comment 18 Adam Barth 2011-10-12 12:27:34 PDT
All reviewed patches have been landed.  Closing bug.