Closed Bug 1002256 Opened 10 years ago Closed 8 years ago

Implement CompositionEvent() constructor

Categories

(Core :: DOM: Events, defect)

x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla53
Tracking Status
firefox53 --- fixed

People

(Reporter: crimsteam, Assigned: ayg)

Details

(Keywords: dev-doc-complete)

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0 (Beta/Release)
Build ID: 20140314220517

Steps to reproduce:

At now document.createEvent("CompositionEvent") and CompositionEvent.initCompositionEvent() working properly, but for some reason still missing CompositionEvent() constructor. Only Chrome support it (of course with lack some properties).
Version: 31 Branch → Trunk
Strange, CompositionEvent appears to have a constructor but it doesn't work (on Firefox 38 for Linux):

> CompositionEvent
function augmentEventConstructor/global[constructorName](type, initDict)
> CompositionEvent.length
2
> new CompositionEvent("compositionStart")
TypeError: Illegal constructor.
>new CompositionEvent("compositionStart", {})
TypeError: Illegal constructor.

I don't see any way to feature detect for this behavior.  It's causing a problem for me in my InputDevice polyfill: https://github.com/RByers/InputDevice/issues/10.
Assignee: nobody → bugs
Hmm, we have .locale in CompositionEvent, but the spec doesn't. Yet the spec has .locale
as a param for initCompositionEvent. 
And looks like https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm has .locale for 
KeyboardEvent.

Ok, the specs are in totally unreadable and unimplementable state, so I'll just add support for
locale also in Constructor case.
No, the spec is in such a mess state now that I don't dare to implement anything.
Assignee: bugs → nobody
Would it make sense to fix CompositionEvent so that clients can tell there is no real constructor?  Eg. I'd expect CompositionEvent.length to be 0, not 2.  In IE 'typeof CompositionEvent == "object"' since they don't support event constructors at all.
(In reply to Olli Pettay [:smaug] from comment #3)
> Hmm, we have .locale in CompositionEvent, but the spec doesn't. Yet the spec
> has .locale
> as a param for initCompositionEvent. 
> And looks like https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm has
> .locale for 
> KeyboardEvent.

.locale has some issues:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=21830
https://lists.w3.org/Archives/Public/www-dom/2013OctDec/0051.html

So, I'm not sure if it will be standardized. Some people of Google really want it, though.
Failing test: http://w3c-test.org/dom/events/Event-subclasses-constructors.html

Chrome, Edge, and Safari 7.1 all pass the CompositionEvent tests there.  Edge has a .locale property, but seems not to support it in the constructor.  Chrome has no .locale at all.  Spec bug: https://github.com/w3c/uievents/issues/48

I don't think the .locale situation needs to block implementing the constructor -- we can just leave out .locale for now and follow the spec (which seems to be what Edge did).  If we later decide to standardize .locale, we can add it to the constructor later.

(In reply to Rick Byers from comment #5)
> Would it make sense to fix CompositionEvent so that clients can tell there
> is no real constructor?  Eg. I'd expect CompositionEvent.length to be 0, not
> 2.

I get 0 here, FWIW.  If you wanted to feature-test without that, you could try calling it and see if it throws.
Assignee: nobody → ayg
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Comment on attachment 8806358 [details] [diff] [review]
Bug 1002256 - Support CompositionEvent constructor;

https://reviewboard.mozilla.org/r/89816/#review90456

Looks reasonable.  r=me

::: dom/webidl/CompositionEvent.webidl:6
(Diff revision 1)
>  /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
>  /* This Source Code Form is subject to the terms of the Mozilla Public
>   * License, v. 2.0. If a copy of the MPL was not distributed with this file,
>   * You can obtain one at http://mozilla.org/MPL/2.0/.
>   *
>   * http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#events-CompositionEvent

Please update the spec link to:

https://w3c.github.io/uievents/#interface-compositionevent

::: dom/webidl/CompositionEvent.webidl:16
(Diff revision 1)
>  
> +[Constructor(DOMString type, optional CompositionEventInit eventInitDict)]
>  interface CompositionEvent : UIEvent
>  {
>    readonly attribute DOMString? data;
>    readonly attribute DOMString  locale;

While you are here, can you add a comment that this is a non-standard extension at the moment?
Attachment #8806358 - Flags: review?(bkelly) → review+
Attachment #8806358 - Attachment is patch: true
Attachment #8806358 - Attachment mime type: text/x-review-board-request → text/plain
Pushed by ayg@aryeh.name:
https://hg.mozilla.org/integration/mozilla-inbound/rev/6626c876b087
Support CompositionEvent constructor; r=bkelly
https://hg.mozilla.org/mozilla-central/rev/6626c876b087
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
I have created a reference page for the constructor:

https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent/CompositionEvent

I've also updated/created pages for the other parts of the API, as the MDN docs were rather old and clunky. Here:

https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent
https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent/data
https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent/locale
https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent/initCompositionEvent

Finally, I've added a not about this to the Fx53 release notes:

https://developer.mozilla.org/en-US/Firefox/Releases/53#DOM_HTML_DOM

Let me know if any of this looks wrong and needs updating. Also, Could anyone provide me with a simple code example showing how you'd actually use this? I've not filled in any examples, as I'm not familiar with this API.
Unfortunately, I can't help you, because I have no idea what this API even does.  I was just fixing some failing tests.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: